Data.UnitEvents.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using CommonAI.Zone.EventTrigger;
  2. using CommonAI.Zone.ZoneEditor.EventTrigger;
  3. using CommonLang.IO;
  4. using CommonLang.IO.Attribute;
  5. using CommonLang.Property;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. namespace CommonAI.Zone
  11. {
  12. /// 事件动作触发器
  13. /// </summary>
  14. [MessageType(0x4502)]
  15. [TableClassAttribute("Name")]
  16. public class UnitEvent : ICloneable, IEventDataNode, IExternalizable
  17. {
  18. public string EventName { get { return this.Name; } set { this.Name = value; } }
  19. public string EventTreePath { get { return this.SavePath; } set { this.SavePath = value; } }
  20. public bool EventIsActive { get { return this.Active; } set { this.Active = value; } }
  21. public string EventComment { get { return this.Comment; } set { this.Comment = value; } }
  22. public int EventDelayTimeMS { get { return this.DelayTimeMS; } set { this.DelayTimeMS = value; } }
  23. public List<LocalVar> EventLocalVars { get { return this.LocalVars.Datas; } }
  24. public List<AbstractTrigger> EventTriggers { get { return this.Triggers.Datas; } }
  25. public List<AbstractCondition> EventConditions { get { return this.Conditions.Datas; } }
  26. public List<AbstractAction> EventActions { get { return this.Actions.Datas; } }
  27. /// <summary>
  28. /// 触发器名字
  29. /// </summary>
  30. public string Name = "Unnamed";
  31. /// <summary>
  32. /// 启用
  33. /// </summary>
  34. public bool Active = true;
  35. /// <summary>
  36. /// 注释
  37. /// </summary>
  38. public string Comment = "";
  39. /// <summary>
  40. /// 保存
  41. /// </summary>
  42. public string SavePath;
  43. /// <summary>
  44. /// 延迟执行
  45. /// </summary>
  46. public int DelayTimeMS;
  47. /// <summary>
  48. /// 临时变量
  49. /// </summary>
  50. public UnitLocalVars LocalVars = new UnitLocalVars();
  51. /// <summary>
  52. /// 事件触发
  53. /// </summary>
  54. public UnitTriggers Triggers = new UnitTriggers();
  55. /// <summary>
  56. /// 条件
  57. /// </summary>
  58. public UnitConditions Conditions = new UnitConditions();
  59. /// <summary>
  60. /// 动作
  61. /// </summary>
  62. public UnitActions Actions = new UnitActions();
  63. public UnitEvent()
  64. {
  65. Triggers.Datas.Add(new BindingUnitDamaged());
  66. Conditions.Datas.Add(new AlwaysTrue());
  67. Actions.Datas.Add(new UnitAddBuffAction());
  68. }
  69. public object Clone()
  70. {
  71. UnitEvent ret = new UnitEvent();
  72. ret.Name = this.Name;
  73. ret.Active = this.Active;
  74. ret.Comment = this.Comment;
  75. ret.SavePath = this.SavePath;
  76. ret.DelayTimeMS = this.DelayTimeMS;
  77. this.LocalVars.Clone(ret.LocalVars);
  78. this.Triggers.Clone(ret.Triggers);
  79. this.Conditions.Clone(ret.Conditions);
  80. this.Actions.Clone(ret.Actions);
  81. return ret;
  82. //return IOUtil.CloneIExternalizable<UnitEvent>(TemplateManager.MessageCodec, this);
  83. }
  84. public override string ToString()
  85. {
  86. return Name + "";
  87. }
  88. public string FunctionText()
  89. {
  90. StringBuilder sb = new StringBuilder();
  91. sb.Append(Triggers.ToString());
  92. sb.Append(",\n");
  93. sb.Append("满足条件:").Append(Conditions.ToString());
  94. sb.Append(",\n");
  95. sb.Append("执行动作:").Append(Actions.ToString());
  96. sb.Append("。");
  97. return sb.ToString();
  98. }
  99. public void WriteExternal(IOutputStream output)
  100. {
  101. output.PutUTF(this.Name);
  102. output.PutBool(this.Active);
  103. output.PutUTF(this.Comment);
  104. output.PutUTF(this.SavePath);
  105. output.PutS32(this.DelayTimeMS);
  106. output.PutObj2Xml(this.LocalVars);
  107. output.PutObj2Xml(this.Triggers);
  108. output.PutObj2Xml(this.Conditions);
  109. output.PutObj2Xml(this.Actions);
  110. }
  111. public void ReadExternal(IInputStream input)
  112. {
  113. this.Name = input.GetUTF();
  114. this.Active = input.GetBool();
  115. this.Comment = input.GetUTF();
  116. this.SavePath = input.GetUTF();
  117. this.DelayTimeMS = input.GetS32();
  118. this.LocalVars = input.GetXml2Obj<UnitLocalVars>();
  119. this.Triggers = input.GetXml2Obj<UnitTriggers>();
  120. this.Conditions = input.GetXml2Obj<UnitConditions>();
  121. this.Actions = input.GetXml2Obj<UnitActions>();
  122. }
  123. // ----------------------------------------------------------------------
  124. public class UnitLocalVars
  125. {
  126. public List<LocalVar> Datas = new List<LocalVar>();
  127. public override string ToString()
  128. {
  129. StringBuilder sb = new StringBuilder();
  130. if (Datas.Count > 0)
  131. {
  132. for (int i = 0; i < Datas.Count; i++)
  133. {
  134. sb.AppendLine(Datas[i].ToString());
  135. }
  136. }
  137. return sb.ToString();
  138. }
  139. public void Clone(UnitLocalVars data)
  140. {
  141. data.Datas.Clear();
  142. for (int i = 0; i < Datas.Count; i++)
  143. {
  144. data.Datas.Add(this.Datas[i]);
  145. }
  146. }
  147. }
  148. public class UnitTriggers
  149. {
  150. public List<AbstractTrigger> Datas = new List<AbstractTrigger>();
  151. public void Clone(UnitTriggers data)
  152. {
  153. data.Datas.Clear();
  154. for (int i = 0; i < Datas.Count; i++)
  155. {
  156. data.Datas.Add(this.Datas[i]);
  157. }
  158. }
  159. public override string ToString()
  160. {
  161. StringBuilder sb = new StringBuilder();
  162. if (Datas.Count > 0)
  163. {
  164. for (int i = 0; i < Datas.Count; i++)
  165. {
  166. sb.Append(Datas[i]);
  167. if (i < Datas.Count - 1)
  168. {
  169. sb.Append(" 或者 ");
  170. }
  171. }
  172. }
  173. else
  174. {
  175. sb.Append("(无起因)");
  176. }
  177. return sb.ToString();
  178. }
  179. }
  180. public class UnitConditions
  181. {
  182. public List<AbstractCondition> Datas = new List<AbstractCondition>();
  183. public void Clone(UnitConditions data)
  184. {
  185. data.Datas.Clear();
  186. for (int i = 0; i < Datas.Count; i++)
  187. {
  188. data.Datas.Add(this.Datas[i]);
  189. }
  190. }
  191. public override string ToString()
  192. {
  193. StringBuilder sb = new StringBuilder();
  194. if (Datas.Count > 0)
  195. {
  196. for (int i = 0; i < Datas.Count; i++)
  197. {
  198. sb.Append(Datas[i]);
  199. if (i < Datas.Count - 1)
  200. {
  201. sb.Append(" 并且 ");
  202. }
  203. }
  204. }
  205. else
  206. {
  207. sb.Append("(无条件)");
  208. }
  209. return sb.ToString();
  210. }
  211. }
  212. public class UnitActions
  213. {
  214. public List<AbstractAction> Datas = new List<AbstractAction>();
  215. public void Clone(UnitActions data)
  216. {
  217. data.Datas.Clear();
  218. for (int i = 0; i < Datas.Count; i++)
  219. {
  220. data.Datas.Add(this.Datas[i]);
  221. }
  222. }
  223. public override string ToString()
  224. {
  225. StringBuilder sb = new StringBuilder();
  226. if (Datas.Count > 0)
  227. {
  228. for (int i = 0; i < Datas.Count; i++)
  229. {
  230. sb.Append(Datas[i]);
  231. if (i < Datas.Count - 1)
  232. {
  233. sb.Append(" 并且 ");
  234. }
  235. }
  236. }
  237. else
  238. {
  239. sb.Append("(无动作)");
  240. }
  241. return sb.ToString();
  242. }
  243. }
  244. // ----------------------------------------------------------------------
  245. }
  246. }