using UnityEngine; using System.Collections; using System.Collections.Generic; namespace YLBattle { /// /// 角色(逻辑层) /// public partial class LogicFighter { #region 基础属性 /// /// 对象唯一标识符 /// private string mID = string.Empty; /// /// 模板ID /// private string mTID = string.Empty; /// /// 数据适配器 /// private IFighterAdapter mAdapter = null; /// /// 战斗环境 /// private BattleParam mEnv = null; /// /// 隶属分组 /// private EBattleTeam mTeam = EBattleTeam.NONE; /// /// 状态机 /// private LogicFighterFSM mFighterFSM = null; /// /// /// private int mSeat = 0; /// /// /// private int mRoleType = 0; /// /// 对象属性 /// private LogicFighterProperty[] mProperty = new LogicFighterProperty[(int)EBattleProperty.MAX]; /// /// 当前锁定目标 /// private string mLockedTarget = string.Empty; /// /// 释放技能时的当前回合数 /// private int mCurtRound = 0; /// /// 上次出手时间(受攻击暂停影响) /// private long mLastAttackTime = 0; #endregion #region 外部调用 /// /// 获取对象唯一标识符 /// /// 对象id public string ID() { return this.mID; } /// /// 获取模板数据ID /// /// 对象模板id public string TID() { return this.mTID; } /// /// 获取状态机 /// /// 状态机管理器对象 public LogicFighterFSM GetState() { return this.mFighterFSM; } /// /// 对象隶属分组 /// /// 详见EBattleTeam定义 public EBattleTeam Team() { return this.mTeam; } /// /// 占位 /// /// public int Seat() { return mSeat; } /// /// 角色类型 0=小怪 1=英雄 (战斗中英雄使用公共技能槽) /// /// public int RoleType() { return mRoleType; } /// /// 获取数据适配器 /// /// 适配器 public IFighterAdapter Adapter() { return this.mAdapter; } /// /// 当前锁定的目标 /// public string LockedTarget { get { return this.mLockedTarget; } set { this.mLockedTarget = value; } } /// /// 当前出手时间 /// public long LastAttackTime { get { return this.mLastAttackTime; } set { this.mLastAttackTime = value; } } #endregion #region 外部排序调用 /// /// 等级 /// /// public int Level { get { return this.mAdapter.Level(); } } /// /// 攻击速度 /// public int AttackSpeed { get { return this.mAdapter.Agile(); } } /// /// 剩余攻击时间 /// public long LeftAttackTime { get { return this.mAdapter.Agile(); } } /// /// 等阶 /// public int StrengthLevel { get { return this.mAdapter.StrengthLevel(); } } #endregion /// /// 初始化(赋值) /// /// /// /// public void SetData(string strId, BattleParam _param, IFighterAdapter _adp, EBattleTeam _eTeam, int _seat) { this.mID = strId; this.mTID = _adp.TID(); this.mAdapter = _adp; this.mTeam = _eTeam; this.mEnv = _param; this.mSeat = _seat; this.mRoleType = _adp.RoleType(); /// 从属性适配器加载角色属性 float val = 0; LogicFighterProperty property = null; ///初始化属性 for (int i = (int)EBattleProperty.NONE; i < (int)EBattleProperty.MAX; ++i) { val = (float)_adp.GetProperty((EBattleProperty)i); property = new LogicFighterProperty(val); this.mProperty[i] = property; } /// 加载技能 this.mNormalSkill = _adp.NormalSkill(); this.mManuSkill1 = _adp.ManuSkill1(); this.mManuSkill2 = _adp.ManuSkill2(); this.mPassiveSkill = _adp.PassiveSkill(); this.mLeaderSkill = _adp.LeaderSkill(); this.mLastAttackTime = 0; /// 初始化状态机 this.mFighterFSM = new LogicFighterFSM(); this.mFighterFSM.Initialize(_param, this); } /// /// /// /// public void OnUpdateSkillPower(long span) { if (this.mManuSkill1 == null) { return; } if (IsPowerFull()) { return; } this.ModifyProperty(EBattleProperty.NPOWER, span); } /// /// red=Boss/blue=Header /// /// public bool IsLeader() { return mAdapter.IsLeader(); } /// /// 是否死亡 /// /// true已死亡, false未死亡 public bool IsDead() { float hp = this.GetProperty(EBattleProperty.HP); if (hp < 0.1) { return true; } return false; } /// /// 检测能量是否已满 /// /// true已满,false未满 public bool IsPowerFull() { float power = this.GetProperty(EBattleProperty.NPOWER); float maxPower = this.GetProperty(EBattleProperty.NMAXPOWER); if (maxPower - power < 0.1) { return true; } return false; } /// /// 获取指定技能实际等级 /// /// 技能id /// 等级,失败0 public int GetSkillLevel(string tid) { return this.Adapter().SkillLevel(tid); } /// /// 检测是否为友方 /// /// 目标对象 /// 友方true,否则为敌方 public EBattleRelation Relation(LogicFighter who) { return ((int)(this.mTeam) & (int)(who.Team())) == 0 ? EBattleRelation.EBATTLE_RELATION_ENEMY : EBattleRelation.EBATTLE_RELATION_FRIEND; } #region 属性操作 /// /// 获取战斗人员指定属性 /// /// 属性索引 /// 属性值 public float GetProperty(EBattleProperty indx) { return this.mProperty[(int)indx].GetValue(); } /// /// 获取属性基础值 /// /// 属性索引 /// 基础值 public float GetPropertyBase(EBattleProperty indx) { return this.mProperty[(int)indx].GetBaseValue(); } /// /// 获取属性修正值 /// /// 属性索引 /// 修正值 public float GetPropertyCorrected(EBattleProperty indx) { return this.mProperty[(int)indx].GetCorrectedValue(); } /// /// 设置指定属性为指定值 /// /// 属性索引 /// 设置的值 /// 设置后的值 public float SetProperty(EBattleProperty indx, float val) { this.mProperty[(int)indx].SetCorrectedValue(val); return this.mProperty[(int)indx].GetValue(); } /// /// 修改指定属性 /// /// 属性索引 /// 修改值 /// 返回修改以后的值 public float ModifyProperty(EBattleProperty indx, float val) { float org = this.mProperty[(int)indx].GetValue(); this.mProperty[(int)indx].ModifyCorrectedValue(val); switch (indx) { case EBattleProperty.HP: float hpMax = this.mProperty[(int)EBattleProperty.HPMAX].GetValue(); if (this.mProperty[(int)EBattleProperty.HP].GetValue() > hpMax) { this.mProperty[(int)indx].SetCorrectedValue(0); } break; case EBattleProperty.NPOWER: float powerMax = this.mProperty[(int)EBattleProperty.NMAXPOWER].GetValue(); if (this.mProperty[(int)EBattleProperty.NPOWER].GetValue() > powerMax) { this.mProperty[(int)indx].SetCorrectedValue(powerMax); } break; } //float crt = this.mProperty[(int)indx].GetValue(); //if ((int)crt != (int)org) //{ // Debug.Log("【" + mID + "】 Pro:" + this.mTempProName[indx] + " Val:" + (val <= 0 ? "减少" : "增加") + val // + " Org:" + org + " Crt:" + crt // ); //} return this.mProperty[(int)indx].GetValue(); } /// /// 临时属性输出参照表 /// Dictionary mTempProName = new Dictionary() { {EBattleProperty.HP,"血量"} , {EBattleProperty.HPMAX,"最大血量"} , {EBattleProperty.ATTACK,"攻击力"} , {EBattleProperty.ATTACKSPEED,"敏捷"} , {EBattleProperty.CRITICALPROB,"暴击"} , {EBattleProperty.DEFENSE,"防御"} , {EBattleProperty.NPOWER,"当前能量"} , {EBattleProperty.NMAXPOWER,"最大能量"} , {EBattleProperty.POSX,"X"} , {EBattleProperty.POSY,"Y"} , }; #endregion #region(技能) /// /// 普通攻击 /// private string mNormalSkill = string.Empty; /// /// 主动技能1 /// private string mManuSkill1 = string.Empty; /// /// 主动技能2 /// private string mManuSkill2 = string.Empty; /// /// 被动技能 /// private string mPassiveSkill = string.Empty; /// /// 队长技能 /// private string mLeaderSkill = string.Empty; /// /// 主动技能1的冷冻回合数 /// private int mManuSkill1Round = 0; /// /// 必杀所需power /// private int mCriticalNeedPower = 0; /// /// 普通攻击 /// /// 技能模板id public string NormalSkill() { return this.mNormalSkill; } /// /// 主动技能1 /// /// 技能模板id public string ManuSkill1() { return this.mManuSkill1; } /// /// 主动技能2 /// /// 技能模板id public string ManuSkill2() { return this.mManuSkill2; } /// /// 被动技能 /// /// 技能模板id public string PassiveSkill() { return this.mPassiveSkill; } /// /// 被动技能 /// /// 技能模板id public string LeaderSkill() { return this.mLeaderSkill; } /// /// 暴击需要的TeamPowerRate /// /// 技能模板id public int CriticalNeedPower() { return this.mCriticalNeedPower; } #endregion } }