From 8d42bc7ab52a3980df2778d2ee7757e60914e6e0 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 24 九月 2025 19:42:45 +0800
Subject: [PATCH] 125 【战斗】战斗系统 战斗封包处理 支持B426拆分FightAction 支持多重嵌套
---
Main/System/Battle/BattleObject/BattleObject.cs | 521 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 414 insertions(+), 107 deletions(-)
diff --git a/Main/System/Battle/BattleObject/BattleObject.cs b/Main/System/Battle/BattleObject/BattleObject.cs
index 4d2010f..c686fea 100644
--- a/Main/System/Battle/BattleObject/BattleObject.cs
+++ b/Main/System/Battle/BattleObject/BattleObject.cs
@@ -5,11 +5,14 @@
using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
+using Spine.Unity;
+using UnityEngine.UI;
+using System.Linq;
public enum BattleCamp
{
- Friendly,
- Enemy
+ Red,
+ Blue
}
public enum BattleState
@@ -25,131 +28,435 @@
public class BattleObject
{
- public string BattleObjectId { get; protected set; }
-
- public BattleCamp Camp { get; protected set; } = BattleCamp.Friendly;
-
+ 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; }
- protected MotionBase motionBase;
+ public MotionBase motionBase;
- protected GameObject cardGO;
-
- public virtual void Init(TeamHero _teamHero)
+ public GameObject heroGo
{
- this.teamHero = _teamHero;
- motionBase = new MotionBase();
+ get;
+ private set;
}
- protected void LoadHero()
+ protected BattleDrops battleDrops;
+
+ private RectTransform m_heroRectTrans;
+
+
+ public RectTransform heroRectTrans
{
-
- }
-
-
- #region 鎴樻枟鐩稿叧鍑芥暟
-
- public virtual void AttackTarget(List<BattleObject> targets)
- {
- // 鎵剧鑷繁鏈�杩戠殑
-
- if (0 == targets.Count) return;
-
- BattleObject target = targets[0];
-
- if (1 != targets.Count)
+ get
{
- for (int i = 1; i < targets.Count; i++)
+ if (m_heroRectTrans == null)
{
- if (Vector3.Distance(cardGO.transform.position, targets[i].cardGO.transform.position) < Vector3.Distance(cardGO.transform.position, target.cardGO.transform.position))
- {
- target = targets[i];
- }
+ m_heroRectTrans = heroGo.GetComponent<RectTransform>();
}
+ return m_heroRectTrans;
}
-
- Vector3 tempPos = cardGO.transform.position;
-
- motionBase.OnAttackAnimationComplete = () => {
- // 鏀诲嚮鍔ㄧ敾缁撴潫涔嬪悗 鍥炲埌鍘熸潵鐨勪綅缃�
-
- cardGO.transform.DOMove(tempPos, 1f).OnComplete(() => {
- // motionBase.ClearEvent();// = null;
-
- // 閫氱煡鏈鏀诲嚮琛屽姩缁撴潫
- // 閫氳繃battleFieldId鏉ュ憡鐭attleFieldMgr
- });
- };
-
- cardGO.transform.DOMove(target.cardGO.transform.position, 1f).OnComplete(() => {
- // 鎾斁鏀诲嚮鍔ㄧ敾
- motionBase.OnAttackHitEvent = (int attackIndex) => {
- for (int i = 0; i < targets.Count; i++)
- {
- targets[i].UnderAttack(this);
- }
- };
-
- //鏅敾鏄痟it1
-
- motionBase.PlayAnimationEx(MotionName.atk1, false, new List<int>(){
- 5//鍋囪鏄�5甯� 鐩墠杩樻病鏈夋暟鎹�
- });
- });
}
- public virtual void CastSkill(List<BattleObject> targets)
+ protected Action onDeathAnimationComplete;
+
+ protected Renderer[] renderers;
+
+ private List<HB405_tagMCAddExp> hB405_tagMCAddExps = new List<HB405_tagMCAddExp>();
+ public BattleHeroInfoBar heroInfoBar;
+
+ public BattleObject(BattleField _battleField)
{
- // 闇�涓嶉渶瑕乵ove 鏀诲嚮鐩爣鏄皝
+ battleField = _battleField;
}
-
- public virtual float UnderAttack(BattleObject attacker)
+
+ public virtual void Init(GameObject _heroGo, TeamHero _teamHero, BattleCamp _camp)
{
- return 0;
+ heroGo = _heroGo;
+ teamHero = _teamHero;
+ Camp = _camp;
+ motionBase = new MotionBase();
+ motionBase.Init(heroGo.GetComponentInChildren<SkeletonGraphic>(true));
+ buffMgr = new BattleObjectBuffMgr();
+ buffMgr.Init(this);
+
+ layerMgr = new BattleObjectLayerMgr();
+ layerMgr.Init(this);
+
+ renderers = heroGo.GetComponentsInChildren<Renderer>(true);
+
+ heroInfoBar = heroGo.GetComponentInChildren<BattleHeroInfoBar>(true);
+ heroInfoBar.SetBattleObject(this);
+
+ // 鏍规嵁闃佃惀缈昏浆琛�鏉�
+ var heroInfoBarScale = heroInfoBar.transform.localScale;
+ heroInfoBarScale.x *= Camp == BattleCamp.Red ? 1 : -1;
+ heroInfoBar.transform.localScale = heroInfoBarScale;
+
+ heroInfoBar.SetActive(true);
+ SetFront();
}
-
- public virtual float HealTargets(List<BattleObject> targets)
- {
- return 0;
- }
-
- public virtual float BeHealed(BattleObject healer, float healAmount)
- {
- return 0;
- }
-
- public virtual bool Revive(BattleObject target)
- {
- return false;
- }
-
- public virtual bool BeRevived(BattleObject reviver, float healthPercent = 0.5f)
- {
- return false;
- }
-
- #endregion
-
- #region 杈呭姪鍑芥暟
-
- public virtual bool IsEnemy(BattleObject other)
- {
- if (other == null) return false;
-
- return Camp != other.Camp;
- }
-
- public virtual bool IsFriendly(BattleObject other)
- {
- if (other == null) return false;
-
- return Camp == other.Camp;
- }
+
public virtual void Run()
{
motionBase.Run();
+ heroInfoBar.Run();
+ buffMgr.Run();
}
-
- #endregion
+
+ public virtual void Pause()
+ {
+ motionBase.Pause();
+ }
+
+ public virtual void Resume()
+ {
+ motionBase.Resume();
+ }
+
+ public virtual void Destroy()
+ {
+
+ motionBase.Release();
+ motionBase = null;
+ teamHero = null;
+ ObjID = 0;
+
+ if (heroGo != null)
+ {
+ GameObject.DestroyImmediate(heroGo);
+ heroGo = null;
+ }
+ }
+
+ public void OnObjInfoRefresh(H0418_tagObjInfoRefresh _refreshInfo)
+ {
+ switch ((PlayerDataType)_refreshInfo.RefreshType)
+ {
+ case PlayerDataType.HP:
+ long toHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
+ heroInfoBar.UpdateHP(teamHero.curHp, toHp, teamHero.maxHp);
+ teamHero.curHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
+ break;
+ case PlayerDataType.MaxHP:
+ teamHero.maxHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
+ heroInfoBar.UpdateHP(teamHero.curHp, teamHero.curHp, teamHero.maxHp);
+ break;
+ case PlayerDataType.XP:
+ long toXp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
+ heroInfoBar.UpdateXP(teamHero.rage, toXp, 100);
+ teamHero.rage = (int)GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
+ break;
+ default:
+ Debug.LogError("BattleObject.ObjInfoRefresh 鍑虹幇鎰忓绫诲瀷 " + _refreshInfo.RefreshType.ToString());
+ break;
+ }
+ }
+
+ public void ObjPropertyRefreshView(HB418_tagSCObjPropertyRefreshView vNetData)
+ {
+ switch ((PlayerDataType)vNetData.RefreshType)
+ {
+ case PlayerDataType.HP:
+ long toHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+ heroInfoBar.UpdateHP(teamHero.curHp, toHp, teamHero.maxHp);
+ teamHero.curHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+ break;
+ case PlayerDataType.MaxHP:
+ teamHero.maxHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+ heroInfoBar.UpdateHP(teamHero.curHp, teamHero.curHp, teamHero.maxHp);
+ break;
+ case PlayerDataType.XP:
+ long toXp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+ heroInfoBar.UpdateXP(teamHero.rage, toXp, 100);
+ teamHero.rage = (int)GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+ break;
+ default:
+ Debug.LogError("BattleObject.ObjPropertyRefreshView 鍑虹幇鎰忓绫诲瀷 " + vNetData.RefreshType.ToString());
+ break;
+ }
+ }
+
+ // 鐪╂檿
+ public bool IsStunned()
+ {
+ return teamHero.isStunned;
+ }
+
+ // 鍐板喕
+ public bool IsFrozen()
+ {
+ return teamHero.isFrozen;
+ }
+
+ // 鐭冲寲
+ public bool IsStoned()
+ {
+ return teamHero.isStoned;
+ }
+
+ // 琚矇榛�
+ public bool IsSlient()
+ {
+ return teamHero.isSlient;
+ }
+
+ // 琚即姊�
+ public bool IsDisarmed()
+ {
+ return teamHero.isDisarmed;
+ }
+
+ // 鏄惁鏃犳晫
+ public bool IsInvincable()
+ {
+ return teamHero.isInvinceble;
+ }
+
+ // 鏄惁姝讳骸
+ public bool IsDead()
+ {
+ return teamHero.isDead;
+ }
+
+ // 鏄惁琚帶浣忎簡
+ public bool IsCrowdControlled()
+ {
+ return IsStunned() || IsStoned() || IsFrozen();
+ }
+
+ public virtual bool IsCanCastSkill()
+ {
+ // 琚帶浣�
+ if (IsCrowdControlled())
+ {
+ return false;
+ }
+
+ // 琚矇榛�
+ if (IsSlient())
+ {
+ return false;
+ }
+
+ // 鐪嬬湅鎬掓皵鏄惁杈惧埌閲婃斁瑕佹眰
+ return teamHero.rage >= 100;
+ }
+
+ public virtual bool IsCanNormalAttack()
+ {
+ // 琚帶浣�
+ if (IsCrowdControlled())
+ {
+ return false;
+ }
+
+ // 缂存
+ if (IsDisarmed())
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public virtual void Hurt(List<long> damageValues, long _totalDamage, HB427_tagSCUseSkill.tagSCUseSkillHurt hurt, SkillConfig skillConfig)
+ {
+ BattleDmgInfo dmgInfo = PopDamage(damageValues, _totalDamage, hurt, skillConfig);
+
+ if (dmgInfo.IsType(DamageType.Damage) || dmgInfo.IsRealdamage())
+ {
+ motionBase.PlayAnimation(MotionName.hit, false);
+ }
+ }
+
+ public void SuckHp(uint suckHP, SkillConfig skillConfig)
+ {
+
+ }
+
+ public void HurtByReflect(uint bounceHP, SkillConfig skillConfig)
+ {
+
+ }
+
+ // 闂伩寮�濮�
+ public virtual void OnDodgeBegin()
+ {
+ float pingpongTime = 0.2f;
+ RectTransform rectTrans = heroRectTrans;
+ var tween = rectTrans.DOAnchorPos(new Vector3(-30, 0, 0), pingpongTime)
+ .SetEase(Ease.OutCubic);
+
+ battleField.battleTweenMgr.OnPlayTween(tween);
+ }
+
+ // 闂伩缁撴潫
+ public virtual void OnDodgeEnd(Action _complete = null)
+ {
+ float pingpongTime = 0.2f;
+ RectTransform rectTrans = heroRectTrans;
+
+ var tween = rectTrans.DOAnchorPos(Vector3.zero, pingpongTime)
+ .SetEase(Ease.OutCubic);
+
+ tween.onComplete += () =>
+ {
+ _complete?.Invoke();
+ };
+
+ battleField.battleTweenMgr.OnPlayTween(tween);
+ }
+
+ public virtual void OnDeath(Action _onDeathAnimationComplete)
+ {
+ motionBase.PlayAnimation(MotionName.dead, false, () =>
+ {
+ teamHero.isDead = true;
+ OnDeadAnimationComplete();
+ _onDeathAnimationComplete?.Invoke();
+ });
+ }
+
+ protected virtual void OnDeadAnimationComplete()
+ {
+ // 鎴栬鐪嬬湅婧惰В鐗规晥锛� YYL TODO
+ heroGo.SetActive(false);
+
+ buffMgr.RemoveAllBuff();
+ }
+
+ public void OnReborn(HB423_tagMCTurnFightObjReborn vNetData)
+ {
+ // 澶勭悊澶嶆椿閫昏緫
+ teamHero.curHp = GeneralDefine.GetFactValue(vNetData.HP, vNetData.HPEx);
+ heroGo.SetActive(true);
+ motionBase.PlayAnimation(MotionName.idle, true);
+ }
+
+ // 浼ゅ杩樿鐪� 鏄惁闂伩 鏆村嚮 and so on 闇�瑕佹湁涓�涓狣amageType 鏈嶅姟鍣ㄥ簲璇ヤ細缁�
+ protected virtual BattleDmgInfo PopDamage(List<long> damageValues, long _totalDamage, HB427_tagSCUseSkill.tagSCUseSkillHurt hurt, SkillConfig skillConfig)
+ {
+ BattleDmgInfo battleDmgInfo = new BattleDmgInfo(battleField.guid, damageValues, this, hurt, skillConfig);
+
+ if (battleDmgInfo.IsType(DamageType.Dodge))
+ {
+ OnDodgeBegin();
+ DodgeFinishAction dodgeFinish = new DodgeFinishAction(battleField, this);
+ battleField.recordPlayer.InsertRecord(dodgeFinish);
+ }
+
+ int currentHurtHp = 0;
+ for (int i = 0; i < damageValues.Count; i++)
+ {
+ currentHurtHp += (int)damageValues[i];
+ }
+
+ heroInfoBar.UpdateHP(teamHero.curHp, Math.Max(0, teamHero.curHp - currentHurtHp), teamHero.maxHp);
+ teamHero.curHp = Math.Max(0, teamHero.curHp - currentHurtHp);
+
+ // YYL TODO 鏄惁闇�瑕佹寕鍦ㄥ湪鑷韩鐨刦ollow鐐逛笂
+ EventBroadcast.Instance.Broadcast(EventName.BATTLE_DAMAGE_TAKEN, battleDmgInfo);
+ return battleDmgInfo;
+ }
+
+ public RectTransform GetAliasTeamNode()
+ {
+ return battleField.GetTeamNode(Camp);
+ }
+
+ public RectTransform GetEnemyTeamNode()
+ {
+ return battleField.GetTeamNode(Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red);
+ }
+
+ public BattleCamp GetEnemyCamp()
+ {
+ return Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red;
+ }
+
+ public void HaveRest()
+ {
+ // YYL TODO
+ // 浼戞伅鐘舵��
+ // 澶氫竴涓獄zz鐨勪竴涓壒鏁�
+ heroGo.SetActive(true);
+ motionBase.HaveRest();
+ heroRectTrans.anchoredPosition = Vector2.zero;
+
+ heroInfoBar.SetActive(false);
+ SetFront();
+ }
+
+ public void PushDropItems(BattleDrops _battleDrops)
+ {
+ battleDrops = _battleDrops;
+ }
+
+ public void PerformDrop()
+ {
+ if (null == battleDrops || battleDrops.dropItemPackIndex.Count == 0)
+ return;
+
+ EventBroadcast.Instance.Broadcast<string, BattleDrops, Action>(
+ EventName.BATTLE_DROP_ITEMS, battleField.guid, battleDrops, OnPerformDropFinish);
+ }
+
+ protected void OnPerformDropFinish()
+ {
+ battleDrops = null;
+ }
+
+ public void SetBack()
+ {
+ layerMgr.SetBack();
+ }
+
+ public void SetFront()
+ {
+ layerMgr.SetFront();
+ }
+
+ public void SetSpeedRatio(float ratio)
+ {
+ motionBase.SetSpeedRatio(ratio);
+ }
+
+
+#if UNITY_EDITOR_STOP_USING
+ public void EditorRevive()
+ {
+ teamHero.curHp = 100;
+ heroGo.SetActive(true);
+ motionBase.PlayAnimation(MotionName.idle, true);
+ }
+
+ public List<int> TryAttack(BattleObject obj, SkillConfig skillConfig)
+ {
+ List<int> damageList = new List<int>();
+
+ int totalDamage = 100;
+
+ int damage1 = (int)((float)totalDamage * 0.3f);
+
+ int damage2 = (int)((float)totalDamage * 0.25f);
+
+ int damage3 = totalDamage - damage1 - damage2;
+
+ damageList.Add(damage1);
+ damageList.Add(damage2);
+ damageList.Add(damage3);
+
+ return damageList;
+ }
+#endif
+
}
\ No newline at end of file
--
Gitblit v1.8.0