Actions.Client.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonLang.Property;
  5. using CommonAI.RTS; using CommonLang.Vector;
  6. using CommonAI.Zone.Instance;
  7. using CommonAI.Zone.Attributes;
  8. using CommonAI.Zone.EventTrigger;
  9. // __客户端动作__
  10. namespace CommonAI.Zone.ZoneEditor.EventTrigger
  11. {
  12. [DescAttribute("客户端")]
  13. public abstract class ClientAction : AbstractAction
  14. {
  15. [DescAttribute("发送给谁(为空表示广播)", "发送者")]
  16. public UnitValue Sender = new UnitValue.Trigging();
  17. public abstract ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args);
  18. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  19. {
  20. ClientEvent evt = AsEvent(api, args);
  21. if (evt != null)
  22. {
  23. evt.sender = Sender.GetValue(api, args);
  24. api.ZoneAPI.queueEvent(evt);
  25. }
  26. }
  27. }
  28. [DescAttribute("客户端动作序列", "客户端 - 动作序列")]
  29. public class ClientActionQueue : ClientAction
  30. {
  31. [DescAttribute("序列")]
  32. [ListAttribute(typeof(ClientAction))]
  33. public List<ClientAction> ActionQueue = new List<ClientAction>();
  34. public override string ToString()
  35. {
  36. StringBuilder sb = new StringBuilder("动作序列: ");
  37. foreach (ClientAction ca in ActionQueue)
  38. {
  39. sb.Append(ca.ToString());
  40. if (ActionQueue[ActionQueue.Count - 1] != ca)
  41. {
  42. sb.Append(" -> ");
  43. }
  44. }
  45. return sb.ToString();
  46. }
  47. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  48. {
  49. ClientEventQueue queue = new ClientEventQueue();
  50. foreach (ClientAction ca in ActionQueue)
  51. {
  52. ClientEvent evt = ca.AsEvent(api, args);
  53. if (evt != null)
  54. {
  55. queue.EventQueue.Add(evt);
  56. }
  57. }
  58. return queue;
  59. }
  60. }
  61. [DescAttribute("提示玩家显示箭头(CheckPoint)", "客户端")]
  62. public class ShowCheckPoint : ClientAction
  63. {
  64. [DescAttribute("位置")]
  65. public PositionValue Position = new PositionValue.VALUE();
  66. public override string ToString()
  67. {
  68. return string.Format("提示玩家显示箭头到({0})", Position);
  69. }
  70. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  71. {
  72. Vector2 pos = Position.GetValue(api, args);
  73. if (pos != null)
  74. {
  75. return new LookAtEvent("", pos.X, pos.Y);
  76. }
  77. return null;
  78. }
  79. }
  80. [DescAttribute("改变游戏运行速度", "客户端")]
  81. public class ChangeTimeScale : ClientAction
  82. {
  83. [DescAttribute("时间尺度百分比")]
  84. public float TimeScalePct = 100f;
  85. public override string ToString()
  86. {
  87. return string.Format("改变游戏运行速度{0}%", TimeScalePct);
  88. }
  89. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  90. {
  91. return new ChangeTimeScaleEvent(TimeScalePct);
  92. }
  93. }
  94. [DescAttribute("暂停游戏", "客户端")]
  95. public class GamePause : ClientAction
  96. {
  97. [DescAttribute("暂停多少秒,如果为0,则无限暂停")]
  98. public float Seconds = 0f;
  99. public override string ToString()
  100. {
  101. if (Seconds > 0)
  102. {
  103. return string.Format("暂停游戏{0}秒", Seconds);
  104. }
  105. return string.Format("暂停游戏");
  106. }
  107. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  108. {
  109. return new GamePauseEvent(Seconds);
  110. }
  111. }
  112. [DescAttribute("继续游戏", "客户端")]
  113. public class GameResume : ClientAction
  114. {
  115. public override string ToString()
  116. {
  117. return string.Format("继续游戏");
  118. }
  119. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  120. {
  121. return new GameResumeEvent();
  122. }
  123. }
  124. [DescAttribute("发送消息到客户端", "客户端")]
  125. public class GameNotify : ClientAction
  126. {
  127. [DescAttribute("消息")]
  128. public StringValue Message = new StringValue.VALUE();
  129. public override string ToString()
  130. {
  131. return string.Format("发送消息到客户端:{0}", Message);
  132. }
  133. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  134. {
  135. return new ClientMsgEvent(Message.GetValue(api, args));
  136. }
  137. }
  138. [DescAttribute("镜头锁定在某处一段时间", "客户端 - 镜头变换")]
  139. public class CameraHold : ClientAction
  140. {
  141. [DescAttribute("位置")]
  142. public PositionValue Position = new PositionValue.VALUE();
  143. [DescAttribute("镜头锁定的总时间(毫秒)")]
  144. public IntegerValue TotalTimeMS = new IntegerValue.VALUE(1000);
  145. public override string ToString()
  146. {
  147. return string.Format("锁定镜头到({0})持续({1})毫秒", Position, TotalTimeMS);
  148. }
  149. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  150. {
  151. Vector2 pos = Position.GetValue(api, args);
  152. int timeMS = TotalTimeMS.GetValue(api, args);
  153. if (pos != null)
  154. {
  155. return new CameraHoldEvent(pos.X, pos.Y, timeMS);
  156. }
  157. return null;
  158. }
  159. }
  160. [DescAttribute("移动镜头到", "客户端 - 镜头变换")]
  161. public class CameraMoveTo : ClientAction
  162. {
  163. [DescAttribute("位置")]
  164. public PositionValue Position = new PositionValue.VALUE();
  165. [DescAttribute("相机高度")]
  166. public RealValue Height = new RealValue.VALUE();
  167. [DescAttribute("镜头移动速度(每秒距离)")]
  168. public float MoveSpeedSec = 1f;
  169. public override string ToString()
  170. {
  171. return string.Format("移动镜头到({0})", Position);
  172. }
  173. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  174. {
  175. Vector2 pos = Position.GetValue(api, args);
  176. if (pos != null)
  177. {
  178. return new CameraMoveToEvent(pos.X, pos.Y, Height.GetValue(api,args), MoveSpeedSec, 0);
  179. }
  180. return null;
  181. }
  182. }
  183. [DescAttribute("移动镜头到(根据时间)", "客户端 - 镜头变换")]
  184. public class CameraMoveToByTime : ClientAction
  185. {
  186. [DescAttribute("位置")]
  187. public PositionValue Position = new PositionValue.VALUE();
  188. [DescAttribute("相机高度")]
  189. public RealValue Height = new RealValue.VALUE();
  190. [DescAttribute("镜头移动过去的总时间(毫秒)")]
  191. public IntegerValue TotalTimeMS = new IntegerValue.VALUE(1000);
  192. public override string ToString()
  193. {
  194. return string.Format("移动镜头到({0})", Position);
  195. }
  196. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  197. {
  198. Vector2 pos = Position.GetValue(api, args);
  199. int timeMS = TotalTimeMS.GetValue(api, args);
  200. if (pos != null)
  201. {
  202. return new CameraMoveToEvent(pos.X, pos.Y, Height.GetValue(api, args), 0, timeMS);
  203. }
  204. return null;
  205. }
  206. }
  207. [DescAttribute("锁定镜头到单位", "客户端 - 镜头变换")]
  208. public class CameraFocusUnit : ClientAction
  209. {
  210. [DescAttribute("单位 - 某个单位")]
  211. public UnitValue Unit = new UnitValue.Trigging();
  212. public override string ToString()
  213. {
  214. return string.Format("锁定镜头到({0})", Unit);
  215. }
  216. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  217. {
  218. InstanceUnit unit = Unit.GetValue(api, args);
  219. if (unit != null)
  220. {
  221. return new CameraFocusUnitEvent(unit.ID);
  222. }
  223. return null;
  224. }
  225. }
  226. [DescAttribute("拉近镜头", "客户端 - 镜头变换")]
  227. public class CameraZoomTo : ClientAction
  228. {
  229. [DescAttribute("镜头拉近距离")]
  230. public float ZoomDistance = 10f;
  231. [DescAttribute("镜头拉近速度(每秒距离)")]
  232. public float ZoomSpeedSec = 1f;
  233. public override string ToString()
  234. {
  235. return string.Format("拉近镜头到({0})", ZoomDistance);
  236. }
  237. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  238. {
  239. return new CameraZoomToEvent(ZoomDistance, ZoomSpeedSec);
  240. }
  241. }
  242. [DescAttribute("旋转镜头", "客户端 - 镜头变换")]
  243. public class CameraRotateTo : ClientAction
  244. {
  245. [DescAttribute("镜头旋转角度(0~360)")]
  246. public float RotateAngle = 10f;
  247. [DescAttribute("镜头旋转速度(每秒角度)")]
  248. public float RotateSpeedSec = 1f;
  249. public override string ToString()
  250. {
  251. return string.Format("旋转镜头到({0})", RotateAngle);
  252. }
  253. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  254. {
  255. return new CameraRotateToEvent(RotateAngle, RotateSpeedSec);
  256. }
  257. }
  258. [DescAttribute("重置镜头", "客户端 - 镜头变换")]
  259. public class CameraReset : ClientAction
  260. {
  261. public override string ToString()
  262. {
  263. return string.Format("重置镜头");
  264. }
  265. public override ClientEvent AsEvent(EventTriggerAdapter api, EventArguments args)
  266. {
  267. return new CameraResetEvent();
  268. }
  269. }
  270. }