EventsAOI.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. using CommonAI.RTS;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Attributes;
  4. using CommonAI.Zone.EventTrigger;
  5. using CommonAI.Zone.Instance;
  6. using CommonAI.Zone.ZoneEditor.EventTrigger;
  7. using CommonLang;
  8. using CommonLang.Property;
  9. using CommonLang.Vector;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using XmdsCommonServer.Plugin.Scene;
  15. namespace XmdsCommonServer.Plugin.Editor
  16. {
  17. [DescAttribute("触发中的玩家添加AOI单位", "Xmds扩展 - 位面")]
  18. public class XmdsAddUnitActionAOI : AbstractAction
  19. {
  20. [DescAttribute("玩家")]
  21. public UnitValue Player = new UnitValue.Trigging();
  22. [DescAttribute("单位模板ID")]
  23. [TemplateIDAttribute(typeof(UnitInfo))]
  24. public int UnitTemplateID = 0;
  25. [DescAttribute("单位等级")]
  26. [TemplateLevelAttribute]
  27. public int UnitLevel = 0;
  28. [DescAttribute("单位阵营")]
  29. public IntegerValue Force = new IntegerValue.VALUE(0);
  30. [DescAttribute("用户定义名字(编辑器名字)")]
  31. public string UnitName;
  32. [DescAttribute("位置")]
  33. public PositionValue Position = new PositionValue.VALUE();
  34. [DescAttribute("朝向")]
  35. public float Direction;
  36. [DescAttribute("开始寻路")]
  37. public FlagValue.EditorPoint StartPoint;
  38. public override string ToString()
  39. {
  40. return string.Format("玩家({0})添加单位({1})到({2})", Player, UnitTemplateID, Position);
  41. }
  42. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  43. {
  44. InstancePlayer player = Player.GetValue(api, args) as InstancePlayer;
  45. Vector2 pos = Position.GetValue(api, args);
  46. if (pos != null && player != null && player.AoiStatus != null)
  47. {
  48. InstanceUnit unit = api.ZoneAPI.AddUnit(UnitTemplateID, UnitName, (byte)Force.GetValue(api, args), UnitLevel, pos.X, pos.Y, Direction);
  49. if (unit != null)
  50. {
  51. unit.setAoiStatus(player.AoiStatus);
  52. if (unit is InstanceGuard && StartPoint != null)
  53. {
  54. InstanceGuard guard = unit as InstanceGuard;
  55. InstanceFlag flag = StartPoint.GetValue(api, args);
  56. if (flag != null)
  57. {
  58. guard.attackTo(flag as ZoneWayPoint);
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. [DescAttribute("玩家进入位面", "Xmds扩展 - 位面")]
  66. public class PlayerEnterAOI : AbstractAction
  67. {
  68. [DescAttribute("玩家")]
  69. public UnitValue Player = new UnitValue.Trigging();
  70. [DescAttribute("别人可看到自己")]
  71. public BooleanValue CanSeeMe = new BooleanValue.VALUE(false);
  72. [DescAttribute("自己可看到别人")]
  73. public BooleanValue CanSeeOther = new BooleanValue.VALUE(false);
  74. [DescAttribute("队伍范围如果为0则代表玩家独立进入位面")]
  75. public IntegerValue TeamRadius = new IntegerValue.VALUE(0);
  76. [DescAttribute("怪物全部死亡则销毁位面")]
  77. public BooleanValue isDestoryedOnMonsterDead = new BooleanValue.VALUE(false);
  78. [DescAttribute("死亡则销毁位面")]
  79. public BooleanValue DeadExit = new BooleanValue.VALUE(false);
  80. [DescAttribute("完成指定任务ID,自动退出位面")]
  81. public StringValue QuestId = new StringValue.VALUE("");
  82. public override string ToString()
  83. {
  84. return string.Format("玩家({0})进入位面", Player);
  85. }
  86. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  87. {
  88. InstancePlayer player = Player.GetValue(api, args) as InstancePlayer;
  89. if (player != null && !player.isTeamMemberAndFollow()) //TODO 队员跟随状态不能进入位面
  90. {
  91. var aoi = new XmdsPlayerAOI(player,
  92. CanSeeMe.GetValue(api, args),
  93. CanSeeOther.GetValue(api, args),
  94. isDestoryedOnMonsterDead.GetValue(api, args),
  95. DeadExit.GetValue(api, args),
  96. QuestId.GetValue(api, args)
  97. );
  98. player.setAoiStatus(aoi);
  99. // -- 判断进入位面的队伍
  100. var tr = TeamRadius.GetValue(api, args);
  101. if (tr > 0)
  102. {
  103. var teamList = (player.Virtual as XmdsVirtual).TeamList;
  104. foreach (var uuid in teamList)
  105. {
  106. var p = player.Parent.getPlayerByUUID(uuid);
  107. if (p != null && CMath.intersectRound(player.X, player.Y, tr, p.X, p.Y, p.Info.BodySize))
  108. {
  109. p.setAoiStatus(aoi);
  110. }
  111. }
  112. }
  113. // END
  114. }
  115. }
  116. }
  117. [DescAttribute("玩家离开位面", "Xmds扩展 - 位面")]
  118. public class PlayerLeaveAOI : AbstractAction
  119. {
  120. [DescAttribute("玩家")]
  121. public UnitValue Player = new UnitValue.Trigging();
  122. public override string ToString()
  123. {
  124. return string.Format("玩家({0})离开位面", Player);
  125. }
  126. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  127. {
  128. InstancePlayer player = Player.GetValue(api, args) as InstancePlayer;
  129. if (player != null && player.AoiStatus is XmdsPlayerAOI)
  130. {
  131. var aoi = player.AoiStatus as XmdsPlayerAOI;
  132. using (var list = ListObjectPool<InstanceZoneObject>.AllocAutoRelease(aoi.Objects))
  133. {
  134. foreach (var obj in list)
  135. {
  136. if (obj != player && !(obj is InstancePlayer) && !(obj is InstanceSpell))
  137. {
  138. api.ZoneAPI.RemoveObjectByID(obj.ID);
  139. }
  140. }
  141. }
  142. player.setAoiStatus(null);
  143. }
  144. }
  145. }
  146. [DescAttribute("单位是否在位面", "Xmds扩展 - 位面")]
  147. public class UnitInAOIStatus : BooleanValue
  148. {
  149. [DescAttribute("单位")]
  150. public UnitValue Player = new UnitValue.Trigging();
  151. public override string ToString()
  152. {
  153. return string.Format("单位({0})是否在位面", Player);
  154. }
  155. public override bool GetValue(IEditorValueAdapter api, EventArguments args)
  156. {
  157. var player = Player.GetValue(api, args);
  158. if (player != null)
  159. {
  160. return player.AoiStatus != null;
  161. }
  162. return false;
  163. }
  164. }
  165. [DescAttribute("单位位面宿主", "Xmds扩展 - 位面")]
  166. public class UnitAOIOwnerUnit : UnitValue
  167. {
  168. [DescAttribute("单位")]
  169. public UnitValue Unit = new UnitValue.Trigging();
  170. public override string ToString()
  171. {
  172. return string.Format("({0})位面宿主", Unit);
  173. }
  174. public override InstanceUnit GetValue(IEditorValueAdapter api, EventArguments args)
  175. {
  176. var unit = Unit.GetValue(api, args);
  177. if (unit != null && unit.AoiStatus is XmdsPlayerAOI)
  178. {
  179. return (unit.AoiStatus as XmdsPlayerAOI).Owner;
  180. }
  181. return null;
  182. }
  183. }
  184. [DescAttribute("位面内单位数", "Xmds扩展 - 位面")]
  185. public class GetAOIUnitCount : IntegerValue
  186. {
  187. [DescAttribute("宿主")]
  188. public UnitValue Owner = new UnitValue.Trigging();
  189. [DescAttribute("指定Force")]
  190. public IntegerValue Force = new IntegerValue.UnitForce();
  191. [DescAttribute("指定TemplateID")]
  192. public IntegerValue TemplateID = new IntegerValue.UnitTemplateID();
  193. public override string ToString()
  194. {
  195. return string.Format("({0})位面内单位数", Owner);
  196. }
  197. public override int GetValue(IEditorValueAdapter api, EventArguments args)
  198. {
  199. var unit = Owner.GetValue(api, args);
  200. if (unit != null && unit.AoiStatus is XmdsPlayerAOI)
  201. {
  202. return (unit.AoiStatus as XmdsPlayerAOI).GetUnitCount(
  203. Force.GetValue(api, args),
  204. TemplateID.GetValue(api, args));
  205. }
  206. return 0;
  207. }
  208. }
  209. [DescAttribute("位面内单位数ByForce", "Xmds扩展 - 位面")]
  210. public class GetAOIUnitCountByForce : IntegerValue
  211. {
  212. [DescAttribute("宿主")]
  213. public UnitValue Owner = new UnitValue.Trigging();
  214. [DescAttribute("指定Force")]
  215. public IntegerValue Force = new IntegerValue.UnitForce();
  216. public override string ToString()
  217. {
  218. return string.Format("({0})位面内(Force={1})单位数", Owner, Force);
  219. }
  220. public override int GetValue(IEditorValueAdapter api, EventArguments args)
  221. {
  222. var unit = Owner.GetValue(api, args);
  223. if (unit != null && unit.AoiStatus is XmdsPlayerAOI)
  224. {
  225. return (unit.AoiStatus as XmdsPlayerAOI).GetUnitCountByForce(
  226. Force.GetValue(api, args));
  227. }
  228. return 0;
  229. }
  230. }
  231. [DescAttribute("位面内单位数ByTemplateID", "Xmds扩展 - 位面")]
  232. public class GetAOIUnitCountByTemplateID : IntegerValue
  233. {
  234. [DescAttribute("宿主")]
  235. public UnitValue Owner = new UnitValue.Trigging();
  236. [DescAttribute("指定TemplateID")]
  237. public IntegerValue TemplateID = new IntegerValue.UnitTemplateID();
  238. public override string ToString()
  239. {
  240. return string.Format("({0})位面内(模板={1})单位数", Owner, TemplateID);
  241. }
  242. public override int GetValue(IEditorValueAdapter api, EventArguments args)
  243. {
  244. var unit = Owner.GetValue(api, args);
  245. if (unit != null && unit.AoiStatus is XmdsPlayerAOI)
  246. {
  247. return (unit.AoiStatus as XmdsPlayerAOI).GetUnitCountByTemplateID(
  248. TemplateID.GetValue(api, args));
  249. }
  250. return 0;
  251. }
  252. }
  253. [DescAttribute("找到指定宿主创建的单位ByTemplateID", "Xmds扩展 - 位面")]
  254. public class GetAOIUnitByTemplateID : UnitValue
  255. {
  256. [DescAttribute("宿主")]
  257. public UnitValue Owner = new UnitValue.Trigging();
  258. [DescAttribute("指定TemplateID")]
  259. public IntegerValue TemplateID = new IntegerValue.UnitTemplateID();
  260. public override string ToString()
  261. {
  262. return string.Format("({0})位面内(TemplateID={1})的单位", Owner, TemplateID);
  263. }
  264. public override InstanceUnit GetValue(IEditorValueAdapter api, EventArguments args)
  265. {
  266. var unit = Owner.GetValue(api, args);
  267. if (unit != null && unit.AoiStatus is XmdsPlayerAOI)
  268. {
  269. return (unit.AoiStatus as XmdsPlayerAOI).FindUnitByTemplateID(TemplateID.GetValue(api, args));
  270. }
  271. return null;
  272. }
  273. }
  274. [DescAttribute("找到指定宿主创建的单位ByName", "Xmds扩展 - 位面")]
  275. public class GetAOIUnitByName : UnitValue
  276. {
  277. [DescAttribute("宿主")]
  278. public UnitValue Owner = new UnitValue.Trigging();
  279. [DescAttribute("指定Name")]
  280. public StringValue Name = new StringValue.VALUE("");
  281. public override string ToString()
  282. {
  283. return string.Format("({0})位面内(Name={1})的单位", Owner, Name);
  284. }
  285. public override InstanceUnit GetValue(IEditorValueAdapter api, EventArguments args)
  286. {
  287. var unit = Owner.GetValue(api, args);
  288. if (unit != null && unit.AoiStatus is XmdsPlayerAOI)
  289. {
  290. return (unit.AoiStatus as XmdsPlayerAOI).FindUnitByName(Name.GetValue(api, args));
  291. }
  292. return null;
  293. }
  294. }
  295. }