EventAdapter.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  1. using CommonAI.Zone.Helper;
  2. using CommonAI.Zone.Instance;
  3. using CommonAI.Zone.Formula;
  4. using CommonAI.Zone.ZoneEditor;
  5. using CommonAI.Zone.ZoneEditor.EventTrigger;
  6. using CommonLang;
  7. using CommonLang.Log;
  8. using CommonLang.Property;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. using System.Text;
  14. using CommonAI.Data;
  15. using CommonAI.ZoneServer.JSGModule;
  16. namespace CommonAI.Zone.EventTrigger
  17. {
  18. //---------------------------------------------------------------------------------
  19. public class EventArguments
  20. {
  21. public InstanceUnit TriggingUnit { get; set; }
  22. public InstanceUnit AttackUnit { get; set; }
  23. public InstanceFlag TriggingFlag { get; set; }
  24. public InstanceItem TriggingItem { get; set; }
  25. public InstanceSpell TriggingSpell { get; set; }
  26. public ItemTemplate TriggingItemTemplate { get; set; }
  27. public BuffTemplate TriggingBuffTemplate { get; set; }
  28. public SkillTemplate TriggingSkillTemplate { get; set; }
  29. public SpellTemplate TriggingSpellTemplate { get; set; }
  30. public string TriggingQuestID { get; set; }
  31. public string TriggingQuestStatusValue { get; set; }
  32. public string TriggingQuestStatusKey { get; set; }
  33. //----------------------------------------------------------------
  34. public ZoneRegion TriggingRegion { get { return TriggingFlag as ZoneRegion; } }
  35. public ZoneWayPoint TriggingPoint { get { return TriggingFlag as ZoneWayPoint; } }
  36. public ZoneDecoration TriggingDecoration { get { return TriggingFlag as ZoneDecoration; } }
  37. public ZoneArea TriggingArea { get { return TriggingFlag as ZoneArea; } }
  38. //----------------------------------------------------------------
  39. public InstanceUnit IteratingUnit { get; set; }
  40. public InstanceItem IteratingItem { get; set; }
  41. public int IteratingInt32 { get; set; }
  42. //----------------------------------------------------------------
  43. public void Set(EventArguments trigger)
  44. {
  45. this.TriggingUnit = trigger.TriggingUnit;
  46. this.TriggingFlag = trigger.TriggingFlag;
  47. this.TriggingItem = trigger.TriggingItem;
  48. this.TriggingSpell = trigger.TriggingSpell;
  49. this.TriggingItemTemplate = trigger.TriggingItemTemplate;
  50. this.TriggingBuffTemplate = trigger.TriggingBuffTemplate;
  51. this.TriggingSkillTemplate = trigger.TriggingSkillTemplate;
  52. this.TriggingSpellTemplate = trigger.TriggingSpellTemplate;
  53. this.TriggingQuestID = trigger.TriggingQuestID;
  54. this.TriggingQuestStatusValue = trigger.TriggingQuestStatusValue;
  55. this.TriggingQuestStatusKey = trigger.TriggingQuestStatusKey;
  56. this.IteratingUnit = trigger.IteratingUnit;
  57. this.IteratingItem = trigger.IteratingItem;
  58. this.IteratingInt32 = trigger.IteratingInt32;
  59. }
  60. public EventArguments Clone()
  61. {
  62. var ret = new EventArguments();
  63. ret.Set(this);
  64. return ret;
  65. }
  66. }
  67. //---------------------------------------------------------------------------------
  68. /// <summary>
  69. /// 抽象值数据接口
  70. /// </summary>
  71. public abstract class IEditorValueAdapter : IDisposable
  72. {
  73. //----------------------------------------------------------------
  74. protected HashMap<string, object> mAttributes = new HashMap<string, object>();
  75. protected HashMap<string, object> mLocalVarMap = new HashMap<string, object>();
  76. //----------------------------------------------------------------
  77. public abstract TemplateManager Templates { get; }
  78. /// <summary>
  79. /// 场景触发器
  80. /// </summary>
  81. public abstract InstanceZone ZoneAPI { get; }
  82. /// <summary>
  83. /// 单位触发器
  84. /// </summary>
  85. public abstract InstanceUnit UnitAPI { get; }
  86. public abstract IEventTriggerCollection Group { get; }
  87. //----------------------------------------------------------------
  88. public abstract bool IsActive { get; set; }
  89. //----------------------------------------------------------------
  90. public void SetLocalVar(string key, object value)
  91. {
  92. if (!string.IsNullOrEmpty(key))
  93. {
  94. mLocalVarMap.Put(key, value);
  95. }
  96. }
  97. public T GetLocalVarAs<T>(string key)
  98. {
  99. if (!string.IsNullOrEmpty(key))
  100. {
  101. try
  102. {
  103. T ret = (T)mLocalVarMap[key];
  104. return ret;
  105. }
  106. catch (Exception er)
  107. {
  108. Console.WriteLine("IEditorValueAdapter : " + key + ", catch: " + er);
  109. }
  110. }
  111. return default(T);
  112. }
  113. public bool IsAttribute(string key)
  114. {
  115. return mAttributes.ContainsKey(key);
  116. }
  117. public void SetAttribute(string key, object value)
  118. {
  119. mAttributes.Put(key, value);
  120. }
  121. public object GetAttribute(string key)
  122. {
  123. return mAttributes.Get(key);
  124. }
  125. public virtual void Dispose()
  126. {
  127. this.mAttributes.Clear();
  128. this.mAttributes = null;
  129. this.mLocalVarMap.Clear();
  130. this.mLocalVarMap = null;
  131. }
  132. }
  133. public interface IEventTriggerCollection : IDisposable
  134. {
  135. void Bind<T>(ICollection<T> events) where T : IEventDataNode;
  136. EventTriggerAdapter GetEditEvent(string name);
  137. void EventActive(string name, EventArguments args);
  138. void EventDeactive(string name, EventArguments args);
  139. }
  140. //---------------------------------------------------------------------------------
  141. /// <summary>
  142. /// 执行事件触发器的数据接口
  143. /// </summary>
  144. public abstract class EventTriggerAdapter : IEditorValueAdapter, IDisposable
  145. {
  146. public static int EXPECT_TEST_AND_DO_ACTION_TIME_MS = 10;
  147. private Logger log = LoggerFactory.GetLogger("ET");
  148. private IEventDataNode mData;
  149. private IEventTriggerCollection mGroup;
  150. private List<TimeTaskMS> mTimes = new List<TimeTaskMS>();
  151. private bool mActive = true;
  152. //-------------------------------------------------------------------------
  153. public string Name { get { return mData.EventName; } }
  154. public override IEventTriggerCollection Group { get { return mGroup; } }
  155. public override TemplateManager Templates { get { return ZoneAPI.Templates; } }
  156. //-------------------------------------------------------------------------
  157. public override bool IsActive
  158. {
  159. get { return mActive; }
  160. set
  161. {
  162. if (mActive != value)
  163. {
  164. mActive = value;
  165. if (mActive)
  166. {
  167. foreach (TimeTaskMS task in mTimes)
  168. {
  169. task.Resume();
  170. }
  171. }
  172. else
  173. {
  174. foreach (TimeTaskMS task in mTimes)
  175. {
  176. task.Pause();
  177. }
  178. }
  179. }
  180. }
  181. }
  182. //-------------------------------------------------------------------------
  183. public EventTriggerAdapter(IEventDataNode evt, IEventTriggerCollection group)
  184. {
  185. this.mData = evt;
  186. this.mGroup = group;
  187. this.mActive = evt.EventIsActive;
  188. }
  189. public override void Dispose()
  190. {
  191. foreach (var t in mData.EventTriggers) { if (t != null) t.Dispose(); }
  192. foreach (var t in mData.EventConditions) { if (t != null) t.Dispose(); }
  193. foreach (var t in mData.EventActions) { if (t != null) t.Dispose(); }
  194. foreach (TimeTaskMS task in mTimes)
  195. {
  196. task.Dispose();
  197. }
  198. mTimes.Clear();
  199. mTimes = null;
  200. if (mOnDisposed != null)
  201. {
  202. mOnDisposed.Invoke(this);
  203. }
  204. mOnDisposed = null;
  205. mOnActionBegin = null;
  206. mOnActionEnd = null;
  207. mData = null;
  208. mGroup = null;
  209. base.Dispose();
  210. }
  211. //-------------------------------------------------------------------------
  212. //-------------------------------------------------------------------------
  213. internal void Start()
  214. {
  215. this.Listen();
  216. if (!mActive)
  217. {
  218. foreach (TimeTaskMS task in mTimes)
  219. {
  220. task.Pause();
  221. }
  222. }
  223. }
  224. private void Listen()
  225. {
  226. var args = new EventArguments();
  227. foreach (AbstractTrigger t in mData.EventTriggers)
  228. {
  229. if (t != null)
  230. {
  231. t.Listen(this, args);
  232. }
  233. }
  234. }
  235. /// <summary>
  236. /// 测试并执行一次触发器
  237. /// </summary>
  238. /// <returns></returns>
  239. public bool TestAndDoAction(EventArguments args)
  240. {
  241. if (!IsActive)
  242. {
  243. return false;
  244. }
  245. int timeUse = 0;
  246. #if JSGProfile
  247. int startTick = System.Environment.TickCount;
  248. bool isTrigger = true;
  249. #endif
  250. Stopwatch stopwatch = Stopwatch.StartNew();
  251. try
  252. {
  253. InitLocalVars(args);
  254. foreach (AbstractCondition c in mData.EventConditions)
  255. {
  256. if (c != null && !c.Test(this, args))
  257. {
  258. #if JSGProfile
  259. isTrigger = false;
  260. #endif
  261. return false;
  262. }
  263. }
  264. }
  265. finally
  266. {
  267. stopwatch.Stop();
  268. PrintStopwatch(stopwatch, "Test");
  269. #if JSGProfile
  270. if (!isTrigger)
  271. {
  272. timeUse = System.Environment.TickCount - startTick;
  273. JSGServerProfile.RecordTrigger(this.ZoneAPI, this.Name, timeUse, false);
  274. }
  275. #endif
  276. }
  277. if (mData.EventDelayTimeMS == 0)
  278. {
  279. RunInternal(args, timeUse);
  280. }
  281. else
  282. {
  283. var argst = args.Clone();
  284. ZoneAPI.AddTimeDelayMS(mData.EventDelayTimeMS, (TimeTaskMS) =>
  285. {
  286. RunInternal(argst, timeUse);
  287. });
  288. }
  289. return true;
  290. }
  291. /// <summary>
  292. /// 重置TaskTimer().
  293. /// </summary>
  294. public void ResetTimeTask()
  295. {
  296. foreach (TimeTaskMS task in mTimes)
  297. {
  298. task.Reset();
  299. }
  300. }
  301. private void RunInternal(EventArguments args, int checkTimeUse)
  302. {
  303. #if JSGProfile
  304. int startTick = System.Environment.TickCount;
  305. #endif
  306. //if(this.Name.Equals("事件重置列表1") || this.Name.Equals("玉重置"))
  307. //{
  308. // int i = 0;
  309. //}
  310. Stopwatch stopwatch = Stopwatch.StartNew();
  311. try
  312. {
  313. if (mOnActionBegin != null)
  314. {
  315. mOnActionBegin.Invoke(this, args);
  316. }
  317. foreach (AbstractAction a in mData.EventActions)
  318. {
  319. if (a != null)
  320. {
  321. a.DoAction(this, args);
  322. }
  323. }
  324. if (mOnActionEnd != null)
  325. {
  326. mOnActionEnd.Invoke(this, args);
  327. }
  328. }
  329. finally
  330. {
  331. stopwatch.Stop();
  332. PrintStopwatch(stopwatch, "RunInternal");
  333. #if JSGProfile
  334. int timeUse = System.Environment.TickCount - startTick + checkTimeUse;
  335. bool needNotice = JSGServerProfile.RecordTrigger(this.ZoneAPI, this.Name, timeUse, true);
  336. if (!"单位受到伤害,发送战报".Equals(this.Name) || GlobalData.BattleReportEventLogCnt == 0)
  337. {
  338. if (GlobalData.GAME_BS_TEST) //内部测试标记开放了
  339. {
  340. log.Warn("--事件: " + this.ZoneAPI.UUID + ", " + this.ZoneAPI.GetSceneID() + ", act:" + this.Name);
  341. }
  342. else if(needNotice)
  343. {
  344. log.Debug("--事件: " + this.ZoneAPI.UUID + ", " + this.ZoneAPI.GetSceneID() + ", act:" + this.Name);
  345. }
  346. }
  347. if ("单位受到伤害,发送战报".Equals(this.Name))
  348. {
  349. GlobalData.BattleReportEventLogCnt += 1;
  350. }
  351. #endif
  352. }
  353. }
  354. public void ProcessActionActive(EventArguments args)
  355. {
  356. if (mOnActionActive != null)
  357. {
  358. mOnActionActive.Invoke(this, args);
  359. }
  360. }
  361. private void PrintStopwatch(Stopwatch stopwatch, string function)
  362. {
  363. if (stopwatch.ElapsedMilliseconds > EXPECT_TEST_AND_DO_ACTION_TIME_MS)
  364. {
  365. log.WarnFormat("[{0}] at scene[{1}] -> event[{2}] : usetime {3} > {4}ms, data{5}",
  366. function,
  367. (ZoneAPI as EditorScene).Data.ToString() + "-" + ZoneAPI.UUID,
  368. mData.EventName,
  369. stopwatch.ElapsedMilliseconds,
  370. EXPECT_TEST_AND_DO_ACTION_TIME_MS,
  371. ZoneAPI.GetInfo());
  372. }
  373. }
  374. //-----------------------------------------------------------------------------------------------
  375. #region _局部变量_
  376. private void InitLocalVars(EventArguments args)
  377. {
  378. mLocalVarMap.Clear();
  379. foreach (LocalVar klv in mData.EventLocalVars)
  380. {
  381. object obj = klv.GetValue(this, args);
  382. mLocalVarMap.Put(klv.Key, obj);
  383. }
  384. }
  385. #endregion
  386. public delegate bool TryPickItemHandler(EventArguments args, InstanceUnit unit, InstanceItem item);
  387. public delegate void TimeTask(EventArguments args);
  388. //-----------------------------------------------------------------------------------------------
  389. #region _时间任务_
  390. internal void listen_TimeDelaySEC(EventArguments args, float TimeSEC)
  391. {
  392. args = args.Clone();
  393. TimeTaskMS task = ZoneAPI.AddTimeDelayMS((int)(TimeSEC * 1000), (time) =>
  394. {
  395. TestAndDoAction(args);
  396. });
  397. this.mTimes.Add(task);
  398. }
  399. internal void listen_TimePeriodicSEC(EventArguments args, float EveryTimeSEC)
  400. {
  401. args = args.Clone();
  402. TimeTaskMS task = ZoneAPI.AddTimePeriodicMS((int)(EveryTimeSEC * 1000), (time) =>
  403. {
  404. TestAndDoAction(args);
  405. });
  406. if (task != null)
  407. {
  408. this.mTimes.Add(task);
  409. }
  410. }
  411. internal void listen_TimeTaskSEC(EventArguments args, float EveryTimeSEC, float DelayTimeSEC, int repeat)
  412. {
  413. args = args.Clone();
  414. TimeTaskMS task = ZoneAPI.AddTimeTask((int)(EveryTimeSEC * 1000), (int)(DelayTimeSEC * 1000), repeat, (time) =>
  415. {
  416. TestAndDoAction(args);
  417. });
  418. this.mTimes.Add(task);
  419. }
  420. internal void listen_TimeTask(EventArguments args, int intervalMS, int delayMS, int repeat, TimeTask handler)
  421. {
  422. args = args.Clone();
  423. TimeTaskMS task = ZoneAPI.AddTimeTask(intervalMS, delayMS, repeat, (t) =>
  424. {
  425. handler(args);
  426. });
  427. this.mTimes.Add(task);
  428. }
  429. #endregion
  430. //-----------------------------------------------------------------------------------------------
  431. //-----------------------------------------------------------------------------------------------
  432. //-----------------------------------------------------------------------------------------------
  433. #region __监听_场景事件__
  434. public void listen_SceneInit(EventArguments args, InstanceZone zone)
  435. {
  436. args = args.Clone();
  437. InstanceZone.InitHandler handler = new InstanceZone.InitHandler((z) =>
  438. {
  439. TestAndDoAction(args);
  440. });
  441. zone.OnInit += handler;
  442. this.OnDisposed += (api) =>
  443. {
  444. zone.OnInit -= handler;
  445. };
  446. }
  447. public void listen_TryPickItem(EventArguments args, InstanceZone zone, TryPickItemHandler action)
  448. {
  449. args = args.Clone();
  450. InstanceZone.TryPickItemHandler handler = new InstanceZone.TryPickItemHandler((z, u, i) =>
  451. {
  452. args.TriggingUnit = u;
  453. args.TriggingItem = i;
  454. args.TriggingItemTemplate = i.Info;
  455. TestAndDoAction(args);
  456. return action.Invoke(args, u, i);
  457. });
  458. zone.OnTryPickItem += handler;
  459. this.OnDisposed += (api) =>
  460. {
  461. zone.OnTryPickItem -= handler;
  462. };
  463. }
  464. public void listen_RecvMessageFromGS(EventArguments args, InstanceZone zone, string msg)
  465. {
  466. args = args.Clone();
  467. InstanceZone.RecvMessageR2BHandler handler = new InstanceZone.RecvMessageR2BHandler((z, m) =>
  468. {
  469. if (m.Message == msg)
  470. {
  471. TestAndDoAction(args);
  472. }
  473. });
  474. zone.OnRecvMessageFromGS += handler;
  475. this.OnDisposed += (api) =>
  476. {
  477. zone.OnRecvMessageFromGS -= handler;
  478. };
  479. }
  480. public void listen_ItemAdded(EventArguments args, InstanceZone zone)
  481. {
  482. args = args.Clone();
  483. InstanceZone.ItemAddedHandler handler = new InstanceZone.ItemAddedHandler((z, i, u) =>
  484. {
  485. args.TriggingItem = i;
  486. args.TriggingItemTemplate = i.Info;
  487. TestAndDoAction(args);
  488. });
  489. zone.OnItemAdded += handler;
  490. this.OnDisposed += (api) =>
  491. {
  492. zone.OnItemAdded -= handler;
  493. };
  494. }
  495. #endregion
  496. //-----------------------------------------------------------------------------------------------
  497. #region __监听_FLAG事件__
  498. public void listen_FlagOpened(EventArguments args, InstanceFlag flag)
  499. {
  500. args = args.Clone();
  501. InstanceFlag.FlagEnabledHandler handler = new InstanceFlag.FlagEnabledHandler((f) =>
  502. {
  503. args.TriggingFlag = f;
  504. TestAndDoAction(args);
  505. });
  506. flag.OnFlagEnabled += handler;
  507. this.OnDisposed += (api) =>
  508. {
  509. flag.OnFlagEnabled -= handler;
  510. };
  511. }
  512. public void listen_FlagClosed(EventArguments args, InstanceFlag flag)
  513. {
  514. args = args.Clone();
  515. InstanceFlag.FlagDisabledHandler handler = new InstanceFlag.FlagDisabledHandler((f) =>
  516. {
  517. args.TriggingFlag = flag;
  518. TestAndDoAction(args);
  519. });
  520. flag.OnFlagDisabled += handler;
  521. this.OnDisposed += (api) =>
  522. {
  523. flag.OnFlagDisabled -= handler;
  524. };
  525. }
  526. public void listen_RegionSpawnOver(EventArguments args, ZoneRegion region)
  527. {
  528. args = args.Clone();
  529. ZoneRegion.SpawnOverHandler handler = new ZoneRegion.SpawnOverHandler((rg) =>
  530. {
  531. args.TriggingFlag = rg;
  532. TestAndDoAction(args);
  533. });
  534. region.OnSpawnOver += handler;
  535. this.OnDisposed += (api) =>
  536. {
  537. region.OnSpawnOver -= handler;
  538. };
  539. }
  540. public void listen_RegionEntered(EventArguments args, ZoneRegion region)
  541. {
  542. args = args.Clone();
  543. ZoneRegion.UnitEnterHandler handler = new ZoneRegion.UnitEnterHandler((rg, u) =>
  544. {
  545. args.TriggingFlag = rg;
  546. args.TriggingUnit = u as InstanceUnit;
  547. TestAndDoAction(args);
  548. });
  549. region.OnUnitEnter += handler;
  550. this.OnDisposed += (api) =>
  551. {
  552. region.OnUnitEnter -= handler;
  553. };
  554. }
  555. public void listen_RegionLeft(EventArguments args, ZoneRegion region)
  556. {
  557. args = args.Clone();
  558. ZoneRegion.UnitLeaveHandler handler = new ZoneRegion.UnitLeaveHandler((rg, u) =>
  559. {
  560. args.TriggingFlag = rg;
  561. args.TriggingUnit = u as InstanceUnit;
  562. TestAndDoAction(args);
  563. });
  564. region.OnUnitLeave += handler;
  565. this.OnDisposed += (api) =>
  566. {
  567. region.OnUnitLeave -= handler;
  568. };
  569. }
  570. public void listen_AreaEntered(EventArguments args, ZoneArea area)
  571. {
  572. args = args.Clone();
  573. ZoneArea.UnitEnterHandler handler = new ZoneArea.UnitEnterHandler((rg, u) =>
  574. {
  575. args.TriggingFlag = rg;
  576. args.TriggingUnit = u as InstanceUnit;
  577. TestAndDoAction(args);
  578. });
  579. area.OnUnitEnter += handler;
  580. this.OnDisposed += (api) =>
  581. {
  582. area.OnUnitEnter -= handler;
  583. };
  584. }
  585. public void listen_AreaLeft(EventArguments args, ZoneArea area)
  586. {
  587. args = args.Clone();
  588. ZoneArea.UnitLeaveHandler handler = new ZoneArea.UnitLeaveHandler((rg, u) =>
  589. {
  590. args.TriggingFlag = rg;
  591. args.TriggingUnit = u as InstanceUnit;
  592. TestAndDoAction(args);
  593. });
  594. area.OnUnitLeave += handler;
  595. this.OnDisposed += (api) =>
  596. {
  597. area.OnUnitLeave -= handler;
  598. };
  599. }
  600. #endregion
  601. //-----------------------------------------------------------------------------------------------
  602. #region __监听_单位事件__
  603. public void listen_GenericUnitAdded(EventArguments args, InstanceZone zone)
  604. {
  605. args = args.Clone();
  606. InstanceZone.UnitAddedHandler handler = new InstanceZone.UnitAddedHandler((z, u) =>
  607. {
  608. args.TriggingUnit = u;
  609. TestAndDoAction(args);
  610. });
  611. zone.OnUnitAdded += handler;
  612. this.OnDisposed += (api) =>
  613. {
  614. zone.OnUnitAdded -= handler;
  615. };
  616. }
  617. public void listen_GenericUnitRemoved(EventArguments args, InstanceZone zone)
  618. {
  619. InstanceZone.UnitRemovedHandler handler = new InstanceZone.UnitRemovedHandler((z, u) =>
  620. {
  621. args.TriggingUnit = u;
  622. TestAndDoAction(args);
  623. });
  624. zone.OnUnitRemoved += handler;
  625. this.OnDisposed += (api) =>
  626. {
  627. zone.OnUnitRemoved -= handler;
  628. };
  629. }
  630. public void listen_GenericUnitActivated(EventArguments args, InstanceZone zone)
  631. {
  632. args = args.Clone();
  633. InstanceZone.UnitActivatedHandler handler = new InstanceZone.UnitActivatedHandler((z, u) =>
  634. {
  635. args.TriggingUnit = u;
  636. TestAndDoAction(args);
  637. });
  638. zone.OnUnitActivated += handler;
  639. this.OnDisposed += (api) =>
  640. {
  641. zone.OnUnitActivated -= handler;
  642. };
  643. }
  644. public void listen_GenericUnitDamaged(EventArguments args, InstanceZone zone)
  645. {
  646. args = args.Clone();
  647. InstanceZone.UnitDamageHandler handler = new InstanceZone.UnitDamageHandler((z, u, attacker, reduceHP, attack) =>
  648. {
  649. args.TriggingUnit = u;
  650. args.AttackUnit = attacker;
  651. args.TriggingSpell = attack.FromSpellUnit;
  652. args.TriggingSkillTemplate = attack.FromSkill;
  653. args.TriggingSpellTemplate = attack.FromSpell;
  654. args.TriggingBuffTemplate = attack.FromBuff;
  655. TestAndDoAction(args);
  656. });
  657. zone.OnUnitDamage += handler;
  658. this.OnDisposed += (api) =>
  659. {
  660. zone.OnUnitDamage -= handler;
  661. };
  662. }
  663. public void listen_GenericUnitDead(EventArguments args, InstanceZone zone)
  664. {
  665. args = args.Clone();
  666. InstanceZone.UnitDeadHandler handler = new InstanceZone.UnitDeadHandler((z, u, attacker) =>
  667. {
  668. args.TriggingUnit = u;
  669. TestAndDoAction(args);
  670. });
  671. zone.OnUnitDead += handler;
  672. this.OnDisposed += (api) =>
  673. {
  674. zone.OnUnitDead -= handler;
  675. };
  676. }
  677. public void listen_GenericUnitRebirth(EventArguments args, InstanceZone zone)
  678. {
  679. InstanceZone.UnitRebirthHandler handler = new InstanceZone.UnitRebirthHandler((z, u) =>
  680. {
  681. args.TriggingUnit = u;
  682. TestAndDoAction(args);
  683. });
  684. zone.OnUnitRebirth += handler;
  685. this.OnDisposed += (api) =>
  686. {
  687. zone.OnUnitRebirth -= handler;
  688. };
  689. }
  690. public void listen_GenericUnitGotInstanceItem(EventArguments args, InstanceZone zone)
  691. {
  692. args = args.Clone();
  693. InstanceZone.UnitGotInstanceItemHandler handler = new InstanceZone.UnitGotInstanceItemHandler((z, u, i) =>
  694. {
  695. args.TriggingUnit = u;
  696. args.TriggingItem = i;
  697. args.TriggingItemTemplate = i.Info;
  698. TestAndDoAction(args);
  699. });
  700. zone.OnUnitGotInstanceItem += handler;
  701. this.OnDisposed += (api) =>
  702. {
  703. zone.OnUnitGotInstanceItem -= handler;
  704. };
  705. }
  706. public void listen_GenericUnitGotInventoryItem(EventArguments args, InstanceZone zone)
  707. {
  708. args = args.Clone();
  709. InstanceZone.UnitGotInventoryItemHandler handler = new InstanceZone.UnitGotInventoryItemHandler((z, u, i, c) =>
  710. {
  711. args.TriggingUnit = u;
  712. args.TriggingItemTemplate = i;
  713. TestAndDoAction(args);
  714. });
  715. zone.OnUnitGotInventoryItem += handler;
  716. this.OnDisposed += (api) =>
  717. {
  718. zone.OnUnitGotInventoryItem -= handler;
  719. };
  720. }
  721. public void listen_GenericUnitLostInventoryItem(EventArguments args, InstanceZone zone)
  722. {
  723. InstanceZone.UnitLostInventoryItemHandler handler = new InstanceZone.UnitLostInventoryItemHandler((z, u, i, c) =>
  724. {
  725. args.TriggingUnit = u;
  726. args.TriggingItemTemplate = i;
  727. TestAndDoAction(args);
  728. });
  729. zone.OnUnitLostInventoryItem += handler;
  730. this.OnDisposed += (api) =>
  731. {
  732. zone.OnUnitLostInventoryItem -= handler;
  733. };
  734. }
  735. public void listen_GenericUnitUseItem(EventArguments args, InstanceZone zone)
  736. {
  737. args = args.Clone();
  738. InstanceZone.UnitUseItemHandler handler = new InstanceZone.UnitUseItemHandler((z, u, i, c) =>
  739. {
  740. args.TriggingUnit = u;
  741. args.TriggingItemTemplate = i;
  742. TestAndDoAction(args);
  743. });
  744. zone.OnUnitUseItem += handler;
  745. this.OnDisposed += (api) =>
  746. {
  747. zone.OnUnitUseItem -= handler;
  748. };
  749. }
  750. public void listen_GenericUnitGotBuff(EventArguments args, InstanceZone zone)
  751. {
  752. args = args.Clone();
  753. InstanceZone.UnitGotBuffHandler handler = new InstanceZone.UnitGotBuffHandler((z, u, b) =>
  754. {
  755. args.TriggingUnit = u;
  756. args.TriggingBuffTemplate = b.Data;
  757. TestAndDoAction(args);
  758. });
  759. zone.OnUnitGotBuff += handler;
  760. this.OnDisposed += (api) =>
  761. {
  762. zone.OnUnitGotBuff -= handler;
  763. };
  764. }
  765. public void listen_GenericUnitLostBuff(EventArguments args, InstanceZone zone)
  766. {
  767. args = args.Clone();
  768. InstanceZone.UnitLostBuffHandler handler = new InstanceZone.UnitLostBuffHandler((z, u, b) =>
  769. {
  770. args.TriggingUnit = u;
  771. args.TriggingBuffTemplate = b.Data;
  772. TestAndDoAction(args);
  773. });
  774. zone.OnUnitLostBuff += handler;
  775. this.OnDisposed += (api) =>
  776. {
  777. zone.OnUnitLostBuff -= handler;
  778. };
  779. }
  780. public void listen_GenericUnitQuestAccepted(EventArguments args, InstanceZone zone)
  781. {
  782. args = args.Clone();
  783. InstanceZone.QuestAcceptedHandler handler = new InstanceZone.QuestAcceptedHandler((u, q) =>
  784. {
  785. args.TriggingUnit = u;
  786. args.TriggingQuestID = q;
  787. TestAndDoAction(args);
  788. });
  789. zone.OnQuestAccepted += handler;
  790. this.OnDisposed += (api) =>
  791. {
  792. zone.OnQuestAccepted -= handler;
  793. };
  794. }
  795. public void listen_GenericUnitQuestCompleted(EventArguments args, InstanceZone zone)
  796. {
  797. args = args.Clone();
  798. InstanceZone.QuestCommittedHandler handler = new InstanceZone.QuestCommittedHandler((u, q) =>
  799. {
  800. args.TriggingUnit = u;
  801. args.TriggingQuestID = q;
  802. TestAndDoAction(args);
  803. });
  804. zone.OnQuestCommitted += handler;
  805. this.OnDisposed += (api) =>
  806. {
  807. zone.OnQuestCommitted -= handler;
  808. };
  809. }
  810. public void listen_GenericUnitQuestDropped(EventArguments args, InstanceZone zone)
  811. {
  812. args = args.Clone();
  813. InstanceZone.QuestDroppedHandler handler = new InstanceZone.QuestDroppedHandler((u, q) =>
  814. {
  815. args.TriggingUnit = u;
  816. args.TriggingQuestID = q;
  817. TestAndDoAction(args);
  818. });
  819. zone.OnQuestDropped += handler;
  820. this.OnDisposed += (api) =>
  821. {
  822. zone.OnQuestDropped -= handler;
  823. };
  824. }
  825. public void listen_GenericUnitQuestStatusChanged(EventArguments args, InstanceZone zone)
  826. {
  827. args = args.Clone();
  828. InstanceZone.QuestStatusChangedHandler handler = new InstanceZone.QuestStatusChangedHandler((u, q, k, v) =>
  829. {
  830. args.TriggingUnit = u;
  831. args.TriggingQuestID = q;
  832. TestAndDoAction(args);
  833. });
  834. zone.OnQuestStatusChanged += handler;
  835. this.OnDisposed += (api) =>
  836. {
  837. zone.OnQuestStatusChanged -= handler;
  838. };
  839. }
  840. public void listen_GenericUnitPickUnit(EventArguments args, InstanceZone zone)
  841. {
  842. args = args.Clone();
  843. InstanceZone.UnitPickUnitHandler handler = new InstanceZone.UnitPickUnitHandler((z, u, p) =>
  844. {
  845. args.TriggingUnit = u;
  846. TestAndDoAction(args);
  847. });
  848. zone.OnUnitPickUnit += handler;
  849. this.OnDisposed += (api) =>
  850. {
  851. zone.OnUnitPickUnit -= handler;
  852. };
  853. }
  854. public void listen_GenericUnitLaunchSkill(EventArguments args, InstanceZone zone)
  855. {
  856. args = args.Clone();
  857. InstanceZone.UnitLaunchSkillHandler handler = new InstanceZone.UnitLaunchSkillHandler((z, u, s) =>
  858. {
  859. args.TriggingUnit = u;
  860. args.TriggingSkillTemplate = s.Data;
  861. TestAndDoAction(args);
  862. });
  863. zone.OnUnitLaunchSkill += handler;
  864. this.OnDisposed += (api) =>
  865. {
  866. zone.OnUnitLaunchSkill -= handler;
  867. };
  868. }
  869. public void listen_GenericPlayerReady(EventArguments args, InstanceZone zone)
  870. {
  871. args = args.Clone();
  872. InstanceZone.PlayerReadyHandler handler = new InstanceZone.PlayerReadyHandler((p) =>
  873. {
  874. args.TriggingUnit = p;
  875. TestAndDoAction(args);
  876. });
  877. zone.OnPlayerReady += handler;
  878. this.OnDisposed += (api) =>
  879. {
  880. zone.OnPlayerReady -= handler;
  881. };
  882. }
  883. //////////////////////////////////////////////////////////////////////////////////////
  884. public void listen_PointUnitDead(EventArguments args, InstanceZone zone, string unitName, int UnitTemplateID = 0)
  885. {
  886. args = args.Clone();
  887. InstanceZone.UnitDeadHandler handler = new InstanceZone.UnitDeadHandler((z, u, attacker) =>
  888. {
  889. if (UnitTemplateID > 0)
  890. {
  891. if (u.Info.ID == UnitTemplateID)
  892. {
  893. args.TriggingUnit = u;
  894. TestAndDoAction(args);
  895. }
  896. }
  897. else
  898. {
  899. if (u.Name.Equals(unitName))
  900. {
  901. args.TriggingUnit = u;
  902. TestAndDoAction(args);
  903. }
  904. }
  905. });
  906. zone.OnUnitDead += handler;
  907. this.OnDisposed += (api) =>
  908. {
  909. zone.OnUnitDead -= handler;
  910. };
  911. }
  912. public void listen_PointUnitOutBattle(EventArguments args, InstanceZone zone, int unitID)
  913. {
  914. args = args.Clone();
  915. InstanceZone.UnitOutBattleHandler handler = new InstanceZone.UnitOutBattleHandler((z, u) =>
  916. {
  917. if (u.Info.ID == unitID)
  918. {
  919. args.TriggingUnit = u;
  920. TestAndDoAction(args);
  921. }
  922. });
  923. zone.OnUnitOutBattle += handler;
  924. this.OnDisposed += (api) =>
  925. {
  926. zone.OnUnitOutBattle -= handler;
  927. };
  928. }
  929. //////////////////////////////////////////////////////////////////////////////////////
  930. public void listen_SpecifyUnitActivated(EventArguments args, InstanceUnit unit)
  931. {
  932. args = args.Clone();
  933. InstanceUnit.ActivatedHandler handler = new InstanceUnit.ActivatedHandler((u) =>
  934. {
  935. args.TriggingUnit = u;
  936. TestAndDoAction(args);
  937. });
  938. unit.OnActivated += handler;
  939. this.OnDisposed += (api) =>
  940. {
  941. unit.OnActivated -= handler;
  942. };
  943. }
  944. public void listen_SpecifyUnitAttack(EventArguments args, InstanceUnit unit)
  945. {
  946. args = args.Clone();
  947. InstanceUnit.AttackHandler handler = new InstanceUnit.AttackHandler((u, t, hp, s) =>
  948. {
  949. args.TriggingUnit = u;
  950. args.TriggingSpell = s.FromSpellUnit;
  951. args.TriggingSkillTemplate = s.FromSkill;
  952. args.TriggingSpellTemplate = s.FromSpell;
  953. args.TriggingBuffTemplate = s.FromBuff;
  954. TestAndDoAction(args);
  955. });
  956. unit.OnAttack += handler;
  957. this.OnDisposed += (api) =>
  958. {
  959. unit.OnAttack -= handler;
  960. };
  961. }
  962. public void listen_PointUnitIDDamaged(EventArguments args, InstanceZone zone, int templateID)
  963. {
  964. args = args.Clone();
  965. InstanceZone.UnitDamageHandler handler = new InstanceZone.UnitDamageHandler((z, u, attacker, reduceHP, attack) =>
  966. {
  967. if (u.Info.ID == templateID)
  968. {
  969. args.TriggingUnit = u;
  970. args.AttackUnit = attacker;
  971. args.TriggingSpell = attack.FromSpellUnit;
  972. args.TriggingSkillTemplate = attack.FromSkill;
  973. args.TriggingSpellTemplate = attack.FromSpell;
  974. args.TriggingBuffTemplate = attack.FromBuff;
  975. TestAndDoAction(args);
  976. }
  977. });
  978. zone.OnUnitDamage += handler;
  979. this.OnDisposed += (api) =>
  980. {
  981. zone.OnUnitDamage -= handler;
  982. };
  983. }
  984. public void listen_SpecifyUnitDamaged(EventArguments args, InstanceUnit unit)
  985. {
  986. args = args.Clone();
  987. InstanceUnit.DamageHandler handler = new InstanceUnit.DamageHandler((u, a, hp, s) =>
  988. {
  989. args.TriggingUnit = u;
  990. args.TriggingSpell = s.FromSpellUnit;
  991. args.TriggingSkillTemplate = s.FromSkill;
  992. args.TriggingSpellTemplate = s.FromSpell;
  993. args.TriggingBuffTemplate = s.FromBuff;
  994. TestAndDoAction(args);
  995. });
  996. unit.OnDamage += handler;
  997. this.OnDisposed += (api) =>
  998. {
  999. unit.OnDamage -= handler;
  1000. };
  1001. }
  1002. public void listen_SpecifyUnitDead(EventArguments args, InstanceUnit unit)
  1003. {
  1004. args = args.Clone();
  1005. InstanceUnit.DeadHandler handler = new InstanceUnit.DeadHandler((u, a) =>
  1006. {
  1007. args.TriggingUnit = u;
  1008. TestAndDoAction(args);
  1009. });
  1010. unit.OnDead += handler;
  1011. this.OnDisposed += (api) =>
  1012. {
  1013. unit.OnDead -= handler;
  1014. };
  1015. }
  1016. public void listen_SpecifyUnitRebirth(EventArguments args, InstanceUnit unit)
  1017. {
  1018. InstanceUnit.RebirthHandler handler = new InstanceUnit.RebirthHandler((u) =>
  1019. {
  1020. args.TriggingUnit = u;
  1021. TestAndDoAction(args);
  1022. });
  1023. unit.OnRebirth += handler;
  1024. this.OnDisposed += (api) =>
  1025. {
  1026. unit.OnRebirth -= handler;
  1027. };
  1028. }
  1029. public void listen_SpecifyUnitGotInstanceItem(EventArguments args, InstanceUnit unit)
  1030. {
  1031. args = args.Clone();
  1032. InstanceUnit.GotInstanceItemHandler handler = new InstanceUnit.GotInstanceItemHandler((u, i) =>
  1033. {
  1034. args.TriggingUnit = u;
  1035. args.TriggingItem = i;
  1036. args.TriggingItemTemplate = i.Info;
  1037. TestAndDoAction(args);
  1038. });
  1039. unit.OnGotInstanceItem += handler;
  1040. this.OnDisposed += (api) =>
  1041. {
  1042. unit.OnGotInstanceItem -= handler;
  1043. };
  1044. }
  1045. public void listen_SpecifyUnitGotInventoryItem(EventArguments args, InstanceUnit unit)
  1046. {
  1047. args = args.Clone();
  1048. InstanceUnit.GotInventoryItemHandler handler = new InstanceUnit.GotInventoryItemHandler((u, i) =>
  1049. {
  1050. args.TriggingUnit = u;
  1051. args.TriggingItemTemplate = i;
  1052. TestAndDoAction(args);
  1053. });
  1054. unit.OnGotInventoryItem += handler;
  1055. this.OnDisposed += (api) =>
  1056. {
  1057. unit.OnGotInventoryItem -= handler;
  1058. };
  1059. }
  1060. public void listen_SpecifyUnitLostInventoryItem(EventArguments args, InstanceUnit unit)
  1061. {
  1062. InstanceUnit.LostInventoryItemHandler handler = new InstanceUnit.LostInventoryItemHandler((u, i) =>
  1063. {
  1064. args.TriggingUnit = u;
  1065. args.TriggingItemTemplate = i;
  1066. TestAndDoAction(args);
  1067. });
  1068. unit.OnLostInventoryItem += handler;
  1069. this.OnDisposed += (api) =>
  1070. {
  1071. unit.OnLostInventoryItem -= handler;
  1072. };
  1073. }
  1074. public void listen_SpecifyUnitUseItem(EventArguments args, InstanceUnit unit)
  1075. {
  1076. args = args.Clone();
  1077. InstanceUnit.UseItemHandler handler = new InstanceUnit.UseItemHandler((u, i, c) =>
  1078. {
  1079. args.TriggingUnit = u;
  1080. args.TriggingItemTemplate = i;
  1081. TestAndDoAction(args);
  1082. });
  1083. unit.OnUseItem += handler;
  1084. this.OnDisposed += (api) =>
  1085. {
  1086. unit.OnUseItem -= handler;
  1087. };
  1088. }
  1089. public void listen_SpecifyUnitGotBuff(EventArguments args, InstanceUnit unit)
  1090. {
  1091. args = args.Clone();
  1092. InstanceUnit.GotBuffHandler handler = new InstanceUnit.GotBuffHandler((u, b) =>
  1093. {
  1094. args.TriggingUnit = u;
  1095. args.TriggingBuffTemplate = b.Data;
  1096. TestAndDoAction(args);
  1097. });
  1098. unit.OnGotBuff += handler;
  1099. this.OnDisposed += (api) =>
  1100. {
  1101. unit.OnGotBuff -= handler;
  1102. };
  1103. }
  1104. public void listen_SpecifyUnitLostBuff(EventArguments args, InstanceUnit unit)
  1105. {
  1106. args = args.Clone();
  1107. InstanceUnit.LostBuffHandler handler = new InstanceUnit.LostBuffHandler((u, b) =>
  1108. {
  1109. args.TriggingUnit = u;
  1110. args.TriggingBuffTemplate = b.Data;
  1111. TestAndDoAction(args);
  1112. });
  1113. unit.OnLostBuff += handler;
  1114. this.OnDisposed += (api) =>
  1115. {
  1116. unit.OnLostBuff -= handler;
  1117. };
  1118. }
  1119. public void listen_SpecifyUnitLaunchSkill(EventArguments args, InstanceUnit unit)
  1120. {
  1121. args = args.Clone();
  1122. InstanceUnit.OnLaunchSkillHandler handler = new InstanceUnit.OnLaunchSkillHandler((u, s) =>
  1123. {
  1124. args.TriggingUnit = u;
  1125. args.TriggingSkillTemplate = s.Data;
  1126. TestAndDoAction(args);
  1127. });
  1128. unit.OnLaunchSkill += handler;
  1129. this.OnDisposed += (api) =>
  1130. {
  1131. unit.OnLaunchSkill -= handler;
  1132. };
  1133. }
  1134. #endregion
  1135. //-----------------------------------------------------------------------------------------------
  1136. #region __监听_触发器事件__
  1137. public void listen_EventActionBegin(EventArguments args, EventTriggerAdapter adapter)
  1138. {
  1139. args = args.Clone();
  1140. OnActionBeginHandler handler = new OnActionBeginHandler((a, g) =>
  1141. {
  1142. TestAndDoAction(g);
  1143. });
  1144. adapter.OnActionBegin += handler;
  1145. this.OnDisposed += (api) =>
  1146. {
  1147. adapter.OnActionBegin -= handler;
  1148. };
  1149. }
  1150. public void listen_EventActionEnd(EventArguments args, EventTriggerAdapter adapter)
  1151. {
  1152. args = args.Clone();
  1153. OnActionEndHandler handler = new OnActionEndHandler((a, g) =>
  1154. {
  1155. TestAndDoAction(g);
  1156. });
  1157. adapter.OnActionEnd += handler;
  1158. this.OnDisposed += (api) =>
  1159. {
  1160. adapter.OnActionEnd -= handler;
  1161. };
  1162. }
  1163. public void listen_EventActionActive(EventArguments args, EventTriggerAdapter adapter)
  1164. {
  1165. args = args.Clone();
  1166. OnActionActiveHandler handler = new OnActionActiveHandler((a, g) =>
  1167. {
  1168. TestAndDoAction(g);
  1169. });
  1170. adapter.mOnActionActive += handler;
  1171. this.OnDisposed += (api) =>
  1172. {
  1173. adapter.mOnActionActive -= handler;
  1174. };
  1175. }
  1176. #endregion
  1177. //-----------------------------------------------------------------------------------------------
  1178. #region Delegates
  1179. public delegate void OnActionBeginHandler(EventTriggerAdapter trigger, EventArguments args);
  1180. public delegate void OnActionEndHandler(EventTriggerAdapter trigger, EventArguments args);
  1181. public delegate void OnActionActiveHandler(EventTriggerAdapter trigger, EventArguments args);
  1182. public delegate void OnDisposedHandler(EventTriggerAdapter trigger);
  1183. private OnActionBeginHandler mOnActionBegin;
  1184. private OnActionEndHandler mOnActionEnd;
  1185. private OnActionActiveHandler mOnActionActive;
  1186. private OnDisposedHandler mOnDisposed;
  1187. public event OnActionBeginHandler OnActionBegin { add { mOnActionBegin += value; } remove { mOnActionBegin -= value; } }
  1188. public event OnActionEndHandler OnActionEnd { add { mOnActionEnd += value; } remove { mOnActionEnd -= value; } }
  1189. public event OnActionActiveHandler OnActionActive { add { mOnActionActive += value; } remove { mOnActionActive -= value; } }
  1190. public event OnDisposedHandler OnDisposed { add { mOnDisposed += value; } remove { mOnDisposed -= value; } }
  1191. #endregion
  1192. //-----------------------------------------------------------------------------------------------
  1193. }
  1194. //---------------------------------------------------------------------------------
  1195. /// <summary>
  1196. /// 绑定环境变量用的数据接口
  1197. /// </summary>
  1198. public class BindValuesAdapter : IEditorValueAdapter
  1199. {
  1200. private IEventTriggerCollection mGroup;
  1201. private InstanceZone mZoneAPI;
  1202. private InstanceUnit mUnitAPI;
  1203. public BindValuesAdapter(EditorScene scene, IEventTriggerCollection group)
  1204. {
  1205. this.IsActive = true;
  1206. this.mGroup = group;
  1207. this.mZoneAPI = scene;
  1208. this.mUnitAPI = null;
  1209. }
  1210. public override void Dispose()
  1211. {
  1212. this.mGroup = null;
  1213. this.mZoneAPI = null;
  1214. this.mUnitAPI = null;
  1215. base.Dispose();
  1216. }
  1217. public override bool IsActive { get; set; }
  1218. public override TemplateManager Templates { get { return mZoneAPI.Templates; } }
  1219. public override IEventTriggerCollection Group { get { return mGroup; } }
  1220. public override InstanceZone ZoneAPI { get { return mZoneAPI; } }
  1221. public override InstanceUnit UnitAPI { get { return mUnitAPI; } }
  1222. }
  1223. //---------------------------------------------------------------------------------
  1224. public class ZoneEventTriggerCollection : IEventTriggerCollection
  1225. {
  1226. private EditorScene mScene;
  1227. private HashMap<string, EventTriggerAdapter> mEvents = new HashMap<string, EventTriggerAdapter>();
  1228. public ZoneEventTriggerCollection(EditorScene scene)
  1229. {
  1230. this.mScene = scene;
  1231. }
  1232. public void Dispose()
  1233. {
  1234. foreach (EventTriggerAdapter trigger in mEvents.Values)
  1235. {
  1236. trigger.Dispose();
  1237. }
  1238. mEvents.Clear();
  1239. mEvents = null;
  1240. mScene = null;
  1241. }
  1242. public void Bind<T>(ICollection<T> events) where T : IEventDataNode
  1243. {
  1244. foreach (IEventDataNode e in events)
  1245. {
  1246. ZoneEventTrigger trigger = new ZoneEventTrigger(mScene, e, this);
  1247. mEvents.Put(e.EventName, trigger);
  1248. }
  1249. foreach (EventTriggerAdapter trigger in mEvents.Values)
  1250. {
  1251. trigger.Start();
  1252. }
  1253. }
  1254. public EventTriggerAdapter GetEditEvent(string name)
  1255. {
  1256. if (name == null) { return null; }
  1257. return mEvents.Get(name);
  1258. }
  1259. public void EventActive(string name, EventArguments args)
  1260. {
  1261. EventTriggerAdapter apt = this.GetEditEvent(name);
  1262. if (apt != null)
  1263. {
  1264. apt.IsActive = true;
  1265. apt.ProcessActionActive(args);
  1266. }
  1267. }
  1268. public void EventDeactive(string name, EventArguments args)
  1269. {
  1270. EventTriggerAdapter apt = this.GetEditEvent(name);
  1271. if (apt != null)
  1272. {
  1273. apt.IsActive = false;
  1274. }
  1275. }
  1276. public class ZoneEventTrigger : EventTriggerAdapter
  1277. {
  1278. private readonly EditorScene mScene;
  1279. public override InstanceZone ZoneAPI { get { return mScene; } }
  1280. public override InstanceUnit UnitAPI { get { return null; } }
  1281. public ZoneEventTrigger(EditorScene scene, IEventDataNode evt, ZoneEventTriggerCollection group)
  1282. : base(evt, group)
  1283. {
  1284. mScene = scene;
  1285. }
  1286. }
  1287. }
  1288. public class UnitEventTriggerCollection : IEventTriggerCollection
  1289. {
  1290. private InstanceUnit mUnit;
  1291. private HashMap<string, EventTriggerAdapter> mEvents = new HashMap<string, EventTriggerAdapter>();
  1292. public UnitEventTriggerCollection(InstanceUnit unit)
  1293. {
  1294. this.mUnit = unit;
  1295. }
  1296. public void Dispose()
  1297. {
  1298. foreach (EventTriggerAdapter trigger in mEvents.Values)
  1299. {
  1300. trigger.Dispose();
  1301. }
  1302. mEvents.Clear();
  1303. mEvents = null;
  1304. mUnit = null;
  1305. }
  1306. public void Bind<T>(ICollection<T> events) where T : IEventDataNode
  1307. {
  1308. foreach (IEventDataNode e in events)
  1309. {
  1310. UnitEventTrigger trigger = new UnitEventTrigger(mUnit, e, this);
  1311. mEvents.Put(e.EventName, trigger);
  1312. }
  1313. foreach (EventTriggerAdapter trigger in mEvents.Values)
  1314. {
  1315. trigger.Start();
  1316. }
  1317. }
  1318. public EventTriggerAdapter GetEditEvent(string name)
  1319. {
  1320. if (name == null) { return null; }
  1321. return mEvents.Get(name);
  1322. }
  1323. public void EventActive(string name, EventArguments args)
  1324. {
  1325. EventTriggerAdapter apt = this.GetEditEvent(name);
  1326. if (apt != null)
  1327. {
  1328. apt.IsActive = true;
  1329. }
  1330. }
  1331. public void EventDeactive(string name, EventArguments args)
  1332. {
  1333. EventTriggerAdapter apt = this.GetEditEvent(name);
  1334. if (apt != null)
  1335. {
  1336. apt.IsActive = false;
  1337. }
  1338. }
  1339. public class UnitEventTrigger : EventTriggerAdapter
  1340. {
  1341. private readonly InstanceZone mScene;
  1342. private readonly InstanceUnit mUnit;
  1343. public override InstanceZone ZoneAPI { get { return mScene; } }
  1344. public override InstanceUnit UnitAPI { get { return mUnit; } }
  1345. public UnitEventTrigger(InstanceUnit unit, IEventDataNode evt, UnitEventTriggerCollection group)
  1346. : base(evt, group)
  1347. {
  1348. mUnit = unit;
  1349. mScene = unit.Parent;
  1350. }
  1351. }
  1352. }
  1353. //---------------------------------------------------------------------------------
  1354. }