12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ET.Server
- {
- [FriendOf(typeof (PlayerBtlComponent))]
- public static class PlayerBtlComponentSystem
- {
- public class PlayerBtlComponentAwakeSystem: AwakeSystem<PlayerBtlComponent>
- {
- protected override void Awake(PlayerBtlComponent self)
- {
- Log.Info($"创建玩家属性组件...");
- WNPlayer player = self.GetParent<WNPlayer>();
- self.CharacterProp = player.BasicProp;
- if (self.CharacterProp == null)
- {
- Log.Warning($"PlayerBtlComponentSystem 玩家职业信息为空: playerId={player.GetId()}, 职业={player.GetPro()}");
- }
- self.CalProLvlData();
- self.CalFinalData();
- }
- }
- public class PlayerBtlComponentDestroySystem: DestroySystem<PlayerBtlComponent>
- {
- protected override void Destroy(PlayerBtlComponent self)
- {
- }
- }
- /// <summary>
- /// 计算角色的职业和等级带来的属性
- /// </summary>
- /// <param name="self"></param>
- public static void CalProLvlData(this PlayerBtlComponent self)
- {
- self.Data_Pro_Lv.Clear();
- // 角色初始属性
- Dictionary<PlayerBtlData, int> iniProp = new Dictionary<PlayerBtlData, int>();
- iniProp.TryAdd(PlayerBtlData.MaxHP, self.CharacterProp.InitMaxHP);
- iniProp.TryAdd(PlayerBtlData.Attack, self.CharacterProp.InitAttack);
- iniProp.TryAdd(PlayerBtlData.RunSpeed, self.CharacterProp.BaseMoveSpeed);
- iniProp.TryAdd(PlayerBtlData.AttackSpeed, self.CharacterProp.BaseAtkSpeed);
- AttributeHelper.AddData2AllData(iniProp, self.Data_Pro_Lv);
- }
- /// <summary>
- /// 计算所有属性
- /// </summary>
- /// <param name="self"></param>
- public static void CalFinalData(this PlayerBtlComponent self)
- {
- // 各模块带来的属性
- self.CalModuleData();
- }
- /// <summary>
- /// 各模块带来的属性
- /// </summary>
- /// <param name="self"></param>
- public static void CalModuleData(this PlayerBtlComponent self)
- {
- self.AllInflus.Clear();
- // 角色初始化属性
- AttributeHelper.AddData2AllData(self.Data_Pro_Lv, self.AllInflus);
- }
- public static int GetAllInflus(this PlayerBtlComponent self, PlayerBtlData key)
- {
- return self.AllInflus.TryGetValue(key, out int value)? value : 0;
- }
- /// <summary>
- /// 发送给场景服的人物数据(战斗属性)
- /// </summary>
- /// <returns></returns>
- public static Dictionary<string, float> GetBattleServerEffects(this PlayerBtlComponent self)
- {
- Dictionary<string, float> data = new Dictionary<string, float>();
- foreach (var keyValue in self.AllInflus.Where(keyValue => keyValue.Value > 0))
- {
- data.Add(keyValue.Key.ToString(), keyValue.Value);
- }
- // 移动速度
- float runSpeed = data.TryGetValue(PlayerBtlData.RunSpeed.ToString(), out float value) ? value : 0;
- float moveSpeed = self.CharacterProp._InitSpeed * (runSpeed / self.Tenthousand);
- data.Add("MoveSpeed", moveSpeed);
- return data;
- }
- }
- }
|