123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using CommonLang.Property;
- using CommonAI.Zone.Attributes;
- using CommonAI.Zone;
- using CommonAI.Zone.ZoneEditor;
- using CommonAI.RTS;
- using CommonLang.Vector;
- using CommonAI.Zone.Instance;
- using CommonAI.Zone.Helper;
- using CommonAI.Zone.EventTrigger;
- using CommonLang;
- namespace CommonAI.Zone.ZoneEditor.EventTrigger
- {
- //-------------------------------------------------------------------
- //-------------------------------------------------------------------
- [DescAttribute("什么都不做", "Nothing")]
- public class DoNoting : AbstractAction
- {
- public override string ToString()
- {
- return "什么都不做";
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- }
- }
- [DescAttribute("消息框", "Test")]
- public class ShowMessageBox : AbstractAction
- {
- [DescAttribute("消息")]
- public StringValue Message = new StringValue.VALUE("");
- public override string ToString()
- {
- return string.Format("消息框({0})", Message);
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- api.ZoneAPI.sendMessageBox(Message.GetValue(api, args));
- }
- }
- [DescAttribute("延时执行一个动作", "流程控制 - 延时执行(DELAY)")]
- public class DelayedAction : AbstractAction
- {
- [DescAttribute("延时毫秒")]
- public IntegerValue DelayTimeMS = new IntegerValue.VALUE(1000);
- [DescAttribute("延时动作")]
- public AbstractAction DelayAction = new DoNoting();
- public override string ToString()
- {
- return string.Format("延时{0}(毫秒)后执行({1})", DelayTimeMS, DelayAction);
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- int delayMS = DelayTimeMS.GetValue(api, args);
- api.listen_TimeTask(args, 0, delayMS, 1, (args2) =>
- {
- DelayAction.DoAction(api, args2);
- });
- }
- }
- [DescAttribute("条件执行一个动作", "流程控制 - 条件执行(IF)")]
- public class ConditionAction : AbstractAction
- {
- [DescAttribute("IF 条件")]
- public BooleanValue Condition = new BooleanValue.BooleanComparison();
- [DescAttribute("THEN 动作")]
- public AbstractAction Action = new DoNoting();
- [DescAttribute("ELSE 动作")]
- public AbstractAction ElseAction = null;
- public override string ToString()
- {
- if (ElseAction == null)
- {
- return string.Format("IF ({0}) THEN ({1})", Condition, Action);
- }
- else
- {
- return string.Format("IF ({0}) THEN ({1}) ELSE ({2})", Condition, Action, ElseAction);
- }
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- if (Condition.GetValue(api, args))
- {
- Action.DoAction(api, args);
- }
- else if (ElseAction != null)
- {
- ElseAction.DoAction(api, args);
- }
- }
- }
- [DescAttribute("整形FOR循环执行一个动作", "流程控制 - 循环执行(FOR)")]
- public class IteratorForInt32Action : AbstractAction
- {
- [DescAttribute("起始值")]
- public IntegerValue BeginIndex = new IntegerValue.VALUE(0);
- [DescAttribute("递增")]
- public IntegerValue Step = new IntegerValue.VALUE(1);
- [DescAttribute("结束值(不包括)")]
- public IntegerValue EndIndex = new IntegerValue.VALUE(10);
- [DescAttribute("动作")]
- public AbstractAction Action = new DoNoting();
- public override string ToString()
- {
- return string.Format("FOR (起始={0} 递增+{1} 结束<{2}) DO {3})", BeginIndex, Step, EndIndex, Action);
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- int start = BeginIndex.GetValue(api, args);
- int step = Step.GetValue(api, args);
- int end = EndIndex.GetValue(api, args);
- args = args.Clone();
- for (int i = start; i < end; i += step)
- {
- args.IteratingInt32 = (i);
- Action.DoAction(api, args);
- args.IteratingInt32 = (0);
- }
- }
- }
- [DescAttribute("执行多条指令", "流程控制 - 执行序列")]
- public class DoAction3 : AbstractAction
- {
- [DescAttribute("动作1")]
- public AbstractAction Action1 = new DoNoting();
- [DescAttribute("动作2")]
- public AbstractAction Action2 = new DoNoting();
- [DescAttribute("动作3")]
- public AbstractAction Action3 = new DoNoting();
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder("执行序列: ");
- if (Action1 != null)
- {
- sb.Append(Action1.ToString()).Append(", ");
- }
- if (Action2 != null)
- {
- sb.Append(Action2.ToString()).Append(", ");
- }
- if (Action3 != null)
- {
- sb.Append(Action3.ToString()).Append(", ");
- }
- return sb.ToString();
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- if (Action1 != null)
- {
- Action1.DoAction(api, args);
- }
- if (Action2 != null)
- {
- Action2.DoAction(api, args);
- }
- if (Action3 != null)
- {
- Action3.DoAction(api, args);
- }
- }
- }
- [DescAttribute("按顺序执行动作(执行多条指令)", "流程控制 - 执行序列")]
- public class DoActionQueue : AbstractAction
- {
- [DescAttribute("动作序列")]
- [ListAttribute(typeof(AbstractAction))]
- public List<AbstractAction> ActionQueue = new List<AbstractAction>();
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder("执行序列: ");
- foreach (AbstractAction ca in ActionQueue)
- {
- sb.Append(ca.ToString());
- if (ActionQueue[ActionQueue.Count - 1] != ca)
- {
- sb.Append(" -> ");
- }
- }
- return sb.ToString();
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- foreach (AbstractAction ca in ActionQueue)
- {
- ca.DoAction(api, args);
- }
- }
- }
- [DescAttribute("Switch ... Case (int32)", "流程控制 - 多条件(SWITCH)")]
- public class SwitchCaseInteger : AbstractAction
- {
- [DescAttribute("Switch值")]
- public IntegerValue SwitchValue = new IntegerValue.RandomInt();
- [DescAttribute("Case集合")]
- [ListAttribute(typeof(CaseActionInt32))]
- public List<CaseActionInt32> Cases = new List<CaseActionInt32>();
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder("switch");
- sb.AppendLine(string.Format("({0})", SwitchValue));
- sb.AppendLine("{");
- foreach (CaseActionInt32 ca in Cases)
- {
- sb.AppendLine(ca.ToString());
- }
- sb.Append("}");
- return sb.ToString();
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- int sv = SwitchValue.GetValue(api, args);
- foreach (CaseActionInt32 ca in Cases)
- {
- int cv = ca.CaseValue.GetValue(api, args);
- if (cv == sv)
- {
- ca.Action.DoAction(api, args);
- }
- }
- }
- [DescAttribute("Case动作")]
- [Expandable]
- public class CaseActionInt32
- {
- [DescAttribute("Case值")]
- public IntegerValue CaseValue = new IntegerValue.VALUE();
- [DescAttribute("Case动作")]
- public AbstractAction Action = new DoNoting();
- public override string ToString()
- {
- return string.Format("case {0}: {1}; break;", CaseValue, Action);
- }
- }
- }
- [DescAttribute("Switch ... Case (string)", "流程控制 - 多条件(SWITCH)")]
- public class SwitchCaseString : AbstractAction
- {
- [DescAttribute("Switch值")]
- public StringValue SwitchValue = new StringValue.NULL();
- [DescAttribute("Case集合")]
- [ListAttribute(typeof(CaseActionString))]
- public List<CaseActionString> Cases = new List<CaseActionString>();
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder("switch");
- sb.AppendLine(string.Format("(\"{0}\")", SwitchValue));
- sb.AppendLine("{");
- foreach (CaseActionString ca in Cases)
- {
- sb.AppendLine(ca.ToString());
- }
- sb.Append("}");
- return sb.ToString();
- }
- public override void DoAction(EventTriggerAdapter api, EventArguments args)
- {
- string sv = SwitchValue.GetValue(api, args);
- foreach (CaseActionString ca in Cases)
- {
- string cv = ca.CaseValue.GetValue(api, args);
- if (cv == sv)
- {
- ca.Action.DoAction(api, args);
- }
- }
- }
- [DescAttribute("Case动作")]
- [Expandable]
- public class CaseActionString
- {
- [DescAttribute("Case值")]
- public StringValue CaseValue = new StringValue.NULL();
- [DescAttribute("Case动作")]
- public AbstractAction Action = new DoNoting();
- public override string ToString()
- {
- return string.Format("case \"{0}\": {1}; break;", CaseValue, Action);
- }
- }
- }
- }
|