using System; using System.Collections.Generic; using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic; using Common.Utility.CombatEvent; using Excel2Json; using Fort23.Core; using GameLogic.Combat.Hero; using GameLogic.Player; using Utility; using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface; namespace GameLogic.Combat.CombatTool { public class CombatCalculateTool : Singleton { public Random Random = new Random(); static readonly WuXingType[] Symbiosis = new WuXingType[5] { WuXingType.Water, // 金生水 WuXingType.Fire, // 木生火 WuXingType.Gold, // 水生金 WuXingType.Earth, // 火生土 WuXingType.Wood // 土生木 }; // 相克关系表(用位表示) static readonly WuXingType[] Restrain = new WuXingType[5] { WuXingType.Wood, // 金克木 WuXingType.Earth, // 木克土 WuXingType.Fire, // 水克火 WuXingType.Gold, // 火克金 WuXingType.Water // 土克水 }; public CombatCalculateTool() { Random = new Random(System.DateTime.Now.Millisecond); } public int GetOdd() { return Random.Next(0, 100); } public int GetOdd(int min, int max) { return Random.Next(min, max); } public long GetVlaueRatioForLong(long value, float ration) { long v = (value * (long)(ration * 100)) / 10000; return v; } public float GetVlaueRatioForFloat(float value, float ration) { float v = (value * ration) / 100f; return v; } public int GetVlaueRatioForInt(int value, float ration) { int v = (value * (int)(ration * 100)) / 10000; return v; } public HarmReturnInfo Harm(CombatHeroEntity source, CombatHeroEntity target, long att, AttType attType, TriggerData triggerData, WuXingType WuXingType, HarmType harmType = HarmType.Null) { return Harm(source, target.GetMainHotPoin(), att, attType, triggerData, WuXingType, harmType); } /// /// 造成伤害 /// n /// 攻击方 /// 被攻击方 /// 伤害值 public HarmReturnInfo Harm(CombatHeroEntity source, CombatHeroHitPoint target, long att, AttType attType, TriggerData triggerData, WuXingType WuXingType, HarmType harmType = HarmType.Default) { HarmReturnInfo harmReturnInfo = CObjectPool.Instance.Fetch(); harmReturnInfo.source = source; harmReturnInfo.target = target; harmReturnInfo.att = att; harmReturnInfo.attType = attType; harmReturnInfo.WuXingType = WuXingType; harmReturnInfo.harmType = harmType; harmReturnInfo.triggerData = triggerData; if (target.combatHeroEntity.isDie) { return harmReturnInfo; } if (CombatController.currActiveCombat.IsGameOver) { return harmReturnInfo; } StartInjuredEventData startInjuredEventData = StartInjuredEventData.Create(); startInjuredEventData.HarmReturnInfo = harmReturnInfo; CombatEventManager.Instance.Dispatch(CombatEventType.StartInjured, startInjuredEventData); target.combatHeroEntity.This().HeroHurt(harmReturnInfo); return harmReturnInfo; } public HarmReturnInfo TrueHarm(CombatHeroEntity source, CombatHeroHitPoint target, long att, AttType attType, TriggerData triggerData, HarmType harmType = HarmType.Default) { HarmReturnInfo harmReturnInfo = CObjectPool.Instance.Fetch(); harmReturnInfo.source = source; harmReturnInfo.target = target; harmReturnInfo.att = att; harmReturnInfo.attType = attType; harmReturnInfo.harmType = harmType; harmReturnInfo.triggerData = triggerData; if (target.combatHeroEntity.isDie) { return harmReturnInfo; } target.combatHeroEntity.This().HeroHurt(harmReturnInfo); return harmReturnInfo; } public HarmReturnInfo Recover(CombatHeroEntity source, CombatHeroHitPoint target, long att, AttType attType, HarmType harmType, TriggerData triggerData) { HarmReturnInfo harmReturnInfo = new HarmReturnInfo(); harmReturnInfo.source = source; harmReturnInfo.target = target; harmReturnInfo.att = att; harmReturnInfo.attType = attType; harmReturnInfo.harmType = harmType; harmReturnInfo.triggerData = triggerData; if (target.combatHeroEntity.isDie) { return harmReturnInfo; } target.combatHeroEntity.This().Recover(harmReturnInfo); return harmReturnInfo; } public ILifetCycleHitPoint[] GetMinHpHero(ILifetCycleHitPoint[] allLifetCycleHitPoints, int count) { if (allLifetCycleHitPoints == null) { return null; } BetterList findHero = new BetterList(); findHero.AddRange(allLifetCycleHitPoints); int currCount = Math.Min(allLifetCycleHitPoints.Length, count); ILifetCycleHitPoint[] minHpHero = new ILifetCycleHitPoint[currCount]; for (int k = 0; k < currCount; k++) { CombatHeroEntity lifetCycleHitPoint = null; int index = 0; if (findHero.Count <= 0) { return minHpHero; } lifetCycleHitPoint = findHero[0].IfLifeCycle.This(); for (int j = 0; j < findHero.Count; j++) { CombatHeroEntity lifetCycleHitPoint2 = findHero[j].IfLifeCycle.This(); if (lifetCycleHitPoint2.HpBl < lifetCycleHitPoint.HpBl) { lifetCycleHitPoint = lifetCycleHitPoint2; index = j; } } ILifetCycleHitPoint currFindHitPoint = lifetCycleHitPoint.GetMainHotPoin(true); minHpHero[k] = currFindHitPoint; findHero.RemoveAt(index); } return minHpHero; } private int GeWuXingTypeIndex(WuXingType e) { switch (e) { case WuXingType.Gold: return 0; case WuXingType.Wood: return 1; case WuXingType.Water: return 2; case WuXingType.Fire: return 3; case WuXingType.Earth: return 4; default: return -1; // 无效元素 } } /// /// 是否相生 /// /// public bool IsSymbiosis(WuXingType a, WuXingType b) { int index = GeWuXingTypeIndex(a); if (index < 0) { return false; } return (b & Symbiosis[index]) != 0; } /// /// 是否相生 /// /// public bool IsRestrain(WuXingType a, WuXingType b) { int index = GeWuXingTypeIndex(a); if (index < 0) { return false; } return (b & Restrain[index]) != 0; } } }