From b0b73f2c1c15caa06bcb374ec345a3cdc45f9915 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 22 八月 2025 14:53:59 +0800
Subject: [PATCH] 155 子 【武将】招募系统 - 优化显示

---
 Main/System/Battle/Skill/SkillBase.cs |  531 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 514 insertions(+), 17 deletions(-)

diff --git a/Main/System/Battle/Skill/SkillBase.cs b/Main/System/Battle/Skill/SkillBase.cs
index 6c8a691..d74d76d 100644
--- a/Main/System/Battle/Skill/SkillBase.cs
+++ b/Main/System/Battle/Skill/SkillBase.cs
@@ -1,28 +1,518 @@
 using System.Collections.Generic;
 using UnityEngine;
+using System;
+using DG.Tweening;
+using Spine;
+using System.Linq;
+using PlasticGui.WorkspaceWindow.BranchExplorer;
 
 
 public class SkillBase
 {
+	protected SkillEffect skillEffect;
+
+	protected HB427_tagSCUseSkill tagUseSkillAttack;
+
 	protected SkillConfig skillConfig;
 
 	protected bool isFinished = false;
 
-	public SkillBase(SkillConfig _skillCfg)
+	protected BattleField battleField = null; // 鎴樺満
+
+	protected RectTransform targetNode = null; // 鐩爣鑺傜偣
+
+	protected BattleObject caster = null; // 鏂芥硶鑰�
+
+	protected bool startCounting = false;
+
+	protected bool pauseState = false;
+
+	protected int curFrame = 0;
+
+	protected List<GameNetPackBasic> packList;
+
+	protected SkillRecordAction otherSkillAction;
+
+	protected List<H0704_tagRolePackRefresh> dropPackList = new List<H0704_tagRolePackRefresh>();
+
+	protected List<HB405_tagMCAddExp> expPackList = new List<HB405_tagMCAddExp>();
+
+	public SkillBase(BattleObject _caster, SkillConfig _skillCfg, HB427_tagSCUseSkill vNetData, List<GameNetPackBasic> _packList, BattleField _battleField = null)
 	{
+		caster = _caster;
 		skillConfig = _skillCfg;
+		tagUseSkillAttack = vNetData;
+		battleField = _battleField;
+		packList = _packList;
+
 	}
 
 	public virtual void Run()
 	{
-		
+		if (startCounting)
+		{
+			curFrame++;
+		}
+
+		if (otherSkillAction != null)
+		{
+			if (otherSkillAction.IsFinished())
+			{
+				otherSkillAction = null;
+				OnSkillFinished();
+			}
+			else
+			{
+				otherSkillAction.Run();
+			}
+		}
 	}
 
-	public virtual void Cast(BattleObject _caster, BattleField battleField, List<Dictionary<int, List<int>>> damageList)
+
+
+	public void Pause()
 	{
-		Debug.LogError("SkillBase Cast should be overridden by derived class");
+		pauseState = startCounting;
+		startCounting = false;
 	}
 
+	public void Resume()
+	{
+		startCounting = pauseState;
+	}
+
+
+	// 0路绉诲姩鍒拌窛绂荤洰鏍噉鐮侊紝鐨勮窛绂婚噴鏀撅紙鍙厤缃紝9999鍗冲師鍦伴噴鏀撅紝璐熸暟鍒欐槸绉诲姩鍒颁汉鐗╄儗闈紝浜虹墿瑕佽浆韬級
+	// 1路绉诲姩鍒拌窛绂婚樀瀹逛綅缃畁鐮佺殑璺濈锛堝2鍙蜂綅锛�5鍙蜂綅锛夐噴鏀撅紙鍗虫垬鍦轰腑澶绫伙級
+	public virtual void Cast()
+	{
+		Debug.LogError(GetType().Name + " Skill Cast Start");
+		//	楂樹寒鎵�鏈夋湰娆℃妧鑳界浉鍏崇殑鐩爣
+		HighLightAllTargets();
+
+		//	璺濈閰嶆垚璐熸暟瑕佽浆韬� TurnBack
+		Debug.LogError(GetType().Name + " Skill CastMode : " + skillConfig.castMode);
+		switch (skillConfig.castMode)
+		{
+			case SkillCastMode.Self:
+				CastImpl();
+				break;
+			case SkillCastMode.Enemy:
+				CastToEnemy();
+				break;
+			case SkillCastMode.Target:
+				CastToTarget();
+				break;
+			case SkillCastMode.Allies:
+				CastToAllies();
+				break;
+			// case SkillCastMode.DashCast:
+			// 	DashToTarget(() => BackToOrigin(OnSkillFinished));
+			// 	break;
+			default:
+				Debug.LogError("鏆傛椂涓嶆敮鎸佸叾浠栫殑鏂瑰紡閲婃斁 鏈夐渶姹傝鑱旂郴绛栧垝 鎶�鑳絠d:" + skillConfig.SkillID + " cast position " + skillConfig.CastPosition);
+				OnSkillFinished();
+				break;
+		}
+	}
+
+	protected void MoveToTarget(RectTransform target, Vector2 offset, float duration, Action onComplete = null)
+	{
+		caster.motionBase.PlayAnimation(MotionName.run, true);
+		var tweener = BattleUtility.MoveToTarget(caster.heroRectTrans, target, offset, duration, () =>
+		{
+			caster.motionBase.PlayAnimation(MotionName.idle, true);
+			onComplete?.Invoke();
+		});
+		battleField.battleTweenMgr.OnPlayTween(tweener);
+	}
+
+	protected void TurnBack(Action _onComplete, float forward)
+	{
+		if (skillConfig.CastDistance < 0)
+		{
+			//	杞韩
+			Vector3 scale = caster.heroGo.transform.localScale;
+			scale.x = Mathf.Abs(scale.x) * forward;
+			caster.heroGo.transform.localScale = scale;
+		}
+		_onComplete?.Invoke();
+	}
+
+	protected void CastToEnemy()
+	{
+		const float moveTime = 0.5f;
+
+		RectTransform target = battleField.GetTeamNode(caster.GetEnemyCamp(), skillConfig);
+
+		MoveToTarget(target, new Vector2(skillConfig.CastDistance, 0), moveTime, () =>
+		{
+			//	鍒颁綅缃浆韬�(涓嶄竴瀹氶潪瑕佽浆韬� 浣嗘槸娴佺▼瑕佸啓)
+			TurnBack(() =>
+			{
+				//	鍒拌揪鐩爣浣嶇疆
+				CastImpl(() =>
+				{
+					TurnBack(
+						() =>
+						{
+							//	鍥炲埌鍘熸潵鐨勪綅缃�
+							MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, moveTime, () =>
+							{
+								TurnBack(null, 1f);
+								caster.motionBase.PlayAnimation(MotionName.idle, true);
+							});
+						}
+					, -1f);
+				});
+			}, -1f);
+		});
+	}
+
+
+
+	protected void CastToTarget()
+	{
+		// 鐩爣鏄晫鏂逛富鐩爣
+		if (tagUseSkillAttack.HurtCount <= 0)
+		{
+			Debug.LogError("鎶�鑳芥敾鍑诲寘娌℃湁鐩爣 HurtCount <= 0");
+			OnSkillFinished();
+			return;
+		}
+
+		var mainHurt = tagUseSkillAttack.HurtList[0];
+
+		BattleObject mainTarget = battleField.battleObjMgr.GetBattleObject((int)mainHurt.ObjID);
+		if (mainTarget == null)
+		{
+			Debug.LogError("鐩爣涓虹┖ mainTarget == null ObjID : " + mainHurt.ObjID);
+			OnSkillFinished();
+			return;
+		}
+		// MoveToTarget(mainTarget.Camp, mainTarget, _onComplete: () => TurnBack(() => CastImpl(() => DoSkillLogic(() => { BackToOrigin(OnSkillFinished); }))));
+	}
+
+	protected void CastToAllies()
+	{
+		// MoveToTarget(caster.Camp, skillConfig, _onComplete: () => TurnBack(() => CastImpl(() => DoSkillLogic(() => { BackToOrigin(OnSkillFinished); }))));
+	}
+
+	protected TrackEntry CastImpl(Action onComplete = null)
+	{
+		// 鎾斁鏂芥硶鍔ㄤ綔
+		return caster.motionBase.PlaySkillAnimation(skillConfig, this, onComplete);//鏀诲嚮涓憞缁撴潫
+	}
+
+	//	鎶�鑳藉紑濮�
+	public virtual void OnSkillStart()
+	{
+		skillEffect = SkillEffectFactory.CreateSkillEffect(
+				caster,
+				skillConfig,
+				tagUseSkillAttack
+			);
+		if (skillEffect != null)
+		{
+			skillEffect.Play(OnHitTargets);
+		}
+	}
+
+	//	鎶�鑳藉墠鎽囧抚缁撴潫
+	public virtual void OnStartSkillFrameEnd()
+	{
+
+	}
+
+	/// <summary>
+	/// 涓憞寮�濮� times=绗嚑娆″惊鐜� 浠�0寮�濮�
+	/// </summary>
+	/// <param name="times"></param>
+	public virtual void OnMiddleFrameStart(int times)
+	{
+
+	}
+
+	public virtual void OnMiddleFrameEnd(int times, int hitIndex)
+	{
+
+	}
+
+	/// <summary>
+	/// 鍚庢憞寮�濮�
+	/// </summary>
+	public virtual void OnFinalFrameStart()
+	{
+
+	}
+
+	/// <summary>
+	/// 鍚庢憞缁撴潫
+	/// </summary>
+	public virtual void OnFinalFrameEnd()
+	{
+
+	}
+
+
+
+	// public void MoveToTarget(BattleCamp camp, BattleObject target, float duration = 0.2f, Action _onComplete = null)
+	// {
+	// 	targetNode = battleField.GetTeamNode(camp, target);
+
+	// 	Vector2 offset = new Vector2(skillConfig.CastDistance, 0);
+	// 	RectTransform selfRect = caster.heroRectTrans;
+	// 	RectTransform targetRect = targetNode;
+
+	// 	var tweener = BattleUtility.MoveToTarget(selfRect, targetRect, offset, duration, _onComplete);
+	// 	battleField.battleTweenMgr.OnPlayTween(tweener);
+	// }
+
+	// public void MoveToTarget(BattleCamp camp, SkillConfig skillCfg, float duration = 0.2f, Action _onComplete = null)
+	// {
+	// 	targetNode = battleField.GetTeamNode(camp, skillCfg);
+
+	// 	Vector2 offset = new Vector2(skillConfig.CastDistance, 0);
+	// 	RectTransform selfRect = caster.heroRectTrans;
+	// 	RectTransform targetRect = targetNode;
+
+	// 	var tweener = BattleUtility.MoveToTarget(selfRect, targetRect, offset, duration, _onComplete);
+	// 	battleField.battleTweenMgr.OnPlayTween(tweener);
+	// }
+
+	// public void TurnBack(Action _onComplete)
+	// {
+	// 	if (skillConfig.CastDistance < 0)
+	// 	{
+	// 		//	杞韩
+	// 		caster.heroGo.transform.localScale = new Vector3(-1, 1, 1);
+	// 	}
+	// 	_onComplete?.Invoke();
+	// }
+
+	// public void BackToOrigin(Action _onComplete = null)
+	// {
+	// 	RectTransform selfRect = caster.heroRectTrans;
+	// 	Vector2 targetAnchoredPos = Vector2.zero;
+	// 	var tween = selfRect.DOAnchorPos(targetAnchoredPos, 0.2f)
+	// 		.SetEase(Ease.Linear);
+
+	// 	tween.onComplete += () =>
+	// 	{
+	// 		//	杞垚姝g‘鏂瑰悜
+	// 		caster.heroGo.transform.localScale = Vector3.one;
+	// 		_onComplete?.Invoke();
+	// 	};
+
+	// 	battleField.battleTweenMgr.OnPlayTween(tween);
+	// }
+
+	protected void HighLightAllTargets()
+	{
+		// 楂樹寒鎵�鏈夌洰鏍�
+		HashSet<BattleObject> highlightList = new HashSet<BattleObject>(battleField.battleObjMgr.GetBattleObjList(tagUseSkillAttack));
+		highlightList.Add(caster);
+
+
+		//	鎶婅繖浜汢O鍏ㄩ珮浜� 鎴栬�呰鎶婇櫎浜嗚繖浜涚殑閮芥斁鍦ㄩ伄缃╁悗闈�
+		//	YYL TODO
+	}
+
+	//	鍛戒腑鐩爣鍚庣殑鍥炶皟 姝e父鏄互鍚勬妧鑳界殑鏂瑰紡鏉ュ鐞嗙殑
+	protected virtual void OnHitTargets(int _hitIndex, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> hitList)
+	{
+		for (int i = 0; i < hitList.Count; i++)
+		{
+			HB427_tagSCUseSkill.tagSCUseSkillHurt hurt = hitList[i];
+
+			BattleObject target = caster.battleField.battleObjMgr.GetBattleObject((int)hurt.ObjID);
+			if (target == null)
+			{
+				Debug.LogError("鐩爣涓虹┖ target == null ObjId : " + hurt.ObjID);
+				continue;
+			}
+
+			// 浼ゅ鍒嗗竷 (涓囧垎姣�)
+			int[] damageDivide = skillConfig.DamageDivide[_hitIndex];
+
+			long totalDamage = GeneralDefine.GetFactValue(hurt.HurtHP, hurt.HurtHPEx);
+
+			// 淇濊瘉鎵�鏈夊垎閰嶉」鍔犺捣鏉ョ瓑浜巘otalDamage锛岄伩鍏嶅洜鏁撮櫎瀵艰嚧鐨勮宸�
+			List<long> damageList = BattleUtility.DivideDamageToList(damageDivide, totalDamage);
+
+			OnHitEachTarget(target, totalDamage, damageList, ref hurt);
+		}
+
+		HandleDead();
+	}
+
+	protected void HandleDead()
+	{
+		var deadPackList = BattleUtility.FindDeadPack(packList);
+		CheckAfterDeadhPack();
+
+		// 澶勭悊鎺夎惤鍖� 鎻愬墠distribute涔嬪悗 PackManager鎵嶆湁鎺夎惤鐗� 鎵�浠ヤ笉璺焌ssignexp涓�鏍穌istribute
+		foreach (var _dropPack in dropPackList)
+		{
+			PackageRegedit.Distribute(_dropPack);
+			packList.Remove(_dropPack);
+		}
+
+		// 鑾峰彇鎺夎惤鐗╁搧
+		var dropPack = PackManager.Instance.GetSinglePack(PackType.DropItem);
+		var itemDict = dropPack.GetAllItems();
+		List<ItemModel> itemList = new List<ItemModel>(
+			from item in itemDict.Values
+			where item != null && item.isAuction
+			select item);
+
+		int deadCount = deadPackList.Count;
+
+		// 鍒嗛厤鎺夎惤鍜岀粡楠�
+		var dropAssign = AssignDrops(itemList, deadCount);
+		var expAssign = AssignExp(expPackList, deadCount);
+
+		// 鏋勯�� BattleDrops 骞跺垎閰�
+		for (int i = 0; i < deadCount; i++)
+		{
+			BattleObject deadTarget = battleField.battleObjMgr.GetBattleObject((int)deadPackList[i].ObjID);
+			List<ItemModel> itemModelDrops = dropAssign[i];
+			List<int> itemModelDropsIndexList = new List<int>(
+				from item in itemModelDrops  select item.gridIndex);
+			BattleDrops battleDrops = new BattleDrops()
+			{
+				rectTransform = deadTarget.heroRectTrans,
+				dropItemPackIndex = itemModelDropsIndexList,
+				expDrops = expAssign[i]
+			};
+			deadTarget.PushDropItems(battleDrops);
+		}
+
+		// 鍒嗗彂姝讳骸鍖�
+		battleField.OnObjsDead(deadPackList);
+		foreach (var deadPack in deadPackList)
+		{
+			packList.Remove(deadPack);
+		}
+		deadPackList.Clear();
+	}
+
+
+
+	// 鍒嗛厤鎺夎惤
+	protected List<List<ItemModel>> AssignDrops(List<ItemModel> itemList, int deadCount)
+	{
+		var dropAssign = new List<List<ItemModel>>(deadCount);
+		for (int i = 0; i < deadCount; i++)
+			dropAssign.Add(new List<ItemModel>());
+		for (int i = 0; i < itemList.Count; i++)
+			dropAssign[i % deadCount].Add(itemList[i]);
+		return dropAssign;
+	}
+
+	// 鍒嗛厤缁忛獙锛氭瘡涓師濮嬪寘閮藉钩鍧囧垎閰嶅埌姣忎釜姝讳骸瀵硅薄
+	protected List<List<HB405_tagMCAddExp>> AssignExp(List<HB405_tagMCAddExp> expList, int deadCount)
+	{
+		var expAssign = new List<List<HB405_tagMCAddExp>>(deadCount);
+		for (int i = 0; i < deadCount; i++)
+			expAssign.Add(new List<HB405_tagMCAddExp>());
+
+		foreach (var expPack in expList)
+		{
+			long totalExp = GeneralDefine.GetFactValue(expPack.Exp, expPack.ExpPoint);
+			long avgExp = totalExp / deadCount;
+			long remain = totalExp % deadCount;
+
+			for (int i = 0; i < deadCount; i++)
+			{
+				long assignExp = avgExp + (i < remain ? 1 : 0);
+				long expPoint = assignExp / 100000000;
+				long exp = assignExp % 100000000;
+				var newPack = new HB405_tagMCAddExp
+				{
+					Exp = (uint)exp,
+					ExpPoint = (uint)expPoint,
+					Source = expPack.Source // 淇濇寔鍘熷寘鏉ユ簮
+				};
+				expAssign[i].Add(newPack);
+			}
+			packList.Remove(expPack);
+		}
+		return expAssign;
+	}
+
+
+
+	protected virtual void OnHitEachTarget(BattleObject target, long totalDamage, List<long> damageList, ref HB427_tagSCUseSkill.tagSCUseSkillHurt hurt)
+	{
+		target.Hurt(damageList, totalDamage, hurt.AttackTypes);
+
+		//	鍑讳腑鐩爣鐨勬椂鍊�,涓嶇杩戞垬杩滅▼ 閮界‘璁や竴涓嬫槸鍚︽湁鐖嗙偢鐗规晥 鐒跺悗鎾斁
+		if (skillConfig.ExplosionEffectId > 0)
+		{
+			// 鎾斁鐖嗙偢鐗规晥
+			target.battleField.battleEffectMgr.PlayEffect(
+				target.ObjID,
+				skillConfig.ExplosionEffectId,
+				target.heroGo.transform
+			);
+		}
+	}
+
+	protected void CheckAfterDeadhPack()
+	{
+		List<int> removeIndexList = new List<int>();
+		for (int i = 0; i < packList.Count; i++)
+		{
+			var pack = packList[i];
+
+			// 	澶嶆椿鍩烘湰閮介潬鎶�鑳藉寘
+			if (pack is CustomHB426CombinePack)
+			{
+				var combinePack = pack as CustomHB426CombinePack;
+				if (combinePack.startTag.Tag.StartsWith("Skill_"))
+				{
+					break; // 鎵惧埌鎶�鑳藉寘灏变笉闇�瑕佸啀澶勭悊浜�
+				}
+			}
+			else if (pack is H0704_tagRolePackRefresh)
+			{
+				var h0704Pack = pack as H0704_tagRolePackRefresh;
+				if (h0704Pack.PackType == (byte)PackType.DropItem)
+				{
+					//	鎺夎惤鐨�
+					if (h0704Pack.IsBind == 1)
+					{
+						//	鎺夎惤鐨勭墿鍝�
+						dropPackList.Add(h0704Pack);
+						removeIndexList.Add(i);
+					}
+					else if (h0704Pack.IsBind == 0)
+					{
+						//	鏇挎崲鐨�
+					}
+				}
+			}
+			else if (pack is HB405_tagMCAddExp)
+			{
+				var h405Pack = pack as HB405_tagMCAddExp;
+
+				//B4 05 鑾峰緱缁忛獙 #tagMCAddExp 閫氱煡鑾峰緱鐨勭粡楠岋紝
+				//鍙敤浜庡仛缁忛獙鑾峰緱琛ㄧ幇 Source = 2 鏃朵负涓荤嚎鍑绘潃鎬墿鑾峰緱缁忛獙
+				if (h405Pack.Source == 2)
+				{
+					expPackList.Add(h405Pack);
+					removeIndexList.Add(i);
+				}
+			}
+
+		}
+
+		for (int i = removeIndexList.Count - 1; i >= 0; i--)
+		{
+			packList.RemoveAt(removeIndexList[i]);
+		}
+	}
 	public virtual bool IsFinished()
 	{
 		return isFinished;
@@ -33,20 +523,27 @@
 		isFinished = true;
 	}
 
