EventAdapter.cs 39 KB

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