12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889 |
- 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;
- using XmdsCommonServer.Plugin.JSGXmdsModule;
- 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 int startDmgData; //开始计算伤害时的值
- 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)
- {
- hitend.startDmgData = 0;
- continue;
- }
- }
-
- damage = hitend.m_hit.Invoke(damage, target, this, source, ref result, damageType, hitend.m_skill, ref isEndDispatch);
- hitend.startDmgData = (int)damage;
- if (isEndDispatch)
- {
- break;
- }
- }
- //检测伤害输出异常
- if(JSGXmdsHackerModule.CheckAndPrintDmgWarn("HitOther-", this, target, sourceDmg, damage, source))
- {
- int startDmg = (int)sourceDmg;
- for (int i = mOnHitOtherLt.Count - 1; i >= 0; --i)
- {
- if(mOnHitOtherLt[i].startDmgData > 0 && startDmg != mOnHitOtherLt[i].startDmgData)
- {
- float rate = mOnHitOtherLt[i].startDmgData * 1.0f / startDmg;
- log.Warn("伤害细则:" + mOnHitOtherLt[i].m_hit.Target + ", " + startDmg + " -> " + mOnHitOtherLt[i].startDmgData + ", 倍率:" + rate);
- startDmg = mOnHitOtherLt[i].startDmgData;
- }
- }
- }
- }
- return damage;
- }
- /// <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);
- JSGXmdsHackerModule.CheckAndPrintDmgWarn("HitDamage", attacker, this, sourceDmg, damage, source);
- 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" + this.mUnit.PlayerUUID + ", 伤害ID:" + prop.SkillTemplateID
- + ", 异常信息:" + JSGModule.GetAttackSourceDes(source) + ", 单位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() + ", 唯一ID" + this.mUnit.PlayerUUID + ", 伤害ID: " + prop.SkillTemplateID
- + ", " + JSGModule.GetAttackSourceDes(source));
-
- }
- 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 int DispatchAddOtherHPEvent(int hp, InstanceUnit hitter, AttackSource source)
- {
- int finalHP = hp;
- for (int i = mAddOtherHPList.Count - 1; i >= 0; --i)
- {
- OnAddOtherHPEvnet hitend = mAddOtherHPList[i];
- if(hp > 0)
- {
- //扣血
- if (hitend.m_hand.Invoke(hp, hitter, this.mUnit, source, out finalHP))
- {
- break;
- }
- }
- else
- {
- //加血
- if (hitend.m_hand.Invoke(hp, this.mUnit, hitter, source, out finalHP))
- {
- break;
- }
- }
-
- }
- return finalHP;
- }
- /** 分发宠物承担主人伤害事件 */
- 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);
- }
- }
- }
- }
- }
|