-#if UNITY_EDITOR
-	public virtual List<BattleObject> GetTargetList(BattleObject _caster, BattleField battleField)
+	public void OnSkillFinished()
 	{
-		SkillTargetType targetType = SkillTargetType.Enemy;
-		SkillTargetRangeType rangeType = SkillTargetRangeType.LowestHP;
+		Debug.LogError(GetType().Name + " Skill Finished");
+		if (packList.Count > 0)
+		{
+			var pack = packList[0];
+			packList.RemoveAt(0);
 
-		List<BattleObject> affectList = battleField.battleObjMgr.GetTargetList(_caster, targetType, rangeType);
-		return affectList;
+			if (pack is CustomHB426CombinePack)
+			{
+				var combinePack = pack as CustomHB426CombinePack;
+				if (combinePack.startTag.Tag.StartsWith("Skill_"))
+				{
+					otherSkillAction = combinePack.CreateSkillAction();
+					return;
+				}
+			}
+
+			PackageRegedit.Distribute(pack);
+		}
+
+		isFinished = true;
 	}
-	
-	public virtual List<Dictionary<int, List<int>>> GetDamageList(BattleObject _caster, BattleField battleField)
-	{
-		Debug.LogError("SkillBase GetDamageList should be overridden by derived class");
-		return null;
-	}
-#endif
 }
\ No newline at end of file

--
Gitblit v1.8.0