From 7514dbcbb81bcbf8a517d14b0e4ddcf12c27457e Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 11 八月 2025 17:26:09 +0800
Subject: [PATCH] 125 【战斗】战斗系统 战斗系统更新
---
Main/System/Battle/BattleObject/BattleObject.cs | 280 ++++++++++++++++++++++++++-----------------------------
1 files changed, 133 insertions(+), 147 deletions(-)
diff --git a/Main/System/Battle/BattleObject/BattleObject.cs b/Main/System/Battle/BattleObject/BattleObject.cs
index b4f0057..3abc1aa 100644
--- a/Main/System/Battle/BattleObject/BattleObject.cs
+++ b/Main/System/Battle/BattleObject/BattleObject.cs
@@ -30,7 +30,9 @@
{
public BattleField battleField;
- public int BattleObjectId { get; set; }
+ public BattleObjectBuffMgr buffMgr;
+
+ public int ObjID { get; set; }
public BattleCamp Camp { get; protected set; }
@@ -38,9 +40,35 @@
// public BuffMgr buffMgr;
- protected MotionBase motionBase;
+ public MotionBase motionBase;
- protected GameObject heroGo;
+ public GameObject heroGo
+ {
+ get;
+ private set;
+ }
+
+ private RectTransform m_heroRectTrans;
+
+ public RectTransform heroRectTrans
+ {
+ get
+ {
+ if (m_heroRectTrans == null)
+ {
+ m_heroRectTrans = heroGo.GetComponent<RectTransform>();
+ }
+ return m_heroRectTrans;
+ }
+ }
+
+ protected Action onDeathAnimationComplete;
+
+ protected Renderer[] renderers;
+
+ public Transform effectNode;
+
+ private List<HB405_tagMCAddExp> hB405_tagMCAddExps = new List<HB405_tagMCAddExp>();
public BattleObject(BattleField _battleField)
{
@@ -54,6 +82,11 @@
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);
}
@@ -75,16 +108,38 @@
public virtual void Destroy()
{
+
+ motionBase.onAnimationComplete -= OnAnimationComplete;
+
+ motionBase.Release();
+ motionBase = null;
+ teamHero = null;
+ ObjID = 0;
+
if (heroGo != null)
{
GameObject.DestroyImmediate(heroGo);
heroGo = null;
}
+ }
- motionBase.Release();
- motionBase = null;
- teamHero = null;
- BattleObjectId = 0;
+ 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;
+ }
}
// 鐪╂檿
@@ -104,12 +159,6 @@
{
return teamHero.isStoned;
}
-
- // // 绂侀敘
- // public bool IsConfined()
- // {
- // return false;
- // }
// 琚矇榛�
public bool IsSlient()
@@ -175,62 +224,53 @@
return true;
}
-
- public virtual void TakeDamage(List<int> damageValues)
- {
- if (IsDead())
- return;
- PopDamage(damageValues);
+ public virtual void Hurt(List<long> damageValues, long _totalDamage, uint attackType)
+ {
+ PopDamage(teamHero.curHp, damageValues, attackType);
motionBase.PlayAnimation(MotionName.hit, false);
- // 璁$畻浼ゅ
- int totalDamage = 0;
- foreach (var damage in damageValues)
- {
- totalDamage += damage;
- }
-
// 鎵h
- teamHero.curHp -= totalDamage;
-
- // 鍏跺疄杩欓噷搴旇鏄瓑鏈嶅姟鍣ㄥ彂death鐨刟ction
- // if (IsDead())
- // {
- // OnDeath();
- // }
+ teamHero.curHp -= _totalDamage;
}
// 闂伩寮�濮�
public virtual void OnDodgeBegin()
{
float pingpongTime = 0.2f;
- RectTransform rectTrans = heroGo.GetComponent<RectTransform>();
- rectTrans.DOAnchorPos(new Vector3(-50, 50, 0), pingpongTime)
+ RectTransform rectTrans = heroRectTrans;
+ var tween = rectTrans.DOAnchorPos(new Vector3(-50, 50, 0), pingpongTime)
.SetEase(Ease.OutCubic);
+
+ battleField.battleTweenMgr.OnPlayTween(tween);
}
// 闂伩缁撴潫
public virtual void OnDodgeEnd()
{
float pingpongTime = 0.2f;
- RectTransform rectTrans = heroGo.GetComponent<RectTransform>();
- rectTrans.DOAnchorPos(Vector3.zero, pingpongTime)
+ RectTransform rectTrans = heroRectTrans;
+
+ var tween = rectTrans.DOAnchorPos(Vector3.zero, pingpongTime)
.SetEase(Ease.OutCubic);
+
+ battleField.battleTweenMgr.OnPlayTween(tween);
}
- protected virtual void OnDeath()
+ public virtual void OnDeath(Action _onDeathAnimationComplete)
{
- motionBase.OnOtherAnimationComplete = OnOtherAnimationComplete;
+ onDeathAnimationComplete = _onDeathAnimationComplete;
motionBase.PlayAnimation(MotionName.dead, false);
}
- protected virtual void OnOtherAnimationComplete(MotionName motionName)
+ protected virtual void OnAnimationComplete(MotionName motionName)
{
if (motionName == MotionName.dead)
{
OnDeadAnimationComplete();
+ onDeathAnimationComplete?.Invoke();
+ onDeathAnimationComplete = null;
}
}
@@ -240,8 +280,16 @@
heroGo.SetActive(false);
}
- // 浼ゅ杩樿鐪� 鏄惁闂伩 鏆村嚮 and so on 闇�瑕佹湁涓�涓狣amageType 鏈嶅姟鍣ㄥ簲璇ヤ細缁�
- protected virtual void PopDamage(List<int> damageValues)
+ 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 void PopDamage(long curHp, List<long> damageValues, uint attackType)
{
// 鍏跺疄搴旇閫氱煡鍑哄幓缁橴I鐣岄潰瑙h�� 璁︰I鐣岄潰鑷繁鏉ユ樉绀虹殑 YYL TODO
// 鎾斁浼ゅ鏁板瓧
@@ -251,120 +299,50 @@
{
Debug.Log($"Damage: {damage}");
}
+
+ // YYL TODO 鏄惁闇�瑕佹寕鍦ㄥ湪鑷韩鐨刦ollow鐐逛笂
+ EventBroadcast.Instance.Broadcast(EventName.BATTLE_DAMAGE_TAKEN, battleField.guid, this, damageValues);
}
- public void PlaySkill(SkillConfig skillConfig, List<Dictionary<int, List<int>>> damageList, Action _onComplete)
+ public RectTransform GetAliasTeamNode()
{
- bool moveToTarget = true;
-
- if (moveToTarget)
- {
- int targetId = damageList[0].First().Key;
- BattleObject _targetObj = battleField.battleObjMgr.GetBattleObject(targetId);
-
- RectTransform selfRect = heroGo.GetComponent<RectTransform>();
- RectTransform targetRect = _targetObj.heroGo.GetComponent<RectTransform>();
- Vector2 curAnchoredPos = selfRect.anchoredPosition;
-
- MoveToTargetUI(selfRect, targetRect, new Vector2(100f, 0f), () =>
- {
- PlaySkillAnimation(skillConfig, damageList, () =>
- {
- // 鍥炲埌鍘熶綅缃�
- selfRect.DOAnchorPos(curAnchoredPos, 0.2f)
- .SetEase(Ease.Linear)
- .OnComplete(() => {
- _onComplete?.Invoke();
- });
- });
- });
- }
- else
- {
- PlaySkillAnimation(skillConfig, damageList, _onComplete);
- }
+ return battleField.GetTeamNode(Camp);
}
- protected void MoveToTargetUI(RectTransform selfRect, RectTransform targetRect, Vector2 offset, Action _onComplete)
+ public RectTransform GetEnemyTeamNode()
{
- // 1. 鐩爣鐨勬湰鍦板潗鏍囪浆涓轰笘鐣屽潗鏍�
- Vector3 targetWorldPos = targetRect.TransformPoint(targetRect.anchoredPosition + offset);
-
- // 2. 涓栫晫鍧愭爣杞负鑷繁鐖惰妭鐐逛笅鐨勬湰鍦板潗鏍�
- RectTransform parentRect = selfRect.parent as RectTransform;
- Vector2 targetAnchoredPos;
- RectTransformUtility.ScreenPointToLocalPointInRectangle(
- parentRect,
- RectTransformUtility.WorldToScreenPoint(null, targetWorldPos),
- null,
- out targetAnchoredPos);
-
- // 3. DOTween 绉诲姩
- selfRect.DOAnchorPos(targetAnchoredPos, 0.2f)
- .SetEase(Ease.Linear)
- .OnComplete(() => _onComplete?.Invoke());
+ return battleField.GetTeamNode(Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red);
}
-
- protected void PlaySkillAnimation(SkillConfig skillConfig, List<Dictionary<int, List<int>>> damageList, Action _onComplete)
+ public BattleCamp GetEnemyCamp()
{
-
- // 鍏抽敭甯у垪琛�
- List<int> keyFrameList = new List<int>() { 15 };
- motionBase.OnAttackHitEvent = (int _frame) =>
- {
- Dictionary<int, List<int>> oneRoundDamage = damageList[keyFrameList.IndexOf(_frame)];
-
- foreach (var kvp in oneRoundDamage)
- {
- int targetId = kvp.Key;
- List<int> damageValues = kvp.Value;
-
- BattleObject targetObj = battleField.battleObjMgr.GetBattleObject(targetId);
- if (targetObj != null && !targetObj.IsDead())
- {
- targetObj.TakeDamage(damageValues);
- }
- }
- };
-
- motionBase.OnAttackAnimationComplete = () =>
- {
- _onComplete?.Invoke();
-
- motionBase.OnAttackHitEvent = null;
- motionBase.OnAttackAnimationComplete = null;
-
- // 姝讳骸纭畾鍏跺疄涓嶅簲璇ュ湪杩欓噷杩涜瑙﹀彂 搴旇鐢辨湇鍔″櫒涓嬪彂 YYL TODO
-
-#if UNITY_EDITOR
- // 鏆傛椂鐨勫鐞�
- HashSet<int> hitTargets = new HashSet<int>();
-
- foreach (var dmgDict in damageList)
- {
- foreach (var kvp in dmgDict)
- {
- int targetId = kvp.Key;
- hitTargets.Add(targetId);
- }
- }
-
- foreach (int targetId in hitTargets)
- {
- BattleObject targetObj = battleField.battleObjMgr.GetBattleObject(targetId);
- if (targetObj != null && targetObj.IsDead())
- {
- targetObj.OnDeath();
- }
- }
-#endif
- };
-
- motionBase.PlayAnimationEx(MotionName.attack, false, keyFrameList);
+ return Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red;
}
-#if UNITY_EDITOR
+ public void HaveRest()
+ {
+ // YYL TODO
+ // 浼戞伅鐘舵��
+ // 澶氫竴涓獄zz鐨勪竴涓壒鏁�
+
+ motionBase.PlayAnimation(MotionName.idle, true);
+ }
+
+ public void PushExpPackList(List<HB405_tagMCAddExp> _hB405_tagMCAddExps)
+ {
+ // YYL TODO 姝讳骸鍚庡脊鍑虹粡楠屾帀钀芥彁閱�
+ hB405_tagMCAddExps = _hB405_tagMCAddExps;
+ }
+
+ public void DropExp()
+ {
+ // YYL TODO
+ // hB405_tagMCAddExps
+ }
+
+
+
+#if UNITY_EDITOR_STOP_USING
public void EditorRevive()
{
teamHero.curHp = 100;
@@ -376,9 +354,17 @@
{
List<int> damageList = new List<int>();
- int totalDamage = teamHero.attack - obj.teamHero.defense;
+ int totalDamage = 100;
- damageList.Add(totalDamage);
+ 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;
}
--
Gitblit v1.8.0