EventAdapter.cs 39 KB

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