123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878 |
- using CommonAI.Zone;
- using CommonAI.Zone.Instance;
- using CommonAI.Zone.Formula;
- using CommonLang;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using XmdsCommon.Plugin;
- using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
- using CommonAI.Data;
- using XmdsCommonSkill.Plugin.CardSkill;
- using XmdsCommon.JSGModule.Interface;
- using CommonAI.ZoneServer.JSGModule;
- namespace XmdsCommonServer.Plugin
- {
- /// <summary>
- /// FileName: XmdsVirtual.cs
- /// Author: Alex.Yu
- /// Corporation:...
- /// Description:注册事件相关.
- /// DateTime: 2015/6/2 17:38:21
- /// </summary>
- partial class XmdsVirtual
- {
- //OnHitOther//
- readonly private List<OnHitHandler> mOnHitOtherLt = new List<OnHitHandler>();
- //OnHitDamage//
- readonly private List<OnHitHandler> mOnHitDamageLt = new List<OnHitHandler>();
- //OnBuffStart//
- readonly private List<OnBuffEventHandler> mOnBuffEventLt = new List<OnBuffEventHandler>();
- //OnCalDamage//
- readonly private List<OnCalDmageHandler> mOnCalDamageLt = new List<OnCalDmageHandler>();
- //OnLaunchSkillOver//
- readonly private List<OnLaunchSkillOverHandler> mOnLaunchSkillOverLt = new List<OnLaunchSkillOverHandler>();
- //OnGetAtkTarget//
- readonly private List<OnGetAtkTargetHandler> mOnGetAtkTargetLt = new List<OnGetAtkTargetHandler>();
- //OnGetSkillDamageInfo //
- readonly private List<OnGetSkillDamageInfo> mOnGetSkillDamageInfoLt = new List<OnGetSkillDamageInfo>();
- //IStateSkillEnd //
- readonly private List<OnStateSkillEnd> mOnStateSkillEndLt = new List<OnStateSkillEnd>();
- //ITryAddBuffEvent//
- readonly private List<OnTryAddBuff> mOnTryAddBuffLt = new List<OnTryAddBuff>();
- readonly private List<OnRemoveBuff> mOnRemoveBuffLt = new List<OnRemoveBuff>();
- //ISendBuffEvent
- //readonly private List<OnSendBuffEvent> mOnSendBuffEvent = new List<OnSendBuffEvent>();
- readonly private List<OnTrySendSpell> mOnTrySendSpellLt = new List<OnTrySendSpell>();
- readonly private List<OnSendSpellOverEvent> mSendSpellOverLt = new List<OnSendSpellOverEvent>();
- readonly private List<OnTryLaucnSkill> mOnTryLaunchSkillLt = new List<OnTryLaucnSkill>();
- //宠物给予人物的主动技能触发
- readonly private List<OnTriggerPetSkill> mOnTriggerPetSkillLt = new List<OnTriggerPetSkill>();
- //计算仇恨值.
- readonly private List<OnCalThreatValue> mOnCalThreatValueLt = new List<OnCalThreatValue>();
- //技能被打断事件监听
- readonly private List<OnSkillBlockEvnet> mOnSkillBlockList = new List<OnSkillBlockEvnet>();
- //加血事件
- readonly private List<OnAddOtherHPEvnet> mAddOtherHPList = new List<OnAddOtherHPEvnet>();
- //承担伤害监听
- readonly private List<OnShareMasterDmgEvent> mShareMasterDmgList = new List<OnShareMasterDmgEvent>();
- //扣定力
- readonly private List<OnReduceOtherMpEvnet> mReduceMPList = new List<OnReduceOtherMpEvnet>();
- //获得卡牌珠监听
- readonly private List<OnTryAddCardBallEvent> mTryAddCardBallList = new List<OnTryAddCardBallEvent>();
- //释放卡牌技能监听
- readonly private List<OnTriggerCardSkillEvent> mTriggerCardSkillList = new List<OnTriggerCardSkillEvent>();
- //击杀其他单位监听
- readonly private List<OnKillOtherUnitEvent> mKillOtherList = new List<OnKillOtherUnitEvent>();
- private HashMap<int, IHandle> mHandleMap = new HashMap<int, IHandle>();
- private int mHandleUUID = 0;
- public enum BuffEventType
- {
- None,
- Begin,
- End,
- Update,
- Hit,
- }
- public abstract class IHandle
- {
- public readonly GameSkill m_skill;
- public readonly bool mListenAll = false;
- public IHandle(GameSkill skill, bool listenAll)
- {
- this.m_skill = skill;
- this.mListenAll = listenAll;
- }
- }
- public class OnHitHandler : IHandle
- {
- public readonly IOnHit m_hit;
- public readonly bool ListenAllSkill = false;
- public OnHitHandler(IOnHit hit, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hit = hit;
- this.ListenAllSkill = listenAll;
- }
- }
- class OnBuffEventHandler : IHandle
- {
- public readonly IOnBuffEvent m_tg;
- public readonly BuffEventType m_type;
- public OnBuffEventHandler(IOnBuffEvent tg, BuffEventType type, GameSkill skill) : base(skill, true)
- {
- m_tg = tg;
- m_type = type;
- }
- }
- public class OnCalDmageHandler : IHandle
- {
- public readonly ICalDamage m_cal;
- public readonly int skillDamageID;
- public OnCalDmageHandler(ICalDamage tg, GameSkill skill, bool listenAll, int skillDamageID) : base(skill, listenAll)
- {
- m_cal = tg;
- this.skillDamageID = skillDamageID;
- }
- public override string ToString()
- {
- return skillDamageID.ToString();
- }
- }
- class OnLaunchSkillOverHandler : IHandle
- {
- public readonly ILaunchSkillOver m_hand;
- public OnLaunchSkillOverHandler(ILaunchSkillOver tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- }
- }
- class OnGetAtkTargetHandler : IHandle
- {
- public readonly IGetAtkTarget m_hand;
- public OnGetAtkTargetHandler(IGetAtkTarget tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- }
- }
- class OnGetSkillDamageInfo : IHandle
- {
- public readonly IGetSkillDamageInfo m_hand;
- public OnGetSkillDamageInfo(IGetSkillDamageInfo tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- }
- }
- class OnStateSkillEnd : IHandle
- {
- public readonly IStateSkillEnd m_hand;
- public OnStateSkillEnd(IStateSkillEnd tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- }
- }
- class OnTryAddBuff : IHandle
- {
- public readonly ITryAddBuffEvent m_hand;
- public OnTryAddBuff(ITryAddBuffEvent tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- }
- }
- class OnRemoveBuff : IHandle
- {
- public readonly IRemoveBuffEvent m_hand;
- public readonly int buffID;
- public OnRemoveBuff(IRemoveBuffEvent tg, int buffID, bool listenAll) : base(null, listenAll)
- {
- m_hand = tg;
- this.buffID = buffID;
- }
- }
- //class OnSendBuffEvent : IHandle
- // {
- // public readonly int listenBuffID;
- // public readonly ISendBuffEvent m_hand;
- // public OnSendBuffEvent(ISendBuffEvent tg, GameSkill skill, int listenBuffID = 0) : base(skill, false)
- // {
- // m_hand = tg;
- // this.listenBuffID = listenBuffID;
- // }
- // }
- class OnSendSpellOverEvent : IHandle
- {
- public readonly ISendSpellOverEvent m_hand;
- public readonly int mListSpellId;
- public OnSendSpellOverEvent(ISendSpellOverEvent tg, int spellId, GameSkill sk, bool listenAll = false) : base(sk, listenAll)
- {
- m_hand = tg;
- this.mListSpellId = spellId;
- }
- }
- class OnTrySendSpell : IHandle
- {
- public readonly ITrySendSpellEvent m_hand;
- public readonly int mListenSpellId;
- public OnTrySendSpell(ITrySendSpellEvent tg, GameSkill skill, int listenSpellId, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- this.mListenSpellId = listenSpellId;
- }
- }
- class OnTryLaucnSkill : IHandle
- {
- public readonly ITryLaunchSkillEvent m_hand;
- public OnTryLaucnSkill(ITryLaunchSkillEvent tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- }
- }
- class OnTriggerPetSkill : IHandle
- {
- public readonly ITriggerPetSkillEvent m_hand;
- public OnTriggerPetSkill(ITriggerPetSkillEvent tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- }
- }
- class OnCalThreatValue : IHandle
- {
- public readonly ICalThreadValue m_hand;
- public OnCalThreatValue(ICalThreadValue tg, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- m_hand = tg;
- }
- }
- class OnSkillBlockEvnet : IHandle
- {
- public readonly ISkillBlockEvent m_hand;
- public OnSkillBlockEvnet(ISkillBlockEvent handler, GameSkill skill, bool listenAll) : base(skill, listenAll)
- {
- this.m_hand = handler;
- }
- }
- class OnAddOtherHPEvnet : IHandle
- {
- public readonly IAddOtherHPEvent m_hand;
- public OnAddOtherHPEvnet(IAddOtherHPEvent handler, GameSkill skill) : base(skill, true)
- {
- this.m_hand = handler;
-
- }
- }
- protected class OnShareMasterDmgEvent : IHandle
- {
- public readonly IShareMasterDmgEvent m_hand;
- public OnShareMasterDmgEvent(IShareMasterDmgEvent handler, GameSkill skill) : base(skill, true)
- {
- this.m_hand = handler;
- }
- }
- class OnReduceOtherMpEvnet : IHandle
- {
- public readonly IReduceOtherMpEvent m_hand;
- public OnReduceOtherMpEvnet(IReduceOtherMpEvent handler, GameSkill skill) : base(skill, true)
- {
- this.m_hand = handler;
- }
- }
- class OnTryAddCardBallEvent : IHandle
- {
- public readonly CreateCardBallSource mType;
- public readonly ITryAddCardBallEvent m_hand;
- public OnTryAddCardBallEvent(ITryAddCardBallEvent handler, CreateCardBallSource type, bool listenAll = false) : base(null, listenAll)
- {
- this.m_hand = handler;
- this.mType = type;
- }
- }
- class OnTriggerCardSkillEvent : IHandle
- {
- public readonly CardType mPointCardType;
- public readonly ITriggerCardSkillEvent m_hand;
- public OnTriggerCardSkillEvent(ITriggerCardSkillEvent handler, GameSkill info, CardType cardType, bool listenAll = false) : base(info, listenAll)
- {
- this.m_hand = handler;
- this.mPointCardType = cardType;
- }
- }
- class OnKillOtherUnitEvent : IHandle
- {
- public readonly int maType;
- public readonly IOnKillOtherUnitEvent m_hand;
- public OnKillOtherUnitEvent(IOnKillOtherUnitEvent handler, GameSkill info, int type) : base(info, false)
- {
- this.m_hand = handler;
- this.maType = type;
- }
- }
- #region 事件监听.
- public delegate void OnHealEvent(XmdsVirtual attacker, XmdsVirtual hitter, int value, ref AtkResult result);
- public delegate void OnCombatStateChangeEvent(XmdsVirtual unit, bool status);
- /// <summary>
- /// 治愈回调.
- /// </summary>
- public event OnHealEvent OnHealEventHandle;
- /// <summary>
- /// 战斗状态变更.
- /// </summary>
- public event OnCombatStateChangeEvent OnCombatStateChangeHandle
- {
- add { event_OnCombatStateChangeHandle += value; }
- remove { event_OnCombatStateChangeHandle -= value; }
- }
- protected OnCombatStateChangeEvent event_OnCombatStateChangeHandle;
- #endregion
- #region 计算伤害时触发.
- public int RegistCalDamage(ICalDamage cal, GameSkill sk, bool listenAll, int skillDamageID = 0)
- {
- OnCalDmageHandler handle = new OnCalDmageHandler(cal, sk, listenAll, skillDamageID);
- int ret = HandleUUIDCreate();
- mOnCalDamageLt.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistCalDamage(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnCalDmageHandler)
- {
- ret = mOnCalDamageLt.Remove(handle as OnCalDmageHandler);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 单位打到别人时开发.
- /// <summary>
- /// 单位打到别人时触发
- /// </summary>
- /// <param name="hit"></param>
- /// <param name="sk"></param>
- public int RegistOnHitOther(IOnHit hit, GameSkill sk, bool listenAll = false)
- {
- OnHitHandler handle = new OnHitHandler(hit, sk, listenAll);
- int ret = HandleUUIDCreate();
- mOnHitOtherLt.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistOnHitOther(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnHitHandler)
- {
- ret = mOnHitOtherLt.Remove(handle as OnHitHandler);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 单位受到攻击时触发.
- /// <summary>
- /// 单位收到攻击时触发
- /// </summary>
- /// <param name="hit"></param>
- /// <param name="sk"></param>
- public int RegistOnHitDamage(IOnHit hit, GameSkill sk, bool listenAll = false)
- {
- OnHitHandler handle = new OnHitHandler(hit, sk, listenAll);
- mOnHitDamageLt.Add(handle);
- int ret = HandleUUIDCreate();
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistOnHitDamage(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnHitHandler)
- {
- ret = mOnHitDamageLt.Remove(handle as OnHitHandler);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region BUFF触发.
- /// <summary>
- /// 注册监听BUFF相关事件.
- /// </summary>
- /// <param name="tg"></param>
- /// <param name="type"></param>
- /// <param name="sk"></param>
- /// <returns></returns>
- public int RegistBuffEvent(IOnBuffEvent tg, BuffEventType type, GameSkill sk)
- {
- OnBuffEventHandler handle = new OnBuffEventHandler(tg, type, sk);
- mOnBuffEventLt.Add(handle);
- int ret = HandleUUIDCreate();
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistBuffEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnBuffEventHandler)
- {
- ret = mOnBuffEventLt.Remove(handle as OnBuffEventHandler);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 增加BUFF.
- /// <summary>
- /// 注册是否能添加BUFF判断事件.
- /// </summary>
- /// <returns></returns>
- public int RegistTryAddBuffEvent(ITryAddBuffEvent tg, GameSkill sk, bool listenAll = false)
- {
- OnTryAddBuff handle = new OnTryAddBuff(tg, sk, listenAll);
- mOnTryAddBuffLt.Add(handle);
- int ret = HandleUUIDCreate();
- mHandleMap.Add(ret, handle);
- return ret;
- }
- /** 注册给其他玩家添加buff时间 */
- //public int RegistSendBuffEvent(ISendBuffEvent tg, GameSkill sk, int listenBuffID = 0)
- //{
- // OnSendBuffEvent handle = new OnSendBuffEvent(tg, sk, listenBuffID);
- // mOnSendBuffEvent.Add(handle);
- // int ret = HandleUUIDCreate();
- // mHandleMap.Add(ret, handle);
- // return ret;
- //}
- /** 注册给其他玩家添加buff时间 */
- public int RegistRemoveBuffEvent(IRemoveBuffEvent tg, int buffID, bool listenAll = false)
- {
- OnRemoveBuff handle = new OnRemoveBuff(tg, buffID, listenAll);
- mOnRemoveBuffLt.Add(handle);
- int ret = HandleUUIDCreate();
- mHandleMap.Add(ret, handle);
- return ret;
- }
- /// <summary>
- /// 取消注册添加BUFF判断.
- /// </summary>
- /// <returns></returns>
- public bool UnRegistTryAddBuffEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnTryAddBuff)
- {
- ret = mOnTryAddBuffLt.Remove(handle as OnTryAddBuff);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- /// <summary>
- /// 取消发送BUFF监听.
- /// </summary>
- /// <returns></returns>
- //public bool UnRegistSendBuffEvent(int handleUUID)
- //{
- // bool ret = false;
- // IHandle handle = null;
- // if (mHandleMap.TryGetValue(handleUUID, out handle))
- // {
- // if (handle != null && handle is OnSendBuffEvent)
- // {
- // ret = mOnSendBuffEvent.Remove(handle as OnSendBuffEvent);
- // mHandleMap.Remove(handleUUID);
- // }
- // }
- // return ret;
- //}
- /// <summary>
- /// 取消注册添加BUFF判断.
- /// </summary>
- /// <returns></returns>
- public bool UnRegistRemoveBuffEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnRemoveBuff)
- {
- ret = mOnRemoveBuffLt.Remove(handle as OnRemoveBuff);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 注册监听spell重定向.
- public int RegistTrySendSpellEvent(ITrySendSpellEvent tg, GameSkill sk, int listenSpellId = 0, bool listenAll = false)
- {
- OnTrySendSpell handle = new OnTrySendSpell(tg, sk, listenSpellId, listenAll);
- mOnTrySendSpellLt.Add(handle);
- int ret = HandleUUIDCreate();
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistTrySendSpellEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnTrySendSpell)
- {
- ret = mOnTrySendSpellLt.Remove(handle as OnTrySendSpell);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- public int RegistSendSpellOverEvent(ISendSpellOverEvent tg, int spellId, GameSkill sk, bool listAll = false)
- {
- OnSendSpellOverEvent handle = new OnSendSpellOverEvent(tg, spellId, sk, listAll);
- mSendSpellOverLt.Add(handle);
- int ret = HandleUUIDCreate();
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistSendSpellOverEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnSendSpellOverEvent)
- {
- ret = mSendSpellOverLt.Remove(handle as OnSendSpellOverEvent);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 监听技能施放.
- public int RegistTryLaunchSkillEvent(ITryLaunchSkillEvent tg, GameSkill sk, bool listenAllSkill = false)
- {
- OnTryLaucnSkill handle = new OnTryLaucnSkill(tg, sk, listenAllSkill);
- mOnTryLaunchSkillLt.Add(handle);
- int ret = HandleUUIDCreate();
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistTryLaunchSkillEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnTryLaucnSkill)
- {
- ret = mOnTryLaunchSkillLt.Remove(handle as OnTryLaucnSkill);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- //ITriggerPetSkillEvent返回true,结束下层传递
- public int RegistTriggerPetSkillEvent(ITriggerPetSkillEvent tg, GameSkill sk, bool listenAllSkill = false)
- {
- OnTriggerPetSkill handle = new OnTriggerPetSkill(tg, sk, listenAllSkill);
- mOnTriggerPetSkillLt.Add(handle);
- int ret = HandleUUIDCreate();
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistTriggerPetSkillEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnTriggerPetSkill)
- {
- ret = mOnTriggerPetSkillLt.Remove(handle as OnTriggerPetSkill);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 释放完技能后.
- /// <summary>
- /// 注册技能释放完毕的监听.
- /// </summary>
- /// <param name="call"></param>
- /// <param name="sk"></param>
- /// <returns></returns>
- public int RegistLaunchSkillOver(ILaunchSkillOver call, GameSkill sk, bool listenAllSkill = false)
- {
- OnLaunchSkillOverHandler handle = new OnLaunchSkillOverHandler(call, sk, listenAllSkill);
- int ret = HandleUUIDCreate();
- mOnLaunchSkillOverLt.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- /// <summary>
- /// 反注册技能释放完毕的监听.
- /// </summary>
- /// <param name="call"></param>
- /// <param name="sk"></param>
- /// <returns></returns>
- public bool UnRegistLaunchSkillOver(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnLaunchSkillOverHandler)
- {
- ret = mOnLaunchSkillOverLt.Remove(handle as OnLaunchSkillOverHandler);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 获得攻击目标.
- /// <summary>
- /// 注册获取攻击目标监听.
- /// </summary>
- /// <param name="call"></param>
- /// <param name="sk"></param>
- /// <returns></returns>
- public int RegistGetAtkTarget(IGetAtkTarget call, GameSkill sk, bool listenAll)
- {
- OnGetAtkTargetHandler handle = new OnGetAtkTargetHandler(call, sk, listenAll);
- int ret = HandleUUIDCreate();
- mOnGetAtkTargetLt.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- /// <summary>
- /// 反注册获取攻击目标监听.
- /// </summary>
- /// <param name="call"></param>
- /// <param name="sk"></param>
- /// <returns></returns>
- public bool UnRegistGetAtkTarget(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnGetAtkTargetHandler)
- {
- ret = mOnGetAtkTargetLt.Remove(handle as OnGetAtkTargetHandler);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 注册获得技能伤害.
- public int RegistGetSkillDamageInfo(IGetSkillDamageInfo call, GameSkill sk, bool listenAll)
- {
- OnGetSkillDamageInfo handle = new OnGetSkillDamageInfo(call, sk, listenAll);
- int ret = HandleUUIDCreate();
- mOnGetSkillDamageInfoLt.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistGetSkillDamageInfo(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnGetSkillDamageInfo)
- {
- ret = mOnGetSkillDamageInfoLt.Remove(handle as OnGetSkillDamageInfo);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 技能结束监听.
- /// <summary>
- /// 注册技能结束监听.
- /// </summary>
- /// <param name="call"></param>
- /// <param name="sk"></param>
- /// <returns></returns>
- public int RegistStateSkillEndEvent(IStateSkillEnd call, GameSkill sk, bool listenAllSkill)
- {
- OnStateSkillEnd handle = new OnStateSkillEnd(call, sk, listenAllSkill);
- int ret = HandleUUIDCreate();
- mOnStateSkillEndLt.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- /// <summary>
- /// 取消技能结束监听.
- /// </summary>
- /// <param name="handleUUID"></param>
- /// <returns></returns>
- public bool UnRegistStateSkillEndEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnStateSkillEnd)
- {
- ret = mOnStateSkillEndLt.Remove(handle as OnStateSkillEnd);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 计算仇恨值监听.
- public int RegistCalThreatValue(ICalThreadValue call, GameSkill gs, bool listenAllSkill)
- {
- OnCalThreatValue handle = new OnCalThreatValue(call, gs, listenAllSkill);
- int ret = HandleUUIDCreate();
- mOnCalThreatValueLt.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistCalThreatValue(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnCalThreatValue)
- {
- ret = mOnCalThreatValueLt.Remove(handle as OnCalThreatValue);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 技能被打断监听.
- public int RegistSkillBlockEvent(ISkillBlockEvent call, GameSkill gs)
- {
- OnSkillBlockEvnet handle = new OnSkillBlockEvnet(call, gs, true);
- int ret = HandleUUIDCreate();
- mOnSkillBlockList.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistSkillBlockEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnSkillBlockEvnet)
- {
- ret = mOnSkillBlockList.Remove(handle as OnSkillBlockEvnet);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- public int RegistAddOtherHPEvent(IAddOtherHPEvent call, GameSkill gs)
- {
- OnAddOtherHPEvnet handle = new OnAddOtherHPEvnet(call, gs);
- int ret = HandleUUIDCreate();
- mAddOtherHPList.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistAddOtherHPEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnAddOtherHPEvnet)
- {
- ret = mAddOtherHPList.Remove(handle as OnAddOtherHPEvnet);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- public int RegistShareMasterDmgEvent(IShareMasterDmgEvent call, GameSkill gs)
- {
- OnShareMasterDmgEvent handle = new OnShareMasterDmgEvent(call, gs);
- int ret = HandleUUIDCreate();
- mShareMasterDmgList.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistShareMasterDmgEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnShareMasterDmgEvent)
- {
- ret = mShareMasterDmgList.Remove(handle as OnShareMasterDmgEvent);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- public int RegistReduceMPEvent(IReduceOtherMpEvent call, GameSkill gs)
- {
- OnReduceOtherMpEvnet handle = new OnReduceOtherMpEvnet(call, gs);
- int ret = HandleUUIDCreate();
- mReduceMPList.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistReduceOtherMpEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnReduceOtherMpEvnet)
- {
- ret = mReduceMPList.Remove(handle as OnReduceOtherMpEvnet);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- public int RegistTryAddCardBallEvent(ITryAddCardBallEvent call, CreateCardBallSource type, bool listenAll = false)
- {
- OnTryAddCardBallEvent handle = new OnTryAddCardBallEvent(call, type, listenAll);
- int ret = HandleUUIDCreate();
- mTryAddCardBallList.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistTryAddCardBallEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnTryAddCardBallEvent)
- {
- ret = mTryAddCardBallList.Remove(handle as OnTryAddCardBallEvent);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- public int RegistTriggerCardSkillEvent(ITriggerCardSkillEvent call, GameSkill info, CardType cardType, bool listenAll = false)
- {
- OnTriggerCardSkillEvent handle = new OnTriggerCardSkillEvent(call, info, cardType, listenAll);
- int ret = HandleUUIDCreate();
- mTriggerCardSkillList.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistTriggerCardSkillEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnTriggerCardSkillEvent)
- {
- ret = mTriggerCardSkillList.Remove(handle as OnTriggerCardSkillEvent);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- public int RegistKillOtherEvent(IOnKillOtherUnitEvent call, GameSkill info, int monsterType)
- {
- OnKillOtherUnitEvent handle = new OnKillOtherUnitEvent(call, info, monsterType);
- int ret = HandleUUIDCreate();
- mKillOtherList.Add(handle);
- mHandleMap.Add(ret, handle);
- return ret;
- }
- public bool UnRegistKillOtherEvent(int handleUUID)
- {
- bool ret = false;
- IHandle handle = null;
- if (mHandleMap.TryGetValue(handleUUID, out handle))
- {
- if (handle != null && handle is OnKillOtherUnitEvent)
- {
- ret = mKillOtherList.Remove(handle as OnKillOtherUnitEvent);
- mHandleMap.Remove(handleUUID);
- }
- }
- return ret;
- }
- #endregion
- #region 事件派发.
- /// <summary>
- /// 分配handleID.
- /// </summary>
- /// <returns></returns>
- private int HandleUUIDCreate()
- {
- return ++mHandleUUID;
- }
- /// <summary>
- ///攻击者监听:打到其他单位.
- /// </summary>
- /// <param name="damage"></param>
- /// <param name="target"></param>
- /// <param name="source"></param>
- /// <returns></returns>
- private float DispatchHitOtherEvent(float damage, XmdsVirtual target, AttackSource source,
- ref XmdsVirtual.AtkResult result, DamageType damageType)
- {
- if (this.mUnit.IsActive)
- {
- float sourceDmg = damage;
- bool isEndDispatch = false;
- for (int i = mOnHitOtherLt.Count - 1; i >= 0; --i)
- {
- OnHitHandler hitend = mOnHitOtherLt[i];
- //伤害单一注册判断
- if (!hitend.ListenAllSkill && hitend.m_skill != null && source.Attack != null)
- {
- XmdsAttackProperties atkProp = source.Attack.Properties as XmdsAttackProperties;
- if (atkProp.SkillTemplateID != hitend.m_skill.SkillID)
- {
- continue;
- }
- }
- damage = hitend.m_hit.Invoke(damage, target, this, source, ref result, damageType, hitend.m_skill, ref isEndDispatch);
- //#if JSG_DMG_LOG
- // this.CheckAndPrintDmgWarn("DispatchHitOtherEvent", this, target, sourceDmg, damage, source);
- //#endif
- if (isEndDispatch)
- {
- break;
- }
- }
- }
- return damage;
- }
- // private void CheckAndPrintDmgWarn(string flag, XmdsVirtual attacker, XmdsVirtual hitter, float sourceDmg, float finalDmg, AttackSource source)
- // {
- // if(source == null || source.Attack == null || source.Attack.Properties.GetAttackID() == XmdsBattleSkill.DefaultSkillScriptID)
- // {
- // return;
- // }
- // int checkValue = (source != null && source.Attack != null && source.Attack.Properties.GetAttackID() / 100 == 1104)
- // ? attacker.mUnit.CurrentHP : attacker.MirrorProp.GetFinalAttack(hitter == null ? false : hitter.mUnit.IsMonster);
- // if (finalDmg / sourceDmg > 5.0f || finalDmg / checkValue > 60)
- // {
- // log.Warn(flag + ", dmg: " + (int)finalDmg + ", src: " + (int)sourceDmg + ", attackerAtk: " + attacker.MirrorProp.MaxAttack + ", "
- // + attacker.MirrorProp.MaxMonsterAttack + ", atkHP:" + mUnit.CurrentHP
- // + ", AttackInfo:[" + attacker.mUnit.Info.ID + ", UUID: " + attacker.mUnit.PlayerUUID
- // + "], hitterInfo:[" + hitter.mUnit.Info.ID + ", UUID: " + hitter.mUnit.PlayerUUID + ", " + JSGModule.GetAttackSourceDes(source));
- // }
- // }
- /// <summary>
- ///受击者监听:受到伤害.
- /// </summary>
- /// <param name="damage"></param>
- /// <param name="attacker"></param>
- /// <param name="source"></param>
- /// skill - 造成伤害的技能信息,可能为空
- /// <returns></returns>
- private float DispatchHitDamageEvent(float damage, XmdsVirtual attacker, AttackSource source,
- ref XmdsVirtual.AtkResult result, DamageType damageType)
- {
- if (this.mUnit.IsActive && mOnHitDamageLt.Count > 0)
- {
- float sourceDmg = damage;
- bool isEndDispatch = false;
- for (int i = mOnHitDamageLt.Count - 1; i >= 0; --i)
- {
- if(i < 0 || i >= mOnHitDamageLt.Count)
- {
- int buffID = source.FromBuff == null ? 0 : source.FromBuff.ID;
- int spellID = source.FromSpell == null ? 0 : source.FromSpell.ID;
- log.Warn("DispatchHitDamageEvent监听改变: " + i + ", " + mOnHitDamageLt.Count + ", BuffID: " + buffID + ", spellID: " + spellID + ", "
- + this.mUnit.PlayerUUID);
- break;
- }
- OnHitHandler hitend = mOnHitDamageLt[i];
- if(!hitend.ListenAllSkill && hitend.m_skill != null && source.Attack != null)
- {
- XmdsAttackProperties atkProp = source.Attack.Properties as XmdsAttackProperties;
- if (atkProp.SkillTemplateID != hitend.m_skill.SkillID)
- {
- continue;
- }
- }
- damage = hitend.m_hit.Invoke(damage, this, attacker, source, ref result, damageType, hitend.m_skill, ref isEndDispatch);
- //#if JSG_DMG_LOG
- // this.CheckAndPrintDmgWarn("DispatchHitDamageEvent", attacker, this, sourceDmg, damage, source);
- //#endif
- if (isEndDispatch)
- {
- break;
- }
- }
- }
- return CUtils.CastInt(damage);//四舍五入
- }
- /// <summary>
- /// 派发技能成功释放事件.
- /// </summary>
- /// <param name="costEnergy"></param>
- /// <param name="attacker"></param>
- /// <param name="state"></param>
- /// <returns></returns>
- private int DispatchLaunchsSkillOverEvent(XmdsVirtual launcher, CommonAI.Zone.Instance.InstanceUnit.SkillState state)
- {
- if (launcher.mUnit.IsActive)
- {
- for (int i = 0; i < mOnLaunchSkillOverLt.Count; i++)
- {
- OnLaunchSkillOverHandler hitend = mOnLaunchSkillOverLt[i];
- if (hitend.mListenAll || hitend.m_skill == null)
- {
- hitend.m_hand.Invoke(hitend.m_skill, launcher, state);
- }
- else if (hitend.m_skill.SkillID == state.ID)
- {
- hitend.m_hand.Invoke(hitend.m_skill, launcher, state);
- }
- }
- }
- return 0;
- }
- /// <summary>
- /// 派发技能造成伤害事件.
- /// </summary>
- /// <param name="hitter"></param>
- /// <param name="source"></param>
- /// <param name="result"></param>
- /// <returns></returns>
- private int DispatchCalDamageEvent(XmdsVirtual hitter, AttackSource source, ref AtkResult result)
- {
- //特殊情况单位是技能触发伤害,则单位必须活着,如果是spell或BUFF无视单位自身状态.
- XmdsAttackProperties prop = (source.Attack.Properties as XmdsAttackProperties);
- if (this.mUnit.IsActive == false && prop.SkillTemplateID != XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills.XmdsBattleSkill.DefaultSkillScriptID)
- {
- //单位已死亡,技能造成的伤害不算.
- return 0;
- }
- int damage = 0;
- if(prop.SkillTemplateID == XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills.XmdsBattleSkill.DefaultSkillScriptID)
- {
- XmdsBattleSkill.mDefDamgageHandler.m_cal.Invoke(this, hitter, source, XmdsBattleSkill.mDefDamgageHandler.m_skill, ref result, ref damage);
- FormatLog(CommonLang.Log.LoggerLevel.INFO, "--【{0}】对目标【{1}】使用技能【{2}】效果 = 【{3}】", this.mInfo.Name, hitter.mInfo.Name, prop.SkillTemplateID, damage);
- }
- else if (prop.SkillTemplateID > 0)
- {
- bool isFind = false;
- for (int i = mOnCalDamageLt.Count - 1; i >= 0; --i)
- {
- OnCalDmageHandler hand = mOnCalDamageLt[i];
- //技能ID匹配时才执行回调.
- if (hand.skillDamageID == prop.SkillTemplateID || hand.m_skill.SkillID == prop.SkillTemplateID)
- {
- isFind = true;
- bool isEnd = hand.m_cal.Invoke(this, hitter, source, hand.m_skill, ref result, ref damage);
- FormatLog(CommonLang.Log.LoggerLevel.INFO, "【{0}】对目标【{1}】使用技能【{2}】效果 = 【{3}】", this.mInfo.Name, hitter.mInfo.Name, prop.SkillTemplateID, damage);
- if (isEnd) { break; }
- }
- }
- if(!isFind)
- {
- log.Error("配置监听事件异常--场景:" + this.mUnit.Parent.GetSceneID() +", 伤害ID:" + prop.SkillTemplateID + ", 异常信息:" +
- (source.FromBuff == null ? "not buff" : "buff:" + source.FromBuff.ID) +(source.FromSkill == null ? ", not skill" : ", skill:" + source.FromSkill.ID)
- + (source.FromSpell == null ? ", not spell" : ", spell:" + source.FromSpell.ID) + ", 单位ID:" + this.mUnit.Info.ID + ", 技能监听:"
- + mOnCalDamageLt.Count + ", 血量:" + this.mUnit.CurrentHP + ", 状态:" + this.mUnit.IsActive + ", " + this.GetDamageListens());
- }
- }
- else if(prop.SkillTemplateID == 0)
- {
- log.Error("配置监听事件为0, 场景:" + this.mUnit.Parent.GetSceneID() + ", " + prop.SkillTemplateID + ", " + (source.FromBuff == null ? "not buff" : "buff:" + source.FromBuff.ID) +
- (source.FromSkill == null ? ", not skill" : ", skill:" + source.FromSkill.ID) + (source.FromSpell == null ? ", not spell" : ", spell:" + source.FromSpell.ID));
-
- }
- return damage;
- }
- private string GetDamageListens()
- {
- string dmgList = "";
- for (int i = mOnCalDamageLt.Count - 1; i >= 0; --i)
- {
- dmgList = dmgList + mOnCalDamageLt[i].skillDamageID + "#";
- }
- return dmgList;
- }
- /// <summary>
- /// 分发BUFF相关事件.
- /// </summary>
- /// <param name="buff"></param>
- /// <param name="type"></param>
- /// <param name="result"></param>
- /// <returns></returns>
- private bool DispatchBuffEvent(InstanceUnit.BuffState buff, BuffEventType type, string result)
- {
- for (int i = mOnBuffEventLt.Count - 1; i >= 0; --i)
- {
- OnBuffEventHandler tg = mOnBuffEventLt[i];
- if (tg.m_type == type)
- {
- tg.m_tg.Invoke(this, buff, result, tg.m_skill);
- }
- }
- return true;
- }
- /// <summary>
- /// 派发获得攻击单位事件.
- /// </summary>
- /// <param name="unit"></param>
- /// <returns></returns>
- private XmdsVirtual DispatchGetAtkUnitEvent(XmdsVirtual unit)
- {
- XmdsVirtual ret = unit;
- if (this.mUnit.IsActive)
- {
- for (int i = mOnGetAtkTargetLt.Count - 1; i >= 0; --i)
- {
- OnGetAtkTargetHandler hitend = mOnGetAtkTargetLt[i];
- ret = hitend.m_hand.Invoke(unit, hitend.m_skill);
- }
- }
- return ret;
- }
- /// <summary>
- /// 玩家离开怪物范围,mOnGetAtkTargetLt清掉
- /// </summary>
- /// <param name="unit"></param>
- /// <returns></returns>
- public void forceRemoveAtkTarget()
- {
- mOnGetAtkTargetLt.Clear();
- }
- /// <summary>
- /// 派发技能伤害参数事件.
- /// </summary>
- /// <param name="skillDamagePer"></param>
- /// <param name="skillDamageMod"></param>
- /// <param name="attacker"></param>
- /// <param name="hitter"></param>
- /// <param name="source"></param>
- public void DispatchSkillDamageEvent(XmdsVirtual attacker,XmdsVirtual hitter, AttackSource source)
- {
- for (int i = mOnGetSkillDamageInfoLt.Count - 1; i >= 0; --i)
- {
- OnGetSkillDamageInfo hitend = mOnGetSkillDamageInfoLt[i];
- hitend.m_hand.Invoke(attacker, hitter, ref source, hitend.m_skill);
- }
- }
- /// <summary>
- /// 派发技能结束事件.
- /// </summary>
- /// <param name="owner"></param>
- /// <param name="state"></param>
- private void DispatchStateSkillEndEvent(XmdsVirtual owner, InstanceUnit.StateSkill state)
- {
- for (int i = 0; i < mOnStateSkillEndLt.Count; i++)
- {
- OnStateSkillEnd hitend = mOnStateSkillEndLt[i];
- if (hitend.mListenAll || hitend.m_skill == null)
- {
- hitend.m_hand.Invoke(owner, state, hitend.m_skill);
- }
- else if (hitend.m_skill.SkillID == state.SkillData.ID)
- {
- hitend.m_hand.Invoke(owner, state, hitend.m_skill);
- }
- }
- }
- /// <summary>
- /// 分发技能施放事件.
- /// </summary>
- /// <param name="st"></param>
- private void DispatchTryLaunchSkillEvent(ref InstanceUnit.SkillState skill, ref bool result, ref InstanceUnit.LaunchSkillParam param)
- {
- bool ret = true;
- for (int i = 0; i < mOnTryLaunchSkillLt.Count; i++)
- {
- OnTryLaucnSkill hitend = mOnTryLaunchSkillLt[i];
- if (hitend.mListenAll || hitend.m_skill == null || hitend.m_skill.SkillID == skill.ID) //是否监听所有技能.
- {
- ret = hitend.m_hand.Invoke(hitend.m_skill, ref skill, this, ref param);
- if (ret == false)
- {
- break;
- }
- }
- }
- result = ret;
- }
- /// <summary>
- /// 分发宠物给人的技能施放事件.
- /// </summary>
- /// <param name="st"></param>
- public bool DispatchTriggerPetSkillEvent(ref InstanceUnit.SkillState skill, ref InstanceUnit.LaunchSkillParam param)
- {
- for (int i = 0; i < mOnTriggerPetSkillLt.Count; i++)
- {
- OnTriggerPetSkill hitend = mOnTriggerPetSkillLt[i];
- if (hitend.mListenAll || hitend.m_skill == null|| hitend.m_skill.SkillID == skill.ID) //是否监听所有技能.
- {
- if (hitend.m_hand.Invoke(hitend.m_skill, ref skill, this, ref param))
- {
- return true;
- }
- }
- }
- return false;
- }
- /// <summary>
- /// 派发是否能添加BUFF事件.k
- /// </summary>
- /// <param name="template"></param>
- /// <param name="hitter"></param>
- /// <param name="result"></param>
- private void DispatchTryAddBuffEvent(ref BuffTemplate template, XmdsVirtual hitter, ref bool result)
- {
- bool ret = true;
- for (int i = mOnTryAddBuffLt.Count - 1; i >= 0; --i)
- {
- OnTryAddBuff hitend = mOnTryAddBuffLt[i];
- ret = hitend.m_hand.Invoke(ref template, this, hitter, hitend.m_skill);
- if (ret == false)
- {
- break;
- }
- }
- result = ret;
- }
- /// <summary>
- /// 派发移除buff
- /// </summary>
- /// <param name="template"></param>
- /// <param name="hitter"></param>
- /// <param name="result"></param>
- private void DispatchRemoveBuffEvent(BuffTemplate template, XmdsVirtual player, BuffRemoveType type)
- {
- for (int i = mOnRemoveBuffLt.Count - 1; i >= 0; --i)
- {
- OnRemoveBuff hitend = mOnRemoveBuffLt[i];
- if(hitend.mListenAll || hitend.buffID == template.ID)
- {
- if (hitend.m_hand.Invoke(ref template, this, type))
- {
- return;
- }
- }
- }
- }
- /// <summary>
- /// 派发添加BUFF事件.k
- /// </summary>
- /// <param name="template"></param>
- /// <param name="hitter"></param>
- /// <param name="result"></param>
- //private void DispatchSendBuffEvent(BuffTemplate template, XmdsVirtual hitter)
- // {
- // for (int i = mOnSendBuffEvent.Count - 1; i >= 0; --i)
- // {
- // OnSendBuffEvent hitend = mOnSendBuffEvent[i];
- // if(hitend.listenBuffID == 0 || hitend.listenBuffID == template.ID)
- // {
- // hitend.m_hand.Invoke(template, this, hitter);
- // }
- // }
- // }
- /** 分发技能被打断事件(暂时只有移动) */
- public void DispatchSkillBlockEvent(InstanceUnit.StateSkill skill, InstanceUnit.State newState)
- {
- for (int i = mOnSkillBlockList.Count - 1; i >= 0; --i)
- {
- OnSkillBlockEvnet hitend = mOnSkillBlockList[i];
- if (hitend.m_skill == null || skill.SkillData.TemplateID == hitend.m_skill.SkillID)
- {
- if(hitend.m_hand.Invoke(this, skill, newState))
- {
- break;
- }
- }
- }
- }
- /** 分发加血事件 */
- public void DispatchAddOtherHPEvent(int hp, InstanceUnit hitter, out int finalHP)
- {
- finalHP = hp;
- for (int i = mAddOtherHPList.Count - 1; i >= 0; --i)
- {
- OnAddOtherHPEvnet hitend = mAddOtherHPList[i];
- if (hitend.m_hand.Invoke(hp, this.mUnit, hitter, out finalHP))
- {
- break;
- }
- }
- }
- /** 分发宠物承担主人伤害事件 */
- public int DispatchShareMasterDmgEvent(int shareDmg, InstanceUnit sender)
- {
- bool isEndDispatch = false;
- for (int i = mShareMasterDmgList.Count - 1; i >= 0; --i)
- {
- OnShareMasterDmgEvent hitend = mShareMasterDmgList[i];
- shareDmg = hitend.m_hand.Invoke(shareDmg, sender, this.mUnit, hitend.m_skill, ref isEndDispatch);
- if (isEndDispatch)
- {
- break;
- }
- }
- return shareDmg;
- }
- /** 分发扣定力事件 */
- public void DispatchAddMPEvent(int mp, InstanceUnit hitter, out int finalMP, AttackSource source)
- {
- finalMP = mp;
- for (int i = mReduceMPList.Count - 1; i >= 0; --i)
- {
- OnReduceOtherMpEvnet hitend = mReduceMPList[i];
- if (hitend.m_hand.Invoke(mp, this.mUnit, hitter, out finalMP, source))
- {
- break;
- }
- }
- }
- /** 分发获得卡牌珠事件 */
- public bool DispatchTryGetCardBallEvent(XmdsVirtual player, CreateCardBallSource type, CardType cardType)
- {
- for (int i = mTryAddCardBallList.Count - 1; i >= 0; --i)
- {
- OnTryAddCardBallEvent hitend = mTryAddCardBallList[i];
- if (hitend.mListenAll || hitend.mType == type)
- {
- if(!hitend.m_hand.Invoke(this, type, cardType))
- {
- return false;
- }
- }
- }
- return true;
- }
- /** 分发释放卡牌技能事件 */
- public bool DispatchTriggerCardSkillEvent(XmdsVirtual player, XmdsVirtual hitter, CardType cardType, int sameNums)
- {
- for (int i = mTriggerCardSkillList.Count - 1; i >= 0; --i)
- {
- OnTriggerCardSkillEvent hitend = mTriggerCardSkillList[i];
- if (hitend.mListenAll || hitend.mPointCardType == cardType)
- {
- if (!hitend.m_hand.Invoke(this, hitter, hitend.m_skill, cardType, sameNums))
- {
- return false;
- }
- }
- }
- return true;
- }
- /** 分发释放卡牌技能事件 */
- public bool DispatchKillOtherEvent(IVirtualUnit attacker, IVirtualUnit deader)
- {
- for (int i = mKillOtherList.Count - 1; i >= 0; --i)
- {
- OnKillOtherUnitEvent hitend = mKillOtherList[i];
- if (deader.GetMaType() >= hitend.maType)
- {
- if (!hitend.m_hand.Invoke(attacker as XmdsVirtual, deader as XmdsVirtual, hitend.m_skill))
- {
- return false;
- }
- }
- }
- return true;
- }
- public void SetSkillActive(int skillTemplateID, bool active, bool pause_on_deactive = false)
- {
- if (this.mSkillHelper != null && this.mSkillHelper.mActiveSkills != null)
- {
- for (int i = 0; i < this.mSkillHelper.mActiveSkills.Count; i++)
- {
- UnitSkill skillInfo = this.mSkillHelper.mActiveSkills[i];
- if(skillInfo != null && skillInfo.SkillID == skillTemplateID)
- {
- skillInfo.IsActive = active;
- }
- }
- }
- }
- /// <summary>
- /// 监听重定向spell.
- /// </summary>
- /// <param name="spt"></param>
- private void DispatchTrySendSpellEvent(LaunchSpell launch, ref SpellTemplate spt, out JSGCreateSpellData createData, ref float startX, ref float startY)
- {
- createData = null;
- for (int i = mOnTrySendSpellLt.Count - 1; i >= 0; --i)
- {
- OnTrySendSpell hitend = mOnTrySendSpellLt[i];
- // 填了技能id,就只发送技能id=法术id的法术
- bool process = hitend.mListenAll;
- if(!process)
- {
- process = (hitend.mListenSpellId > 0) ? (hitend.mListenSpellId == launch.SpellID) : (hitend.m_skill.SkillID == spt.TemplateID);
- }
- if (process)
- {
- if(createData == null)
- {
- createData = new JSGCreateSpellData();
- }
- hitend.m_hand.Invoke(hitend.m_skill, this, launch, ref spt, ref createData, ref startX, ref startY);
- }
- }
- }
- /// <summary>
- /// 监听spell释放完毕
- /// </summary>
- /// <param name="spt"></param>
- public void DispatchSendSpellOverEvent(LaunchSpell launch, SpellTemplate spt, float startX, float startY)
- {
- for (int i = mSendSpellOverLt.Count - 1; i >= 0; --i)
- {
- OnSendSpellOverEvent hitend = mSendSpellOverLt[i];
- // 填了技能id,就只发送技能id=法术id的法术
- if (hitend.mListenAll || hitend.mListSpellId == spt.TemplateID)
- {
- hitend.m_hand.Invoke(launch, this, spt, hitend.m_skill, startX, startY);
- }
- }
- }
- private void DispatchCalThreatValueEvent(XmdsVirtual hitter, AttackSource source, ref AtkResult result)
- {
- for (int i = 0; i < mOnCalThreatValueLt.Count; i++)
- {
- OnCalThreatValue hitend = mOnCalThreatValueLt[i];
- if (hitend.mListenAll || hitend.m_skill == null || hitend.m_skill.SkillID == ((source.Attack.Properties) as XmdsAttackProperties).SkillTemplateID)
- {
- hitend.m_hand.Invoke(this, hitter, source, hitend.m_skill, ref result);
- }
- }
- }
- #endregion
- /// <summary>
- /// 清理注册信息.
- /// </summary>
- public void ClearRegistEvent()
- {
- mHandleMap.Clear();
- mOnHitOtherLt.Clear();
- mOnHitDamageLt.Clear();
- mOnBuffEventLt.Clear();
- mOnCalDamageLt.Clear();
- mOnLaunchSkillOverLt.Clear();
- mOnGetAtkTargetLt.Clear();
- mOnGetSkillDamageInfoLt.Clear();
- mOnStateSkillEndLt.Clear();
- mOnTryAddBuffLt.Clear();
- //mOnSendBuffEvent.Clear();
- mOnTrySendSpellLt.Clear();
- mSendSpellOverLt.Clear();
- mOnTryLaunchSkillLt.Clear();
- mOnTriggerPetSkillLt.Clear();
- mOnCalThreatValueLt.Clear();
- mOnSkillBlockList.Clear();
- mAddOtherHPList.Clear();
- this.mOnRemoveBuffLt.Clear();
- this.mTryAddCardBallList.Clear();
- this.mReduceMPList.Clear();
- this.mTriggerCardSkillList.Clear();
- this.mShareMasterDmgList.Clear();
- this.mKillOtherList.Clear();
- mHandleUUID = 0;
- }
- /// <summary>
- /// 删除技能相关事件.
- /// </summary>
- /// <param name="skillID"></param>
- public void RemoveEventBySkillID(int skillID)
- {
- try
- {
- using (var removeList = ListObjectPool<int>.AllocAutoRelease())
- {
- foreach (KeyValuePair<int, IHandle> pair in mHandleMap)
- {
- if (pair.Value != null && pair.Value.m_skill != null && skillID == pair.Value.m_skill.SkillID)
- {
- removeList.Add(pair.Key);
- }
- }
- for (int i = 0; i < removeList.Count; i++)
- {
- RemoveEventByUUID(removeList[i]);
- }
- }
- }
- catch (Exception error)
- {
- throw new Exception(error.StackTrace);
- }
- }
- private void RemoveEventByUUID(int uuid)
- {
- IHandle handle = null;
- if (mHandleMap.TryGetValue(uuid, out handle))
- {
- bool result = false;
- if (handle is OnHitHandler)
- {
- bool result1 = UnRegistOnHitOther(uuid);
- bool result2 = UnRegistOnHitDamage(uuid);
- result = result1 | result2;
- }
- else if (handle is OnBuffEventHandler)
- {
- result = UnRegistBuffEvent(uuid);
- }
- else if (handle is OnCalDmageHandler)
- {
- result = UnRegistCalDamage(uuid);
- }
- else if (handle is OnLaunchSkillOverHandler)
- {
- result = UnRegistLaunchSkillOver(uuid);
- }
- else if (handle is OnGetAtkTargetHandler)
- {
- result = UnRegistGetAtkTarget(uuid);
- }
- else if (handle is OnGetSkillDamageInfo)
- {
- result = UnRegistGetSkillDamageInfo(uuid);
- }
- else if(handle is OnStateSkillEnd)
- {
- result = UnRegistStateSkillEndEvent(uuid);
- }
- else if (handle is OnTryAddBuff)
- {
- result = UnRegistTryAddBuffEvent(uuid);
- }
- else if(handle is OnRemoveBuff)
- {
- result = UnRegistRemoveBuffEvent(uuid);
- }
- else if(handle is OnSendSpellOverEvent)
- {
- result = UnRegistSendSpellOverEvent(uuid);
- }
- else if (handle is OnTrySendSpell)
- {
- result = UnRegistTrySendSpellEvent(uuid);
- }
-
- else if (handle is OnTryLaucnSkill)
- {
- result = UnRegistTryLaunchSkillEvent(uuid);
- }
- else if (handle is OnTriggerPetSkill)
- {
- result = UnRegistTriggerPetSkillEvent(uuid);
- }
- else if (handle is OnCalThreatValue)
- {
- result = UnRegistCalThreatValue(uuid);
- }
- else if(handle is OnSkillBlockEvnet)
- {
- result = UnRegistSkillBlockEvent(uuid);
- }
- else if(handle is OnAddOtherHPEvnet)
- {
- result = UnRegistAddOtherHPEvent(uuid);
- }
- else if(handle is OnReduceOtherMpEvnet)
- {
- result = UnRegistReduceOtherMpEvent(uuid);
- }
- else if(handle is OnTryAddCardBallEvent)
- {
- result = UnRegistTryAddCardBallEvent(uuid);
- }
- else if(handle is OnTriggerCardSkillEvent)
- {
- result = UnRegistTriggerCardSkillEvent(uuid);
- }
- else if(handle is OnShareMasterDmgEvent)
- {
- result = UnRegistShareMasterDmgEvent(uuid);
- }
- else if (handle is OnKillOtherUnitEvent)
- {
- result = UnRegistKillOtherEvent(uuid);
- }
- else
- {
- log.Error("RemoveEventByUUID not process type: " + handle);
- }
- }
- }
- }
- }
|