123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- using System;
- using System.Collections.Generic;
- using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic;
- using Common.Utility.CombatEvent;
- using Excel2Json;
- using Fort23.Core;
- using Fort23.UTool;
- using GameLogic.Combat.Hero;
- using GameLogic.Combat.Skill;
- using GameLogic.Player;
- using UnityEngine;
- using Utility;
- using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
- using Random = System.Random;
- namespace GameLogic.Combat.CombatTool
- {
- public class CombatCalculateTool : Singleton<CombatCalculateTool>
- {
- public Random Random = new Random();
- static readonly WuXingType[] Symbiosis = new WuXingType[6]
- {
- WuXingType.Water, // 金生水
- WuXingType.Fire, // 木生火
- WuXingType.Wood, // 水生木
- WuXingType.Earth, // 火生土
- WuXingType.Gold, // 土生金
- WuXingType.Null
- };
- // 相克关系表(用位表示)
- static readonly WuXingType[] Restrain = new WuXingType[6]
- {
- WuXingType.Wood, // 金克木
- WuXingType.Earth, // 木克土
- WuXingType.Fire, // 水克火
- WuXingType.Gold, // 火克金
- WuXingType.Water, // 土克水
- WuXingType.Null
- };
- 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<CombatHeroHitPoint>(), att,
- attType, triggerData, WuXingType, harmType);
- }
- /// <summary>
- /// 造成伤害
- /// </summary>n
- /// <param name="source">攻击方</param>
- /// <param name="target">被攻击方</param>
- /// <param name="att">伤害值</param>
- 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>();
- 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;
- }
- float wuxing = source.CurrCombatHeroInfo.GetWuXingShuXing(WuXingType);
- // int index = GeWuXingTypeIndex(WuXingType);
- // WuXingType kzWuXing = Restrain[index];
- // float direnWuXing = target.combatHeroEntity.CurrCombatHeroInfo.GetWuXingShuXing(kzWuXing);
- att += GetVlaueRatioForLong(att, wuxing);
- float def =
- (target.combatHeroEntity.CurrCombatHeroInfo.defense.Value * 100.0f / source.CurrCombatHeroInfo.k);
- int p1_id = (int)def;
- p1_id = Math.Min(100, Math.Max(1, p1_id));
- MitigationParaConfig mitigationParaConfig = ConfigComponent.Instance.Get<MitigationParaConfig>(p1_id);
- float p1 = (def * mitigationParaConfig.mitigationPara) / 100f;
- att = GetVlaueRatioForLong(att, 100 - p1);
- harmReturnInfo.att = att;
- StartInjuredEventData startInjuredEventData = StartInjuredEventData.Create();
- startInjuredEventData.HarmReturnInfo = harmReturnInfo;
- CombatEventManager.Instance.Dispatch(CombatEventType.StartInjured, startInjuredEventData);
- target.combatHeroEntity.This<CombatHeroEntity>().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>();
- 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<CombatHeroEntity>().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<CombatHeroEntity>().Recover(harmReturnInfo);
- return harmReturnInfo;
- }
- public ILifetCycleHitPoint[] GetMinHpHero(ILifetCycleHitPoint[] allLifetCycleHitPoints, int count)
- {
- if (allLifetCycleHitPoints == null)
- {
- return null;
- }
- BetterList<ILifetCycleHitPoint> findHero = new BetterList<ILifetCycleHitPoint>();
- 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<CombatHeroEntity>();
- for (int j = 0; j < findHero.Count; j++)
- {
- CombatHeroEntity lifetCycleHitPoint2 =
- findHero[j].IfLifeCycle.This<CombatHeroEntity>();
- if (lifetCycleHitPoint2.HpBl < lifetCycleHitPoint.HpBl)
- {
- lifetCycleHitPoint = lifetCycleHitPoint2;
- index = j;
- }
- }
- ILifetCycleHitPoint currFindHitPoint = lifetCycleHitPoint.GetMainHotPoin<ILifetCycleHitPoint>(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 5; // 无效元素
- }
- }
- public int GetRestrained(WuXingType WuXingType,WuXingType targetWuXingType)
- {
- int c = 0;
- if (WuXingType.HasFlag(WuXingType.Gold))
- {
- if (targetWuXingType.HasFlag(WuXingType.Wood))
- {
- c++;
- }
- }
- if (WuXingType.HasFlag(WuXingType.Wood))
- {
- if (targetWuXingType.HasFlag(WuXingType.Earth))
- {
- c++;
- }
- }
- if (WuXingType.HasFlag(WuXingType.Water))
- {
- if (targetWuXingType.HasFlag(WuXingType.Fire))
- {
- c++;
- }
- }
- if (WuXingType.HasFlag(WuXingType.Fire))
- {
- if (targetWuXingType.HasFlag(WuXingType.Gold))
- {
- c++;
- }
- }
- if (WuXingType.HasFlag(WuXingType.Earth))
- {
- if (targetWuXingType.HasFlag(WuXingType.Wood))
- {
- c++;
- }
- }
- return c;
- }
- public void FaBaoPengZhuang(CombatMagicWeaponEntity a, CombatMagicWeaponEntity b)
- {
- CombatHeroEntity heroEntityA= a.MagicWeaponControl.combatHeroEntity;
- CombatHeroEntity heroEntityB = b.MagicWeaponControl.combatHeroEntity;
- int myRestrained = GetRestrained(a.WuXingType, b.WuXingType);
- int targetRestrained = GetRestrained(b.WuXingType,a.WuXingType);
- float lg_a = heroEntityA.CurrCombatHeroInfo.GetWuXingShuXing(a.WuXingType);
- float lg_b = heroEntityB.CurrCombatHeroInfo.GetWuXingShuXing(b.WuXingType);
- int c = myRestrained - targetRestrained;
- long myHp = (long)(a.HpBl);
- long targetHp = (long)(b.HpBl);
- float p2 = 100;
- if (c < 0) //a被压制
- {
- p2 = Mathf.Max(100, Mathf.Min(200, 30 + lg_b - lg_a));
- targetHp = (long)(targetHp * p2);
- }
- else if (c > 0)
- {
- p2 = Mathf.Max(100, Mathf.Min(200, 30 + lg_a - lg_b));
- myHp = (long)(myHp * p2);
- }
- if (myHp > targetHp)
- {
- myHp -= targetHp;
- a.HpBl = myHp;
- }
- else if (myHp < targetHp)
- {
- targetHp -= myHp;
- b.HpBl = targetHp;
- }
- else if (myHp == targetHp)
- {
- a.HpBl = 0;
- b.HpBl = 0;
- }
- }
- public void GongFaPengZhuang(SkillFeaturesData a, SkillFeaturesData b, CombatHeroEntity heroEntityA,
- CombatHeroEntity heroEntityB)
- {
- int myRestrained = GetRestrained(a.WuXingType, b.WuXingType);
- int targetRestrained = GetRestrained(b.WuXingType,a.WuXingType);
- float lg_a = heroEntityA.CurrCombatHeroInfo.GetWuXingShuXing(a.WuXingType);
- float lg_b = heroEntityB.CurrCombatHeroInfo.GetWuXingShuXing(b.WuXingType);
- int c = myRestrained - targetRestrained;
- long myHp = (long)(a.hp);
- long targetHp = (long)(b.hp);
- float p2 = 100;
- if (c < 0) //a被压制
- {
- p2 = Mathf.Max(100, Mathf.Min(200, 30 + lg_b - lg_a));
- targetHp = (long)(targetHp * p2);
- }
- else if (c > 0)
- {
- p2 = Mathf.Max(100, Mathf.Min(200, 30 + lg_a - lg_b));
- myHp = (long)(myHp * p2);
- }
- if (myHp > targetHp)
- {
- myHp -= targetHp;
- a.hp = myHp;
- }
- else if (myHp < targetHp)
- {
- targetHp -= myHp;
- b.hp = targetHp;
- }
- else if (myHp == targetHp)
- {
- a.hp = 0;
- b.hp = 0;
- }
- }
- /// <summary>
- /// 是否相生
- /// </summary>
- /// <returns></returns>
- public bool IsSymbiosis(WuXingType a, WuXingType b)
- {
- int index = GeWuXingTypeIndex(a);
- if (index < 0)
- {
- return false;
- }
- return (b & Symbiosis[index]) != 0;
- }
- /// <summary>
- /// 是否相生
- /// </summary>
- /// <returns></returns>
- public bool IsRestrain(WuXingType a, WuXingType b)
- {
- int index = GeWuXingTypeIndex(a);
- if (index < 0)
- {
- return false;
- }
- return (b & Restrain[index]) != 0;
- }
- }
- }
|