XmdsVirtual.Event.cs 56 KB

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