| | |
| | | Burned = 1 << 5 |
| | | } |
| | | |
| | | public class BattleObject |
| | | public abstract class BattleObject |
| | | { |
| | | public BattleField battleField; |
| | | |
| | | public BattleObjectBuffMgr buffMgr; |
| | | public BattleObjectLayerMgr layerMgr; |
| | | |
| | | public int ObjID { get; set; } |
| | | |
| | | public BattleCamp Camp { get; protected set; } |
| | | |
| | | public TeamHero teamHero { get; protected set; } |
| | | |
| | | // public BuffMgr buffMgr; |
| | | |
| | | public MotionBase motionBase; |
| | | |
| | | public GameObject heroGo |
| | | { |
| | | get; |
| | | private set; |
| | | } |
| | | |
| | | protected Action onDeathAnimationComplete; |
| | | |
| | | protected Renderer[] renderers; |
| | | |
| | | public Transform effectNode; |
| | | |
| | | public BattleObject(BattleField _battleField) |
| | | { |
| | | battleField = _battleField; |
| | | } |
| | | |
| | | public virtual void Init(GameObject _heroGo, TeamHero _teamHero, BattleCamp _camp) |
| | | // ============ 抽象访问方法(子类返回各自的Team类型信息) ============ |
| | | |
| | | public abstract int GetPositionNum(); |
| | | public abstract float GetModelScale(); |
| | | public abstract string GetName(); |
| | | |
| | | // Buff 管理器访问方法(Hero 有 buff,Mingge 返回 null) |
| | | public abstract BattleObjectBuffMgr GetBuffMgr(); |
| | | |
| | | // 状态查询抽象方法 |
| | | protected abstract bool GetIsStunned(); |
| | | protected abstract bool GetIsFrozen(); |
| | | protected abstract bool GetIsStoned(); |
| | | protected abstract bool GetIsSlient(); |
| | | protected abstract bool GetIsDisarmed(); |
| | | protected abstract bool GetIsInvincible(); |
| | | protected abstract bool GetIsDead(); |
| | | public abstract int GetRage(); |
| | | |
| | | // 血量相关抽象方法(Hero 特有,Mingge 返回默认值) |
| | | public abstract long GetCurHp(); |
| | | public abstract long GetMaxHp(); |
| | | public abstract void SetCurHp(long value); |
| | | public abstract void SetIsDead(bool value); |
| | | |
| | | // 其他属性访问方法 |
| | | public abstract int GetNPCID(); |
| | | public abstract long GetFightPower(); |
| | | |
| | | public abstract void Run(); |
| | | |
| | | public abstract void Pause(); |
| | | |
| | | public abstract void Resume(); |
| | | |
| | | public abstract void Destroy(); |
| | | |
| | | // ============ 动画相关抽象方法(替代 motionBase 直接调用) ============ |
| | | |
| | | /// <summary> |
| | | /// 播放动画 |
| | | /// </summary> |
| | | public abstract void PlayAnimation(MotionName motionName, bool loop); |
| | | |
| | | /// <summary> |
| | | /// 显示幻影残影 |
| | | /// </summary> |
| | | public abstract void ShowIllusionShadow(bool show, Color? color = null); |
| | | |
| | | /// <summary> |
| | | /// 播放技能动画 |
| | | /// </summary> |
| | | public abstract Spine.TrackEntry PlaySkillAnimation(SkillConfig skillConfig, SkillSkinConfig skillSkinConfig, SkillBase skillBase, bool isCounter, Action onComplete); |
| | | |
| | | /// <summary> |
| | | /// 检查是否可以开始死亡 |
| | | /// </summary> |
| | | public abstract bool CanStartDeath(); |
| | | |
| | | /// <summary> |
| | | /// 检查是否可以释放技能 |
| | | /// </summary> |
| | | public abstract bool CanCastSkillAnimation(SkillSkinConfig skillSkinConfig); |
| | | |
| | | /// <summary> |
| | | /// 获取骨骼动画组件(用于特效挂载等) |
| | | /// </summary> |
| | | public abstract SkeletonAnimation GetSkeletonAnimation(); |
| | | |
| | | /// <summary> |
| | | /// 设置骨骼动画透明度 |
| | | /// </summary> |
| | | public abstract void SetSkeletonAlpha(float alpha); |
| | | |
| | | /// <summary> |
| | | /// 获取 RectTransform(用于移动等操作) |
| | | /// </summary> |
| | | public virtual RectTransform GetRectTransform() => null; |
| | | |
| | | /// <summary> |
| | | /// 获取 GameObject |
| | | /// </summary> |
| | | public virtual GameObject GetGameObject() => null; |
| | | |
| | | /// <summary> |
| | | /// 获取 Transform(用于特效挂载等) |
| | | /// </summary> |
| | | public virtual Transform GetTransform() => null; |
| | | |
| | | /// <summary> |
| | | /// 获取世界坐标位置 |
| | | /// </summary> |
| | | public virtual Vector3 GetPosition() => Vector3.zero; |
| | | |
| | | /// <summary> |
| | | /// 获取血条信息栏 |
| | | /// </summary> |
| | | public virtual BattleHeroInfoBar GetHeroInfoBar() => null; |
| | | |
| | | /// <summary> |
| | | /// 刷新Buff显示 |
| | | /// </summary> |
| | | public virtual void RefreshBuff(List<HB428_tagSCBuffRefresh> buffList) { } |
| | | |
| | | /// <summary> |
| | | /// 更新血量显示 |
| | | /// </summary> |
| | | public virtual void UpdateHP(float percentage) { } |
| | | |
| | | /// <summary> |
| | | /// 是否正在复活中 |
| | | /// </summary> |
| | | public virtual bool IsReborning() => false; |
| | | |
| | | /// <summary> |
| | | /// 设置复活状态 |
| | | /// </summary> |
| | | public virtual void SetReborning(bool value) { } |
| | | |
| | | /// <summary> |
| | | /// 设置 GameObject 激活状态 |
| | | /// </summary> |
| | | public virtual void SetActive(bool active) { } |
| | | |
| | | /// <summary> |
| | | /// 重置位置到原点 |
| | | /// </summary> |
| | | public virtual void ResetPosition() { } |
| | | |
| | | /// <summary> |
| | | /// 设置朝向(通过缩放) |
| | | /// </summary> |
| | | public virtual void SetFacing(float direction) { } |
| | | |
| | | /// <summary> |
| | | /// 重置朝向(朝向右边) |
| | | /// </summary> |
| | | public virtual void ResetFacing() { } |
| | | |
| | | /// <summary> |
| | | /// 停止所有移动动画 |
| | | /// </summary> |
| | | public virtual void StopMoveAnimation() { } |
| | | |
| | | /// <summary> |
| | | /// 显示提示信息(简单版本) |
| | | /// </summary> |
| | | public virtual void ShowTips(string message, bool useArtText = false, bool followCharacter = true, float scaleRatio = 1f) { } |
| | | |
| | | /// <summary> |
| | | /// 显示提示信息(完整版本) |
| | | /// </summary> |
| | | public virtual void ShowTips(BattleHeroInfoBar.TipsInfo tipsInfo) { } |
| | | |
| | | /// <summary> |
| | | /// 设置死亡状态(Hero 特定) |
| | | /// </summary> |
| | | public virtual void SetDeath() { } |
| | | |
| | | /// <summary> |
| | | /// 复活后处理(Hero 特定) |
| | | /// </summary> |
| | | public virtual void AfterReborn() { } |
| | | |
| | | /// <summary> |
| | | /// 复活前准备(Hero 特定) |
| | | /// </summary> |
| | | public virtual void PreReborn(bool reviveSelf = false) { } |
| | | |
| | | /// <summary> |
| | | /// 复活动作(Hero 特定) |
| | | /// </summary> |
| | | public virtual void OnReborn(HB427_tagSCUseSkill.tagSCUseSkillHurt vNetData, bool reviveSelf = false, RecordAction parentAction = null) { } |
| | | |
| | | public virtual void OnObjInfoRefresh(H0418_tagObjInfoRefresh _refreshInfo) |
| | | { |
| | | heroGo = _heroGo; |
| | | teamHero = _teamHero; |
| | | Camp = _camp; |
| | | motionBase = new MotionBase(); |
| | | motionBase.Init(heroGo.GetComponentInChildren<SkeletonGraphic>(true)); |
| | | motionBase.onAnimationComplete += OnAnimationComplete; |
| | | buffMgr = new BattleObjectBuffMgr(); |
| | | buffMgr.Init(this); |
| | | |
| | | renderers = heroGo.GetComponentsInChildren<Renderer>(true); |
| | | } |
| | | |
| | | |
| | | |
| | | public virtual void Run() |
| | | { |
| | | motionBase.Run(); |
| | | } |
| | | |
| | | public virtual void Pause() |
| | | { |
| | | motionBase.Pause(); |
| | | } |
| | | |
| | | public virtual void Resume() |
| | | { |
| | | motionBase.Resume(); |
| | | } |
| | | |
| | | public virtual void Destroy() |
| | | { |
| | | if (heroGo != null) |
| | | { |
| | | GameObject.DestroyImmediate(heroGo); |
| | | heroGo = null; |
| | | } |
| | | |
| | | motionBase.Release(); |
| | | motionBase = null; |
| | | teamHero = null; |
| | | ObjID = 0; |
| | | motionBase.onAnimationComplete -= OnAnimationComplete; |
| | | } |
| | | |
| | | public void OnObjInfoRefresh(H0418_tagObjInfoRefresh _refreshInfo) |
| | | { |
| | | switch ((PlayerDataType)_refreshInfo.RefreshType) |
| | | { |
| | | case PlayerDataType.HP: |
| | | teamHero.curHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx); |
| | | break; |
| | | case PlayerDataType.MaxHP: |
| | | teamHero.maxHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx); |
| | | break; |
| | | case PlayerDataType.XP: |
| | | teamHero.rage = (int)GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx); |
| | | break; |
| | | default: |
| | | Debug.LogError("BattleObject.ObjInfoRefresh 出现意外类型 " + _refreshInfo.RefreshType.ToString()); |
| | | break; |
| | | } |
| | | // 子类实现 |
| | | } |
| | | |
| | | // 眩晕 |
| | | public bool IsStunned() |
| | | { |
| | | return teamHero.isStunned; |
| | | return GetIsStunned(); |
| | | } |
| | | |
| | | // 冰冻 |
| | | public bool IsFrozen() |
| | | { |
| | | return teamHero.isFrozen; |
| | | return GetIsFrozen(); |
| | | } |
| | | |
| | | // 石化 |
| | | public bool IsStoned() |
| | | { |
| | | return teamHero.isStoned; |
| | | return GetIsStoned(); |
| | | } |
| | | |
| | | // 被沉默 |
| | | public bool IsSlient() |
| | | { |
| | | return teamHero.isSlient; |
| | | return GetIsSlient(); |
| | | } |
| | | |
| | | // 被缴械 |
| | | public bool IsDisarmed() |
| | | { |
| | | return teamHero.isDisarmed; |
| | | return GetIsDisarmed(); |
| | | } |
| | | |
| | | // 是否无敌 |
| | | public bool IsInvincable() |
| | | { |
| | | return teamHero.isInvinceble; |
| | | return GetIsInvincible(); |
| | | } |
| | | |
| | | // 是否死亡 |
| | | public bool IsDead() |
| | | { |
| | | return teamHero.isDead; |
| | | return GetIsDead(); |
| | | } |
| | | |
| | | // 是否被控住了 |
| | |
| | | } |
| | | |
| | | // 看看怒气是否达到释放要求 |
| | | return teamHero.rage >= 100; |
| | | return GetRage() >= 100; |
| | | } |
| | | |
| | | public virtual bool IsCanNormalAttack() |
| | |
| | | return true; |
| | | } |
| | | |
| | | public virtual void Hurt(List<long> damageValues, int attackType) |
| | | { |
| | | PopDamage(teamHero.curHp, damageValues, attackType); |
| | | public abstract DeathRecordAction Hurt(BattleHurtParam battleHurtParam, SkillRecordAction _parentSkillAction = null); |
| | | |
| | | motionBase.PlayAnimation(MotionName.hit, false); |
| | | public abstract void OnDodgeBegin(DamageType damageType); |
| | | |
| | | // 计算伤害 |
| | | long totalDamage = 0; |
| | | foreach (var damage in damageValues) |
| | | { |
| | | totalDamage += damage; |
| | | } |
| | | public abstract void OnDodgeEnd(Action _complete = null); |
| | | |
| | | // 扣血 |
| | | teamHero.curHp -= totalDamage; |
| | | } |
| | | public abstract void OnDeath(Action _onDeathAnimationComplete, bool withoutAnime = false); |
| | | |
| | | // 闪避开始 |
| | | public virtual void OnDodgeBegin() |
| | | { |
| | | float pingpongTime = 0.2f; |
| | | RectTransform rectTrans = heroGo.GetComponent<RectTransform>(); |
| | | var tween = rectTrans.DOAnchorPos(new Vector3(-50, 50, 0), pingpongTime) |
| | | .SetEase(Ease.OutCubic); |
| | | protected abstract BattleDmgInfo PopDamage(BattleHurtParam battleHurtParam); |
| | | |
| | | battleField.battleTweenMgr.OnPlayTween(tween); |
| | | } |
| | | |
| | | // 闪避结束 |
| | | public virtual void OnDodgeEnd() |
| | | { |
| | | float pingpongTime = 0.2f; |
| | | RectTransform rectTrans = heroGo.GetComponent<RectTransform>(); |
| | | |
| | | var tween = rectTrans.DOAnchorPos(Vector3.zero, pingpongTime) |
| | | .SetEase(Ease.OutCubic); |
| | | |
| | | battleField.battleTweenMgr.OnPlayTween(tween); |
| | | } |
| | | |
| | | public virtual void OnDeath(Action _onDeathAnimationComplete) |
| | | { |
| | | onDeathAnimationComplete = _onDeathAnimationComplete; |
| | | motionBase.PlayAnimation(MotionName.dead, false); |
| | | } |
| | | |
| | | protected virtual void OnAnimationComplete(MotionName motionName) |
| | | { |
| | | if (motionName == MotionName.dead) |
| | | { |
| | | OnDeadAnimationComplete(); |
| | | onDeathAnimationComplete?.Invoke(); |
| | | onDeathAnimationComplete = null; |
| | | } |
| | | } |
| | | |
| | | protected virtual void OnDeadAnimationComplete() |
| | | { |
| | | // 或许看看溶解特效? YYL TODO |
| | | heroGo.SetActive(false); |
| | | } |
| | | |
| | | // 伤害还要看 是否闪避 暴击 and so on 需要有一个DamageType 服务器应该会给 |
| | | protected virtual void PopDamage(long curHp, List<long> damageValues, int attackType) |
| | | { |
| | | // 其实应该通知出去给UI界面解耦 让UI界面自己来显示的 YYL TODO |
| | | // 播放伤害数字 |
| | | // 这里可以实现一个伤害数字的弹出效果 |
| | | // 比如使用一个UI组件来显示伤害数字 |
| | | foreach (var damage in damageValues) |
| | | { |
| | | Debug.Log($"Damage: {damage}"); |
| | | } |
| | | |
| | | EventBroadcast.Instance.Broadcast(EventName.BATTLE_DAMAGE_TAKEN, battleField.guid, this, damageValues); |
| | | } |
| | | protected abstract BattleDmgInfo PopDamageForCaster(BattleHurtParam battleHurtParam); |
| | | |
| | | public RectTransform GetAliasTeamNode() |
| | | { |
| | |
| | | return Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red; |
| | | } |
| | | |
| | | public void HaveRest() |
| | | public abstract void HaveRest(); |
| | | |
| | | protected BattleDrops m_battleDrops; |
| | | |
| | | public virtual void PushDropItems(BattleDrops _battleDrops) |
| | | { |
| | | // YYL TODO |
| | | // 休息状态 |
| | | // 多一个zzz的一个特效 |
| | | m_battleDrops = _battleDrops; |
| | | } |
| | | |
| | | #if UNITY_EDITOR_STOP_USING |
| | | public void EditorRevive() |
| | | public virtual void PerformDrop() |
| | | { |
| | | teamHero.curHp = 100; |
| | | heroGo.SetActive(true); |
| | | motionBase.PlayAnimation(MotionName.idle, true); |
| | | if (null == m_battleDrops) |
| | | return; |
| | | |
| | | EventBroadcast.Instance.Broadcast<string, BattleDrops, Action>( |
| | | EventName.BATTLE_DROP_ITEMS, battleField.guid, m_battleDrops, OnPerformDropFinish); |
| | | } |
| | | |
| | | protected virtual void OnPerformDropFinish() |
| | | { |
| | | m_battleDrops = null; |
| | | } |
| | | |
| | | public void SetBack() |
| | | { |
| | | layerMgr.SetBack(); |
| | | } |
| | | |
| | | public void SetFront() |
| | | { |
| | | layerMgr.SetFront(); |
| | | } |
| | | |
| | | public abstract void SetSpeedRatio(float ratio); |
| | | |
| | | public abstract void OnObjPropertyRefreshView(HB418_tagSCObjPropertyRefreshView vNetData); |
| | | |
| | | |
| | | #if UNITY_EDITOR_STOP_USING |
| | | public abstract void EditorRevive(); |
| | | |
| | | public List<int> TryAttack(BattleObject obj, SkillConfig skillConfig) |
| | | { |
| | |
| | | } |
| | | #endif |
| | | |
| | | // BattleObject.cs |
| | | |
| | | public virtual void OnHurtTarget(BattleHurtParam battleHurtParam) |
| | | { |
| | | // 检查是否有吸血或反伤 |
| | | bool hasSuckHp = battleHurtParam.caster.suckHpList != null && battleHurtParam.caster.suckHpList.Count > 0; |
| | | bool hasReflectHp = battleHurtParam.caster.reflectHpList != null && battleHurtParam.caster.reflectHpList.Count > 0; |
| | | |
| | | if (!hasSuckHp && !hasReflectHp) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | // ============ 应用施法者的血量和护盾变化 ============ |
| | | bool isLastHit = battleHurtParam.hitIndex >= battleHurtParam.skillSkinConfig.DamageDivide.Length - 1; |
| | | ApplyHurtToCaster(battleHurtParam, isLastHit); |
| | | |
| | | // 和Hurt一样,调用PopDamage处理吸血/反伤的显示 |
| | | BattleDmgInfo casterDmgInfo = PopDamageForCaster(battleHurtParam); |
| | | |
| | | // 如果有反伤,施法者播放受击动画 |
| | | if (hasReflectHp && casterDmgInfo.casterDamageList != null && casterDmgInfo.casterDamageList.Count > 0) |
| | | { |
| | | long totalReflect = casterDmgInfo.casterDamageList.Sum(d => d.damage); |
| | | var buffMgr = GetBuffMgr(); |
| | | if (totalReflect > 0 && buffMgr != null && !buffMgr.isControled[BattleConst.HardControlGroup]) |
| | | { |
| | | OnPlayHitAnimation(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 应用施法者的血量和护盾变化(吸血和反伤) |
| | | /// </summary> |
| | | private void ApplyHurtToCaster(BattleHurtParam battleHurtParam, bool isLastHit) |
| | | { |
| | | BattleCastObj caster = battleHurtParam.caster; |
| | | |
| | | // 应用血量变化(由子类实现) |
| | | ApplyCasterHpChange(caster.toHp); |
| | | |
| | | // 打印所有角色的名字和当前血量跟总血量 |
| | | // foreach (var obj in battleField.battleObjMgr.allBattleObjDict.Values) |
| | | // { |
| | | // Debug.LogError($"[ApplyHurtToCaster] ObjID: {obj.ObjID}, Name: {obj.teamHero.heroConfig.Name}, CurHp: {obj.teamHero.curHp}, MaxHp: {obj.teamHero.maxHp} Skill {battleHurtParam.hB427_TagSCUseSkill.packUID} " ); |
| | | // } |
| | | |
| | | // 护盾值由buff系统自动管理,不需要手动设置 |
| | | |
| | | #if UNITY_EDITOR |
| | | // 最后一击时验证血量是否与服务器一致 |
| | | if (isLastHit) |
| | | { |
| | | BattleUtility.ValidateHpConsistencyForCaster(battleHurtParam, "施法者吸血/反伤"); |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | public bool IsTianziBoss() |
| | | { |
| | | return battleField.MapID == 30020 && battleField.FindBoss() == this; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放受击动画(只有 Hero 有实现,Mingge 留空) |
| | | /// </summary> |
| | | protected abstract void OnPlayHitAnimation(); |
| | | |
| | | /// <summary> |
| | | /// 应用施法者血量变化(吸血/反伤) |
| | | /// </summary> |
| | | protected abstract void ApplyCasterHpChange(long newHp); |
| | | } |