123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- using CommonAI.Zone.EventTrigger;
- using CommonAI.Zone.ZoneEditor.EventTrigger;
- using CommonLang.IO;
- using CommonLang.IO.Attribute;
- using CommonLang.Property;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CommonAI.Zone
- {
- /// 事件动作触发器
- /// </summary>
- [MessageType(0x4502)]
- [TableClassAttribute("Name")]
- public class UnitEvent : ICloneable, IEventDataNode, IExternalizable
- {
- public string EventName { get { return this.Name; } set { this.Name = value; } }
- public string EventTreePath { get { return this.SavePath; } set { this.SavePath = value; } }
- public bool EventIsActive { get { return this.Active; } set { this.Active = value; } }
- public string EventComment { get { return this.Comment; } set { this.Comment = value; } }
- public int EventDelayTimeMS { get { return this.DelayTimeMS; } set { this.DelayTimeMS = value; } }
- public List<LocalVar> EventLocalVars { get { return this.LocalVars.Datas; } }
- public List<AbstractTrigger> EventTriggers { get { return this.Triggers.Datas; } }
- public List<AbstractCondition> EventConditions { get { return this.Conditions.Datas; } }
- public List<AbstractAction> EventActions { get { return this.Actions.Datas; } }
- /// <summary>
- /// 触发器名字
- /// </summary>
- public string Name = "Unnamed";
- /// <summary>
- /// 启用
- /// </summary>
- public bool Active = true;
- /// <summary>
- /// 注释
- /// </summary>
- public string Comment = "";
- /// <summary>
- /// 保存
- /// </summary>
- public string SavePath;
- /// <summary>
- /// 延迟执行
- /// </summary>
- public int DelayTimeMS;
- /// <summary>
- /// 临时变量
- /// </summary>
- public UnitLocalVars LocalVars = new UnitLocalVars();
- /// <summary>
- /// 事件触发
- /// </summary>
- public UnitTriggers Triggers = new UnitTriggers();
- /// <summary>
- /// 条件
- /// </summary>
- public UnitConditions Conditions = new UnitConditions();
- /// <summary>
- /// 动作
- /// </summary>
- public UnitActions Actions = new UnitActions();
- public UnitEvent()
- {
- Triggers.Datas.Add(new BindingUnitDamaged());
- Conditions.Datas.Add(new AlwaysTrue());
- Actions.Datas.Add(new UnitAddBuffAction());
- }
- public object Clone()
- {
- UnitEvent ret = new UnitEvent();
- ret.Name = this.Name;
- ret.Active = this.Active;
- ret.Comment = this.Comment;
- ret.SavePath = this.SavePath;
- ret.DelayTimeMS = this.DelayTimeMS;
- this.LocalVars.Clone(ret.LocalVars);
- this.Triggers.Clone(ret.Triggers);
- this.Conditions.Clone(ret.Conditions);
- this.Actions.Clone(ret.Actions);
- return ret;
- //return IOUtil.CloneIExternalizable<UnitEvent>(TemplateManager.MessageCodec, this);
- }
- public override string ToString()
- {
- return Name + "";
- }
- public string FunctionText()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append(Triggers.ToString());
- sb.Append(",\n");
- sb.Append("满足条件:").Append(Conditions.ToString());
- sb.Append(",\n");
- sb.Append("执行动作:").Append(Actions.ToString());
- sb.Append("。");
- return sb.ToString();
- }
- public void WriteExternal(IOutputStream output)
- {
- output.PutUTF(this.Name);
- output.PutBool(this.Active);
- output.PutUTF(this.Comment);
- output.PutUTF(this.SavePath);
- output.PutS32(this.DelayTimeMS);
- output.PutObj2Xml(this.LocalVars);
- output.PutObj2Xml(this.Triggers);
- output.PutObj2Xml(this.Conditions);
- output.PutObj2Xml(this.Actions);
- }
- public void ReadExternal(IInputStream input)
- {
- this.Name = input.GetUTF();
- this.Active = input.GetBool();
- this.Comment = input.GetUTF();
- this.SavePath = input.GetUTF();
- this.DelayTimeMS = input.GetS32();
- this.LocalVars = input.GetXml2Obj<UnitLocalVars>();
- this.Triggers = input.GetXml2Obj<UnitTriggers>();
- this.Conditions = input.GetXml2Obj<UnitConditions>();
- this.Actions = input.GetXml2Obj<UnitActions>();
- }
- // ----------------------------------------------------------------------
- public class UnitLocalVars
- {
- public List<LocalVar> Datas = new List<LocalVar>();
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- if (Datas.Count > 0)
- {
- for (int i = 0; i < Datas.Count; i++)
- {
- sb.AppendLine(Datas[i].ToString());
- }
- }
- return sb.ToString();
- }
- public void Clone(UnitLocalVars data)
- {
- data.Datas.Clear();
- for (int i = 0; i < Datas.Count; i++)
- {
- data.Datas.Add(this.Datas[i]);
- }
- }
- }
- public class UnitTriggers
- {
- public List<AbstractTrigger> Datas = new List<AbstractTrigger>();
- public void Clone(UnitTriggers data)
- {
- data.Datas.Clear();
- for (int i = 0; i < Datas.Count; i++)
- {
- data.Datas.Add(this.Datas[i]);
- }
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- if (Datas.Count > 0)
- {
- for (int i = 0; i < Datas.Count; i++)
- {
- sb.Append(Datas[i]);
- if (i < Datas.Count - 1)
- {
- sb.Append(" 或者 ");
- }
- }
- }
- else
- {
- sb.Append("(无起因)");
- }
- return sb.ToString();
- }
- }
- public class UnitConditions
- {
- public List<AbstractCondition> Datas = new List<AbstractCondition>();
- public void Clone(UnitConditions data)
- {
- data.Datas.Clear();
- for (int i = 0; i < Datas.Count; i++)
- {
- data.Datas.Add(this.Datas[i]);
- }
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- if (Datas.Count > 0)
- {
- for (int i = 0; i < Datas.Count; i++)
- {
- sb.Append(Datas[i]);
- if (i < Datas.Count - 1)
- {
- sb.Append(" 并且 ");
- }
- }
- }
- else
- {
- sb.Append("(无条件)");
- }
- return sb.ToString();
- }
- }
- public class UnitActions
- {
- public List<AbstractAction> Datas = new List<AbstractAction>();
- public void Clone(UnitActions data)
- {
- data.Datas.Clear();
- for (int i = 0; i < Datas.Count; i++)
- {
- data.Datas.Add(this.Datas[i]);
- }
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- if (Datas.Count > 0)
- {
- for (int i = 0; i < Datas.Count; i++)
- {
- sb.Append(Datas[i]);
- if (i < Datas.Count - 1)
- {
- sb.Append(" 并且 ");
- }
- }
- }
- else
- {
- sb.Append("(无动作)");
- }
- return sb.ToString();
- }
- }
- // ----------------------------------------------------------------------
- }
- }
|