EventsClientScript.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. using CommonAI.Zone.Attributes;
  2. using CommonAI.Zone.EventTrigger;
  3. using CommonAI.Zone.Instance;
  4. using CommonAI.Zone.ZoneEditor.EventTrigger;
  5. using CommonLang;
  6. using CommonLang.Property;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using XmdsCommon.Message;
  12. using XmdsCommonServer.Message;
  13. using XmdsCommonServer.Plugin.Scene;
  14. namespace XmdsCommonServer.Plugin.Editor
  15. {
  16. [DescAttribute("Xmds脚本-通知客户端添加单位", "Xmds扩展")]
  17. public class ScriptUnitAddedAction : AbstractAction
  18. {
  19. [DescAttribute("单位")]
  20. public UnitValue Unit = new UnitValue.LastAdded();
  21. public override string ToString()
  22. {
  23. return string.Format("Xmds脚本-通知客户端添加单位({0})", Unit);
  24. }
  25. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  26. {
  27. InstanceUnit unit = Unit.GetValue(api, args);
  28. if (unit != null)
  29. {
  30. api.ZoneAPI.queueEvent(new ScriptAddUnitEventsB2C(unit));
  31. }
  32. }
  33. }
  34. [DescAttribute("Xmds脚本-通知客户端删除", "Xmds扩展")]
  35. public class ScriptUnitRemovedAction : AbstractAction
  36. {
  37. [DescAttribute("单位")]
  38. public UnitValue Unit = new UnitValue.LastKilled();
  39. public override string ToString()
  40. {
  41. return string.Format("Xmds脚本-通知客户端删除单位({0})", Unit);
  42. }
  43. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  44. {
  45. InstanceUnit unit = Unit.GetValue(api, args);
  46. if (unit != null)
  47. {
  48. api.ZoneAPI.queueEvent(new ScriptRemoveUnitEventsB2C(unit));
  49. }
  50. }
  51. }
  52. [DescAttribute("Xmds扩展事件-通知服务端传送单位", "Xmds扩展")]
  53. public class XmdsTransUnitEventAction : AbstractAction
  54. {
  55. [DescAttribute("单位")]
  56. public UnitValue Unit = new UnitValue.LastKilled();
  57. [DescAttribute("目的地场景ID")]
  58. public int SceneID = 0;
  59. [DescAttribute("场景坐标X")]
  60. public int X = 0;
  61. [DescAttribute("场景坐标Y")]
  62. public int Y = 0;
  63. public override string ToString()
  64. {
  65. return string.Format("Xmds扩展事件-通知服务端传送单位{0}至场景{1},坐标:X = {2} Y = {3}", Unit, SceneID, X, Y);
  66. }
  67. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  68. {
  69. InstancePlayer unit = Unit.GetValue(api, args) as InstancePlayer;
  70. if (unit != null)
  71. {
  72. TransUnitEventB2R evt = new TransUnitEventB2R();
  73. evt.playerId = unit.PlayerUUID;
  74. evt.SceneID = SceneID;
  75. evt.TargetX = X;
  76. evt.TargetY = Y;
  77. unit.queueEvent(evt);
  78. }
  79. }
  80. }
  81. [DescAttribute("Xmds扩展事件-通知战斗服重置所有状态", "Xmds扩展")]
  82. public class XmdsUnitResetAction : AbstractAction
  83. {
  84. [DescAttribute("单位")]
  85. public UnitValue Unit = new UnitValue.LastKilled();
  86. public override string ToString()
  87. {
  88. return string.Format("Xmds扩展事件-重置指定单位{0}所有状态", Unit);
  89. }
  90. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  91. {
  92. InstancePlayer unit = Unit.GetValue(api, args) as InstancePlayer;
  93. if (unit != null)
  94. {
  95. (unit.Virtual as XmdsVirtual).Reset();
  96. }
  97. }
  98. }
  99. [DescAttribute("Xmds扩展事件-事件计时器重置", "Xmds扩展")]
  100. public class ResetTriggerTimerAction : AbstractAction
  101. {
  102. [DescAttribute("重置触发器名字")]
  103. public string TriggerName = null;
  104. [DescAttribute("触发器")]
  105. public override string ToString()
  106. {
  107. return string.Format("Xmds扩展事件-重置计时器");
  108. }
  109. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  110. {
  111. EventTriggerAdapter eta = api.Group.GetEditEvent(TriggerName);
  112. if (eta != null)
  113. {
  114. eta.ResetTimeTask();
  115. }
  116. }
  117. }
  118. [DescAttribute("某个玩家的剧情脚本已结束", "Xmds扩展")]
  119. public class DramaOverTrigger : AbstractTrigger
  120. {
  121. public override void Listen(EventTriggerAdapter api, EventArguments args)
  122. {
  123. var args2 = args.Clone();
  124. XmdsServerScene scene = (api.ZoneAPI as XmdsServerScene);
  125. XmdsServerScene.OnHandleObjectActionHandler handler = new XmdsServerScene.OnHandleObjectActionHandler((unit, action) =>
  126. {
  127. if (action is PlayerDramaEndAction)
  128. {
  129. args2.TriggingUnit = unit as InstanceUnit;
  130. api.SetAttribute("TriggingDramaID", (action as PlayerDramaEndAction).dramaId);
  131. api.TestAndDoAction(args2);
  132. }
  133. });
  134. scene.OnHandleObjectAction += handler;
  135. api.OnDisposed += (a) =>
  136. {
  137. scene.OnHandleObjectAction -= handler;
  138. };
  139. }
  140. public override string ToString()
  141. {
  142. return string.Format("某个玩家的剧情脚本已结束");
  143. }
  144. }
  145. [DescAttribute("触发中的剧情ID", "Xmds扩展")]
  146. public class TriggingDramaID : StringValue
  147. {
  148. public override string ToString()
  149. {
  150. return string.Format("触发中的剧情ID");
  151. }
  152. public override string GetValue(IEditorValueAdapter api, EventArguments args)
  153. {
  154. return api.GetAttribute("TriggingDramaID") as string;
  155. }
  156. }
  157. /// <summary>
  158. /// 发送战中特殊飘字事件.
  159. /// </summary>
  160. [DescAttribute("Xmds扩展事件-发送战中飘字事件", "Xmds扩展")]
  161. public class SendBattleFloatTipsEventAction : AbstractAction
  162. {
  163. [DescAttribute("单位")]
  164. public UnitValue Unit = new UnitValue.Trigging();
  165. [DescAttribute("飘字类型")]
  166. public CommonAI.XmdsConstConfig.BattleFloatTipsType Type;
  167. public override string ToString()
  168. {
  169. return string.Format("Xmds扩展事件-向{0}发送战中飘字事件", Unit);
  170. }
  171. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  172. {
  173. InstancePlayer unit = Unit.GetValue(api, args) as InstancePlayer;
  174. if (unit != null)
  175. {
  176. BattleFloatTipsEventB2C evt = new BattleFloatTipsEventB2C();
  177. evt.Type = Type;
  178. (unit.Virtual as XmdsVirtual).SendBattleFloatTipsEventB2C(evt);
  179. }
  180. }
  181. }
  182. [DescAttribute("Xmds扩展事件-通知游戏服触发场景事件", "Xmds扩展")]
  183. public class XmdsTriggerSceneEventtAction : AbstractAction
  184. {
  185. [DescAttribute("单位")]
  186. public UnitValue Unit = new UnitValue.LastKilled();
  187. [DescAttribute("事件ID")]
  188. public string EventID = null;
  189. public override string ToString()
  190. {
  191. return string.Format("Xmds扩展事件-通知服务端玩家单位{0}触发场景事件{1}", Unit, EventID);
  192. }
  193. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  194. {
  195. InstancePlayer unit = Unit.GetValue(api, args) as InstancePlayer;
  196. if (unit != null)
  197. {
  198. TriggerSceneEventB2R evt = new TriggerSceneEventB2R();
  199. evt.playerId = unit.PlayerUUID;
  200. evt.EventID = EventID;
  201. unit.queueEvent(evt);
  202. }
  203. }
  204. }
  205. [DescAttribute("Xmds扩展事件-通知客户端指定单位播放声音.", "Xmds扩展")]
  206. public class XmdsPlaySoundForOne : AbstractAction
  207. {
  208. [DescAttribute("单位")]
  209. public UnitValue Unit = new UnitValue.LastKilled();
  210. [DescAttribute("声音文件")]
  211. [ResourceIDAttribute]
  212. public string SoundName = null;
  213. public override string ToString()
  214. {
  215. return string.Format("Xmds扩展事件-通知客户端向个别单位播放声音");
  216. }
  217. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  218. {
  219. InstancePlayer unit = Unit.GetValue(api, args) as InstancePlayer;
  220. if (unit != null)
  221. {
  222. PlaySoundEventB2CForOne evt = new PlaySoundEventB2CForOne();
  223. evt.SoundName = SoundName;
  224. unit.queueEvent(evt);
  225. }
  226. }
  227. }
  228. [DescAttribute("Xmds扩展事件-通知客户端广播播放声音.", "Xmds扩展")]
  229. public class XmdsPlaySoundForAll : AbstractAction
  230. {
  231. [DescAttribute("声音文件名")]
  232. [ResourceIDAttribute]
  233. public string SoundName = null;
  234. public override string ToString()
  235. {
  236. return string.Format("Xmds扩展事件-通知客户端广播播放声音");
  237. }
  238. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  239. {
  240. PlaySoundEventB2CForAll evt = new PlaySoundEventB2CForAll();
  241. evt.SoundName = SoundName;
  242. api.ZoneAPI.queueEvent(evt);
  243. }
  244. }
  245. [DescAttribute("Xmds扩展事件-向游戏服发送战报", "Xmds扩展")]
  246. public class SendXmdsBattleReportAction : AbstractAction
  247. {
  248. public override string ToString()
  249. {
  250. return string.Format("Xmds扩展事件-向游戏服发送战报");
  251. }
  252. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  253. {
  254. var e = new BattleReportEventB2R
  255. {
  256. instanceId = api.ZoneAPI.UUID
  257. };
  258. // using (var a = ListObjectPool<InstancePlayer>.AllocAutoRelease(api.ZoneAPI.AllPlayers))
  259. using (var a = ListObjectPool<InstanceUnit>.AllocAutoRelease(api.ZoneAPI.AllUnits))
  260. {
  261. e.data = new List<UnitBattleReportDetail>();
  262. foreach (var b in a.Where(b => b.Statistic.TotalDamage > 0 || b.Statistic.TotalHealing > 0))
  263. {
  264. e.data.Add(new UnitBattleReportDetail()
  265. {
  266. ID = b.ID,
  267. PlayerUUID = b.PlayerUUID,
  268. TemplateID = b.Info.TemplateID,
  269. Force = b.Force,
  270. TotalDamage = (int)b.Statistic.TotalDamage,
  271. TotalHealing = (int)b.Statistic.TotalHealing,
  272. });
  273. }
  274. }
  275. api.ZoneAPI.queueEvent(e);
  276. }
  277. }
  278. /// <summary>
  279. /// 发送BOSS被击杀通知.
  280. /// </summary>
  281. [DescAttribute("Xmds扩展事件-向游戏服发送谁击杀了BOSS.", "Xmds扩展")]
  282. public class SendBossKillEventAction : AbstractAction
  283. {
  284. [DescAttribute("单位")]
  285. public UnitValue Unit = new UnitValue.LastKilled();
  286. public override string ToString()
  287. {
  288. return string.Format("Xmds扩展事件-向游戏服发送谁击杀了BOSS");
  289. }
  290. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  291. {
  292. InstancePlayer unit = Unit.GetValue(api, args) as InstancePlayer;
  293. if (unit != null && unit.Virtual != null)
  294. {
  295. var evt = new KillBossEventB2R();
  296. evt.instanceId = api.ZoneAPI.UUID;
  297. evt.PlayerUUID = (unit.Virtual as XmdsVirtual).GetPlayerUUID();
  298. api.ZoneAPI.queueEvent(evt);
  299. }
  300. }
  301. }
  302. }