EventTriggers.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using CommonAI.Zone.EventTrigger;
  3. using CommonLang.Property;
  4. using XmdsCommon.Message;
  5. using XmdsCommonServer.Plugin.Scene;
  6. using CommonAI.Zone.ZoneEditor.EventTrigger;
  7. using XmdsCommonServer.Plugin.Units;
  8. using CommonAI.Zone.Attributes;
  9. using CommonAI.Zone;
  10. using CommonAI.Zone.Instance;
  11. using XmdsCommon.Plugin;
  12. using CommonAI.Data;
  13. using CommonLang;
  14. namespace XmdsCommonServer.Plugin.Editor
  15. {
  16. [DescAttribute("某个单位进入战斗", "Xmds扩展 - 战斗")]
  17. public class XmdsUnitCombatStateChanged : AbstractTrigger
  18. {
  19. public override void Listen(EventTriggerAdapter api, EventArguments args)
  20. {
  21. var args2 = args.Clone();
  22. var scene = (api.ZoneAPI as XmdsServerScene);
  23. var handler = new XmdsServerScene.CombatStateChangeHandler((unit, status) =>
  24. {
  25. if (status != BattleStatus.None)
  26. {
  27. args2.TriggingUnit = unit;
  28. api.TestAndDoAction(args2);
  29. }
  30. });
  31. scene.OnCombatStateChange += handler;
  32. api.OnDisposed += (a) =>
  33. {
  34. scene.OnCombatStateChange -= handler;
  35. };
  36. }
  37. public override string ToString()
  38. {
  39. return string.Format("某个单位进入战斗");
  40. }
  41. }
  42. [DescAttribute("激活单位", "Xmds扩展 - 战斗")]
  43. public class XmdsPlayerReady : AbstractAction
  44. {
  45. [DescAttribute("玩家")]
  46. public UnitValue Player = new UnitValue.Trigging();
  47. public override void DoAction(EventTriggerAdapter api, EventArguments args)
  48. {
  49. var unit = Player.GetValue(api, args) as XmdsInstancePlayer;
  50. if (unit != null)
  51. {
  52. unit.PlayerReady();
  53. }
  54. }
  55. public override string ToString()
  56. {
  57. return string.Format("激活单位{0}", Player);
  58. }
  59. }
  60. [DescAttribute("添加变身单位", "Xmds扩展 - 战斗")]
  61. public class UnitShapeshiftingAction : AbstractAction
  62. {
  63. [DescAttribute("单位")]
  64. public readonly UnitValue Unit = new UnitValue.Trigging();
  65. [DescAttribute("变身前动作")]
  66. public string PreAnimationName;
  67. [DescAttribute("变身前动作持续时间(秒)")]
  68. public RealValue PreAnimationTimeSEC = new RealValue.VALUE();
  69. [DescAttribute("变身后模板ID")]
  70. [TemplateIDAttribute(typeof(UnitInfo))]
  71. public int ShapeshiftingTemplateID = 0;
  72. public override string ToString()
  73. {
  74. return string.Format("添加({0})->变身({1})", Unit, ShapeshiftingTemplateID);
  75. }
  76. override public void DoAction(EventTriggerAdapter api, EventArguments args)
  77. {
  78. var unit1 = Unit.GetValue(api, args) as InstanceGuard;
  79. var state1 = new InstanceUnit.ForceStateActionTime(unit1, PreAnimationTimeSEC.GetValue(api, args), PreAnimationName);
  80. state1.AddStopOnce((obj, st) =>
  81. {
  82. addShapeshifting(api, args, unit1);
  83. api.ZoneAPI.RemoveObject(unit1);
  84. });
  85. unit1.queueState(state1);
  86. }
  87. void addShapeshifting(EventTriggerAdapter api, EventArguments args, InstanceGuard src)
  88. {
  89. var info = api.ZoneAPI.Templates.getUnit(ShapeshiftingTemplateID);
  90. //
  91. var unit2 = api.ZoneAPI.AddUnit(info, src.Name, src.Force, src.Level, src.X, src.Y, src.Direction) as InstanceGuard;
  92. unit2.CurrentHP = CUtils.CastInt(src.CurrentHP_Pct * 0.01f * unit2.MaxHP);
  93. var c_target = src.TracingTarget;
  94. if (c_target != null)
  95. {
  96. unit2.queueState(new InstanceUnit.StateFollowAndAttack(unit2, c_target));
  97. }
  98. }
  99. }
  100. }