XmdsVirtual.Event.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.Instance;
  3. using CommonAI.Zone.Formula;
  4. using CommonLang;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using XmdsCommon.Plugin;
  11. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  12. using CommonAI.Data;
  13. using XmdsCommonSkill.Plugin.CardSkill;
  14. using XmdsCommon.JSGModule.Interface;
  15. using CommonAI.ZoneServer.JSGModule;
  16. using XmdsCommonServer.Plugin.JSGXmdsModule;
  17. namespace XmdsCommonServer.Plugin
  18. {
  19. /// <summary>
  20. /// FileName: XmdsVirtual.cs
  21. /// Author: Alex.Yu
  22. /// Corporation:...
  23. /// Description:注册事件相关.
  24. /// DateTime: 2015/6/2 17:38:21
  25. /// </summary>
  26. partial class XmdsVirtual
  27. {
  28. //OnHitOther//
  29. readonly private List<OnHitHandler> mOnHitOtherLt = new List<OnHitHandler>();
  30. //OnHitDamage//
  31. readonly private List<OnHitHandler> mOnHitDamageLt = new List<OnHitHandler>();
  32. //OnBuffStart//
  33. readonly private List<OnBuffEventHandler> mOnBuffEventLt = new List<OnBuffEventHandler>();
  34. //OnCalDamage//
  35. readonly private List<OnCalDmageHandler> mOnCalDamageLt = new List<OnCalDmageHandler>();
  36. //OnLaunchSkillOver//
  37. readonly private List<OnLaunchSkillOverHandler> mOnLaunchSkillOverLt = new List<OnLaunchSkillOverHandler>();
  38. //OnGetAtkTarget//
  39. readonly private List<OnGetAtkTargetHandler> mOnGetAtkTargetLt = new List<OnGetAtkTargetHandler>();
  40. //OnGetSkillDamageInfo //
  41. readonly private List<OnGetSkillDamageInfo> mOnGetSkillDamageInfoLt = new List<OnGetSkillDamageInfo>();
  42. //IStateSkillEnd //
  43. readonly private List<OnStateSkillEnd> mOnStateSkillEndLt = new List<OnStateSkillEnd>();
  44. //ITryAddBuffEvent//
  45. readonly private List<OnTryAddBuff> mOnTryAddBuffLt = new List<OnTryAddBuff>();
  46. readonly private List<OnRemoveBuff> mOnRemoveBuffLt = new List<OnRemoveBuff>();
  47. //ISendBuffEvent
  48. //readonly private List<OnSendBuffEvent> mOnSendBuffEvent = new List<OnSendBuffEvent>();
  49. readonly private List<OnTrySendSpell> mOnTrySendSpellLt = new List<OnTrySendSpell>();
  50. readonly private List<OnSendSpellOverEvent> mSendSpellOverLt = new List<OnSendSpellOverEvent>();
  51. readonly private List<OnTryLaucnSkill> mOnTryLaunchSkillLt = new List<OnTryLaucnSkill>();
  52. //宠物给予人物的主动技能触发
  53. readonly private List<OnTriggerPetSkill> mOnTriggerPetSkillLt = new List<OnTriggerPetSkill>();
  54. //计算仇恨值.
  55. readonly private List<OnCalThreatValue> mOnCalThreatValueLt = new List<OnCalThreatValue>();
  56. //技能被打断事件监听
  57. readonly private List<OnSkillBlockEvnet> mOnSkillBlockList = new List<OnSkillBlockEvnet>();
  58. //加血事件
  59. readonly private List<OnAddOtherHPEvnet> mAddOtherHPList = new List<OnAddOtherHPEvnet>();
  60. //承担伤害监听
  61. readonly private List<OnShareMasterDmgEvent> mShareMasterDmgList = new List<OnShareMasterDmgEvent>();
  62. //扣定力
  63. readonly private List<OnReduceOtherMpEvnet> mReduceMPList = new List<OnReduceOtherMpEvnet>();
  64. //获得卡牌珠监听
  65. readonly private List<OnTryAddCardBallEvent> mTryAddCardBallList = new List<OnTryAddCardBallEvent>();
  66. //释放卡牌技能监听
  67. readonly private List<OnTriggerCardSkillEvent> mTriggerCardSkillList = new List<OnTriggerCardSkillEvent>();
  68. //击杀其他单位监听
  69. readonly private List<OnKillOtherUnitEvent> mKillOtherList = new List<OnKillOtherUnitEvent>();
  70. private HashMap<int, IHandle> mHandleMap = new HashMap<int, IHandle>();
  71. private int mHandleUUID = 0;
  72. public enum BuffEventType
  73. {
  74. None,
  75. Begin,
  76. End,
  77. Update,
  78. Hit,
  79. }
  80. public abstract class IHandle
  81. {
  82. public readonly GameSkill m_skill;
  83. public readonly bool mListenAll = false;
  84. public IHandle(GameSkill skill, bool listenAll)
  85. {
  86. this.m_skill = skill;
  87. this.mListenAll = listenAll;
  88. }
  89. }
  90. public class OnHitHandler : IHandle
  91. {
  92. public readonly IOnHit m_hit;
  93. public readonly bool ListenAllSkill = false;
  94. public OnHitHandler(IOnHit hit, GameSkill skill, bool listenAll) : base(skill, listenAll)
  95. {
  96. m_hit = hit;
  97. this.ListenAllSkill = listenAll;
  98. }
  99. }
  100. class OnBuffEventHandler : IHandle
  101. {
  102. public readonly IOnBuffEvent m_tg;
  103. public readonly BuffEventType m_type;
  104. public OnBuffEventHandler(IOnBuffEvent tg, BuffEventType type, GameSkill skill) : base(skill, true)
  105. {
  106. m_tg = tg;
  107. m_type = type;
  108. }
  109. }
  110. public class OnCalDmageHandler : IHandle
  111. {
  112. public readonly ICalDamage m_cal;
  113. public readonly int skillDamageID;
  114. public OnCalDmageHandler(ICalDamage tg, GameSkill skill, bool listenAll, int skillDamageID) : base(skill, listenAll)
  115. {
  116. m_cal = tg;
  117. this.skillDamageID = skillDamageID;
  118. }
  119. public override string ToString()
  120. {
  121. return skillDamageID.ToString();
  122. }
  123. }
  124. class OnLaunchSkillOverHandler : IHandle
  125. {
  126. public readonly ILaunchSkillOver m_hand;
  127. public OnLaunchSkillOverHandler(ILaunchSkillOver tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
  128. {
  129. m_hand = tg;
  130. }
  131. }
  132. class OnGetAtkTargetHandler : IHandle
  133. {
  134. public readonly IGetAtkTarget m_hand;
  135. public OnGetAtkTargetHandler(IGetAtkTarget tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
  136. {
  137. m_hand = tg;
  138. }
  139. }
  140. class OnGetSkillDamageInfo : IHandle
  141. {
  142. public readonly IGetSkillDamageInfo m_hand;
  143. public OnGetSkillDamageInfo(IGetSkillDamageInfo tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
  144. {
  145. m_hand = tg;
  146. }
  147. }
  148. class OnStateSkillEnd : IHandle
  149. {
  150. public readonly IStateSkillEnd m_hand;
  151. public OnStateSkillEnd(IStateSkillEnd tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
  152. {
  153. m_hand = tg;
  154. }
  155. }
  156. class OnTryAddBuff : IHandle
  157. {
  158. public readonly ITryAddBuffEvent m_hand;
  159. public OnTryAddBuff(ITryAddBuffEvent tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
  160. {
  161. m_hand = tg;
  162. }
  163. }
  164. class OnRemoveBuff : IHandle
  165. {
  166. public readonly IRemoveBuffEvent m_hand;
  167. public readonly int buffID;
  168. public OnRemoveBuff(IRemoveBuffEvent tg, int buffID, bool listenAll) : base(null, listenAll)
  169. {
  170. m_hand = tg;
  171. this.buffID = buffID;
  172. }
  173. }
  174. //class OnSendBuffEvent : IHandle
  175. // {
  176. // public readonly int listenBuffID;
  177. // public readonly ISendBuffEvent m_hand;
  178. // public OnSendBuffEvent(ISendBuffEvent tg, GameSkill skill, int listenBuffID = 0) : base(skill, false)
  179. // {
  180. // m_hand = tg;
  181. // this.listenBuffID = listenBuffID;
  182. // }
  183. // }
  184. class OnSendSpellOverEvent : IHandle
  185. {
  186. public readonly ISendSpellOverEvent m_hand;
  187. public readonly int mListSpellId;
  188. public OnSendSpellOverEvent(ISendSpellOverEvent tg, int spellId, GameSkill sk, bool listenAll = false) : base(sk, listenAll)
  189. {
  190. m_hand = tg;
  191. this.mListSpellId = spellId;
  192. }
  193. }
  194. class OnTrySendSpell : IHandle
  195. {
  196. public readonly ITrySendSpellEvent m_hand;
  197. public readonly int mListenSpellId;
  198. public OnTrySendSpell(ITrySendSpellEvent tg, GameSkill skill, int listenSpellId, bool listenAll) : base(skill, listenAll)
  199. {
  200. m_hand = tg;
  201. this.mListenSpellId = listenSpellId;
  202. }
  203. }
  204. class OnTryLaucnSkill : IHandle
  205. {
  206. public readonly ITryLaunchSkillEvent m_hand;
  207. public OnTryLaucnSkill(ITryLaunchSkillEvent tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
  208. {
  209. m_hand = tg;
  210. }
  211. }
  212. class OnTriggerPetSkill : IHandle
  213. {
  214. public readonly ITriggerPetSkillEvent m_hand;
  215. public OnTriggerPetSkill(ITriggerPetSkillEvent tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
  216. {
  217. m_hand = tg;
  218. }
  219. }
  220. class OnCalThreatValue : IHandle
  221. {
  222. public readonly ICalThreadValue m_hand;
  223. public OnCalThreatValue(ICalThreadValue tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
  224. {
  225. m_hand = tg;
  226. }
  227. }
  228. class OnSkillBlockEvnet : IHandle
  229. {
  230. public readonly ISkillBlockEvent m_hand;
  231. public OnSkillBlockEvnet(ISkillBlockEvent handler, GameSkill skill, bool listenAll) : base(skill, listenAll)
  232. {
  233. this.m_hand = handler;
  234. }
  235. }
  236. class OnAddOtherHPEvnet : IHandle
  237. {
  238. public readonly IAddOtherHPEvent m_hand;
  239. public OnAddOtherHPEvnet(IAddOtherHPEvent handler, GameSkill skill) : base(skill, true)
  240. {
  241. this.m_hand = handler;
  242. }
  243. }
  244. protected class OnShareMasterDmgEvent : IHandle
  245. {
  246. public readonly IShareMasterDmgEvent m_hand;
  247. public OnShareMasterDmgEvent(IShareMasterDmgEvent handler, GameSkill skill) : base(skill, true)
  248. {
  249. this.m_hand = handler;
  250. }
  251. }
  252. class OnReduceOtherMpEvnet : IHandle
  253. {
  254. public readonly IReduceOtherMpEvent m_hand;
  255. public OnReduceOtherMpEvnet(IReduceOtherMpEvent handler, GameSkill skill) : base(skill, true)
  256. {
  257. this.m_hand = handler;
  258. }
  259. }
  260. class OnTryAddCardBallEvent : IHandle
  261. {
  262. public readonly CreateCardBallSource mType;
  263. public readonly ITryAddCardBallEvent m_hand;
  264. public OnTryAddCardBallEvent(ITryAddCardBallEvent handler, CreateCardBallSource type, bool listenAll = false) : base(null, listenAll)
  265. {
  266. this.m_hand = handler;
  267. this.mType = type;
  268. }
  269. }
  270. class OnTriggerCardSkillEvent : IHandle
  271. {
  272. public readonly CardType mPointCardType;
  273. public readonly ITriggerCardSkillEvent m_hand;
  274. public OnTriggerCardSkillEvent(ITriggerCardSkillEvent handler, GameSkill info, CardType cardType, bool listenAll = false) : base(info, listenAll)
  275. {
  276. this.m_hand = handler;
  277. this.mPointCardType = cardType;
  278. }
  279. }
  280. class OnKillOtherUnitEvent : IHandle
  281. {
  282. public readonly int maType;
  283. public readonly IOnKillOtherUnitEvent m_hand;
  284. public OnKillOtherUnitEvent(IOnKillOtherUnitEvent handler, GameSkill info, int type) : base(info, false)
  285. {
  286. this.m_hand = handler;
  287. this.maType = type;
  288. }
  289. }
  290. #region 事件监听.
  291. public delegate void OnHealEvent(XmdsVirtual attacker, XmdsVirtual hitter, int value, ref AtkResult result);
  292. public delegate void OnCombatStateChangeEvent(XmdsVirtual unit, bool status);
  293. /// <summary>
  294. /// 治愈回调.
  295. /// </summary>
  296. public event OnHealEvent OnHealEventHandle;
  297. /// <summary>
  298. /// 战斗状态变更.
  299. /// </summary>
  300. public event OnCombatStateChangeEvent OnCombatStateChangeHandle
  301. {
  302. add { event_OnCombatStateChangeHandle += value; }
  303. remove { event_OnCombatStateChangeHandle -= value; }
  304. }
  305. protected OnCombatStateChangeEvent event_OnCombatStateChangeHandle;
  306. #endregion
  307. #region 计算伤害时触发.
  308. public int RegistCalDamage(ICalDamage cal, GameSkill sk, bool listenAll, int skillDamageID = 0)
  309. {
  310. OnCalDmageHandler handle = new OnCalDmageHandler(cal, sk, listenAll, skillDamageID);
  311. int ret = HandleUUIDCreate();
  312. mOnCalDamageLt.Add(handle);
  313. mHandleMap.Add(ret, handle);
  314. return ret;
  315. }
  316. public bool UnRegistCalDamage(int handleUUID)
  317. {
  318. bool ret = false;
  319. IHandle handle = null;
  320. if (mHandleMap.TryGetValue(handleUUID, out handle))
  321. {
  322. if (handle != null && handle is OnCalDmageHandler)
  323. {
  324. ret = mOnCalDamageLt.Remove(handle as OnCalDmageHandler);
  325. mHandleMap.Remove(handleUUID);
  326. }
  327. }
  328. return ret;
  329. }
  330. #endregion
  331. #region 单位打到别人时开发.
  332. /// <summary>
  333. /// 单位打到别人时触发
  334. /// </summary>
  335. /// <param name="hit"></param>
  336. /// <param name="sk"></param>
  337. public int RegistOnHitOther(IOnHit hit, GameSkill sk, bool listenAll = false)
  338. {
  339. OnHitHandler handle = new OnHitHandler(hit, sk, listenAll);
  340. int ret = HandleUUIDCreate();
  341. mOnHitOtherLt.Add(handle);
  342. mHandleMap.Add(ret, handle);
  343. return ret;
  344. }
  345. public bool UnRegistOnHitOther(int handleUUID)
  346. {
  347. bool ret = false;
  348. IHandle handle = null;
  349. if (mHandleMap.TryGetValue(handleUUID, out handle))
  350. {
  351. if (handle != null && handle is OnHitHandler)
  352. {
  353. ret = mOnHitOtherLt.Remove(handle as OnHitHandler);
  354. mHandleMap.Remove(handleUUID);
  355. }
  356. }
  357. return ret;
  358. }
  359. #endregion
  360. #region 单位受到攻击时触发.
  361. /// <summary>
  362. /// 单位收到攻击时触发
  363. /// </summary>
  364. /// <param name="hit"></param>
  365. /// <param name="sk"></param>
  366. public int RegistOnHitDamage(IOnHit hit, GameSkill sk, bool listenAll = false)
  367. {
  368. OnHitHandler handle = new OnHitHandler(hit, sk, listenAll);
  369. mOnHitDamageLt.Add(handle);
  370. int ret = HandleUUIDCreate();
  371. mHandleMap.Add(ret, handle);
  372. return ret;
  373. }
  374. public bool UnRegistOnHitDamage(int handleUUID)
  375. {
  376. bool ret = false;
  377. IHandle handle = null;
  378. if (mHandleMap.TryGetValue(handleUUID, out handle))
  379. {
  380. if (handle != null && handle is OnHitHandler)
  381. {
  382. ret = mOnHitDamageLt.Remove(handle as OnHitHandler);
  383. mHandleMap.Remove(handleUUID);
  384. }
  385. }
  386. return ret;
  387. }
  388. #endregion
  389. #region BUFF触发.
  390. /// <summary>
  391. /// 注册监听BUFF相关事件.
  392. /// </summary>
  393. /// <param name="tg"></param>
  394. /// <param name="type"></param>
  395. /// <param name="sk"></param>
  396. /// <returns></returns>
  397. public int RegistBuffEvent(IOnBuffEvent tg, BuffEventType type, GameSkill sk)
  398. {
  399. OnBuffEventHandler handle = new OnBuffEventHandler(tg, type, sk);
  400. mOnBuffEventLt.Add(handle);
  401. int ret = HandleUUIDCreate();
  402. mHandleMap.Add(ret, handle);
  403. return ret;
  404. }
  405. public bool UnRegistBuffEvent(int handleUUID)
  406. {
  407. bool ret = false;
  408. IHandle handle = null;
  409. if (mHandleMap.TryGetValue(handleUUID, out handle))
  410. {
  411. if (handle != null && handle is OnBuffEventHandler)
  412. {
  413. ret = mOnBuffEventLt.Remove(handle as OnBuffEventHandler);
  414. mHandleMap.Remove(handleUUID);
  415. }
  416. }
  417. return ret;
  418. }
  419. #endregion
  420. #region 增加BUFF.
  421. /// <summary>
  422. /// 注册是否能添加BUFF判断事件.
  423. /// </summary>
  424. /// <returns></returns>
  425. public int RegistTryAddBuffEvent(ITryAddBuffEvent tg, GameSkill sk, bool listenAll = false)
  426. {
  427. OnTryAddBuff handle = new OnTryAddBuff(tg, sk, listenAll);
  428. mOnTryAddBuffLt.Add(handle);
  429. int ret = HandleUUIDCreate();
  430. mHandleMap.Add(ret, handle);
  431. return ret;
  432. }
  433. /** 注册给其他玩家添加buff时间 */
  434. //public int RegistSendBuffEvent(ISendBuffEvent tg, GameSkill sk, int listenBuffID = 0)
  435. //{
  436. // OnSendBuffEvent handle = new OnSendBuffEvent(tg, sk, listenBuffID);
  437. // mOnSendBuffEvent.Add(handle);
  438. // int ret = HandleUUIDCreate();
  439. // mHandleMap.Add(ret, handle);
  440. // return ret;
  441. //}
  442. /** 注册给其他玩家添加buff时间 */
  443. public int RegistRemoveBuffEvent(IRemoveBuffEvent tg, int buffID, bool listenAll = false)
  444. {
  445. OnRemoveBuff handle = new OnRemoveBuff(tg, buffID, listenAll);
  446. mOnRemoveBuffLt.Add(handle);
  447. int ret = HandleUUIDCreate();
  448. mHandleMap.Add(ret, handle);
  449. return ret;
  450. }
  451. /// <summary>
  452. /// 取消注册添加BUFF判断.
  453. /// </summary>
  454. /// <returns></returns>
  455. public bool UnRegistTryAddBuffEvent(int handleUUID)
  456. {
  457. bool ret = false;
  458. IHandle handle = null;
  459. if (mHandleMap.TryGetValue(handleUUID, out handle))
  460. {
  461. if (handle != null && handle is OnTryAddBuff)
  462. {
  463. ret = mOnTryAddBuffLt.Remove(handle as OnTryAddBuff);
  464. mHandleMap.Remove(handleUUID);
  465. }
  466. }
  467. return ret;
  468. }
  469. /// <summary>
  470. /// 取消发送BUFF监听.
  471. /// </summary>
  472. /// <returns></returns>
  473. //public bool UnRegistSendBuffEvent(int handleUUID)
  474. //{
  475. // bool ret = false;
  476. // IHandle handle = null;
  477. // if (mHandleMap.TryGetValue(handleUUID, out handle))
  478. // {
  479. // if (handle != null && handle is OnSendBuffEvent)
  480. // {
  481. // ret = mOnSendBuffEvent.Remove(handle as OnSendBuffEvent);
  482. // mHandleMap.Remove(handleUUID);
  483. // }
  484. // }
  485. // return ret;
  486. //}
  487. /// <summary>
  488. /// 取消注册添加BUFF判断.
  489. /// </summary>
  490. /// <returns></returns>
  491. public bool UnRegistRemoveBuffEvent(int handleUUID)
  492. {
  493. bool ret = false;
  494. IHandle handle = null;
  495. if (mHandleMap.TryGetValue(handleUUID, out handle))
  496. {
  497. if (handle != null && handle is OnRemoveBuff)
  498. {
  499. ret = mOnRemoveBuffLt.Remove(handle as OnRemoveBuff);
  500. mHandleMap.Remove(handleUUID);
  501. }
  502. }
  503. return ret;
  504. }
  505. #endregion
  506. #region 注册监听spell重定向.
  507. public int RegistTrySendSpellEvent(ITrySendSpellEvent tg, GameSkill sk, int listenSpellId = 0, bool listenAll = false)
  508. {
  509. OnTrySendSpell handle = new OnTrySendSpell(tg, sk, listenSpellId, listenAll);
  510. mOnTrySendSpellLt.Add(handle);
  511. int ret = HandleUUIDCreate();
  512. mHandleMap.Add(ret, handle);
  513. return ret;
  514. }
  515. public bool UnRegistTrySendSpellEvent(int handleUUID)
  516. {
  517. bool ret = false;
  518. IHandle handle = null;
  519. if (mHandleMap.TryGetValue(handleUUID, out handle))
  520. {
  521. if (handle != null && handle is OnTrySendSpell)
  522. {
  523. ret = mOnTrySendSpellLt.Remove(handle as OnTrySendSpell);
  524. mHandleMap.Remove(handleUUID);
  525. }
  526. }
  527. return ret;
  528. }
  529. public int RegistSendSpellOverEvent(ISendSpellOverEvent tg, int spellId, GameSkill sk, bool listAll = false)
  530. {
  531. OnSendSpellOverEvent handle = new OnSendSpellOverEvent(tg, spellId, sk, listAll);
  532. mSendSpellOverLt.Add(handle);
  533. int ret = HandleUUIDCreate();
  534. mHandleMap.Add(ret, handle);
  535. return ret;
  536. }
  537. public bool UnRegistSendSpellOverEvent(int handleUUID)
  538. {
  539. bool ret = false;
  540. IHandle handle = null;
  541. if (mHandleMap.TryGetValue(handleUUID, out handle))
  542. {
  543. if (handle != null && handle is OnSendSpellOverEvent)
  544. {
  545. ret = mSendSpellOverLt.Remove(handle as OnSendSpellOverEvent);
  546. mHandleMap.Remove(handleUUID);
  547. }
  548. }
  549. return ret;
  550. }
  551. #endregion
  552. #region 监听技能施放.
  553. public int RegistTryLaunchSkillEvent(ITryLaunchSkillEvent tg, GameSkill sk, bool listenAllSkill = false)
  554. {
  555. OnTryLaucnSkill handle = new OnTryLaucnSkill(tg, sk, listenAllSkill);
  556. mOnTryLaunchSkillLt.Add(handle);
  557. int ret = HandleUUIDCreate();
  558. mHandleMap.Add(ret, handle);
  559. return ret;
  560. }
  561. public bool UnRegistTryLaunchSkillEvent(int handleUUID)
  562. {
  563. bool ret = false;
  564. IHandle handle = null;
  565. if (mHandleMap.TryGetValue(handleUUID, out handle))
  566. {
  567. if (handle != null && handle is OnTryLaucnSkill)
  568. {
  569. ret = mOnTryLaunchSkillLt.Remove(handle as OnTryLaucnSkill);
  570. mHandleMap.Remove(handleUUID);
  571. }
  572. }
  573. return ret;
  574. }
  575. //ITriggerPetSkillEvent返回true,结束下层传递
  576. public int RegistTriggerPetSkillEvent(ITriggerPetSkillEvent tg, GameSkill sk, bool listenAllSkill = false)
  577. {
  578. OnTriggerPetSkill handle = new OnTriggerPetSkill(tg, sk, listenAllSkill);
  579. mOnTriggerPetSkillLt.Add(handle);
  580. int ret = HandleUUIDCreate();
  581. mHandleMap.Add(ret, handle);
  582. return ret;
  583. }
  584. public bool UnRegistTriggerPetSkillEvent(int handleUUID)
  585. {
  586. bool ret = false;
  587. IHandle handle = null;
  588. if (mHandleMap.TryGetValue(handleUUID, out handle))
  589. {
  590. if (handle != null && handle is OnTriggerPetSkill)
  591. {
  592. ret = mOnTriggerPetSkillLt.Remove(handle as OnTriggerPetSkill);
  593. mHandleMap.Remove(handleUUID);
  594. }
  595. }
  596. return ret;
  597. }
  598. #endregion
  599. #region 释放完技能后.
  600. /// <summary>
  601. /// 注册技能释放完毕的监听.
  602. /// </summary>
  603. /// <param name="call"></param>
  604. /// <param name="sk"></param>
  605. /// <returns></returns>
  606. public int RegistLaunchSkillOver(ILaunchSkillOver call, GameSkill sk, bool listenAllSkill = false)
  607. {
  608. OnLaunchSkillOverHandler handle = new OnLaunchSkillOverHandler(call, sk, listenAllSkill);
  609. int ret = HandleUUIDCreate();
  610. mOnLaunchSkillOverLt.Add(handle);
  611. mHandleMap.Add(ret, handle);
  612. return ret;
  613. }
  614. /// <summary>
  615. /// 反注册技能释放完毕的监听.
  616. /// </summary>
  617. /// <param name="call"></param>
  618. /// <param name="sk"></param>
  619. /// <returns></returns>
  620. public bool UnRegistLaunchSkillOver(int handleUUID)
  621. {
  622. bool ret = false;
  623. IHandle handle = null;
  624. if (mHandleMap.TryGetValue(handleUUID, out handle))
  625. {
  626. if (handle != null && handle is OnLaunchSkillOverHandler)
  627. {
  628. ret = mOnLaunchSkillOverLt.Remove(handle as OnLaunchSkillOverHandler);
  629. mHandleMap.Remove(handleUUID);
  630. }
  631. }
  632. return ret;
  633. }
  634. #endregion
  635. #region 获得攻击目标.
  636. /// <summary>
  637. /// 注册获取攻击目标监听.
  638. /// </summary>
  639. /// <param name="call"></param>
  640. /// <param name="sk"></param>
  641. /// <returns></returns>
  642. public int RegistGetAtkTarget(IGetAtkTarget call, GameSkill sk, bool listenAll)
  643. {
  644. OnGetAtkTargetHandler handle = new OnGetAtkTargetHandler(call, sk, listenAll);
  645. int ret = HandleUUIDCreate();
  646. mOnGetAtkTargetLt.Add(handle);
  647. mHandleMap.Add(ret, handle);
  648. return ret;
  649. }
  650. /// <summary>
  651. /// 反注册获取攻击目标监听.
  652. /// </summary>
  653. /// <param name="call"></param>
  654. /// <param name="sk"></param>
  655. /// <returns></returns>
  656. public bool UnRegistGetAtkTarget(int handleUUID)
  657. {
  658. bool ret = false;
  659. IHandle handle = null;
  660. if (mHandleMap.TryGetValue(handleUUID, out handle))
  661. {
  662. if (handle != null && handle is OnGetAtkTargetHandler)
  663. {
  664. ret = mOnGetAtkTargetLt.Remove(handle as OnGetAtkTargetHandler);
  665. mHandleMap.Remove(handleUUID);
  666. }
  667. }
  668. return ret;
  669. }
  670. #endregion
  671. #region 注册获得技能伤害.
  672. public int RegistGetSkillDamageInfo(IGetSkillDamageInfo call, GameSkill sk, bool listenAll)
  673. {
  674. OnGetSkillDamageInfo handle = new OnGetSkillDamageInfo(call, sk, listenAll);
  675. int ret = HandleUUIDCreate();
  676. mOnGetSkillDamageInfoLt.Add(handle);
  677. mHandleMap.Add(ret, handle);
  678. return ret;
  679. }
  680. public bool UnRegistGetSkillDamageInfo(int handleUUID)
  681. {
  682. bool ret = false;
  683. IHandle handle = null;
  684. if (mHandleMap.TryGetValue(handleUUID, out handle))
  685. {
  686. if (handle != null && handle is OnGetSkillDamageInfo)
  687. {
  688. ret = mOnGetSkillDamageInfoLt.Remove(handle as OnGetSkillDamageInfo);
  689. mHandleMap.Remove(handleUUID);
  690. }
  691. }
  692. return ret;
  693. }
  694. #endregion
  695. #region 技能结束监听.
  696. /// <summary>
  697. /// 注册技能结束监听.
  698. /// </summary>
  699. /// <param name="call"></param>
  700. /// <param name="sk"></param>
  701. /// <returns></returns>
  702. public int RegistStateSkillEndEvent(IStateSkillEnd call, GameSkill sk, bool listenAllSkill)
  703. {
  704. OnStateSkillEnd handle = new OnStateSkillEnd(call, sk, listenAllSkill);
  705. int ret = HandleUUIDCreate();
  706. mOnStateSkillEndLt.Add(handle);
  707. mHandleMap.Add(ret, handle);
  708. return ret;
  709. }
  710. /// <summary>
  711. /// 取消技能结束监听.
  712. /// </summary>
  713. /// <param name="handleUUID"></param>
  714. /// <returns></returns>
  715. public bool UnRegistStateSkillEndEvent(int handleUUID)
  716. {
  717. bool ret = false;
  718. IHandle handle = null;
  719. if (mHandleMap.TryGetValue(handleUUID, out handle))
  720. {
  721. if (handle != null && handle is OnStateSkillEnd)
  722. {
  723. ret = mOnStateSkillEndLt.Remove(handle as OnStateSkillEnd);
  724. mHandleMap.Remove(handleUUID);
  725. }
  726. }
  727. return ret;
  728. }
  729. #endregion
  730. #region 计算仇恨值监听.
  731. public int RegistCalThreatValue(ICalThreadValue call, GameSkill gs, bool listenAllSkill)
  732. {
  733. OnCalThreatValue handle = new OnCalThreatValue(call, gs, listenAllSkill);
  734. int ret = HandleUUIDCreate();
  735. mOnCalThreatValueLt.Add(handle);
  736. mHandleMap.Add(ret, handle);
  737. return ret;
  738. }
  739. public bool UnRegistCalThreatValue(int handleUUID)
  740. {
  741. bool ret = false;
  742. IHandle handle = null;
  743. if (mHandleMap.TryGetValue(handleUUID, out handle))
  744. {
  745. if (handle != null && handle is OnCalThreatValue)
  746. {
  747. ret = mOnCalThreatValueLt.Remove(handle as OnCalThreatValue);
  748. mHandleMap.Remove(handleUUID);
  749. }
  750. }
  751. return ret;
  752. }
  753. #endregion
  754. #region 技能被打断监听.
  755. public int RegistSkillBlockEvent(ISkillBlockEvent call, GameSkill gs)
  756. {
  757. OnSkillBlockEvnet handle = new OnSkillBlockEvnet(call, gs, true);
  758. int ret = HandleUUIDCreate();
  759. mOnSkillBlockList.Add(handle);
  760. mHandleMap.Add(ret, handle);
  761. return ret;
  762. }
  763. public bool UnRegistSkillBlockEvent(int handleUUID)
  764. {
  765. bool ret = false;
  766. IHandle handle = null;
  767. if (mHandleMap.TryGetValue(handleUUID, out handle))
  768. {
  769. if (handle != null && handle is OnSkillBlockEvnet)
  770. {
  771. ret = mOnSkillBlockList.Remove(handle as OnSkillBlockEvnet);
  772. mHandleMap.Remove(handleUUID);
  773. }
  774. }
  775. return ret;
  776. }
  777. public int RegistAddOtherHPEvent(IAddOtherHPEvent call, GameSkill gs)
  778. {
  779. OnAddOtherHPEvnet handle = new OnAddOtherHPEvnet(call, gs);
  780. int ret = HandleUUIDCreate();
  781. mAddOtherHPList.Add(handle);
  782. mHandleMap.Add(ret, handle);
  783. return ret;
  784. }
  785. public bool UnRegistAddOtherHPEvent(int handleUUID)
  786. {
  787. bool ret = false;
  788. IHandle handle = null;
  789. if (mHandleMap.TryGetValue(handleUUID, out handle))
  790. {
  791. if (handle != null && handle is OnAddOtherHPEvnet)
  792. {
  793. ret = mAddOtherHPList.Remove(handle as OnAddOtherHPEvnet);
  794. mHandleMap.Remove(handleUUID);
  795. }
  796. }
  797. return ret;
  798. }
  799. public int RegistShareMasterDmgEvent(IShareMasterDmgEvent call, GameSkill gs)
  800. {
  801. OnShareMasterDmgEvent handle = new OnShareMasterDmgEvent(call, gs);
  802. int ret = HandleUUIDCreate();
  803. mShareMasterDmgList.Add(handle);
  804. mHandleMap.Add(ret, handle);
  805. return ret;
  806. }
  807. public bool UnRegistShareMasterDmgEvent(int handleUUID)
  808. {
  809. bool ret = false;
  810. IHandle handle = null;
  811. if (mHandleMap.TryGetValue(handleUUID, out handle))
  812. {
  813. if (handle != null && handle is OnShareMasterDmgEvent)
  814. {
  815. ret = mShareMasterDmgList.Remove(handle as OnShareMasterDmgEvent);
  816. mHandleMap.Remove(handleUUID);
  817. }
  818. }
  819. return ret;
  820. }
  821. public int RegistReduceMPEvent(IReduceOtherMpEvent call, GameSkill gs)
  822. {
  823. OnReduceOtherMpEvnet handle = new OnReduceOtherMpEvnet(call, gs);
  824. int ret = HandleUUIDCreate();
  825. mReduceMPList.Add(handle);
  826. mHandleMap.Add(ret, handle);
  827. return ret;
  828. }
  829. public bool UnRegistReduceOtherMpEvent(int handleUUID)
  830. {
  831. bool ret = false;
  832. IHandle handle = null;
  833. if (mHandleMap.TryGetValue(handleUUID, out handle))
  834. {
  835. if (handle != null && handle is OnReduceOtherMpEvnet)
  836. {
  837. ret = mReduceMPList.Remove(handle as OnReduceOtherMpEvnet);
  838. mHandleMap.Remove(handleUUID);
  839. }
  840. }
  841. return ret;
  842. }
  843. public int RegistTryAddCardBallEvent(ITryAddCardBallEvent call, CreateCardBallSource type, bool listenAll = false)
  844. {
  845. OnTryAddCardBallEvent handle = new OnTryAddCardBallEvent(call, type, listenAll);
  846. int ret = HandleUUIDCreate();
  847. mTryAddCardBallList.Add(handle);
  848. mHandleMap.Add(ret, handle);
  849. return ret;
  850. }
  851. public bool UnRegistTryAddCardBallEvent(int handleUUID)
  852. {
  853. bool ret = false;
  854. IHandle handle = null;
  855. if (mHandleMap.TryGetValue(handleUUID, out handle))
  856. {
  857. if (handle != null && handle is OnTryAddCardBallEvent)
  858. {
  859. ret = mTryAddCardBallList.Remove(handle as OnTryAddCardBallEvent);
  860. mHandleMap.Remove(handleUUID);
  861. }
  862. }
  863. return ret;
  864. }
  865. public int RegistTriggerCardSkillEvent(ITriggerCardSkillEvent call, GameSkill info, CardType cardType, bool listenAll = false)
  866. {
  867. OnTriggerCardSkillEvent handle = new OnTriggerCardSkillEvent(call, info, cardType, listenAll);
  868. int ret = HandleUUIDCreate();
  869. mTriggerCardSkillList.Add(handle);
  870. mHandleMap.Add(ret, handle);
  871. return ret;
  872. }
  873. public bool UnRegistTriggerCardSkillEvent(int handleUUID)
  874. {
  875. bool ret = false;
  876. IHandle handle = null;
  877. if (mHandleMap.TryGetValue(handleUUID, out handle))
  878. {
  879. if (handle != null && handle is OnTriggerCardSkillEvent)
  880. {
  881. ret = mTriggerCardSkillList.Remove(handle as OnTriggerCardSkillEvent);
  882. mHandleMap.Remove(handleUUID);
  883. }
  884. }
  885. return ret;
  886. }
  887. public int RegistKillOtherEvent(IOnKillOtherUnitEvent call, GameSkill info, int monsterType)
  888. {
  889. OnKillOtherUnitEvent handle = new OnKillOtherUnitEvent(call, info, monsterType);
  890. int ret = HandleUUIDCreate();
  891. mKillOtherList.Add(handle);
  892. mHandleMap.Add(ret, handle);
  893. return ret;
  894. }
  895. public bool UnRegistKillOtherEvent(int handleUUID)
  896. {
  897. bool ret = false;
  898. IHandle handle = null;
  899. if (mHandleMap.TryGetValue(handleUUID, out handle))
  900. {
  901. if (handle != null && handle is OnKillOtherUnitEvent)
  902. {
  903. ret = mKillOtherList.Remove(handle as OnKillOtherUnitEvent);
  904. mHandleMap.Remove(handleUUID);
  905. }
  906. }
  907. return ret;
  908. }
  909. #endregion
  910. #region 事件派发.
  911. /// <summary>
  912. /// 分配handleID.
  913. /// </summary>
  914. /// <returns></returns>
  915. private int HandleUUIDCreate()
  916. {
  917. return ++mHandleUUID;
  918. }
  919. /// <summary>
  920. ///攻击者监听:打到其他单位.
  921. /// </summary>
  922. /// <param name="damage"></param>
  923. /// <param name="target"></param>
  924. /// <param name="source"></param>
  925. /// <returns></returns>
  926. private float DispatchHitOtherEvent(float damage, XmdsVirtual target, AttackSource source,
  927. ref XmdsVirtual.AtkResult result, DamageType damageType)
  928. {
  929. if (this.mUnit.IsActive)
  930. {
  931. float sourceDmg = damage;
  932. bool isEndDispatch = false;
  933. for (int i = mOnHitOtherLt.Count - 1; i >= 0; --i)
  934. {
  935. OnHitHandler hitend = mOnHitOtherLt[i];
  936. //伤害单一注册判断
  937. if (!hitend.ListenAllSkill && hitend.m_skill != null && source.Attack != null)
  938. {
  939. XmdsAttackProperties atkProp = source.Attack.Properties as XmdsAttackProperties;
  940. if (atkProp.SkillTemplateID != hitend.m_skill.SkillID)
  941. {
  942. continue;
  943. }
  944. }
  945. damage = hitend.m_hit.Invoke(damage, target, this, source, ref result, damageType, hitend.m_skill, ref isEndDispatch);
  946. //检测伤害输出异常
  947. JSGXmdsHackerModule.CheckAndPrintDmgWarn("HitOther", this, target, sourceDmg, damage, source);
  948. if (isEndDispatch)
  949. {
  950. break;
  951. }
  952. }
  953. }
  954. return damage;
  955. }
  956. /// <summary>
  957. ///受击者监听:受到伤害.
  958. /// </summary>
  959. /// <param name="damage"></param>
  960. /// <param name="attacker"></param>
  961. /// <param name="source"></param>
  962. /// skill - 造成伤害的技能信息,可能为空
  963. /// <returns></returns>
  964. private float DispatchHitDamageEvent(float damage, XmdsVirtual attacker, AttackSource source,
  965. ref XmdsVirtual.AtkResult result, DamageType damageType)
  966. {
  967. if (this.mUnit.IsActive && mOnHitDamageLt.Count > 0)
  968. {
  969. float sourceDmg = damage;
  970. bool isEndDispatch = false;
  971. for (int i = mOnHitDamageLt.Count - 1; i >= 0; --i)
  972. {
  973. if(i < 0 || i >= mOnHitDamageLt.Count)
  974. {
  975. int buffID = source.FromBuff == null ? 0 : source.FromBuff.ID;
  976. int spellID = source.FromSpell == null ? 0 : source.FromSpell.ID;
  977. log.Warn("DispatchHitDamageEvent监听改变: " + i + ", " + mOnHitDamageLt.Count + ", BuffID: " + buffID + ", spellID: " + spellID + ", "
  978. + this.mUnit.PlayerUUID);
  979. break;
  980. }
  981. OnHitHandler hitend = mOnHitDamageLt[i];
  982. if(!hitend.ListenAllSkill && hitend.m_skill != null && source.Attack != null)
  983. {
  984. XmdsAttackProperties atkProp = source.Attack.Properties as XmdsAttackProperties;
  985. if (atkProp.SkillTemplateID != hitend.m_skill.SkillID)
  986. {
  987. continue;
  988. }
  989. }
  990. damage = hitend.m_hit.Invoke(damage, this, attacker, source, ref result, damageType, hitend.m_skill, ref isEndDispatch);
  991. JSGXmdsHackerModule.CheckAndPrintDmgWarn("HitDamage", attacker, this, sourceDmg, damage, source);
  992. if (isEndDispatch)
  993. {
  994. break;
  995. }
  996. }
  997. }
  998. return CUtils.CastInt(damage);//四舍五入
  999. }
  1000. /// <summary>
  1001. /// 派发技能成功释放事件.
  1002. /// </summary>
  1003. /// <param name="costEnergy"></param>
  1004. /// <param name="attacker"></param>
  1005. /// <param name="state"></param>
  1006. /// <returns></returns>
  1007. private int DispatchLaunchsSkillOverEvent(XmdsVirtual launcher, CommonAI.Zone.Instance.InstanceUnit.SkillState state)
  1008. {
  1009. if (launcher.mUnit.IsActive)
  1010. {
  1011. for (int i = 0; i < mOnLaunchSkillOverLt.Count; i++)
  1012. {
  1013. OnLaunchSkillOverHandler hitend = mOnLaunchSkillOverLt[i];
  1014. if (hitend.mListenAll || hitend.m_skill == null)
  1015. {
  1016. hitend.m_hand.Invoke(hitend.m_skill, launcher, state);
  1017. }
  1018. else if (hitend.m_skill.SkillID == state.ID)
  1019. {
  1020. hitend.m_hand.Invoke(hitend.m_skill, launcher, state);
  1021. }
  1022. }
  1023. }
  1024. return 0;
  1025. }
  1026. /// <summary>
  1027. /// 派发技能造成伤害事件.
  1028. /// </summary>
  1029. /// <param name="hitter"></param>
  1030. /// <param name="source"></param>
  1031. /// <param name="result"></param>
  1032. /// <returns></returns>
  1033. private int DispatchCalDamageEvent(XmdsVirtual hitter, AttackSource source, ref AtkResult result)
  1034. {
  1035. //特殊情况单位是技能触发伤害,则单位必须活着,如果是spell或BUFF无视单位自身状态.
  1036. XmdsAttackProperties prop = (source.Attack.Properties as XmdsAttackProperties);
  1037. if (this.mUnit.IsActive == false && prop.SkillTemplateID != XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills.XmdsBattleSkill.DefaultSkillScriptID)
  1038. {
  1039. //单位已死亡,技能造成的伤害不算.
  1040. return 0;
  1041. }
  1042. int damage = 0;
  1043. if(prop.SkillTemplateID == XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills.XmdsBattleSkill.DefaultSkillScriptID)
  1044. {
  1045. XmdsBattleSkill.mDefDamgageHandler.m_cal.Invoke(this, hitter, source, XmdsBattleSkill.mDefDamgageHandler.m_skill, ref result, ref damage);
  1046. //FormatLog(CommonLang.Log.LoggerLevel.INFO, "--【{0}】对目标【{1}】使用技能【{2}】效果 = 【{3}】", this.mInfo.Name, hitter.mInfo.Name, prop.SkillTemplateID, damage);
  1047. }
  1048. else if (prop.SkillTemplateID > 0)
  1049. {
  1050. bool isFind = false;
  1051. for (int i = mOnCalDamageLt.Count - 1; i >= 0; --i)
  1052. {
  1053. OnCalDmageHandler hand = mOnCalDamageLt[i];
  1054. //技能ID匹配时才执行回调.
  1055. if (hand.skillDamageID == prop.SkillTemplateID || hand.m_skill.SkillID == prop.SkillTemplateID)
  1056. {
  1057. isFind = true;
  1058. bool isEnd = hand.m_cal.Invoke(this, hitter, source, hand.m_skill, ref result, ref damage);
  1059. //FormatLog(CommonLang.Log.LoggerLevel.INFO, "【{0}】对目标【{1}】使用技能【{2}】效果 = 【{3}】", this.mInfo.Name, hitter.mInfo.Name, prop.SkillTemplateID, damage);
  1060. if (isEnd) { break; }
  1061. }
  1062. }
  1063. if(!isFind)
  1064. {
  1065. log.Error("配置监听事件异常--场景:" + this.mUnit.Parent.GetSceneID() + ", 唯一ID" + this.mUnit.PlayerUUID + ", 伤害ID:" + prop.SkillTemplateID
  1066. + ", 异常信息:" + JSGModule.GetAttackSourceDes(source) + ", 单位ID:" + this.mUnit.Info.ID + ", 技能监听:"
  1067. + mOnCalDamageLt.Count + ", 血量:" + this.mUnit.CurrentHP + ", 状态:" + this.mUnit.IsActive + ", " + this.GetDamageListens());
  1068. }
  1069. }
  1070. else if(prop.SkillTemplateID == 0)
  1071. {
  1072. log.Error("配置监听事件为0, 场景:" + this.mUnit.Parent.GetSceneID() + ", 唯一ID" + this.mUnit.PlayerUUID + ", 伤害ID: " + prop.SkillTemplateID
  1073. + ", " + JSGModule.GetAttackSourceDes(source));
  1074. }
  1075. return damage;
  1076. }
  1077. private string GetDamageListens()
  1078. {
  1079. string dmgList = "";
  1080. for (int i = mOnCalDamageLt.Count - 1; i >= 0; --i)
  1081. {
  1082. dmgList = dmgList + mOnCalDamageLt[i].skillDamageID + "#";
  1083. }
  1084. return dmgList;
  1085. }
  1086. /// <summary>
  1087. /// 分发BUFF相关事件.
  1088. /// </summary>
  1089. /// <param name="buff"></param>
  1090. /// <param name="type"></param>
  1091. /// <param name="result"></param>
  1092. /// <returns></returns>
  1093. private bool DispatchBuffEvent(InstanceUnit.BuffState buff, BuffEventType type, string result)
  1094. {
  1095. for (int i = mOnBuffEventLt.Count - 1; i >= 0; --i)
  1096. {
  1097. OnBuffEventHandler tg = mOnBuffEventLt[i];
  1098. if (tg.m_type == type)
  1099. {
  1100. tg.m_tg.Invoke(this, buff, result, tg.m_skill);
  1101. }
  1102. }
  1103. return true;
  1104. }
  1105. /// <summary>
  1106. /// 派发获得攻击单位事件.
  1107. /// </summary>
  1108. /// <param name="unit"></param>
  1109. /// <returns></returns>
  1110. private XmdsVirtual DispatchGetAtkUnitEvent(XmdsVirtual unit)
  1111. {
  1112. XmdsVirtual ret = unit;
  1113. if (this.mUnit.IsActive)
  1114. {
  1115. for (int i = mOnGetAtkTargetLt.Count - 1; i >= 0; --i)
  1116. {
  1117. OnGetAtkTargetHandler hitend = mOnGetAtkTargetLt[i];
  1118. ret = hitend.m_hand.Invoke(unit, hitend.m_skill);
  1119. }
  1120. }
  1121. return ret;
  1122. }
  1123. /// <summary>
  1124. /// 玩家离开怪物范围,mOnGetAtkTargetLt清掉
  1125. /// </summary>
  1126. /// <param name="unit"></param>
  1127. /// <returns></returns>
  1128. public void forceRemoveAtkTarget()
  1129. {
  1130. mOnGetAtkTargetLt.Clear();
  1131. }
  1132. /// <summary>
  1133. /// 派发技能伤害参数事件.
  1134. /// </summary>
  1135. /// <param name="skillDamagePer"></param>
  1136. /// <param name="skillDamageMod"></param>
  1137. /// <param name="attacker"></param>
  1138. /// <param name="hitter"></param>
  1139. /// <param name="source"></param>
  1140. public void DispatchSkillDamageEvent(XmdsVirtual attacker,XmdsVirtual hitter, AttackSource source)
  1141. {
  1142. for (int i = mOnGetSkillDamageInfoLt.Count - 1; i >= 0; --i)
  1143. {
  1144. OnGetSkillDamageInfo hitend = mOnGetSkillDamageInfoLt[i];
  1145. hitend.m_hand.Invoke(attacker, hitter, ref source, hitend.m_skill);
  1146. }
  1147. }
  1148. /// <summary>
  1149. /// 派发技能结束事件.
  1150. /// </summary>
  1151. /// <param name="owner"></param>
  1152. /// <param name="state"></param>
  1153. private void DispatchStateSkillEndEvent(XmdsVirtual owner, InstanceUnit.StateSkill state)
  1154. {
  1155. for (int i = 0; i < mOnStateSkillEndLt.Count; i++)
  1156. {
  1157. OnStateSkillEnd hitend = mOnStateSkillEndLt[i];
  1158. if (hitend.mListenAll || hitend.m_skill == null)
  1159. {
  1160. hitend.m_hand.Invoke(owner, state, hitend.m_skill);
  1161. }
  1162. else if (hitend.m_skill.SkillID == state.SkillData.ID)
  1163. {
  1164. hitend.m_hand.Invoke(owner, state, hitend.m_skill);
  1165. }
  1166. }
  1167. }
  1168. /// <summary>
  1169. /// 分发技能施放事件.
  1170. /// </summary>
  1171. /// <param name="st"></param>
  1172. private void DispatchTryLaunchSkillEvent(ref InstanceUnit.SkillState skill, ref bool result, ref InstanceUnit.LaunchSkillParam param)
  1173. {
  1174. bool ret = true;
  1175. for (int i = 0; i < mOnTryLaunchSkillLt.Count; i++)
  1176. {
  1177. OnTryLaucnSkill hitend = mOnTryLaunchSkillLt[i];
  1178. if (hitend.mListenAll || hitend.m_skill == null || hitend.m_skill.SkillID == skill.ID) //是否监听所有技能.
  1179. {
  1180. ret = hitend.m_hand.Invoke(hitend.m_skill, ref skill, this, ref param);
  1181. if (ret == false)
  1182. {
  1183. break;
  1184. }
  1185. }
  1186. }
  1187. result = ret;
  1188. }
  1189. /// <summary>
  1190. /// 分发宠物给人的技能施放事件.
  1191. /// </summary>
  1192. /// <param name="st"></param>
  1193. public bool DispatchTriggerPetSkillEvent(ref InstanceUnit.SkillState skill, ref InstanceUnit.LaunchSkillParam param)
  1194. {
  1195. for (int i = 0; i < mOnTriggerPetSkillLt.Count; i++)
  1196. {
  1197. OnTriggerPetSkill hitend = mOnTriggerPetSkillLt[i];
  1198. if (hitend.mListenAll || hitend.m_skill == null|| hitend.m_skill.SkillID == skill.ID) //是否监听所有技能.
  1199. {
  1200. if (hitend.m_hand.Invoke(hitend.m_skill, ref skill, this, ref param))
  1201. {
  1202. return true;
  1203. }
  1204. }
  1205. }
  1206. return false;
  1207. }
  1208. /// <summary>
  1209. /// 派发是否能添加BUFF事件.k
  1210. /// </summary>
  1211. /// <param name="template"></param>
  1212. /// <param name="hitter"></param>
  1213. /// <param name="result"></param>
  1214. private void DispatchTryAddBuffEvent(ref BuffTemplate template, XmdsVirtual hitter, ref bool result)
  1215. {
  1216. bool ret = true;
  1217. for (int i = mOnTryAddBuffLt.Count - 1; i >= 0; --i)
  1218. {
  1219. OnTryAddBuff hitend = mOnTryAddBuffLt[i];
  1220. ret = hitend.m_hand.Invoke(ref template, this, hitter, hitend.m_skill);
  1221. if (ret == false)
  1222. {
  1223. break;
  1224. }
  1225. }
  1226. result = ret;
  1227. }
  1228. /// <summary>
  1229. /// 派发移除buff
  1230. /// </summary>
  1231. /// <param name="template"></param>
  1232. /// <param name="hitter"></param>
  1233. /// <param name="result"></param>
  1234. private void DispatchRemoveBuffEvent(BuffTemplate template, XmdsVirtual player, BuffRemoveType type)
  1235. {
  1236. for (int i = mOnRemoveBuffLt.Count - 1; i >= 0; --i)
  1237. {
  1238. OnRemoveBuff hitend = mOnRemoveBuffLt[i];
  1239. if(hitend.mListenAll || hitend.buffID == template.ID)
  1240. {
  1241. if (hitend.m_hand.Invoke(ref template, this, type))
  1242. {
  1243. return;
  1244. }
  1245. }
  1246. }
  1247. }
  1248. /// <summary>
  1249. /// 派发添加BUFF事件.k
  1250. /// </summary>
  1251. /// <param name="template"></param>
  1252. /// <param name="hitter"></param>
  1253. /// <param name="result"></param>
  1254. //private void DispatchSendBuffEvent(BuffTemplate template, XmdsVirtual hitter)
  1255. // {
  1256. // for (int i = mOnSendBuffEvent.Count - 1; i >= 0; --i)
  1257. // {
  1258. // OnSendBuffEvent hitend = mOnSendBuffEvent[i];
  1259. // if(hitend.listenBuffID == 0 || hitend.listenBuffID == template.ID)
  1260. // {
  1261. // hitend.m_hand.Invoke(template, this, hitter);
  1262. // }
  1263. // }
  1264. // }
  1265. /** 分发技能被打断事件(暂时只有移动) */
  1266. public void DispatchSkillBlockEvent(InstanceUnit.StateSkill skill, InstanceUnit.State newState)
  1267. {
  1268. for (int i = mOnSkillBlockList.Count - 1; i >= 0; --i)
  1269. {
  1270. OnSkillBlockEvnet hitend = mOnSkillBlockList[i];
  1271. if (hitend.m_skill == null || skill.SkillData.TemplateID == hitend.m_skill.SkillID)
  1272. {
  1273. if(hitend.m_hand.Invoke(this, skill, newState))
  1274. {
  1275. break;
  1276. }
  1277. }
  1278. }
  1279. }
  1280. /** 分发加血事件 */
  1281. public void DispatchAddOtherHPEvent(int hp, InstanceUnit hitter, out int finalHP)
  1282. {
  1283. finalHP = hp;
  1284. for (int i = mAddOtherHPList.Count - 1; i >= 0; --i)
  1285. {
  1286. OnAddOtherHPEvnet hitend = mAddOtherHPList[i];
  1287. if (hitend.m_hand.Invoke(hp, this.mUnit, hitter, out finalHP))
  1288. {
  1289. break;
  1290. }
  1291. }
  1292. }
  1293. /** 分发宠物承担主人伤害事件 */
  1294. public int DispatchShareMasterDmgEvent(int shareDmg, InstanceUnit sender)
  1295. {
  1296. bool isEndDispatch = false;
  1297. for (int i = mShareMasterDmgList.Count - 1; i >= 0; --i)
  1298. {
  1299. OnShareMasterDmgEvent hitend = mShareMasterDmgList[i];
  1300. shareDmg = hitend.m_hand.Invoke(shareDmg, sender, this.mUnit, hitend.m_skill, ref isEndDispatch);
  1301. if (isEndDispatch)
  1302. {
  1303. break;
  1304. }
  1305. }
  1306. return shareDmg;
  1307. }
  1308. /** 分发扣定力事件 */
  1309. public void DispatchAddMPEvent(int mp, InstanceUnit hitter, out int finalMP, AttackSource source)
  1310. {
  1311. finalMP = mp;
  1312. for (int i = mReduceMPList.Count - 1; i >= 0; --i)
  1313. {
  1314. OnReduceOtherMpEvnet hitend = mReduceMPList[i];
  1315. if (hitend.m_hand.Invoke(mp, this.mUnit, hitter, out finalMP, source))
  1316. {
  1317. break;
  1318. }
  1319. }
  1320. }
  1321. /** 分发获得卡牌珠事件 */
  1322. public bool DispatchTryGetCardBallEvent(XmdsVirtual player, CreateCardBallSource type, CardType cardType)
  1323. {
  1324. for (int i = mTryAddCardBallList.Count - 1; i >= 0; --i)
  1325. {
  1326. OnTryAddCardBallEvent hitend = mTryAddCardBallList[i];
  1327. if (hitend.mListenAll || hitend.mType == type)
  1328. {
  1329. if(!hitend.m_hand.Invoke(this, type, cardType))
  1330. {
  1331. return false;
  1332. }
  1333. }
  1334. }
  1335. return true;
  1336. }
  1337. /** 分发释放卡牌技能事件 */
  1338. public bool DispatchTriggerCardSkillEvent(XmdsVirtual player, XmdsVirtual hitter, CardType cardType, int sameNums)
  1339. {
  1340. for (int i = mTriggerCardSkillList.Count - 1; i >= 0; --i)
  1341. {
  1342. OnTriggerCardSkillEvent hitend = mTriggerCardSkillList[i];
  1343. if (hitend.mListenAll || hitend.mPointCardType == cardType)
  1344. {
  1345. if (!hitend.m_hand.Invoke(this, hitter, hitend.m_skill, cardType, sameNums))
  1346. {
  1347. return false;
  1348. }
  1349. }
  1350. }
  1351. return true;
  1352. }
  1353. /** 分发释放卡牌技能事件 */
  1354. public bool DispatchKillOtherEvent(IVirtualUnit attacker, IVirtualUnit deader)
  1355. {
  1356. for (int i = mKillOtherList.Count - 1; i >= 0; --i)
  1357. {
  1358. OnKillOtherUnitEvent hitend = mKillOtherList[i];
  1359. if (deader.GetMaType() >= hitend.maType)
  1360. {
  1361. if (!hitend.m_hand.Invoke(attacker as XmdsVirtual, deader as XmdsVirtual, hitend.m_skill))
  1362. {
  1363. return false;
  1364. }
  1365. }
  1366. }
  1367. return true;
  1368. }
  1369. public void SetSkillActive(int skillTemplateID, bool active, bool pause_on_deactive = false)
  1370. {
  1371. if (this.mSkillHelper != null && this.mSkillHelper.mActiveSkills != null)
  1372. {
  1373. for (int i = 0; i < this.mSkillHelper.mActiveSkills.Count; i++)
  1374. {
  1375. UnitSkill skillInfo = this.mSkillHelper.mActiveSkills[i];
  1376. if(skillInfo != null && skillInfo.SkillID == skillTemplateID)
  1377. {
  1378. skillInfo.IsActive = active;
  1379. }
  1380. }
  1381. }
  1382. }
  1383. /// <summary>
  1384. /// 监听重定向spell.
  1385. /// </summary>
  1386. /// <param name="spt"></param>
  1387. private void DispatchTrySendSpellEvent(LaunchSpell launch, ref SpellTemplate spt, out JSGCreateSpellData createData, ref float startX, ref float startY)
  1388. {
  1389. createData = null;
  1390. for (int i = mOnTrySendSpellLt.Count - 1; i >= 0; --i)
  1391. {
  1392. OnTrySendSpell hitend = mOnTrySendSpellLt[i];
  1393. // 填了技能id,就只发送技能id=法术id的法术
  1394. bool process = hitend.mListenAll;
  1395. if(!process)
  1396. {
  1397. process = (hitend.mListenSpellId > 0) ? (hitend.mListenSpellId == launch.SpellID) : (hitend.m_skill.SkillID == spt.TemplateID);
  1398. }
  1399. if (process)
  1400. {
  1401. if(createData == null)
  1402. {
  1403. createData = new JSGCreateSpellData();
  1404. }
  1405. hitend.m_hand.Invoke(hitend.m_skill, this, launch, ref spt, ref createData, ref startX, ref startY);
  1406. }
  1407. }
  1408. }
  1409. /// <summary>
  1410. /// 监听spell释放完毕
  1411. /// </summary>
  1412. /// <param name="spt"></param>
  1413. public void DispatchSendSpellOverEvent(LaunchSpell launch, SpellTemplate spt, float startX, float startY)
  1414. {
  1415. for (int i = mSendSpellOverLt.Count - 1; i >= 0; --i)
  1416. {
  1417. OnSendSpellOverEvent hitend = mSendSpellOverLt[i];
  1418. // 填了技能id,就只发送技能id=法术id的法术
  1419. if (hitend.mListenAll || hitend.mListSpellId == spt.TemplateID)
  1420. {
  1421. hitend.m_hand.Invoke(launch, this, spt, hitend.m_skill, startX, startY);
  1422. }
  1423. }
  1424. }
  1425. private void DispatchCalThreatValueEvent(XmdsVirtual hitter, AttackSource source, ref AtkResult result)
  1426. {
  1427. for (int i = 0; i < mOnCalThreatValueLt.Count; i++)
  1428. {
  1429. OnCalThreatValue hitend = mOnCalThreatValueLt[i];
  1430. if (hitend.mListenAll || hitend.m_skill == null || hitend.m_skill.SkillID == ((source.Attack.Properties) as XmdsAttackProperties).SkillTemplateID)
  1431. {
  1432. hitend.m_hand.Invoke(this, hitter, source, hitend.m_skill, ref result);
  1433. }
  1434. }
  1435. }
  1436. #endregion
  1437. /// <summary>
  1438. /// 清理注册信息.
  1439. /// </summary>
  1440. public void ClearRegistEvent()
  1441. {
  1442. mHandleMap.Clear();
  1443. mOnHitOtherLt.Clear();
  1444. mOnHitDamageLt.Clear();
  1445. mOnBuffEventLt.Clear();
  1446. mOnCalDamageLt.Clear();
  1447. mOnLaunchSkillOverLt.Clear();
  1448. mOnGetAtkTargetLt.Clear();
  1449. mOnGetSkillDamageInfoLt.Clear();
  1450. mOnStateSkillEndLt.Clear();
  1451. mOnTryAddBuffLt.Clear();
  1452. //mOnSendBuffEvent.Clear();
  1453. mOnTrySendSpellLt.Clear();
  1454. mSendSpellOverLt.Clear();
  1455. mOnTryLaunchSkillLt.Clear();
  1456. mOnTriggerPetSkillLt.Clear();
  1457. mOnCalThreatValueLt.Clear();
  1458. mOnSkillBlockList.Clear();
  1459. mAddOtherHPList.Clear();
  1460. this.mOnRemoveBuffLt.Clear();
  1461. this.mTryAddCardBallList.Clear();
  1462. this.mReduceMPList.Clear();
  1463. this.mTriggerCardSkillList.Clear();
  1464. this.mShareMasterDmgList.Clear();
  1465. this.mKillOtherList.Clear();
  1466. mHandleUUID = 0;
  1467. }
  1468. /// <summary>
  1469. /// 删除技能相关事件.
  1470. /// </summary>
  1471. /// <param name="skillID"></param>
  1472. public void RemoveEventBySkillID(int skillID)
  1473. {
  1474. try
  1475. {
  1476. using (var removeList = ListObjectPool<int>.AllocAutoRelease())
  1477. {
  1478. foreach (KeyValuePair<int, IHandle> pair in mHandleMap)
  1479. {
  1480. if (pair.Value != null && pair.Value.m_skill != null && skillID == pair.Value.m_skill.SkillID)
  1481. {
  1482. removeList.Add(pair.Key);
  1483. }
  1484. }
  1485. for (int i = 0; i < removeList.Count; i++)
  1486. {
  1487. RemoveEventByUUID(removeList[i]);
  1488. }
  1489. }
  1490. }
  1491. catch (Exception error)
  1492. {
  1493. throw new Exception(error.StackTrace);
  1494. }
  1495. }
  1496. private void RemoveEventByUUID(int uuid)
  1497. {
  1498. IHandle handle = null;
  1499. if (mHandleMap.TryGetValue(uuid, out handle))
  1500. {
  1501. bool result = false;
  1502. if (handle is OnHitHandler)
  1503. {
  1504. bool result1 = UnRegistOnHitOther(uuid);
  1505. bool result2 = UnRegistOnHitDamage(uuid);
  1506. result = result1 | result2;
  1507. }
  1508. else if (handle is OnBuffEventHandler)
  1509. {
  1510. result = UnRegistBuffEvent(uuid);
  1511. }
  1512. else if (handle is OnCalDmageHandler)
  1513. {
  1514. result = UnRegistCalDamage(uuid);
  1515. }
  1516. else if (handle is OnLaunchSkillOverHandler)
  1517. {
  1518. result = UnRegistLaunchSkillOver(uuid);
  1519. }
  1520. else if (handle is OnGetAtkTargetHandler)
  1521. {
  1522. result = UnRegistGetAtkTarget(uuid);
  1523. }
  1524. else if (handle is OnGetSkillDamageInfo)
  1525. {
  1526. result = UnRegistGetSkillDamageInfo(uuid);
  1527. }
  1528. else if(handle is OnStateSkillEnd)
  1529. {
  1530. result = UnRegistStateSkillEndEvent(uuid);
  1531. }
  1532. else if (handle is OnTryAddBuff)
  1533. {
  1534. result = UnRegistTryAddBuffEvent(uuid);
  1535. }
  1536. else if(handle is OnRemoveBuff)
  1537. {
  1538. result = UnRegistRemoveBuffEvent(uuid);
  1539. }
  1540. else if(handle is OnSendSpellOverEvent)
  1541. {
  1542. result = UnRegistSendSpellOverEvent(uuid);
  1543. }
  1544. else if (handle is OnTrySendSpell)
  1545. {
  1546. result = UnRegistTrySendSpellEvent(uuid);
  1547. }
  1548. else if (handle is OnTryLaucnSkill)
  1549. {
  1550. result = UnRegistTryLaunchSkillEvent(uuid);
  1551. }
  1552. else if (handle is OnTriggerPetSkill)
  1553. {
  1554. result = UnRegistTriggerPetSkillEvent(uuid);
  1555. }
  1556. else if (handle is OnCalThreatValue)
  1557. {
  1558. result = UnRegistCalThreatValue(uuid);
  1559. }
  1560. else if(handle is OnSkillBlockEvnet)
  1561. {
  1562. result = UnRegistSkillBlockEvent(uuid);
  1563. }
  1564. else if(handle is OnAddOtherHPEvnet)
  1565. {
  1566. result = UnRegistAddOtherHPEvent(uuid);
  1567. }
  1568. else if(handle is OnReduceOtherMpEvnet)
  1569. {
  1570. result = UnRegistReduceOtherMpEvent(uuid);
  1571. }
  1572. else if(handle is OnTryAddCardBallEvent)
  1573. {
  1574. result = UnRegistTryAddCardBallEvent(uuid);
  1575. }
  1576. else if(handle is OnTriggerCardSkillEvent)
  1577. {
  1578. result = UnRegistTriggerCardSkillEvent(uuid);
  1579. }
  1580. else if(handle is OnShareMasterDmgEvent)
  1581. {
  1582. result = UnRegistShareMasterDmgEvent(uuid);
  1583. }
  1584. else if (handle is OnKillOtherUnitEvent)
  1585. {
  1586. result = UnRegistKillOtherEvent(uuid);
  1587. }
  1588. else
  1589. {
  1590. log.Error("RemoveEventByUUID not process type: " + handle);
  1591. }
  1592. }
  1593. }
  1594. }
  1595. }