XmdsVirtual.Damage.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. using CommonAI.Data;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Formula;
  4. using CommonAI.ZoneServer.JSGModule;
  5. using CommonLang;
  6. using NPOI.SS.Formula;
  7. using System;
  8. using System.Collections.Generic;
  9. using XmdsCommon.Message;
  10. using XmdsCommon.Plugin;
  11. using XmdsCommonServer.Plugin.Scene;
  12. using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator;
  13. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  14. using XmdsCommonServer.XLS;
  15. using XmdsCommonServer.XLS.Data;
  16. namespace XmdsCommonServer.Plugin
  17. {
  18. /// <summary>
  19. /// FileName: XmdsVirtual.cs
  20. /// Author: Alex.Yu
  21. /// Corporation:...
  22. /// Description: 用于伤害数值计算.
  23. /// DateTime: 2015/5/13 14:17:23
  24. /// </summary>
  25. partial class XmdsVirtual
  26. {
  27. /// <summary>
  28. /// 攻击结果.
  29. /// </summary>
  30. public enum UnitHitEventState
  31. {
  32. Normal = 0, //普通攻击.
  33. Crit = 1, //暴击.
  34. Dodge = 2, //闪避.
  35. Parry = 3, //招架.
  36. Absorb = 4, //吸收.
  37. Immunity = 5, //免疫.
  38. IronMaiden = 6, //反伤.
  39. MP = 7, //法力.
  40. KillMonsterCrit = 8, //斩妖系统暴击
  41. }
  42. /// <summary>
  43. /// 攻击结果:暴击、闪避、普通伤害.
  44. /// </summary>
  45. public enum AttackRlt : int
  46. {
  47. NoControl = -1,
  48. NormalAttack,
  49. CritAttack,
  50. ParryAttack,
  51. }
  52. //单位vs单位计算hit计算.
  53. private int On_hit_unit_vs_unit(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, ref AtkResult result)
  54. {
  55. source.OutClientState = (int)UnitHitEventState.Normal;
  56. //是否为技能.
  57. bool isSkill = source.FromBuffState == null ? true : false;
  58. int damage = 0;
  59. //result.rlt = AttackRlt.NormalAttack;
  60. if (isSkill == false)
  61. {
  62. BuffTemplate template = source.FromBuffState.Data;
  63. //XmdsBuffProperties prop = template.Properties as XmdsBuffProperties;
  64. List<XmdsBuffVirtual> list = source.FromBuffState.Tag as List<XmdsBuffVirtual>;
  65. if (list != null)
  66. {
  67. for (int i = 0; i < list.Count; i++)
  68. {
  69. UnitBuff ub = list[i] as UnitBuff;
  70. damage += ub.BuffHit(hitter, attacker, source, ref result);
  71. }
  72. }
  73. //分发事件单位收到伤害.
  74. damage = (int)hitter.DispatchHitDamageEvent(damage, attacker, source,ref result, template.IsHarmful ? DamageType.Damage : DamageType.Heal);
  75. }
  76. else
  77. {
  78. //1.计算攻击结果.2计算攻击伤害.
  79. damage = CalDamage(attacker, hitter, source, ref result);
  80. }
  81. damage += source.Attack.Attack;
  82. //设置结果.
  83. switch (source.OutClientState)
  84. {
  85. case (int)UnitHitEventState.Dodge:
  86. //source.OutClientState = (int)UnitHitEventState.Dodge;
  87. XmdsAttackProperties prop = (source.Attack.Properties as XmdsAttackProperties);
  88. FormatLog("{0}对目标{1}使用技能【{2}】被目标【闪避】", attacker.mInfo.Name, hitter.mInfo.Name, prop.SkillTemplateID);
  89. damage = 0;
  90. break;
  91. case (int)UnitHitEventState.Crit:
  92. //source.OutClientState = (int)UnitHitEventState.Crit;
  93. FormatLog("【{0}】攻击【{1}】结果 =【{2}】,伤害 =【{3}】", attacker.mInfo.Name, hitter.mInfo.Name, "暴击", damage);
  94. break;
  95. case (int)UnitHitEventState.Normal:
  96. //source.OutClientState = (int)UnitHitEventState.Normal;
  97. FormatLog("【{0}】攻击【{1}】结果 =【{2}】,伤害 =【{3}】", attacker.mInfo.Name, hitter.mInfo.Name, "普攻", damage);
  98. break;
  99. case (int)UnitHitEventState.Immunity:
  100. //source.OutClientState = (int)UnitHitEventState.Normal;
  101. FormatLog("【{0}】攻击【{1}】结果 =【{2}】,伤害 =【{3}】", attacker.mInfo.Name, hitter.mInfo.Name, "免疫", damage);
  102. break;
  103. case (int)UnitHitEventState.Absorb:
  104. //source.OutClientState = (int)UnitHitEventState.Normal;
  105. FormatLog("【{0}】攻击【{1}】结果 =【{2}】,伤害 =【{3}】", attacker.mInfo.Name, hitter.mInfo.Name, "吸收", damage);
  106. break;
  107. case (int)UnitHitEventState.IronMaiden:
  108. //source.OutClientState = (int)UnitHitEventState.Normal;
  109. FormatLog("【{0}】攻击【{1}】结果 =【{2}】,伤害 =【{3}】", attacker.mInfo.Name, hitter.mInfo.Name, "反伤", damage);
  110. break;
  111. default:
  112. break;
  113. }
  114. if (damage == 0)
  115. {
  116. //闪避时不产生受击.
  117. //source.OutIsDamage = false;
  118. }
  119. else
  120. {
  121. hitter.mUnit.mLastDamageTime = CommonLang.CUtils.localTimeMS;
  122. attacker.mUnit.mLastHitOtherTime = CommonLang.CUtils.localTimeMS;
  123. }
  124. return damage;
  125. }
  126. /// <summary>
  127. /// 纷发单位打到其他单位,其他单位被攻击,(XmdsSkillBase调用).
  128. /// </summary>
  129. /// <param name="damage"></param>
  130. /// <param name="attacker"></param>
  131. /// <param name="hitter"></param>
  132. /// <param name="source"></param>
  133. public void DispatchHitEvents(ref int damage, XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source,
  134. ref XmdsVirtual.AtkResult result, DamageType damageType)
  135. {
  136. //分发事件单位打到别人.
  137. damage = (int)attacker.DispatchHitOtherEvent(damage, hitter, source, ref result, damageType);
  138. //分发事件单位收到伤害.
  139. damage = (int)hitter.DispatchHitDamageEvent(damage, attacker, source, ref result, damageType);
  140. //分发卡牌时间
  141. // attacker.mCardModule.OnHitOther(hitter, source, damage, damageType);
  142. // hitter.mCardModule.OnHitDamage(attacker, source, damage, damageType);
  143. }
  144. private int CalDamage(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, ref AtkResult result)
  145. {
  146. int ret = 0;
  147. //攻击者调用计算伤害.
  148. attacker.DispatchSkillDamageEvent(attacker, hitter, source);
  149. ret = attacker.DispatchCalDamageEvent(hitter, source, ref result);
  150. return ret;
  151. }
  152. /// <summary>
  153. /// 伤害计算扩展类.
  154. /// </summary>
  155. public struct AtkResult
  156. {
  157. ///// <summary>
  158. ///// 攻击结果.
  159. ///// </summary>
  160. //public AttackRlt rlt;
  161. public int ThreatValue { get; set; }
  162. /// <summary>
  163. /// 更改百分比.
  164. /// </summary>
  165. public int ThreatValueChangePer { get; set; }
  166. /// <summary>
  167. /// 更改绝对值.
  168. /// </summary>
  169. public int ThreatValueChangeModify { get; set; }
  170. //破定值
  171. public int breakShieldValue;
  172. }
  173. protected void dynamicCalcBy(XmdsUnitProp ret, float hp, float atk, float def, float crit, float CritDamage, float ignoreDef)
  174. {
  175. ret.BaseMaxHP = (int)(ret.BaseMaxHP * hp);
  176. ret.BaseAttack = (int)(ret.BaseAttack * atk);
  177. ret.BaseDefence = (int)(ret.BaseDefence * def);
  178. ret.CritRate = (int)(ret.CritRate * crit);
  179. ret.CritDamage = (int)(ret.CritDamage * CritDamage);
  180. ret.IgnoreDefensePer = (int)(ret.IgnoreDefensePer * ignoreDef);
  181. }
  182. protected void restoreMa2Ret(XmdsUnitProp ret, MonsterData ma)
  183. {
  184. if (ma.MaxHP != -1)
  185. {
  186. ret.BaseMaxHP = ma.MaxHP;
  187. }
  188. if (ma.MaxAttack != -1)
  189. {
  190. ret.BaseAttack = ma.MaxAttack;
  191. }
  192. if (ma.MaxDefence != -1)
  193. {
  194. ret.BaseDefence = ma.MaxDefence;
  195. }
  196. if (ma.CritRate != -1)
  197. {
  198. ret.CritRate = ma.CritRate;
  199. }
  200. if (ma.CritDamage != -1)
  201. {
  202. ret.CritDamage = ma.CritDamage;
  203. }
  204. if (ma.IgnoreDefencePer != -1)
  205. {
  206. ret.IgnoreDefensePer = ma.IgnoreDefencePer;
  207. }
  208. }
  209. protected void initProp(MonsterProp prop, MonsterData ma, XmdsUnitProp ret)
  210. {
  211. ret.BaseMaxHP = prop.MaxHP;
  212. ret.HP = prop.MaxHP;
  213. ret.BaseAttack = prop.Attack;
  214. ret.BaseDefence = prop.Def;
  215. ret.CritRate = prop.CritRate;
  216. ret.CritDamage = prop.CritDamage;
  217. ret.IgnoreDefensePer = prop.IgnoreDefensePer;
  218. this.mProp.ServerData.BaseInfo.UnitLv = prop.Mon_Level;
  219. this.mUnit.Level = prop.Mon_Level;
  220. }
  221. protected void initProp2(MonsterData ma, OrigData oData, UserDefineConfig udc, XmdsUnitProp ret)
  222. {
  223. UserDefineConfig config = XmdsDataMgr.GetInstance().mMonsterDynamicLoader.GetUserDefineConfig(ma.Type);
  224. float atkTemp = oData.Atk * config.Atk_Ratio;
  225. float defTemp = oData.Def * config.Def_Ratio;
  226. float hpTemp = oData.Hp * config.HP_Ratio;
  227. float critTemp = oData.CritRate * config.Crit_Ratio;
  228. float critDamageTemp = oData.CritDamage * config.CritDamage_Ratio;
  229. float ignoreDefTemp = oData.IgnoreDefensePer * config.IgnoreDef_Ratio;
  230. //防御值 * (1 — 穿透值)
  231. float drdaTemp1 = defTemp * (1 - ignoreDefTemp / XmdsDamageCalculator.PERER);
  232. //暴击值 * 爆伤值 + 1 - 暴击值
  233. float drdaTemp2 = (critTemp / XmdsDamageCalculator.PERER * critDamageTemp / XmdsDamageCalculator.PERER + 1
  234. - critTemp / XmdsDamageCalculator.PERER);
  235. //XmdsDamageCalculator.GetDefByLevel是获得该等级的防御基础值。人物的那个映射表
  236. // 43428, 43428, 45437, 47936, 50852, 54111, 57633, 61315, 65018, 68550, 71651, 73963, 75000
  237. float drda = 1 - (drdaTemp1 / (drdaTemp1 + XmdsDamageCalculator.GetDefByLevel(ma.Level)));
  238. ret.BaseMaxHP = (int)(ma.Fight_Count * ma.AliveTime * atkTemp * drda * drdaTemp2);
  239. float hpParma = ma.KillPlayerTime;// * drda * drdaTemp2;
  240. ret.BaseAttack = (int)(hpParma == 0 ? hpTemp : (hpTemp / hpParma));
  241. ret.BaseDefence = (int)defTemp;
  242. ret.CritRate = (int)(critTemp);
  243. ret.CritDamage = (int)(critDamageTemp);
  244. ret.IgnoreDefensePer = (int)(ignoreDefTemp);
  245. }
  246. }
  247. }