Actions.Zone.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. using CommonAI.Zone.Attributes;
  2. using CommonAI.Zone.EventTrigger;
  3. using CommonAI.Zone.Helper;
  4. using CommonAI.Zone.Instance;
  5. using CommonLang.Property;
  6. using CommonLang.Vector;
  7. using System;
  8. using System.Collections.Generic;
  9. namespace CommonAI.Zone.ZoneEditor.EventTrigger
  10. {
  11. [DescAttribute("发送系统聊天消息", "场景")]
  12. public class SendChatMessage : AbstractAction
  13. {
  14. [DescAttribute("消息")]
  15. public StringValue Message = new StringValue.VALUE("你好世界!");
  16. [DescAttribute("消息类型")]
  17. public ChatMessageType SendTo = ChatMessageType.SystemToAll;
  18. [DescAttribute("持续时间(毫秒)")]
  19. public uint KeepTimeMS = 2000;
  20. [DescAttribute("预计发送的阵营", "可选")]
  21. public IntegerValue ToForce = new IntegerValue.VALUE(0);
  22. [DescAttribute("预计发送的单位", "可选")]
  23. public UnitValue ToPlayer = new UnitValue.NA();
  24. public override string ToString()
  25. {
  26. return string.Format("发送聊天消息: \"{0}\"", Message);
  27. }
  28. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  29. {
  30. string msg = Message.GetValue(api, args);
  31. if (!string.IsNullOrEmpty(msg))
  32. {
  33. ChatEvent chat = new ChatEvent(SendTo, KeepTimeMS);
  34. chat.Message = msg;
  35. chat.To = SendTo;
  36. switch (SendTo)
  37. {
  38. case ChatMessageType.SystemToPlayer:
  39. InstancePlayer target = ToPlayer.GetValue(api, args) as InstancePlayer;
  40. if (target == null)
  41. {
  42. break;
  43. }
  44. chat.ToPlayerUUID = target.PlayerUUID;
  45. #region <<判断演绎位面>>
  46. if (target.isTeamMemberAndFollow())
  47. {
  48. return;
  49. }
  50. var evt_param = msg.Split('|');
  51. if (evt_param.Length == 2)
  52. {
  53. var e = evt_param[0];
  54. var p = evt_param[1].Split(',');
  55. if (e == "Drama.Start" && p.Length > 1 && p[1] == "AOI")
  56. {
  57. if (!target.IsRobot)
  58. {
  59. target.setAoiStatus(new DarmaAOI(p[0]));
  60. }
  61. }
  62. }
  63. #endregion
  64. break;
  65. case ChatMessageType.SystemToForce:
  66. chat.Force = (byte)ToForce.GetValue(api, args);
  67. break;
  68. case ChatMessageType.SystemToAll:
  69. break;
  70. }
  71. api.ZoneAPI.queueEvent(chat);
  72. }
  73. }
  74. }
  75. [DescAttribute("游戏结束", "场景")]
  76. public class GameOverAction : AbstractAction
  77. {
  78. [DescAttribute("胜利方")]
  79. public IntegerValue WinForce = new IntegerValue.VALUE(0);
  80. [DescAttribute("消息")]
  81. public string Message;
  82. public override string ToString()
  83. {
  84. return string.Format("游戏结束 胜利方:{0} 消息:\"{1}\"", WinForce, Message);
  85. }
  86. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  87. {
  88. api.ZoneAPI.send_game_over(WinForce.GetValue(api, args), Message);
  89. }
  90. }
  91. [DescAttribute("游戏结束(变量)", "场景")]
  92. public class GameOverActionVar : AbstractAction
  93. {
  94. [DescAttribute("胜利方")]
  95. public IntegerValue WinForce = new IntegerValue.VALUE(0);
  96. [DescAttribute("消息")]
  97. public StringValue Message = new StringValue.VALUE("");
  98. public override string ToString()
  99. {
  100. return string.Format("游戏结束 胜利方:{0} 消息:\"{1}\"", WinForce, Message);
  101. }
  102. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  103. {
  104. api.ZoneAPI.send_game_over(WinForce.GetValue(api, args), Message.GetValue(api, args));
  105. }
  106. }
  107. [DescAttribute("客户端执行脚本文件", "场景")]
  108. public class RunClientScriptFileAction : AbstractAction
  109. {
  110. [DescAttribute("脚本文件")]
  111. public StringValue Script = new StringValue.NULL();
  112. public override string ToString()
  113. {
  114. return string.Format("客户端执行脚本文件:{0}", Script);
  115. }
  116. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  117. {
  118. string sc = Script.GetValue(api, args);
  119. if (sc != null)
  120. {
  121. api.ZoneAPI.do_client_script(sc);
  122. }
  123. }
  124. }
  125. [DescAttribute("客户端执行脚本代码", "场景")]
  126. public class RunScriptCodeAction : AbstractAction
  127. {
  128. [DescAttribute("脚本代码")]
  129. public StringValue Script = new StringValue.NULL();
  130. public override string ToString()
  131. {
  132. return string.Format("客户端执行脚本代码:{0}", Script);
  133. }
  134. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  135. {
  136. string sc = Script.GetValue(api, args);
  137. if (sc != null)
  138. {
  139. api.ZoneAPI.send_script_command(sc);
  140. }
  141. }
  142. }
  143. [DescAttribute("改变背景音乐", "场景")]
  144. public class ChangeBGMAction : AbstractAction
  145. {
  146. [DescAttribute("背景音乐文件")]
  147. [ResourceIDAttribute]
  148. public string MusicFile;
  149. public override string ToString()
  150. {
  151. return string.Format("改变背景音乐");
  152. }
  153. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  154. {
  155. api.ZoneAPI.queueEvent(new ChangeBGMEvent(MusicFile));
  156. }
  157. }
  158. [DescAttribute("激活场景事件触发器", "场景触发器")]
  159. public class EventTriggerActive : AbstractAction
  160. {
  161. [DescAttribute("事件触发器名字")]
  162. [SceneEventIDAttribute]
  163. public string EventName;
  164. public override string ToString()
  165. {
  166. return string.Format("激活场景事件触发器({0})", EventName);
  167. }
  168. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  169. {
  170. api.Group.EventActive(EventName, args);
  171. }
  172. }
  173. [DescAttribute("关闭场景事件触发器", "场景触发器")]
  174. public class EventTriggerDeactive : AbstractAction
  175. {
  176. [DescAttribute("事件触发器名字")]
  177. [SceneEventIDAttribute]
  178. public string EventName;
  179. public override string ToString()
  180. {
  181. return string.Format("关闭场景事件触发器({0})", EventName);
  182. }
  183. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  184. {
  185. api.Group.EventDeactive(EventName, args);
  186. }
  187. }
  188. [DescAttribute("在指定地点放一个特效", "特效表现")]
  189. public class AddZoneEffect : AbstractAction
  190. {
  191. [DescAttribute("特效")]
  192. public LaunchEffect Effect = new LaunchEffect();
  193. [DescAttribute("位置")]
  194. public PositionValue Pos = new PositionValue.VALUE();
  195. [DescAttribute("方向")]
  196. public RealValue Direction = new RealValue.VALUE();
  197. public override string ToString()
  198. {
  199. return string.Format("在({0})位置添加特效({1})", Pos, Effect);
  200. }
  201. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  202. {
  203. Vector2 pos = Pos.GetValue(api, args);
  204. if (pos != null)
  205. {
  206. float d = Direction.GetValue(api, args);
  207. api.ZoneAPI.queueEvent(new AddEffectEvent(0 , pos.X, pos.Y, d, Effect));
  208. }
  209. }
  210. }
  211. [DescAttribute("在指定单位身上放一个特效", "特效表现")]
  212. public class AddUnitEffect : AbstractAction
  213. {
  214. [DescAttribute("特效")]
  215. public LaunchEffect Effect = new LaunchEffect();
  216. [DescAttribute("单位 - 某个单位")]
  217. public UnitValue Unit = new UnitValue.Trigging();
  218. public override string ToString()
  219. {
  220. return string.Format("在({0})添加特效({1})", Unit, Effect);
  221. }
  222. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  223. {
  224. InstanceUnit u = Unit.GetValue(api, args);
  225. if (u != null)
  226. {
  227. u.queueEvent(new UnitEffectEvent(u.ID, Effect));
  228. }
  229. }
  230. }
  231. [DescAttribute("发送消息到游戏服", "游戏服")]
  232. public class SendMessageToGS : AbstractAction
  233. {
  234. [DescAttribute("消息")]
  235. public StringValue Message = new StringValue.VALUE("msg");
  236. public override string ToString()
  237. {
  238. return string.Format("发送消息到游戏服:{0}", Message);
  239. }
  240. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  241. {
  242. string msg = Message.GetValue(api, args);
  243. if (!string.IsNullOrEmpty(msg))
  244. {
  245. if(msg.Contains("{objid}"))
  246. {
  247. var unit = args.TriggingUnit;
  248. if(unit == null)
  249. {
  250. return;
  251. }
  252. msg = msg.Replace("{objid}", $"{unit.get_id()}");
  253. }
  254. api.ZoneAPI.SendMessageToGameServer(msg);
  255. }
  256. }
  257. }
  258. [DescAttribute("气泡聊天", "场景")]
  259. public class BubbleTalk : AbstractAction
  260. {
  261. [DescAttribute("是否暂停战斗")]
  262. public bool PauseBattle = false;
  263. [DescAttribute("内容")]
  264. [ListAttribute(typeof(TalkInfo))]
  265. public List<TalkInfo> Talks = new List<TalkInfo>();
  266. [DescAttribute("单位 - 某个单位")]
  267. public UnitValue TalkUnit = new UnitValue.NA();
  268. public override string ToString()
  269. {
  270. return string.Format("气泡聊天");
  271. }
  272. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  273. {
  274. InstancePlayer pointUnit = TalkUnit.GetValue(api, args) as InstancePlayer;
  275. BubbleTalkEvent e = new BubbleTalkEvent();
  276. e.PauseBattle = PauseBattle;
  277. e.TalkInfos.Clear();
  278. foreach (TalkInfo t in Talks)
  279. {
  280. if (t.IsNarrator)
  281. {
  282. BubbleTalkEvent.TalkInfo info = new BubbleTalkEvent.TalkInfo(0, t.TalkContent, t.TalkActionType, t.TalkDelayTimeMS, t.TalkKeepTimeMS);
  283. e.TalkInfos.Add(info);
  284. }
  285. else
  286. {
  287. InstanceUnit unit = t.TalkUnit.GetValue(api, args);
  288. if (unit != null)
  289. {
  290. BubbleTalkEvent.TalkInfo info = new BubbleTalkEvent.TalkInfo(unit.ID, t.TalkContent, t.TalkActionType, t.TalkDelayTimeMS, t.TalkKeepTimeMS);
  291. e.TalkInfos.Add(info);
  292. }
  293. }
  294. }
  295. if(pointUnit == null)
  296. {
  297. api.ZoneAPI.queueEvent(e);
  298. }
  299. else
  300. {
  301. api.ZoneAPI.doSendMsgToPlayer(pointUnit, e);
  302. }
  303. }
  304. [DescAttribute("聊天内容")]
  305. [Expandable]
  306. public class TalkInfo
  307. {
  308. [DescAttribute("单位 - 某个单位")]
  309. public UnitValue TalkUnit = new UnitValue.NA();
  310. [DescAttribute("是否是旁边白")]
  311. public bool IsNarrator = false;
  312. [LocalizationTextAttribute]
  313. [DescAttribute("内容")]
  314. public string TalkContent;
  315. [DescAttribute("动作")]
  316. public string TalkActionType;
  317. [DescAttribute("延迟时间")]
  318. public int TalkDelayTimeMS;
  319. [DescAttribute("持续时间")]
  320. public int TalkKeepTimeMS;
  321. }
  322. }
  323. }