Actions.A.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonLang.Property;
  5. using CommonAI.Zone.Attributes;
  6. using CommonAI.Zone;
  7. using CommonAI.Zone.ZoneEditor;
  8. using CommonAI.RTS;
  9. using CommonLang.Vector;
  10. using CommonAI.Zone.Instance;
  11. using CommonAI.Zone.Helper;
  12. using CommonAI.Zone.EventTrigger;
  13. using CommonLang;
  14. namespace CommonAI.Zone.ZoneEditor.EventTrigger
  15. {
  16. //-------------------------------------------------------------------
  17. //-------------------------------------------------------------------
  18. [DescAttribute("什么都不做", "Nothing")]
  19. public class DoNoting : AbstractAction
  20. {
  21. public override string ToString()
  22. {
  23. return "什么都不做";
  24. }
  25. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  26. {
  27. }
  28. }
  29. [DescAttribute("消息框", "Test")]
  30. public class ShowMessageBox : AbstractAction
  31. {
  32. [DescAttribute("消息")]
  33. public StringValue Message = new StringValue.VALUE("");
  34. public override string ToString()
  35. {
  36. return string.Format("消息框({0})", Message);
  37. }
  38. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  39. {
  40. api.ZoneAPI.sendMessageBox(Message.GetValue(api, args));
  41. }
  42. }
  43. [DescAttribute("延时执行一个动作", "流程控制 - 延时执行(DELAY)")]
  44. public class DelayedAction : AbstractAction
  45. {
  46. [DescAttribute("延时毫秒")]
  47. public IntegerValue DelayTimeMS = new IntegerValue.VALUE(1000);
  48. [DescAttribute("延时动作")]
  49. public AbstractAction DelayAction = new DoNoting();
  50. public override string ToString()
  51. {
  52. return string.Format("延时{0}(毫秒)后执行({1})", DelayTimeMS, DelayAction);
  53. }
  54. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  55. {
  56. int delayMS = DelayTimeMS.GetValue(api, args);
  57. api.listen_TimeTask(args, 0, delayMS, 1, (args2) =>
  58. {
  59. DelayAction.DoAction(api, args2);
  60. });
  61. }
  62. }
  63. [DescAttribute("条件执行一个动作", "流程控制 - 条件执行(IF)")]
  64. public class ConditionAction : AbstractAction
  65. {
  66. [DescAttribute("IF 条件")]
  67. public BooleanValue Condition = new BooleanValue.BooleanComparison();
  68. [DescAttribute("THEN 动作")]
  69. public AbstractAction Action = new DoNoting();
  70. [DescAttribute("ELSE 动作")]
  71. public AbstractAction ElseAction = null;
  72. public override string ToString()
  73. {
  74. if (ElseAction == null)
  75. {
  76. return string.Format("IF ({0}) THEN ({1})", Condition, Action);
  77. }
  78. else
  79. {
  80. return string.Format("IF ({0}) THEN ({1}) ELSE ({2})", Condition, Action, ElseAction);
  81. }
  82. }
  83. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  84. {
  85. if (Condition.GetValue(api, args))
  86. {
  87. Action.DoAction(api, args);
  88. }
  89. else if (ElseAction != null)
  90. {
  91. ElseAction.DoAction(api, args);
  92. }
  93. }
  94. }
  95. [DescAttribute("整形FOR循环执行一个动作", "流程控制 - 循环执行(FOR)")]
  96. public class IteratorForInt32Action : AbstractAction
  97. {
  98. [DescAttribute("起始值")]
  99. public IntegerValue BeginIndex = new IntegerValue.VALUE(0);
  100. [DescAttribute("递增")]
  101. public IntegerValue Step = new IntegerValue.VALUE(1);
  102. [DescAttribute("结束值(不包括)")]
  103. public IntegerValue EndIndex = new IntegerValue.VALUE(10);
  104. [DescAttribute("动作")]
  105. public AbstractAction Action = new DoNoting();
  106. public override string ToString()
  107. {
  108. return string.Format("FOR (起始={0} 递增+{1} 结束<{2}) DO {3})", BeginIndex, Step, EndIndex, Action);
  109. }
  110. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  111. {
  112. int start = BeginIndex.GetValue(api, args);
  113. int step = Step.GetValue(api, args);
  114. int end = EndIndex.GetValue(api, args);
  115. args = args.Clone();
  116. for (int i = start; i < end; i += step)
  117. {
  118. args.IteratingInt32 = (i);
  119. Action.DoAction(api, args);
  120. args.IteratingInt32 = (0);
  121. }
  122. }
  123. }
  124. [DescAttribute("执行多条指令", "流程控制 - 执行序列")]
  125. public class DoAction3 : AbstractAction
  126. {
  127. [DescAttribute("动作1")]
  128. public AbstractAction Action1 = new DoNoting();
  129. [DescAttribute("动作2")]
  130. public AbstractAction Action2 = new DoNoting();
  131. [DescAttribute("动作3")]
  132. public AbstractAction Action3 = new DoNoting();
  133. public override string ToString()
  134. {
  135. StringBuilder sb = new StringBuilder("执行序列: ");
  136. if (Action1 != null)
  137. {
  138. sb.Append(Action1.ToString()).Append(", ");
  139. }
  140. if (Action2 != null)
  141. {
  142. sb.Append(Action2.ToString()).Append(", ");
  143. }
  144. if (Action3 != null)
  145. {
  146. sb.Append(Action3.ToString()).Append(", ");
  147. }
  148. return sb.ToString();
  149. }
  150. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  151. {
  152. if (Action1 != null)
  153. {
  154. Action1.DoAction(api, args);
  155. }
  156. if (Action2 != null)
  157. {
  158. Action2.DoAction(api, args);
  159. }
  160. if (Action3 != null)
  161. {
  162. Action3.DoAction(api, args);
  163. }
  164. }
  165. }
  166. [DescAttribute("按顺序执行动作(执行多条指令)", "流程控制 - 执行序列")]
  167. public class DoActionQueue : AbstractAction
  168. {
  169. [DescAttribute("动作序列")]
  170. [ListAttribute(typeof(AbstractAction))]
  171. public List<AbstractAction> ActionQueue = new List<AbstractAction>();
  172. public override string ToString()
  173. {
  174. StringBuilder sb = new StringBuilder("执行序列: ");
  175. foreach (AbstractAction ca in ActionQueue)
  176. {
  177. sb.Append(ca.ToString());
  178. if (ActionQueue[ActionQueue.Count - 1] != ca)
  179. {
  180. sb.Append(" -> ");
  181. }
  182. }
  183. return sb.ToString();
  184. }
  185. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  186. {
  187. foreach (AbstractAction ca in ActionQueue)
  188. {
  189. ca.DoAction(api, args);
  190. }
  191. }
  192. }
  193. [DescAttribute("Switch ... Case (int32)", "流程控制 - 多条件(SWITCH)")]
  194. public class SwitchCaseInteger : AbstractAction
  195. {
  196. [DescAttribute("Switch值")]
  197. public IntegerValue SwitchValue = new IntegerValue.RandomInt();
  198. [DescAttribute("Case集合")]
  199. [ListAttribute(typeof(CaseActionInt32))]
  200. public List<CaseActionInt32> Cases = new List<CaseActionInt32>();
  201. public override string ToString()
  202. {
  203. StringBuilder sb = new StringBuilder("switch");
  204. sb.AppendLine(string.Format("({0})", SwitchValue));
  205. sb.AppendLine("{");
  206. foreach (CaseActionInt32 ca in Cases)
  207. {
  208. sb.AppendLine(ca.ToString());
  209. }
  210. sb.Append("}");
  211. return sb.ToString();
  212. }
  213. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  214. {
  215. int sv = SwitchValue.GetValue(api, args);
  216. foreach (CaseActionInt32 ca in Cases)
  217. {
  218. int cv = ca.CaseValue.GetValue(api, args);
  219. if (cv == sv)
  220. {
  221. ca.Action.DoAction(api, args);
  222. }
  223. }
  224. }
  225. [DescAttribute("Case动作")]
  226. [Expandable]
  227. public class CaseActionInt32
  228. {
  229. [DescAttribute("Case值")]
  230. public IntegerValue CaseValue = new IntegerValue.VALUE();
  231. [DescAttribute("Case动作")]
  232. public AbstractAction Action = new DoNoting();
  233. public override string ToString()
  234. {
  235. return string.Format("case {0}: {1}; break;", CaseValue, Action);
  236. }
  237. }
  238. }
  239. [DescAttribute("Switch ... Case (string)", "流程控制 - 多条件(SWITCH)")]
  240. public class SwitchCaseString : AbstractAction
  241. {
  242. [DescAttribute("Switch值")]
  243. public StringValue SwitchValue = new StringValue.NULL();
  244. [DescAttribute("Case集合")]
  245. [ListAttribute(typeof(CaseActionString))]
  246. public List<CaseActionString> Cases = new List<CaseActionString>();
  247. public override string ToString()
  248. {
  249. StringBuilder sb = new StringBuilder("switch");
  250. sb.AppendLine(string.Format("(\"{0}\")", SwitchValue));
  251. sb.AppendLine("{");
  252. foreach (CaseActionString ca in Cases)
  253. {
  254. sb.AppendLine(ca.ToString());
  255. }
  256. sb.Append("}");
  257. return sb.ToString();
  258. }
  259. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  260. {
  261. string sv = SwitchValue.GetValue(api, args);
  262. foreach (CaseActionString ca in Cases)
  263. {
  264. string cv = ca.CaseValue.GetValue(api, args);
  265. if (cv == sv)
  266. {
  267. ca.Action.DoAction(api, args);
  268. }
  269. }
  270. }
  271. [DescAttribute("Case动作")]
  272. [Expandable]
  273. public class CaseActionString
  274. {
  275. [DescAttribute("Case值")]
  276. public StringValue CaseValue = new StringValue.NULL();
  277. [DescAttribute("Case动作")]
  278. public AbstractAction Action = new DoNoting();
  279. public override string ToString()
  280. {
  281. return string.Format("case \"{0}\": {1}; break;", CaseValue, Action);
  282. }
  283. }
  284. }
  285. }