EventAdapter.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  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("EventTriggerAdapter");
  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.GetSceneID(), 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 (GlobalData.GAME_BS_TEST)
  307. {
  308. log.Warn("--调试场景: " + this.ZoneAPI.UUID + ", " + this.ZoneAPI.GetSceneID() + ", 执行动作:" + this.Name);
  309. }
  310. else
  311. {
  312. log.Debug("--调试场景: " + this.ZoneAPI.UUID + ", " + this.ZoneAPI.GetSceneID() + ", 执行动作:" + this.Name);
  313. }
  314. //if(this.Name.Equals("事件重置列表1") || this.Name.Equals("玉重置"))
  315. //{
  316. // int i = 0;
  317. //}
  318. Stopwatch stopwatch = Stopwatch.StartNew();
  319. try
  320. {
  321. if (mOnActionBegin != null)
  322. {
  323. mOnActionBegin.Invoke(this, args);
  324. }
  325. foreach (AbstractAction a in mData.EventActions)
  326. {
  327. if (a != null)
  328. {
  329. a.DoAction(this, args);
  330. }
  331. }
  332. if (mOnActionEnd != null)
  333. {
  334. mOnActionEnd.Invoke(this, args);
  335. }
  336. }
  337. finally
  338. {
  339. stopwatch.Stop();
  340. PrintStopwatch(stopwatch, "RunInternal");
  341. #if JSGProfile
  342. int timeUse = System.Environment.TickCount - startTick + checkTimeUse;
  343. JSGServerProfile.RecordTrigger(this.ZoneAPI.GetSceneID(), this.Name, timeUse, true);
  344. #endif
  345. }
  346. }
  347. public void ProcessActionActive(EventArguments args)
  348. {
  349. if (mOnActionActive != null)
  350. {
  351. mOnActionActive.Invoke(this, args);
  352. }
  353. }
  354. private void PrintStopwatch(Stopwatch stopwatch, string function)
  355. {
  356. if (stopwatch.ElapsedMilliseconds > EXPECT_TEST_AND_DO_ACTION_TIME_MS)
  357. {
  358. log.WarnFormat("[{0}] at scene[{1}] -> event[{2}] : usetime {3} > {4}ms, data{5}",
  359. function,
  360. (ZoneAPI as EditorScene).Data.ToString() + "-" + ZoneAPI.UUID,
  361. mData.EventName,
  362. stopwatch.ElapsedMilliseconds,
  363. EXPECT_TEST_AND_DO_ACTION_TIME_MS,
  364. ZoneAPI.GetInfo());
  365. }
  366. }
  367. //-----------------------------------------------------------------------------------------------
  368. #region _局部变量_
  369. private void InitLocalVars(EventArguments args)
  370. {
  371. mLocalVarMap.Clear();
  372. foreach (LocalVar klv in mData.EventLocalVars)
  373. {
  374. object obj = klv.GetValue(this, args);
  375. mLocalVarMap.Put(klv.Key, obj);
  376. }
  377. }
  378. #endregion
  379. public delegate bool TryPickItemHandler(EventArguments args, InstanceUnit unit, InstanceItem item);
  380. public delegate void TimeTask(EventArguments args);
  381. //-----------------------------------------------------------------------------------------------
  382. #region _时间任务_
  383. internal void listen_TimeDelaySEC(EventArguments args, float TimeSEC)
  384. {
  385. args = args.Clone();
  386. TimeTaskMS task = ZoneAPI.AddTimeDelayMS((int)(TimeSEC * 1000), (time) =>
  387. {
  388. TestAndDoAction(args);
  389. });
  390. this.mTimes.Add(task);
  391. }
  392. internal void listen_TimePeriodicSEC(EventArguments args, float EveryTimeSEC)
  393. {
  394. args = args.Clone();
  395. TimeTaskMS task = ZoneAPI.AddTimePeriodicMS((int)(EveryTimeSEC * 1000), (time) =>
  396. {
  397. TestAndDoAction(args);
  398. });
  399. if (task != null)
  400. {
  401. this.mTimes.Add(task);
  402. }
  403. }
  404. internal void listen_TimeTaskSEC(EventArguments args, float EveryTimeSEC, float DelayTimeSEC, int repeat)
  405. {
  406. args = args.Clone();
  407. TimeTaskMS task = ZoneAPI.AddTimeTask((int)(EveryTimeSEC * 1000), (int)(DelayTimeSEC * 1000), repeat, (time) =>
  408. {
  409. TestAndDoAction(args);
  410. });
  411. this.mTimes.Add(task);
  412. }
  413. internal void listen_TimeTask(EventArguments args, int intervalMS, int delayMS, int repeat, TimeTask handler)
  414. {
  415. args = args.Clone();
  416. TimeTaskMS task = ZoneAPI.AddTimeTask(intervalMS, delayMS, repeat, (t) =>
  417. {
  418. handler(args);
  419. });
  420. this.mTimes.Add(task);
  421. }
  422. #endregion
  423. //-----------------------------------------------------------------------------------------------
  424. //-----------------------------------------------------------------------------------------------
  425. //-----------------------------------------------------------------------------------------------
  426. #region __监听_场景事件__
  427. public void listen_SceneInit(EventArguments args, InstanceZone zone)
  428. {
  429. args = args.Clone();
  430. InstanceZone.InitHandler handler = new InstanceZone.InitHandler((z) =>
  431. {
  432. TestAndDoAction(args);
  433. });
  434. zone.OnInit += handler;
  435. this.OnDisposed += (api) =>
  436. {
  437. zone.OnInit -= handler;
  438. };
  439. }
  440. public void listen_TryPickItem(EventArguments args, InstanceZone zone, TryPickItemHandler action)
  441. {
  442. args = args.Clone();
  443. InstanceZone.TryPickItemHandler handler = new InstanceZone.TryPickItemHandler((z, u, i) =>
  444. {
  445. args.TriggingUnit = u;
  446. args.TriggingItem = i;
  447. args.TriggingItemTemplate = i.Info;
  448. TestAndDoAction(args);
  449. return action.Invoke(args, u, i);
  450. });
  451. zone.OnTryPickItem += handler;
  452. this.OnDisposed += (api) =>
  453. {
  454. zone.OnTryPickItem -= handler;
  455. };
  456. }
  457. public void listen_RecvMessageFromGS(EventArguments args, InstanceZone zone)
  458. {
  459. args = args.Clone();
  460. InstanceZone.RecvMessageR2BHandler handler = new InstanceZone.RecvMessageR2BHandler((z, m) =>
  461. {
  462. TestAndDoAction(args);
  463. });
  464. zone.OnRecvMessageFromGS += handler;
  465. this.OnDisposed += (api) =>
  466. {
  467. zone.OnRecvMessageFromGS -= handler;
  468. };
  469. }
  470. public void listen_ItemAdded(EventArguments args, InstanceZone zone)
  471. {
  472. args = args.Clone();
  473. InstanceZone.ItemAddedHandler handler = new InstanceZone.ItemAddedHandler((z, i, u) =>
  474. {
  475. args.TriggingItem = i;
  476. args.TriggingItemTemplate = i.Info;
  477. TestAndDoAction(args);
  478. });
  479. zone.OnItemAdded += handler;
  480. this.OnDisposed += (api) =>
  481. {
  482. zone.OnItemAdded -= handler;
  483. };
  484. }
  485. #endregion
  486. //-----------------------------------------------------------------------------------------------
  487. #region __监听_FLAG事件__
  488. public void listen_FlagOpened(EventArguments args, InstanceFlag flag)
  489. {
  490. args = args.Clone();
  491. InstanceFlag.FlagEnabledHandler handler = new InstanceFlag.FlagEnabledHandler((f) =>
  492. {
  493. args.TriggingFlag = f;
  494. TestAndDoAction(args);
  495. });
  496. flag.OnFlagEnabled += handler;
  497. this.OnDisposed += (api) =>
  498. {
  499. flag.OnFlagEnabled -= handler;
  500. };
  501. }
  502. public void listen_FlagClosed(EventArguments args, InstanceFlag flag)
  503. {
  504. args = args.Clone();
  505. InstanceFlag.FlagDisabledHandler handler = new InstanceFlag.FlagDisabledHandler((f) =>
  506. {
  507. args.TriggingFlag = flag;
  508. TestAndDoAction(args);
  509. });
  510. flag.OnFlagDisabled += handler;
  511. this.OnDisposed += (api) =>
  512. {
  513. flag.OnFlagDisabled -= handler;
  514. };
  515. }
  516. public void listen_RegionSpawnOver(EventArguments args, ZoneRegion region)
  517. {
  518. args = args.Clone();
  519. ZoneRegion.SpawnOverHandler handler = new ZoneRegion.SpawnOverHandler((rg) =>
  520. {
  521. args.TriggingFlag = rg;
  522. TestAndDoAction(args);
  523. });
  524. region.OnSpawnOver += handler;
  525. this.OnDisposed += (api) =>
  526. {
  527. region.OnSpawnOver -= handler;
  528. };
  529. }
  530. public void listen_RegionEntered(EventArguments args, ZoneRegion region)
  531. {
  532. args = args.Clone();
  533. ZoneRegion.UnitEnterHandler handler = new ZoneRegion.UnitEnterHandler((rg, u) =>
  534. {
  535. args.TriggingFlag = rg;
  536. args.TriggingUnit = u as InstanceUnit;
  537. TestAndDoAction(args);
  538. });
  539. region.OnUnitEnter += handler;
  540. this.OnDisposed += (api) =>
  541. {
  542. region.OnUnitEnter -= handler;
  543. };
  544. }
  545. public void listen_RegionLeft(EventArguments args, ZoneRegion region)
  546. {
  547. args = args.Clone();
  548. ZoneRegion.UnitLeaveHandler handler = new ZoneRegion.UnitLeaveHandler((rg, u) =>
  549. {
  550. args.TriggingFlag = rg;
  551. args.TriggingUnit = u as InstanceUnit;
  552. TestAndDoAction(args);
  553. });
  554. region.OnUnitLeave += handler;
  555. this.OnDisposed += (api) =>
  556. {
  557. region.OnUnitLeave -= handler;
  558. };
  559. }
  560. public void listen_AreaEntered(EventArguments args, ZoneArea area)
  561. {
  562. args = args.Clone();
  563. ZoneArea.UnitEnterHandler handler = new ZoneArea.UnitEnterHandler((rg, u) =>
  564. {
  565. args.TriggingFlag = rg;
  566. args.TriggingUnit = u as InstanceUnit;
  567. TestAndDoAction(args);
  568. });
  569. area.OnUnitEnter += handler;
  570. this.OnDisposed += (api) =>
  571. {
  572. area.OnUnitEnter -= handler;
  573. };
  574. }
  575. public void listen_AreaLeft(EventArguments args, ZoneArea area)
  576. {
  577. args = args.Clone();
  578. ZoneArea.UnitLeaveHandler handler = new ZoneArea.UnitLeaveHandler((rg, u) =>
  579. {
  580. args.TriggingFlag = rg;
  581. args.TriggingUnit = u as InstanceUnit;
  582. TestAndDoAction(args);
  583. });
  584. area.OnUnitLeave += handler;
  585. this.OnDisposed += (api) =>
  586. {
  587. area.OnUnitLeave -= handler;
  588. };
  589. }
  590. #endregion
  591. //-----------------------------------------------------------------------------------------------
  592. #region __监听_单位事件__
  593. public void listen_GenericUnitAdded(EventArguments args, InstanceZone zone)
  594. {
  595. args = args.Clone();
  596. InstanceZone.UnitAddedHandler handler = new InstanceZone.UnitAddedHandler((z, u) =>
  597. {
  598. args.TriggingUnit = u;
  599. TestAndDoAction(args);
  600. });
  601. zone.OnUnitAdded += handler;
  602. this.OnDisposed += (api) =>
  603. {
  604. zone.OnUnitAdded -= handler;
  605. };
  606. }
  607. public void listen_GenericUnitRemoved(EventArguments args, InstanceZone zone)
  608. {
  609. InstanceZone.UnitRemovedHandler handler = new InstanceZone.UnitRemovedHandler((z, u) =>
  610. {
  611. args.TriggingUnit = u;
  612. TestAndDoAction(args);
  613. });
  614. zone.OnUnitRemoved += handler;
  615. this.OnDisposed += (api) =>
  616. {
  617. zone.OnUnitRemoved -= handler;
  618. };
  619. }
  620. public void listen_GenericUnitActivated(EventArguments args, InstanceZone zone)
  621. {
  622. args = args.Clone();
  623. InstanceZone.UnitActivatedHandler handler = new InstanceZone.UnitActivatedHandler((z, u) =>
  624. {
  625. args.TriggingUnit = u;
  626. TestAndDoAction(args);
  627. });
  628. zone.OnUnitActivated += handler;
  629. this.OnDisposed += (api) =>
  630. {
  631. zone.OnUnitActivated -= handler;
  632. };
  633. }
  634. public void listen_GenericUnitDamaged(EventArguments args, InstanceZone zone)
  635. {
  636. args = args.Clone();
  637. InstanceZone.UnitDamageHandler handler = new InstanceZone.UnitDamageHandler((z, u, attacker, reduceHP, attack) =>
  638. {
  639. args.TriggingUnit = u;
  640. args.AttackUnit = attacker;
  641. args.TriggingSpell = attack.FromSpellUnit;
  642. args.TriggingSkillTemplate = attack.FromSkill;
  643. args.TriggingSpellTemplate = attack.FromSpell;
  644. args.TriggingBuffTemplate = attack.FromBuff;
  645. TestAndDoAction(args);
  646. });
  647. zone.OnUnitDamage += handler;
  648. this.OnDisposed += (api) =>
  649. {
  650. zone.OnUnitDamage -= handler;
  651. };
  652. }
  653. public void listen_GenericUnitDead(EventArguments args, InstanceZone zone)
  654. {
  655. args = args.Clone();
  656. InstanceZone.UnitDeadHandler handler = new InstanceZone.UnitDeadHandler((z, u, attacker) =>
  657. {
  658. args.TriggingUnit = u;
  659. TestAndDoAction(args);
  660. });
  661. zone.OnUnitDead += handler;
  662. this.OnDisposed += (api) =>
  663. {
  664. zone.OnUnitDead -= handler;
  665. };
  666. }
  667. public void listen_GenericUnitRebirth(EventArguments args, InstanceZone zone)
  668. {
  669. InstanceZone.UnitRebirthHandler handler = new InstanceZone.UnitRebirthHandler((z, u) =>
  670. {
  671. args.TriggingUnit = u;
  672. TestAndDoAction(args);
  673. });
  674. zone.OnUnitRebirth += handler;
  675. this.OnDisposed += (api) =>
  676. {
  677. zone.OnUnitRebirth -= handler;
  678. };
  679. }
  680. public void listen_GenericUnitGotInstanceItem(EventArguments args, InstanceZone zone)
  681. {
  682. args = args.Clone();
  683. InstanceZone.UnitGotInstanceItemHandler handler = new InstanceZone.UnitGotInstanceItemHandler((z, u, i) =>
  684. {
  685. args.TriggingUnit = u;
  686. args.TriggingItem = i;
  687. args.TriggingItemTemplate = i.Info;
  688. TestAndDoAction(args);
  689. });
  690. zone.OnUnitGotInstanceItem += handler;
  691. this.OnDisposed += (api) =>
  692. {
  693. zone.OnUnitGotInstanceItem -= handler;
  694. };
  695. }
  696. public void listen_GenericUnitGotInventoryItem(EventArguments args, InstanceZone zone)
  697. {
  698. args = args.Clone();
  699. InstanceZone.UnitGotInventoryItemHandler handler = new InstanceZone.UnitGotInventoryItemHandler((z, u, i, c) =>
  700. {
  701. args.TriggingUnit = u;
  702. args.TriggingItemTemplate = i;
  703. TestAndDoAction(args);
  704. });
  705. zone.OnUnitGotInventoryItem += handler;
  706. this.OnDisposed += (api) =>
  707. {
  708. zone.OnUnitGotInventoryItem -= handler;
  709. };
  710. }
  711. public void listen_GenericUnitLostInventoryItem(EventArguments args, InstanceZone zone)
  712. {
  713. InstanceZone.UnitLostInventoryItemHandler handler = new InstanceZone.UnitLostInventoryItemHandler((z, u, i, c) =>
  714. {
  715. args.TriggingUnit = u;
  716. args.TriggingItemTemplate = i;
  717. TestAndDoAction(args);
  718. });
  719. zone.OnUnitLostInventoryItem += handler;
  720. this.OnDisposed += (api) =>
  721. {
  722. zone.OnUnitLostInventoryItem -= handler;
  723. };
  724. }
  725. public void listen_GenericUnitUseItem(EventArguments args, InstanceZone zone)
  726. {
  727. args = args.Clone();
  728. InstanceZone.UnitUseItemHandler handler = new InstanceZone.UnitUseItemHandler((z, u, i, c) =>
  729. {
  730. args.TriggingUnit = u;
  731. args.TriggingItemTemplate = i;
  732. TestAndDoAction(args);
  733. });
  734. zone.OnUnitUseItem += handler;
  735. this.OnDisposed += (api) =>
  736. {
  737. zone.OnUnitUseItem -= handler;
  738. };
  739. }
  740. public void listen_GenericUnitGotBuff(EventArguments args, InstanceZone zone)
  741. {
  742. args = args.Clone();
  743. InstanceZone.UnitGotBuffHandler handler = new InstanceZone.UnitGotBuffHandler((z, u, b) =>
  744. {
  745. args.TriggingUnit = u;
  746. args.TriggingBuffTemplate = b.Data;
  747. TestAndDoAction(args);
  748. });
  749. zone.OnUnitGotBuff += handler;
  750. this.OnDisposed += (api) =>
  751. {
  752. zone.OnUnitGotBuff -= handler;
  753. };
  754. }
  755. public void listen_GenericUnitLostBuff(EventArguments args, InstanceZone zone)
  756. {
  757. args = args.Clone();
  758. InstanceZone.UnitLostBuffHandler handler = new InstanceZone.UnitLostBuffHandler((z, u, b) =>
  759. {
  760. args.TriggingUnit = u;
  761. args.TriggingBuffTemplate = b.Data;
  762. TestAndDoAction(args);
  763. });
  764. zone.OnUnitLostBuff += handler;
  765. this.OnDisposed += (api) =>
  766. {
  767. zone.OnUnitLostBuff -= handler;
  768. };
  769. }
  770. public void listen_GenericUnitQuestAccepted(EventArguments args, InstanceZone zone)
  771. {
  772. args = args.Clone();
  773. InstanceZone.QuestAcceptedHandler handler = new InstanceZone.QuestAcceptedHandler((u, q) =>
  774. {
  775. args.TriggingUnit = u;
  776. args.TriggingQuestID = q;
  777. TestAndDoAction(args);
  778. });
  779. zone.OnQuestAccepted += handler;
  780. this.OnDisposed += (api) =>
  781. {
  782. zone.OnQuestAccepted -= handler;
  783. };
  784. }
  785. public void listen_GenericUnitQuestCompleted(EventArguments args, InstanceZone zone)
  786. {
  787. args = args.Clone();
  788. InstanceZone.QuestCommittedHandler handler = new InstanceZone.QuestCommittedHandler((u, q) =>
  789. {
  790. args.TriggingUnit = u;
  791. args.TriggingQuestID = q;
  792. TestAndDoAction(args);
  793. });
  794. zone.OnQuestCommitted += handler;
  795. this.OnDisposed += (api) =>
  796. {
  797. zone.OnQuestCommitted -= handler;
  798. };
  799. }
  800. public void listen_GenericUnitQuestDropped(EventArguments args, InstanceZone zone)
  801. {
  802. args = args.Clone();
  803. InstanceZone.QuestDroppedHandler handler = new InstanceZone.QuestDroppedHandler((u, q) =>
  804. {
  805. args.TriggingUnit = u;
  806. args.TriggingQuestID = q;
  807. TestAndDoAction(args);
  808. });
  809. zone.OnQuestDropped += handler;
  810. this.OnDisposed += (api) =>
  811. {
  812. zone.OnQuestDropped -= handler;
  813. };
  814. }
  815. public void listen_GenericUnitQuestStatusChanged(EventArguments args, InstanceZone zone)
  816. {
  817. args = args.Clone();
  818. InstanceZone.QuestStatusChangedHandler handler = new InstanceZone.QuestStatusChangedHandler((u, q, k, v) =>
  819. {
  820. args.TriggingUnit = u;
  821. args.TriggingQuestID = q;
  822. TestAndDoAction(args);
  823. });
  824. zone.OnQuestStatusChanged += handler;
  825. this.OnDisposed += (api) =>
  826. {
  827. zone.OnQuestStatusChanged -= handler;
  828. };
  829. }
  830. public void listen_GenericUnitPickUnit(EventArguments args, InstanceZone zone)
  831. {
  832. args = args.Clone();
  833. InstanceZone.UnitPickUnitHandler handler = new InstanceZone.UnitPickUnitHandler((z, u, p) =>
  834. {
  835. args.TriggingUnit = u;
  836. TestAndDoAction(args);
  837. });
  838. zone.OnUnitPickUnit += handler;
  839. this.OnDisposed += (api) =>
  840. {
  841. zone.OnUnitPickUnit -= handler;
  842. };
  843. }
  844. public void listen_GenericUnitLaunchSkill(EventArguments args, InstanceZone zone)
  845. {
  846. args = args.Clone();
  847. InstanceZone.UnitLaunchSkillHandler handler = new InstanceZone.UnitLaunchSkillHandler((z, u, s) =>
  848. {
  849. args.TriggingUnit = u;
  850. args.TriggingSkillTemplate = s.Data;
  851. TestAndDoAction(args);
  852. });
  853. zone.OnUnitLaunchSkill += handler;
  854. this.OnDisposed += (api) =>
  855. {
  856. zone.OnUnitLaunchSkill -= handler;
  857. };
  858. }
  859. public void listen_GenericPlayerReady(EventArguments args, InstanceZone zone)
  860. {
  861. args = args.Clone();
  862. InstanceZone.PlayerReadyHandler handler = new InstanceZone.PlayerReadyHandler((p) =>
  863. {
  864. args.TriggingUnit = p;
  865. TestAndDoAction(args);
  866. });
  867. zone.OnPlayerReady += handler;
  868. this.OnDisposed += (api) =>
  869. {
  870. zone.OnPlayerReady -= handler;
  871. };
  872. }
  873. //////////////////////////////////////////////////////////////////////////////////////
  874. public void listen_PointUnitDead(EventArguments args, InstanceZone zone, string unitName, int UnitTemplateID = 0)
  875. {
  876. args = args.Clone();
  877. InstanceZone.UnitDeadHandler handler = new InstanceZone.UnitDeadHandler((z, u, attacker) =>
  878. {
  879. if (UnitTemplateID > 0)
  880. {
  881. if (u.Info.ID == UnitTemplateID)
  882. {
  883. args.TriggingUnit = u;
  884. TestAndDoAction(args);
  885. }
  886. }
  887. else
  888. {
  889. if (u.Name.Equals(unitName))
  890. {
  891. args.TriggingUnit = u;
  892. TestAndDoAction(args);
  893. }
  894. }
  895. });
  896. zone.OnUnitDead += handler;
  897. this.OnDisposed += (api) =>
  898. {
  899. zone.OnUnitDead -= handler;
  900. };
  901. }
  902. public void listen_PointUnitOutBattle(EventArguments args, InstanceZone zone, int unitID)
  903. {
  904. args = args.Clone();
  905. InstanceZone.UnitOutBattleHandler handler = new InstanceZone.UnitOutBattleHandler((z, u) =>
  906. {
  907. if (u.Info.ID == unitID)
  908. {
  909. args.TriggingUnit = u;
  910. TestAndDoAction(args);
  911. }
  912. });
  913. zone.OnUnitOutBattle += handler;
  914. this.OnDisposed += (api) =>
  915. {
  916. zone.OnUnitOutBattle -= handler;
  917. };
  918. }
  919. //////////////////////////////////////////////////////////////////////////////////////
  920. public void listen_SpecifyUnitActivated(EventArguments args, InstanceUnit unit)
  921. {
  922. args = args.Clone();
  923. InstanceUnit.ActivatedHandler handler = new InstanceUnit.ActivatedHandler((u) =>
  924. {
  925. args.TriggingUnit = u;
  926. TestAndDoAction(args);
  927. });
  928. unit.OnActivated += handler;
  929. this.OnDisposed += (api) =>
  930. {
  931. unit.OnActivated -= handler;
  932. };
  933. }
  934. public void listen_SpecifyUnitAttack(EventArguments args, InstanceUnit unit)
  935. {
  936. args = args.Clone();
  937. InstanceUnit.AttackHandler handler = new InstanceUnit.AttackHandler((u, t, hp, s) =>
  938. {
  939. args.TriggingUnit = u;
  940. args.TriggingSpell = s.FromSpellUnit;
  941. args.TriggingSkillTemplate = s.FromSkill;
  942. args.TriggingSpellTemplate = s.FromSpell;
  943. args.TriggingBuffTemplate = s.FromBuff;
  944. TestAndDoAction(args);
  945. });
  946. unit.OnAttack += handler;
  947. this.OnDisposed += (api) =>
  948. {
  949. unit.OnAttack -= handler;
  950. };
  951. }
  952. public void listen_PointUnitIDDamaged(EventArguments args, InstanceZone zone, int templateID)
  953. {
  954. args = args.Clone();
  955. InstanceZone.UnitDamageHandler handler = new InstanceZone.UnitDamageHandler((z, u, attacker, reduceHP, attack) =>
  956. {
  957. if (u.Info.ID == templateID)
  958. {
  959. args.TriggingUnit = u;
  960. args.AttackUnit = attacker;
  961. args.TriggingSpell = attack.FromSpellUnit;
  962. args.TriggingSkillTemplate = attack.FromSkill;
  963. args.TriggingSpellTemplate = attack.FromSpell;
  964. args.TriggingBuffTemplate = attack.FromBuff;
  965. TestAndDoAction(args);
  966. }
  967. });
  968. zone.OnUnitDamage += handler;
  969. this.OnDisposed += (api) =>
  970. {
  971. zone.OnUnitDamage -= handler;
  972. };
  973. }
  974. public void listen_SpecifyUnitDamaged(EventArguments args, InstanceUnit unit)
  975. {
  976. args = args.Clone();
  977. InstanceUnit.DamageHandler handler = new InstanceUnit.DamageHandler((u, a, hp, s) =>
  978. {
  979. args.TriggingUnit = u;
  980. args.TriggingSpell = s.FromSpellUnit;
  981. args.TriggingSkillTemplate = s.FromSkill;
  982. args.TriggingSpellTemplate = s.FromSpell;
  983. args.TriggingBuffTemplate = s.FromBuff;
  984. TestAndDoAction(args);
  985. });
  986. unit.OnDamage += handler;
  987. this.OnDisposed += (api) =>
  988. {
  989. unit.OnDamage -= handler;
  990. };
  991. }
  992. public void listen_SpecifyUnitDead(EventArguments args, InstanceUnit unit)
  993. {
  994. args = args.Clone();
  995. InstanceUnit.DeadHandler handler = new InstanceUnit.DeadHandler((u, a) =>
  996. {
  997. args.TriggingUnit = u;
  998. TestAndDoAction(args);
  999. });
  1000. unit.OnDead += handler;
  1001. this.OnDisposed += (api) =>
  1002. {
  1003. unit.OnDead -= handler;
  1004. };
  1005. }
  1006. public void listen_SpecifyUnitRebirth(EventArguments args, InstanceUnit unit)
  1007. {
  1008. InstanceUnit.RebirthHandler handler = new InstanceUnit.RebirthHandler((u) =>
  1009. {
  1010. args.TriggingUnit = u;
  1011. TestAndDoAction(args);
  1012. });
  1013. unit.OnRebirth += handler;
  1014. this.OnDisposed += (api) =>
  1015. {
  1016. unit.OnRebirth -= handler;
  1017. };
  1018. }
  1019. public void listen_SpecifyUnitGotInstanceItem(EventArguments args, InstanceUnit unit)
  1020. {
  1021. args = args.Clone();
  1022. InstanceUnit.GotInstanceItemHandler handler = new InstanceUnit.GotInstanceItemHandler((u, i) =>
  1023. {
  1024. args.TriggingUnit = u;
  1025. args.TriggingItem = i;
  1026. args.TriggingItemTemplate = i.Info;
  1027. TestAndDoAction(args);
  1028. });
  1029. unit.OnGotInstanceItem += handler;
  1030. this.OnDisposed += (api) =>
  1031. {
  1032. unit.OnGotInstanceItem -= handler;
  1033. };
  1034. }
  1035. public void listen_SpecifyUnitGotInventoryItem(EventArguments args, InstanceUnit unit)
  1036. {
  1037. args = args.Clone();
  1038. InstanceUnit.GotInventoryItemHandler handler = new InstanceUnit.GotInventoryItemHandler((u, i) =>
  1039. {
  1040. args.TriggingUnit = u;
  1041. args.TriggingItemTemplate = i;
  1042. TestAndDoAction(args);
  1043. });
  1044. unit.OnGotInventoryItem += handler;
  1045. this.OnDisposed += (api) =>
  1046. {
  1047. unit.OnGotInventoryItem -= handler;
  1048. };
  1049. }
  1050. public void listen_SpecifyUnitLostInventoryItem(EventArguments args, InstanceUnit unit)
  1051. {
  1052. InstanceUnit.LostInventoryItemHandler handler = new InstanceUnit.LostInventoryItemHandler((u, i) =>
  1053. {
  1054. args.TriggingUnit = u;
  1055. args.TriggingItemTemplate = i;
  1056. TestAndDoAction(args);
  1057. });
  1058. unit.OnLostInventoryItem += handler;
  1059. this.OnDisposed += (api) =>
  1060. {
  1061. unit.OnLostInventoryItem -= handler;
  1062. };
  1063. }
  1064. public void listen_SpecifyUnitUseItem(EventArguments args, InstanceUnit unit)
  1065. {
  1066. args = args.Clone();
  1067. InstanceUnit.UseItemHandler handler = new InstanceUnit.UseItemHandler((u, i, c) =>
  1068. {
  1069. args.TriggingUnit = u;
  1070. args.TriggingItemTemplate = i;
  1071. TestAndDoAction(args);
  1072. });
  1073. unit.OnUseItem += handler;
  1074. this.OnDisposed += (api) =>
  1075. {
  1076. unit.OnUseItem -= handler;
  1077. };
  1078. }
  1079. public void listen_SpecifyUnitGotBuff(EventArguments args, InstanceUnit unit)
  1080. {
  1081. args = args.Clone();
  1082. InstanceUnit.GotBuffHandler handler = new InstanceUnit.GotBuffHandler((u, b) =>
  1083. {
  1084. args.TriggingUnit = u;
  1085. args.TriggingBuffTemplate = b.Data;
  1086. TestAndDoAction(args);
  1087. });
  1088. unit.OnGotBuff += handler;
  1089. this.OnDisposed += (api) =>
  1090. {
  1091. unit.OnGotBuff -= handler;
  1092. };
  1093. }
  1094. public void listen_SpecifyUnitLostBuff(EventArguments args, InstanceUnit unit)
  1095. {
  1096. args = args.Clone();
  1097. InstanceUnit.LostBuffHandler handler = new InstanceUnit.LostBuffHandler((u, b) =>
  1098. {
  1099. args.TriggingUnit = u;
  1100. args.TriggingBuffTemplate = b.Data;
  1101. TestAndDoAction(args);
  1102. });
  1103. unit.OnLostBuff += handler;
  1104. this.OnDisposed += (api) =>
  1105. {
  1106. unit.OnLostBuff -= handler;
  1107. };
  1108. }
  1109. public void listen_SpecifyUnitLaunchSkill(EventArguments args, InstanceUnit unit)
  1110. {
  1111. args = args.Clone();
  1112. InstanceUnit.OnLaunchSkillHandler handler = new InstanceUnit.OnLaunchSkillHandler((u, s) =>
  1113. {
  1114. args.TriggingUnit = u;
  1115. args.TriggingSkillTemplate = s.Data;
  1116. TestAndDoAction(args);
  1117. });
  1118. unit.OnLaunchSkill += handler;
  1119. this.OnDisposed += (api) =>
  1120. {
  1121. unit.OnLaunchSkill -= handler;
  1122. };
  1123. }
  1124. #endregion
  1125. //-----------------------------------------------------------------------------------------------
  1126. #region __监听_触发器事件__
  1127. public void listen_EventActionBegin(EventArguments args, EventTriggerAdapter adapter)
  1128. {
  1129. args = args.Clone();
  1130. OnActionBeginHandler handler = new OnActionBeginHandler((a, g) =>
  1131. {
  1132. TestAndDoAction(g);
  1133. });
  1134. adapter.OnActionBegin += handler;
  1135. this.OnDisposed += (api) =>
  1136. {
  1137. adapter.OnActionBegin -= handler;
  1138. };
  1139. }
  1140. public void listen_EventActionEnd(EventArguments args, EventTriggerAdapter adapter)
  1141. {
  1142. args = args.Clone();
  1143. OnActionEndHandler handler = new OnActionEndHandler((a, g) =>
  1144. {
  1145. TestAndDoAction(g);
  1146. });
  1147. adapter.OnActionEnd += handler;
  1148. this.OnDisposed += (api) =>
  1149. {
  1150. adapter.OnActionEnd -= handler;
  1151. };
  1152. }
  1153. public void listen_EventActionActive(EventArguments args, EventTriggerAdapter adapter)
  1154. {
  1155. args = args.Clone();
  1156. OnActionActiveHandler handler = new OnActionActiveHandler((a, g) =>
  1157. {
  1158. TestAndDoAction(g);
  1159. });
  1160. adapter.mOnActionActive += handler;
  1161. this.OnDisposed += (api) =>
  1162. {
  1163. adapter.mOnActionActive -= handler;
  1164. };
  1165. }
  1166. #endregion
  1167. //-----------------------------------------------------------------------------------------------
  1168. #region Delegates
  1169. public delegate void OnActionBeginHandler(EventTriggerAdapter trigger, EventArguments args);
  1170. public delegate void OnActionEndHandler(EventTriggerAdapter trigger, EventArguments args);
  1171. public delegate void OnActionActiveHandler(EventTriggerAdapter trigger, EventArguments args);
  1172. public delegate void OnDisposedHandler(EventTriggerAdapter trigger);
  1173. private OnActionBeginHandler mOnActionBegin;
  1174. private OnActionEndHandler mOnActionEnd;
  1175. private OnActionActiveHandler mOnActionActive;
  1176. private OnDisposedHandler mOnDisposed;
  1177. public event OnActionBeginHandler OnActionBegin { add { mOnActionBegin += value; } remove { mOnActionBegin -= value; } }
  1178. public event OnActionEndHandler OnActionEnd { add { mOnActionEnd += value; } remove { mOnActionEnd -= value; } }
  1179. public event OnActionActiveHandler OnActionActive { add { mOnActionActive += value; } remove { mOnActionActive -= value; } }
  1180. public event OnDisposedHandler OnDisposed { add { mOnDisposed += value; } remove { mOnDisposed -= value; } }
  1181. #endregion
  1182. //-----------------------------------------------------------------------------------------------
  1183. }
  1184. //---------------------------------------------------------------------------------
  1185. /// <summary>
  1186. /// 绑定环境变量用的数据接口
  1187. /// </summary>
  1188. public class BindValuesAdapter : IEditorValueAdapter
  1189. {
  1190. private IEventTriggerCollection mGroup;
  1191. private InstanceZone mZoneAPI;
  1192. private InstanceUnit mUnitAPI;
  1193. public BindValuesAdapter(EditorScene scene, IEventTriggerCollection group)
  1194. {
  1195. this.IsActive = true;
  1196. this.mGroup = group;
  1197. this.mZoneAPI = scene;
  1198. this.mUnitAPI = null;
  1199. }
  1200. public override void Dispose()
  1201. {
  1202. this.mGroup = null;
  1203. this.mZoneAPI = null;
  1204. this.mUnitAPI = null;
  1205. base.Dispose();
  1206. }
  1207. public override bool IsActive { get; set; }
  1208. public override TemplateManager Templates { get { return mZoneAPI.Templates; } }
  1209. public override IEventTriggerCollection Group { get { return mGroup; } }
  1210. public override InstanceZone ZoneAPI { get { return mZoneAPI; } }
  1211. public override InstanceUnit UnitAPI { get { return mUnitAPI; } }
  1212. }
  1213. //---------------------------------------------------------------------------------
  1214. public class ZoneEventTriggerCollection : IEventTriggerCollection
  1215. {
  1216. private EditorScene mScene;
  1217. private HashMap<string, EventTriggerAdapter> mEvents = new HashMap<string, EventTriggerAdapter>();
  1218. public ZoneEventTriggerCollection(EditorScene scene)
  1219. {
  1220. this.mScene = scene;
  1221. }
  1222. public void Dispose()
  1223. {
  1224. foreach (EventTriggerAdapter trigger in mEvents.Values)
  1225. {
  1226. trigger.Dispose();
  1227. }
  1228. mEvents.Clear();
  1229. mEvents = null;
  1230. mScene = null;
  1231. }
  1232. public void Bind<T>(ICollection<T> events) where T : IEventDataNode
  1233. {
  1234. foreach (IEventDataNode e in events)
  1235. {
  1236. ZoneEventTrigger trigger = new ZoneEventTrigger(mScene, e, this);
  1237. mEvents.Put(e.EventName, trigger);
  1238. }
  1239. foreach (EventTriggerAdapter trigger in mEvents.Values)
  1240. {
  1241. trigger.Start();
  1242. }
  1243. }
  1244. public EventTriggerAdapter GetEditEvent(string name)
  1245. {
  1246. if (name == null) { return null; }
  1247. return mEvents.Get(name);
  1248. }
  1249. public void EventActive(string name, EventArguments args)
  1250. {
  1251. EventTriggerAdapter apt = this.GetEditEvent(name);
  1252. if (apt != null)
  1253. {
  1254. apt.IsActive = true;
  1255. apt.ProcessActionActive(args);
  1256. }
  1257. }
  1258. public void EventDeactive(string name, EventArguments args)
  1259. {
  1260. EventTriggerAdapter apt = this.GetEditEvent(name);
  1261. if (apt != null)
  1262. {
  1263. apt.IsActive = false;
  1264. }
  1265. }
  1266. public class ZoneEventTrigger : EventTriggerAdapter
  1267. {
  1268. private readonly EditorScene mScene;
  1269. public override InstanceZone ZoneAPI { get { return mScene; } }
  1270. public override InstanceUnit UnitAPI { get { return null; } }
  1271. public ZoneEventTrigger(EditorScene scene, IEventDataNode evt, ZoneEventTriggerCollection group)
  1272. : base(evt, group)
  1273. {
  1274. mScene = scene;
  1275. }
  1276. }
  1277. }
  1278. public class UnitEventTriggerCollection : IEventTriggerCollection
  1279. {
  1280. private InstanceUnit mUnit;
  1281. private HashMap<string, EventTriggerAdapter> mEvents = new HashMap<string, EventTriggerAdapter>();
  1282. public UnitEventTriggerCollection(InstanceUnit unit)
  1283. {
  1284. this.mUnit = unit;
  1285. }
  1286. public void Dispose()
  1287. {
  1288. foreach (EventTriggerAdapter trigger in mEvents.Values)
  1289. {
  1290. trigger.Dispose();
  1291. }
  1292. mEvents.Clear();
  1293. mEvents = null;
  1294. mUnit = null;
  1295. }
  1296. public void Bind<T>(ICollection<T> events) where T : IEventDataNode
  1297. {
  1298. foreach (IEventDataNode e in events)
  1299. {
  1300. UnitEventTrigger trigger = new UnitEventTrigger(mUnit, e, this);
  1301. mEvents.Put(e.EventName, trigger);
  1302. }
  1303. foreach (EventTriggerAdapter trigger in mEvents.Values)
  1304. {
  1305. trigger.Start();
  1306. }
  1307. }
  1308. public EventTriggerAdapter GetEditEvent(string name)
  1309. {
  1310. if (name == null) { return null; }
  1311. return mEvents.Get(name);
  1312. }
  1313. public void EventActive(string name, EventArguments args)
  1314. {
  1315. EventTriggerAdapter apt = this.GetEditEvent(name);
  1316. if (apt != null)
  1317. {
  1318. apt.IsActive = true;
  1319. }
  1320. }
  1321. public void EventDeactive(string name, EventArguments args)
  1322. {
  1323. EventTriggerAdapter apt = this.GetEditEvent(name);
  1324. if (apt != null)
  1325. {
  1326. apt.IsActive = false;
  1327. }
  1328. }
  1329. public class UnitEventTrigger : EventTriggerAdapter
  1330. {
  1331. private readonly InstanceZone mScene;
  1332. private readonly InstanceUnit mUnit;
  1333. public override InstanceZone ZoneAPI { get { return mScene; } }
  1334. public override InstanceUnit UnitAPI { get { return mUnit; } }
  1335. public UnitEventTrigger(InstanceUnit unit, IEventDataNode evt, UnitEventTriggerCollection group)
  1336. : base(evt, group)
  1337. {
  1338. mUnit = unit;
  1339. mScene = unit.Parent;
  1340. }
  1341. }
  1342. }
  1343. //---------------------------------------------------------------------------------
  1344. }