FighterBuffFunctionMgr.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. delegate DurationFunctionEvent DurationFunctionEventCreator(BuffFunctionData data);
  5. delegate TickFunctionEvent TickFunctionEventCreator(BuffFunctionData data);
  6. public class FighterBuffFunctionMgr
  7. {
  8. Dictionary<Buff_Function_Type, DurationFunctionEventCreator> creators;
  9. Dictionary<Buff_Function_Type, TickFunctionEventCreator> tickCreators;
  10. Fighter mFighter;
  11. List<DurationFunctionEvent> mFunEventList;
  12. List<TickFunctionEvent> mInstanceEventList = null;
  13. SInt mCurrentShieldValue = 0;
  14. int mShieldEffectInstanceID = 0;
  15. int mShieldEndEffectId = 0;
  16. //float mShieldDurationTime = 0; //护盾时长
  17. private int mShieldFrame = 0;
  18. bool mIsShield = false; //是否处于护盾状态
  19. public List<TickFunctionEvent> TickEventList
  20. {
  21. get { return mInstanceEventList; }
  22. }
  23. public FighterBuffFunctionMgr(Fighter fighter)
  24. {
  25. mFighter = fighter;
  26. mFunEventList = new List<DurationFunctionEvent>();
  27. mInstanceEventList = new List<TickFunctionEvent>();
  28. RegisterCreators();
  29. }
  30. void RegisterCreators()
  31. {
  32. creators = new Dictionary<Buff_Function_Type, DurationFunctionEventCreator>();
  33. creators.Add(Buff_Function_Type.Body_Size_Change_Value, ChangeModelSizeFunEvent.Creator);
  34. creators.Add(Buff_Function_Type.Confusion, ConfusionFunEvent.Creator);
  35. creators.Add(Buff_Function_Type.Curse, CurseFunEvent.Creator);
  36. creators.Add(Buff_Function_Type.Fear, FearFunEvent.Creator);
  37. creators.Add(Buff_Function_Type.Forbid_NormalSkill, ForbidNormalSkillFunEvent.Creator);
  38. creators.Add(Buff_Function_Type.Forget, ForgetFunEvent.Creator);
  39. creators.Add(Buff_Function_Type.Frozen, FrozenFunEvent.Creator);
  40. creators.Add(Buff_Function_Type.Immunity, ImmunityFunEvent.Creator);
  41. creators.Add(Buff_Function_Type.Invincible, InvincibleFunEvent.Creator);
  42. creators.Add(Buff_Function_Type.Poison, PoisonFunEvent.Creator);
  43. creators.Add(Buff_Function_Type.Silence, SilenceFunEvent.Creator);
  44. creators.Add(Buff_Function_Type.Sleep, SleepFunEvent.Creator);
  45. creators.Add(Buff_Function_Type.Sneer, SneerFunEvent.Creator);
  46. creators.Add(Buff_Function_Type.Stiff, StiffFunEvent.Creator);
  47. creators.Add(Buff_Function_Type.Vertigo, VertigoFunEvent.Creator);
  48. creators.Add(Buff_Function_Type.STR_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  49. creators.Add(Buff_Function_Type.INT_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  50. creators.Add(Buff_Function_Type.AGI_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  51. creators.Add(Buff_Function_Type.Change_MaxHP_Percent, ChangeMaxHpPercent.Creator);
  52. creators.Add(Buff_Function_Type.SP_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  53. creators.Add(Buff_Function_Type.LUK_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  54. creators.Add(Buff_Function_Type.Ten_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  55. creators.Add(Buff_Function_Type.Crit_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  56. creators.Add(Buff_Function_Type.AttackCD_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  57. creators.Add(Buff_Function_Type.Phyx_Defense_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  58. creators.Add(Buff_Function_Type.Magic_Defense_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  59. creators.Add(Buff_Function_Type.Damage_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  60. creators.Add(Buff_Function_Type.ChangeSkill, ChangeSkillFunEvent.Creator);
  61. creators.Add(Buff_Function_Type.Attack_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  62. creators.Add(Buff_Function_Type.MagicAttack_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  63. creators.Add(Buff_Function_Type.Heal_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  64. creators.Add(Buff_Function_Type.Hit_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  65. creators.Add(Buff_Function_Type.Dodge_Change_Percent, ChangeAttrPercentFunEvent.Creator);
  66. creators.Add(Buff_Function_Type.Hit_Change_Value, ChangeAttrValueFunEvent.Creator);
  67. creators.Add(Buff_Function_Type.Dodge_Change_Value, ChangeAttrValueFunEvent.Creator);
  68. creators.Add(Buff_Function_Type.IgnorePhysicDefense_Change_Value, ChangeAttrValueFunEvent.Creator);
  69. creators.Add(Buff_Function_Type.IgnoreMagicDefense_Change_Value, ChangeAttrValueFunEvent.Creator);
  70. creators.Add(Buff_Function_Type.PhysicDamagePercent_Change_Value, ChangeAttrValueFunEvent.Creator);
  71. creators.Add(Buff_Function_Type.MagicDamagePercent_Change_Value, ChangeAttrValueFunEvent.Creator);
  72. creators.Add(Buff_Function_Type.CritDamagePercent_Change_Value, ChangeAttrValueFunEvent.Creator);
  73. creators.Add(Buff_Function_Type.PhysicDamageReflectPercent_Change_Value, ChangeAttrValueFunEvent.Creator);
  74. creators.Add(Buff_Function_Type.MagicDamageReflectPercent_Change_Value, ChangeAttrValueFunEvent.Creator);
  75. creators.Add(Buff_Function_Type.AntiPhysicDamagePercent_Change_Value, ChangeAttrValueFunEvent.Creator);
  76. creators.Add(Buff_Function_Type.AntiMagicDamagePercent_Change_Value, ChangeAttrValueFunEvent.Creator);
  77. creators.Add(Buff_Function_Type.Nature_None_Change_Value, ChangeAttrValueFunEvent.Creator);
  78. creators.Add(Buff_Function_Type.Nature_Water_Change_Value, ChangeAttrValueFunEvent.Creator);
  79. creators.Add(Buff_Function_Type.Nature_Ground_Change_Value, ChangeAttrValueFunEvent.Creator);
  80. creators.Add(Buff_Function_Type.Nature_Fire_Change_Value, ChangeAttrValueFunEvent.Creator);
  81. creators.Add(Buff_Function_Type.Nature_Wind_Change_Value, ChangeAttrValueFunEvent.Creator);
  82. creators.Add(Buff_Function_Type.Nature_Saint_Change_Value, ChangeAttrValueFunEvent.Creator);
  83. creators.Add(Buff_Function_Type.Nature_Dark_Change_Value, ChangeAttrValueFunEvent.Creator);
  84. creators.Add(Buff_Function_Type.Nature_Read_Change_Value, ChangeAttrValueFunEvent.Creator);
  85. creators.Add(Buff_Function_Type.AntiNature_None_Change_Value, ChangeAttrValueFunEvent.Creator);
  86. creators.Add(Buff_Function_Type.AntiNature_Water_Change_Value, ChangeAttrValueFunEvent.Creator);
  87. creators.Add(Buff_Function_Type.AntiNature_Ground_Change_Value, ChangeAttrValueFunEvent.Creator);
  88. creators.Add(Buff_Function_Type.AntiNature_Fire_Change_Value, ChangeAttrValueFunEvent.Creator);
  89. creators.Add(Buff_Function_Type.AntiNature_Wind_Change_Value, ChangeAttrValueFunEvent.Creator);
  90. creators.Add(Buff_Function_Type.AntiNature_Saint_Change_Value, ChangeAttrValueFunEvent.Creator);
  91. creators.Add(Buff_Function_Type.AntiNature_Dark_Change_Value, ChangeAttrValueFunEvent.Creator);
  92. creators.Add(Buff_Function_Type.AntiNature_Read_Change_Value, ChangeAttrValueFunEvent.Creator);
  93. creators.Add(Buff_Function_Type.Attack_Change_Value, ChangeAttrValueFunEvent.Creator);
  94. creators.Add(Buff_Function_Type.MagicAttack_Change_Value, ChangeAttrValueFunEvent.Creator);
  95. creators.Add(Buff_Function_Type.STR_Change_Value, ChangeAttrValueFunEvent.Creator);
  96. creators.Add(Buff_Function_Type.INT_Change_Value, ChangeAttrValueFunEvent.Creator);
  97. creators.Add(Buff_Function_Type.AGI_Change_Value, ChangeAttrValueFunEvent.Creator);
  98. creators.Add(Buff_Function_Type.Change_MaxHP_Value, ChangeMaxHpValue.Creator);
  99. creators.Add(Buff_Function_Type.SP_Change_Value, ChangeAttrValueFunEvent.Creator);
  100. creators.Add(Buff_Function_Type.LUK_Change_Value, ChangeAttrValueFunEvent.Creator);
  101. creators.Add(Buff_Function_Type.Ten_Change_Value, ChangeAttrValueFunEvent.Creator);
  102. creators.Add(Buff_Function_Type.Crit_Change_Value, ChangeAttrValueFunEvent.Creator);
  103. creators.Add(Buff_Function_Type.AttackCD_Change_Value, ChangeAttrValueFunEvent.Creator);
  104. creators.Add(Buff_Function_Type.Phyx_Defense_Change_Value, ChangeAttrValueFunEvent.Creator);
  105. creators.Add(Buff_Function_Type.Magic_Defense_Change_Value, ChangeAttrValueFunEvent.Creator);
  106. creators.Add(Buff_Function_Type.Shield_AbsortAttack_Fixed_Change_Value, ChangeAttrValueFunEvent.Creator);
  107. creators.Add(Buff_Function_Type.ChangeHP_FromAttr_Percent, ChangeHP_FromAttrFunEvent.Creator);
  108. creators.Add(Buff_Function_Type.ChangeHP_From_CasterAttr_Percent, ChangeHP_FromCasterAttrFunEvent.Creator);
  109. creators.Add(Buff_Function_Type.Break, BreakFunEvent.Creator);
  110. creators.Add(Buff_Function_Type.RageStatus, RageStatusFunEvent.Creator);
  111. creators.Add(Buff_Function_Type.ChangeSkillSpeed, ChangeSkillAnimSpeed.Creator);
  112. creators.Add(Buff_Function_Type.AttackSpeed_Change_Percent, ChangeAttrValueFunEvent.Creator);
  113. creators.Add(Buff_Function_Type.Add_Duration_Hurt, HurtChangeValueFromCasterAttr.Creator);
  114. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_STR, HurtChangeValueFromCasterAttr.Creator);
  115. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_AGI, HurtChangeValueFromCasterAttr.Creator);
  116. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_INT, HurtChangeValueFromCasterAttr.Creator);
  117. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_VIT, HurtChangeValueFromCasterAttr.Creator);
  118. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_DEX, HurtChangeValueFromCasterAttr.Creator);
  119. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_LUK, HurtChangeValueFromCasterAttr.Creator);
  120. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_HP, HurtChangeValueFromCasterAttr.Creator);
  121. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_SP, HurtChangeValueFromCasterAttr.Creator);
  122. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_Attack, HurtChangeValueFromCasterAttr.Creator);
  123. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_MagicAttack, HurtChangeValueFromCasterAttr.Creator);
  124. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_Defense, HurtChangeValueFromCasterAttr.Creator);
  125. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_MagicDefense, HurtChangeValueFromCasterAttr.Creator);
  126. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_Hit, HurtChangeValueFromCasterAttr.Creator);
  127. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_Dodge, HurtChangeValueFromCasterAttr.Creator);
  128. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_Crit, HurtChangeValueFromCasterAttr.Creator);
  129. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_Ten, HurtChangeValueFromCasterAttr.Creator);
  130. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_AttackSpeed, HurtChangeValueFromCasterAttr.Creator);
  131. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_MaxHp, HurtChangeValueFromCasterAttr.Creator);
  132. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Caster_MaxSP, HurtChangeValueFromCasterAttr.Creator);
  133. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Target_HP, HurtChangeValueFromTargetAttr.Creator);
  134. creators.Add(Buff_Function_Type.Hurt_Change_Value_From_Target_MaxHP, HurtChangeValueFromTargetAttr.Creator);
  135. creators.Add(Buff_Function_Type.PassiveSkill_Trigger, PassiveSkillTriggerEvent.Creator);
  136. //-----------new
  137. creators.Add(Buff_Function_Type.Hurt_Targert_SuckBlood, SuckBloodFunEvent.Creator);
  138. creators.Add(Buff_Function_Type.Attack_Change_ByTargetAttr, ChangeAttrValueFunEvent.Creator);
  139. creators.Add(Buff_Function_Type.MagicAttack_Change_ByTargetAttr, ChangeAttrValueFunEvent.Creator);
  140. creators.Add(Buff_Function_Type.AttackDefense_Change_ByTargetAttr, ChangeAttrValueFunEvent.Creator);
  141. creators.Add(Buff_Function_Type.MagicDefense_Change_ByTargetAttr, ChangeAttrValueFunEvent.Creator);
  142. creators.Add(Buff_Function_Type.Attack_Change_BySourceAttr, ChangeAttrValueFunEvent.Creator);
  143. creators.Add(Buff_Function_Type.MagicAttack_Change_BySourceAttr, ChangeAttrValueFunEvent.Creator);
  144. creators.Add(Buff_Function_Type.AttackDefense_Change_BySourceAttr, ChangeAttrValueFunEvent.Creator);
  145. creators.Add(Buff_Function_Type.MagicDefense_Change_BySourceAttr, ChangeAttrValueFunEvent.Creator);
  146. creators.Add(Buff_Function_Type.Attack_Change_ByTargetCostHpPercent, ChangeAttrPercentFunEvent.Creator);
  147. creators.Add(Buff_Function_Type.MagicAttack_Change_ByTargetCostHpPercent, ChangeAttrPercentFunEvent.Creator);
  148. creators.Add(Buff_Function_Type.Attack_Change_BySourceCostHpPercent, ChangeAttrPercentFunEvent.Creator);
  149. creators.Add(Buff_Function_Type.MagicAttack_Change_BySourceCostHpPercent, ChangeAttrPercentFunEvent.Creator);
  150. creators.Add(Buff_Function_Type.Attack_Change_ByTargetCurHpPercent, ChangeAttrPercentFunEvent.Creator);
  151. creators.Add(Buff_Function_Type.MagicAttack_Change_ByTargetCurHpPercent, ChangeAttrPercentFunEvent.Creator);
  152. creators.Add(Buff_Function_Type.Attack_Change_BySourceCurHpPercent, ChangeAttrPercentFunEvent.Creator);
  153. creators.Add(Buff_Function_Type.MagicAttack_Change_BySourceCurHpPercent, ChangeAttrPercentFunEvent.Creator);
  154. creators.Add(Buff_Function_Type.Reflect_Hurt_ByTargetAttr, ReflectPercentHurtFunEvent.Creator);
  155. creators.Add(Buff_Function_Type.Reflect_Hurt_BySourceAttr, ReflectPercentHurtFunEvent.Creator);
  156. creators.Add(Buff_Function_Type.Reflect_Fix_Hurt, ReflectFixHurtFunEvent.Creator);
  157. creators.Add(Buff_Function_Type.Hurt_Attack_SuckDamage, ChangeAttrValueFunEvent.Creator);
  158. creators.Add(Buff_Function_Type.Hurt_MagicAttack_SuckDamage, ChangeAttrValueFunEvent.Creator);
  159. creators.Add(Buff_Function_Type.Change_Hit_Value, ChangeAttrValueFunEvent.Creator);
  160. creators.Add(Buff_Function_Type.Change_Doge_Value, ChangeAttrValueFunEvent.Creator);
  161. creators.Add(Buff_Function_Type.Change_Crit_Value, ChangeAttrValueFunEvent.Creator);
  162. creators.Add(Buff_Function_Type.Change_Ten_Value, ChangeAttrValueFunEvent.Creator);
  163. //------------------------------------------------------------
  164. tickCreators = new Dictionary<Buff_Function_Type, TickFunctionEventCreator>();
  165. tickCreators.Add(Buff_Function_Type.Heal_Change_Percent_From_Target, HealHPPercent.Creator);
  166. tickCreators.Add(Buff_Function_Type.Heal_Target_HP_Change_Value, HealHP.Creator);
  167. tickCreators.Add(Buff_Function_Type.Heal_Change_Percent_From_Caster, HealHPFromCaster.Creator);
  168. tickCreators.Add(Buff_Function_Type.SP_Change_Percent, SPChangePercent.Creator);
  169. tickCreators.Add(Buff_Function_Type.SP_Change_Value, SPChange.Creator);
  170. tickCreators.Add(Buff_Function_Type.Add_SP_From_Caster, SPChangeFromCaster.Creator);
  171. tickCreators.Add(Buff_Function_Type.Add_Function_Point_Value, AddFunctionPoint.Creator);
  172. tickCreators.Add(Buff_Function_Type.Deduct_Function_Point_Value, DetectFunctionPoint.Creator);
  173. tickCreators.Add(Buff_Function_Type.ChangeBuff_Using_Function_Point, TriggerBuffUsingFunctionPoint.Creator);
  174. }
  175. public FunctionEvent AddFunctionEvent(int buffId,BuffFunctionData data,Fighter caster, SkillHitFighterInfo hitInfo)
  176. {
  177. if (mFighter == null || !mFighter.IsAlive) return null;
  178. //判断是否处于免疫效果
  179. if (mFighter.StateData.IsImmunity && data.buffType == BattleBuffType.Negative) {
  180. //DebugHelper.LogError(mFighter.Name + " 当前处于免疫,不能增加" + data.functionType);
  181. return null;
  182. }
  183. //被诅咒时,不能增加增益效果
  184. if (mFighter.StateData.IsCurse && data.buffType == BattleBuffType.Enhance)
  185. {
  186. return null;
  187. }
  188. if (data == null) return null;
  189. string skillName = null;
  190. if (hitInfo.Skill != null && !hitInfo.Skill.IsNormalAttack)
  191. skillName = hitInfo.Skill.SkillName;
  192. if (data.functionType == Buff_Function_Type.Shield_AbsortAttack_Change_Percent ||
  193. data.functionType == Buff_Function_Type.Shield_AbsortAttack_Fixed_Change_Value ||
  194. data.functionType == Buff_Function_Type.Shield_AbsortAttack_Change_Percent_From_Caster)
  195. {
  196. CheckShield(caster,data, skillName);
  197. return null;
  198. }
  199. if (!string.IsNullOrEmpty(data.word))
  200. {
  201. if(data.buffType == BattleBuffType.Negative)
  202. {
  203. EventMgr.DispatchEvent<Fighter, string>(new CoreEvent<Fighter, string>(ECoreEventType.EID_NEGATIVE_FUNCTION, mFighter, data.word));
  204. }
  205. else
  206. {
  207. EventMgr.DispatchEvent<Fighter, string>(new CoreEvent<Fighter, string>(ECoreEventType.EID_ADD_FUNCTION, mFighter, data.word));
  208. }
  209. }
  210. if (caster != null)
  211. {
  212. if (data.buffType == BattleBuffType.Negative)
  213. {
  214. if(caster.Statistics!=null)
  215. caster.Statistics.StatBuffInfo(caster, true);
  216. }
  217. else if (data.buffType == BattleBuffType.Enhance)
  218. {
  219. if(caster.Statistics!=null)
  220. caster.Statistics.StatBuffInfo(caster, false);
  221. }
  222. }
  223. if (data.IsInstantFunc)
  224. {
  225. int skillLv = data.SkillLv;
  226. if (hitInfo.Skill != null)
  227. {
  228. skillLv = hitInfo.Skill.Level;
  229. }
  230. skillLv = skillLv < 1 ? 1 : skillLv;
  231. return ExecuteInstanceFunc(buffId,data,caster, skillLv,skillName);
  232. }
  233. //DebugHelper.Log("----fighter: " + mFighter.Name + " 增加效果id:" + data.functionType);
  234. if (ExistBuffFunction(data.functionType,data.buffType,data.Group))
  235. {
  236. DurationFunctionEvent funEvent = GetFunctionByType(data.functionType,data.Group);
  237. if (funEvent.Data.value > data.value) return funEvent;
  238. funEvent.Caster = caster;
  239. funEvent.BuffId = buffId;
  240. funEvent.HitInfo = hitInfo;
  241. funEvent.ResetData(data);
  242. funEvent.ResetDuration(data.duration);
  243. return funEvent;
  244. }
  245. if (!creators.ContainsKey(data.functionType)) return null;
  246. //打断
  247. if (data.functionType == Buff_Function_Type.Break)
  248. {
  249. if (mFighter.CurrentSkill != null && mFighter.CurrentSkill.CanBreak)
  250. {
  251. DurationFunctionEvent newEvt = creators[data.functionType](data);
  252. newEvt.Caster = caster;
  253. newEvt.BuffId = buffId;
  254. newEvt.HitInfo = hitInfo;
  255. newEvt.Enter(mFighter);
  256. mFunEventList.Add(newEvt);
  257. //if(caster!=null && caster.StateData.CurrentSkill != null && caster.StateData.CurrentSkill.HasBuff(buffId))
  258. //{
  259. // caster.TriggerBuffByType(caster.StateData.CurrentSkill, SkillTriggerBuffType.Skill_Break_Trigger);
  260. //}
  261. if(caster!=null && caster.StateData.CurrentSkill!= null)
  262. {
  263. string sName = null;
  264. if(!caster.StateData.CurrentSkill.IsNormalAttack)
  265. {
  266. sName = caster.StateData.CurrentSkill.SkillName;
  267. }
  268. string targetSkillName = mFighter.CurrentSkill != null ? mFighter.CurrentSkill.SkillName : "";
  269. caster.Battle.Output(OutputType.Break, caster, mFighter, sName, targetSkillName);
  270. EventMgr.DispatchEvent<Fighter, BaseSkill>(new CoreEvent<Fighter, BaseSkill>(ECoreEventType.EID_Fighter_Break_Skill, caster,caster.StateData.CurrentSkill));
  271. }
  272. return newEvt;
  273. }
  274. }
  275. else
  276. {
  277. DurationFunctionEvent newEvt = creators[data.functionType](data);
  278. newEvt.Caster = caster;
  279. newEvt.BuffId = buffId;
  280. newEvt.HitInfo = hitInfo;
  281. newEvt.SkillName = skillName;
  282. newEvt.Enter(mFighter);
  283. mFunEventList.Add(newEvt);
  284. //判断效果清除
  285. if (newEvt.IsHurtEvent)
  286. {
  287. RemoveFunctionByHurtBreak();
  288. }
  289. return newEvt;
  290. }
  291. return null;
  292. }
  293. public int NegativeFunCnt
  294. {
  295. get
  296. {
  297. int cnt = 0;
  298. if(mFunEventList != null)
  299. {
  300. for (int idx = 0; idx < mFunEventList.Count; idx++)
  301. {
  302. if(mFunEventList[idx].BuffType == BattleBuffType.Negative)
  303. {
  304. cnt++;
  305. }
  306. }
  307. }
  308. if(mInstanceEventList != null)
  309. {
  310. for(int idx =0; idx < mInstanceEventList.Count;idx++)
  311. {
  312. if (mInstanceEventList[idx].BuffType == BattleBuffType.Negative)
  313. cnt++;
  314. }
  315. }
  316. return cnt;
  317. }
  318. }
  319. //是否存在释放技能效果
  320. public bool HaveForbidSkillFunc()
  321. {
  322. if (mFunEventList == null) return false;
  323. //if (mFighter.Battle.IsPlayRecord) return false;
  324. for (int idx =0; idx < mFunEventList.Count;idx++)
  325. {
  326. if (mFunEventList[idx].Data.forbidSkill)
  327. {
  328. return true;
  329. }
  330. }
  331. return false;
  332. }
  333. //判断是否存在禁止普攻释放
  334. public bool HaveForbidNormalAttackFunc()
  335. {
  336. if (mFunEventList == null) return false;
  337. for (int idx =0; idx < mFunEventList.Count;idx++)
  338. {
  339. if (mFunEventList[idx].Data.forbidNormalAttack)
  340. return true;
  341. }
  342. return false;
  343. }
  344. //是否存在禁止移动
  345. public bool HaveForbidMoveFunc()
  346. {
  347. if (mFunEventList == null) return false;
  348. for(int idx =0; idx < mFunEventList.Count;idx++)
  349. {
  350. if (mFunEventList[idx].Data.forbidMove)
  351. return true;
  352. }
  353. return false;
  354. }
  355. //是否存在忽视闪避的效果
  356. public bool HaveIgoreDodgeFunction()
  357. {
  358. if (mFunEventList == null) return false;
  359. for (int idx = 0; idx < mFunEventList.Count; idx++)
  360. {
  361. if (mFunEventList[idx].Data.canIgnoreDodge)
  362. return true;
  363. }
  364. return false;
  365. }
  366. public bool ExistBuffFunction(Buff_Function_Type type,BattleBuffType buffType,int group)
  367. {
  368. for(int idx =0; idx < mFunEventList.Count;idx++)
  369. {
  370. if (mFunEventList[idx].Type == type && mFunEventList[idx].BuffType == buffType && mFunEventList[idx].Group == group) return true;
  371. }
  372. for(int idx =0; idx < mInstanceEventList.Count;idx++)
  373. {
  374. if (mInstanceEventList[idx].Type == type && mInstanceEventList[idx].BuffType == buffType && mFunEventList[idx].Group == group) return true;
  375. }
  376. return false;
  377. }
  378. public bool HaveBuffFunction(Buff_Function_Type type)
  379. {
  380. for (int idx = 0; idx < mFunEventList.Count; idx++)
  381. {
  382. if (mFunEventList[idx].Type == type) return true;
  383. }
  384. for (int idx = 0; idx < mInstanceEventList.Count; idx++)
  385. {
  386. if (mInstanceEventList[idx].Type == type) return true;
  387. }
  388. return false;
  389. }
  390. public bool HaveBuffType(BattleBuffType buffType)
  391. {
  392. for(int idx =0; idx < mFunEventList.Count;idx++)
  393. {
  394. if (mFunEventList[idx].Data.buffType == buffType)
  395. return true;
  396. }
  397. for(int idx =0; idx < mInstanceEventList.Count;idx++)
  398. {
  399. if (mInstanceEventList[idx].Data.buffType == buffType)
  400. return true;
  401. }
  402. return false;
  403. }
  404. public DurationFunctionEvent GetFunctionByType(Buff_Function_Type type)
  405. {
  406. for (int idx = 0; idx < mFunEventList.Count; idx++)
  407. {
  408. if (mFunEventList[idx].Type == type) return mFunEventList[idx];
  409. }
  410. return null;
  411. }
  412. public DurationFunctionEvent GetFunctionByType(Buff_Function_Type type, int group)
  413. {
  414. for (int idx = 0; idx < mFunEventList.Count; idx++)
  415. {
  416. if (mFunEventList[idx].Type == type && mFunEventList[idx].Group == group) return mFunEventList[idx];
  417. }
  418. return null;
  419. }
  420. public SFloat GetBuffValue(Buff_Function_Type functionType)
  421. {
  422. SFloat val = 0;
  423. if(mFunEventList != null)
  424. {
  425. for (int idx = mFunEventList.Count - 1; idx >= 0; idx--)
  426. {
  427. var fun = mFunEventList[idx];
  428. if (fun.Data.functionType == functionType)
  429. {
  430. val += fun.GetValue();
  431. }
  432. }
  433. }
  434. if(mInstanceEventList!=null)
  435. {
  436. for (int idx = mInstanceEventList.Count - 1; idx >= 0; idx--)
  437. {
  438. var fun = mInstanceEventList[idx];
  439. if (fun.Data.functionType == functionType)
  440. {
  441. val += fun.GetValue();
  442. }
  443. }
  444. }
  445. return val;
  446. }
  447. public bool GetSuckDamage(Buff_Function_Type functionType,out SFloat val, out int nMaxHpPercent)
  448. {
  449. val = 0;
  450. nMaxHpPercent = 0;
  451. if(functionType == Buff_Function_Type.Hurt_Attack_SuckDamage || functionType == Buff_Function_Type.Hurt_MagicAttack_SuckDamage)
  452. if (mFunEventList != null)
  453. {
  454. for (int idx = mFunEventList.Count - 1; idx >= 0; idx--)
  455. {
  456. var fun = mFunEventList[idx];
  457. if (fun.Data.functionType == functionType)
  458. {
  459. val += fun.GetValue();
  460. int MaxHp = 0;
  461. int.TryParse(fun.Data.extendParam, out MaxHp);
  462. nMaxHpPercent = Mathf.Max(MaxHp,nMaxHpPercent);
  463. }
  464. }
  465. }
  466. return val != 0;
  467. }
  468. public SInt DamageOnShield(SInt damage)
  469. {
  470. if (mIsShield && damage > 0)
  471. {
  472. SInt decValue = Mathf.Min(damage, mCurrentShieldValue);
  473. damage -= decValue;
  474. mCurrentShieldValue -= decValue;
  475. if(mCurrentShieldValue <= 0)
  476. {
  477. mCurrentShieldValue = 0;
  478. ClearShield(true);
  479. }
  480. if(decValue > 0)
  481. {
  482. EventMgr.DispatchEvent<Fighter, int>(new CoreEvent<Fighter, int>(ECoreEventType.EID_SHIELD_ABSORT_HURT, mFighter, -decValue));
  483. //DebugHelper.Log("Fighter:" + mFighter.Name + " DamageOnShield" + decValue);
  484. }
  485. }
  486. return damage;
  487. }
  488. public void Update(float deltaTime)
  489. {
  490. if(mIsShield)
  491. {
  492. //mShieldDurationTime -= deltaTime;
  493. //if(mShieldDurationTime <=0)
  494. //{
  495. // ClearShield();
  496. //}
  497. mShieldFrame--;
  498. if(mShieldFrame<=0)
  499. {
  500. ClearShield(true);
  501. }
  502. }
  503. for(int idx =0; idx < mFunEventList.Count;idx++)
  504. {
  505. mFunEventList[idx].Update(deltaTime);
  506. }
  507. for(int idx = mFunEventList.Count -1; idx>=0;idx--)
  508. {
  509. if(mFunEventList[idx].Expired(mFighter))
  510. {
  511. mFunEventList[idx].Exit(mFighter);
  512. mFunEventList.RemoveAt(idx);
  513. }
  514. }
  515. for(int idx = mInstanceEventList.Count - 1;idx >=0;idx--)
  516. {
  517. if (mInstanceEventList[idx].Expired())
  518. {
  519. mInstanceEventList.RemoveAt(idx);
  520. }
  521. }
  522. }
  523. public void OnFightingEnd()
  524. {
  525. Clear();
  526. }
  527. public void RemoveNegativeFunction()
  528. {
  529. RemoveFunctionByBuffType(BattleBuffType.Negative);
  530. }
  531. public void RemoveEnhanceFunction()
  532. {
  533. RemoveFunctionByBuffType(BattleBuffType.Enhance);
  534. }
  535. //异常伤害打断的效果
  536. public void RemoveFunctionByHurtBreak()
  537. {
  538. for(int idx = mFunEventList.Count - 1; idx >= 0;idx--)
  539. {
  540. var evt = mFunEventList[idx];
  541. if(evt.Data.canHurtStop)
  542. {
  543. evt.Exit(mFighter);
  544. mFunEventList.RemoveAt(idx);
  545. }
  546. }
  547. }
  548. public void RemoveFunctionByBuffType(BattleBuffType type)
  549. {
  550. for(int idx = mFunEventList.Count -1;idx>=0;idx--)
  551. {
  552. if(mFunEventList[idx].Data.buffType == type)
  553. {
  554. mFunEventList[idx].Exit(mFighter);
  555. mFunEventList.RemoveAt(idx);
  556. }
  557. }
  558. for(int idx = mInstanceEventList.Count-1; idx >=0;idx--)
  559. {
  560. if (mInstanceEventList[idx].Data.buffType == type)
  561. {
  562. mInstanceEventList[idx].Exit(mFighter);
  563. mInstanceEventList.RemoveAt(idx);
  564. }
  565. }
  566. }
  567. public void RemoveFunctionByBuffType(BattleBuffType type,int group)
  568. {
  569. for (int idx = mFunEventList.Count - 1; idx >= 0; idx--)
  570. {
  571. if (mFunEventList[idx].Data.buffType == type && mFunEventList[idx].Group == group)
  572. {
  573. mFunEventList[idx].Exit(mFighter);
  574. mFunEventList.RemoveAt(idx);
  575. }
  576. }
  577. for (int idx = mInstanceEventList.Count - 1; idx >= 0; idx--)
  578. {
  579. if (mInstanceEventList[idx].Data.buffType == type && mInstanceEventList[idx].Group == group)
  580. {
  581. mInstanceEventList[idx].Exit(mFighter);
  582. mInstanceEventList.RemoveAt(idx);
  583. }
  584. }
  585. }
  586. public void RemoveFunctionByFunType(Buff_Function_Type type)
  587. {
  588. for(int idx = mFunEventList.Count -1; idx>=0;idx--)
  589. {
  590. if(mFunEventList[idx].Data.functionType == type)
  591. {
  592. mFunEventList[idx].Exit(mFighter);
  593. mFunEventList.RemoveAt(idx);
  594. }
  595. }
  596. for (int idx = mInstanceEventList.Count - 1; idx >= 0; idx--)
  597. {
  598. if (mInstanceEventList[idx].Data.functionType == type)
  599. {
  600. mInstanceEventList[idx].Exit(mFighter);
  601. mInstanceEventList.RemoveAt(idx);
  602. }
  603. }
  604. }
  605. public void RemoveDurationFunEvent(int funId,int group)
  606. {
  607. for(int idx =mFunEventList.Count -1; idx>=0; idx--)
  608. {
  609. if(mFunEventList[idx].Data.id == funId && mFunEventList[idx].Group == group)
  610. {
  611. mFunEventList[idx].Exit(mFighter);
  612. mFunEventList.RemoveAt(idx);
  613. }
  614. }
  615. }
  616. public void Clear()
  617. {
  618. for(int idx = 0; idx < mFunEventList.Count;idx++)
  619. {
  620. mFunEventList[idx].Exit(mFighter);
  621. }
  622. mFunEventList.Clear();
  623. for (int idx = mInstanceEventList.Count - 1; idx >= 0; idx--)
  624. {
  625. mInstanceEventList[idx].Exit(mFighter);
  626. }
  627. mInstanceEventList.Clear();
  628. ClearShield();
  629. }
  630. public void Dispose()
  631. {
  632. Clear();
  633. creators.Clear();
  634. mFighter = null;
  635. mFunEventList = null;
  636. creators = null;
  637. }
  638. void CheckShield(Fighter caster,BuffFunctionData data,string skillName)
  639. {
  640. SInt value = 0;
  641. if (data.functionType == Buff_Function_Type.Shield_AbsortAttack_Change_Percent)
  642. {
  643. value = (SInt)(mFighter.GetAttrByType(data.fromAttr) * data.value * 0.01f);
  644. }
  645. else if(data.functionType == Buff_Function_Type.Shield_AbsortAttack_Fixed_Change_Value)
  646. {
  647. value = (SInt)data.value;
  648. }else if(data.functionType == Buff_Function_Type.Shield_AbsortAttack_Change_Percent_From_Caster)
  649. {
  650. if(caster!=null)
  651. {
  652. value = (SInt)(caster.GetAttrByType(data.fromAttr) * data.value * 0.01f);
  653. }
  654. }
  655. if(value > mCurrentShieldValue)
  656. {
  657. mShieldFrame = (int)(data.duration * Constants.frame_to_time);
  658. mCurrentShieldValue = value;
  659. if(caster!=null)
  660. {
  661. caster.Battle.Output(OutputType.Shield, caster, mFighter, skillName, (int)mCurrentShieldValue);
  662. }
  663. }
  664. if(!mIsShield && mCurrentShieldValue > 0)
  665. {
  666. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_FIGHTER_ADD_SHIELD, mFighter));
  667. if(data.effectId > 0)
  668. mShieldEffectInstanceID = EffectManager.Instance.PlayEffect(data.effectId, mFighter, mFighter);
  669. mShieldEndEffectId = data.endeffectId;
  670. }
  671. mIsShield = mCurrentShieldValue > 0;
  672. }
  673. void ClearShield(bool notified =false)
  674. {
  675. if(mShieldEffectInstanceID > 0)
  676. {
  677. EffectManager.Instance.RemoveEffectByInstanceID(mShieldEffectInstanceID);
  678. mShieldEffectInstanceID = 0;
  679. if (mShieldEndEffectId > 0)
  680. EffectManager.Instance.PlayEffect(mShieldEndEffectId, mFighter, mFighter);
  681. }
  682. mShieldEndEffectId = 0;
  683. mCurrentShieldValue = 0;
  684. mIsShield = false;
  685. mShieldFrame = 0;
  686. if(notified)
  687. {
  688. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_FIGHTER_CLEAR_SHIELD, mFighter));
  689. }
  690. }
  691. FunctionEvent ExecuteInstanceFunc(int BuffId,BuffFunctionData data,Fighter caster,int castingSkillLv,string skillName)
  692. {
  693. if (tickCreators.ContainsKey(data.functionType))
  694. {
  695. data.SetLevel(castingSkillLv);
  696. TickFunctionEvent newEvt = tickCreators[data.functionType](data);
  697. newEvt.Caster = caster;
  698. newEvt.BuffId = BuffId;
  699. newEvt.SkillName = skillName;
  700. mInstanceEventList.Add(newEvt);
  701. newEvt.Enter(mFighter);
  702. mInstanceEventList.Remove(newEvt);
  703. return newEvt;
  704. }
  705. TickFunctionEvent evt = new TickFunctionEvent(data);
  706. evt.SkillName = skillName;
  707. mInstanceEventList.Add(evt);
  708. //净化
  709. if(HaveBuffFunction(Buff_Function_Type.Clean))
  710. {
  711. if (caster != null && HaveBuffType(BattleBuffType.Negative))
  712. {
  713. caster.Battle.Output(OutputType.Clean, caster, mFighter, skillName, 0);
  714. if (caster != null && caster.StateData.CurrentSkill != null && caster.StateData.CurrentSkill.HasBuff(BuffId))
  715. {
  716. //caster.TriggerBuffByType(caster.StateData.CurrentSkill, SkillTriggerBuffType.Purify_Target_Debuff_Trigger);
  717. EventMgr.DispatchEvent<Fighter, BaseSkill>(new CoreEvent<Fighter, BaseSkill>(ECoreEventType.EID_Fighter_Purify_Debuff, caster, caster.StateData.CurrentSkill));
  718. }
  719. }
  720. RemoveNegativeFunction();
  721. }
  722. //驱散
  723. if(HaveBuffFunction(Buff_Function_Type.Disperse))
  724. {
  725. if(caster!=null && (HaveBuffType(BattleBuffType.Enhance) || mIsShield))
  726. {
  727. caster.Battle.Output(OutputType.Disperse, caster, mFighter, skillName, 0);
  728. if (caster != null && caster.StateData.CurrentSkill != null && caster.StateData.CurrentSkill.HasBuff(BuffId))
  729. {
  730. //caster.TriggerBuffByType(caster.StateData.CurrentSkill, SkillTriggerBuffType.Disperse_Target_Buff_Trigger);
  731. EventMgr.DispatchEvent<Fighter, BaseSkill>(new CoreEvent<Fighter, BaseSkill>(ECoreEventType.EID_Fighter_Disperse_Buff, caster, caster.StateData.CurrentSkill));
  732. }
  733. }
  734. RemoveEnhanceFunction();
  735. ClearShield();
  736. }
  737. return evt;
  738. }
  739. }