using System; using System.Collections.Generic; using System.Text; using CommonLang.Property; using CommonAI.Zone.Attributes; using CommonAI.Zone.ZoneEditor; using CommonLang.Formula; using CommonAI.Zone.Instance; using CommonAI.RTS; using CommonLang.Vector; using CommonLang; using CommonAI.Zone.EventTrigger; namespace CommonAI.Zone.ZoneEditor.EventTrigger { [DescAttribute("布尔型")] public abstract class BooleanValue : AbstractValue { [DescAttribute("值", "值")] public class VALUE : BooleanValue { [DescAttribute("值")] public bool Value; public VALUE() { this.Value = true; } public VALUE(bool value) { this.Value = value; } public override string ToString() { return Value + ""; } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { return Value; } } [DescAttribute("百分比几率", "几率")] public class RandomPercent : BooleanValue { [DescAttribute("百分比几率")] public RealValue Percent = new RealValue.VALUE(50); public override string ToString() { return string.Format("{0}%几率", Percent); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { float pct = Percent.GetValue(api, args); if (pct > 0) { return CUtils.RandomPercent(api.ZoneAPI.RandomN, pct); } return false; } } [DescAttribute("布尔运算", "比较")] public class BooleanOperator : BooleanValue { [DescAttribute("值1")] public BooleanValue Condition1 = new VALUE(); [DescAttribute("运算符")] public BooleanOP Op = BooleanOP.EQUAL; [DescAttribute("值2")] public BooleanValue Condition2 = new VALUE(); public override string ToString() { return string.Format("({0}){1}({2})", Condition1, FormulaHelper.ToString(Op), Condition2); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { Boolean c1 = Condition1.GetValue(api, args); Boolean c2 = Condition2.GetValue(api, args); return FormulaHelper.Calculate(c1, Op, c2); } } [DescAttribute("布尔比较", "比较")] public class BooleanComparison : BooleanValue { [DescAttribute("值1")] public BooleanValue Condition1 = new VALUE(); [DescAttribute("比较符")] public ObjectComparisonOP Op = ObjectComparisonOP.EQUAL; [DescAttribute("值2")] public BooleanValue Condition2 = new VALUE(); public override string ToString() { return string.Format("({0}){1}({2})", Condition1, FormulaHelper.ToString(Op), Condition2); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { Boolean c1 = Condition1.GetValue(api, args); Boolean c2 = Condition2.GetValue(api, args); return FormulaHelper.Compare(c1, Op, c2); } } [DescAttribute("字符串比较", "比较")] public class StringComparison : BooleanValue { [DescAttribute("字符串1")] public StringValue String1 = new StringValue.VALUE(); [DescAttribute("比较符")] public ObjectComparisonOP Op = ObjectComparisonOP.EQUAL; [DescAttribute("字符串2")] public StringValue String2 = new StringValue.VALUE(); public override string ToString() { return string.Format("({0}){1}({2})", String1, FormulaHelper.ToString(Op), String2); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { string c1 = String1.GetValue(api, args); string c2 = String2.GetValue(api, args); return FormulaHelper.Compare(c1, Op, c2); } } [DescAttribute("字符串是否包含", "比较")] public class StringContains : BooleanValue { [DescAttribute("字符串")] public StringValue String = new StringValue.VALUE(); [DescAttribute("子字符串")] public StringValue SubString = new StringValue.VALUE(); public override string ToString() { return string.Format("({0}).Contains({1})", String, SubString); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { string c1 = String.GetValue(api, args); string c2 = SubString.GetValue(api, args); return c1.Contains(c2); } } [DescAttribute("字符串前缀比较", "比较")] public class StringStartsWith : BooleanValue { [DescAttribute("字符串")] public StringValue String = new StringValue.VALUE(); [DescAttribute("前缀")] public StringValue Prefix = new StringValue.VALUE(); public override string ToString() { return string.Format("({0}).StartsWith({1})", String, Prefix); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { string c1 = String.GetValue(api, args); string c2 = Prefix.GetValue(api, args); return c1.StartsWith(c2); } } [DescAttribute("字符串后缀比较", "比较")] public class StringEndsWith : BooleanValue { [DescAttribute("字符串")] public StringValue String = new StringValue.VALUE(); [DescAttribute("后缀")] public StringValue Suffix = new StringValue.VALUE(); public override string ToString() { return string.Format("({0}).EndsWith({1})", String, Suffix); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { string c1 = String.GetValue(api, args); string c2 = Suffix.GetValue(api, args); return c1.EndsWith(c2); } } [DescAttribute("小数比较", "比较")] public class RealComparison : BooleanValue { [DescAttribute("值1")] public RealValue Value1 = new RealValue.VALUE(); [DescAttribute("比较符")] public NumericComparisonOP Op = NumericComparisonOP.EQUAL; [DescAttribute("值2")] public RealValue Value2 = new RealValue.VALUE(); public override string ToString() { return string.Format("({0}){1}({2})", Value1, FormulaHelper.ToString(Op), Value2); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { Single c1 = Value1.GetValue(api, args); Single c2 = Value2.GetValue(api, args); return FormulaHelper.Compare(c1, Op, c2); } } [DescAttribute("整数比较", "比较")] public class IntegerComparison : BooleanValue { [DescAttribute("值1")] public IntegerValue Value1 = new IntegerValue.VALUE(); [DescAttribute("比较符")] public NumericComparisonOP Op = NumericComparisonOP.EQUAL; [DescAttribute("值2")] public IntegerValue Value2 = new IntegerValue.VALUE(); public override string ToString() { return string.Format("({0}){1}({2})", Value1, FormulaHelper.ToString(Op), Value2); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { Int32 c1 = Value1.GetValue(api, args); Int32 c2 = Value2.GetValue(api, args); return FormulaHelper.Compare(c1, Op, c2); } } [DescAttribute("单位比较", "比较")] public class UnitComparison : BooleanValue { [DescAttribute("单位1")] public UnitValue Value1 = new UnitValue.NA(); [DescAttribute("比较符")] public ObjectComparisonOP Op = ObjectComparisonOP.EQUAL; [DescAttribute("单位2")] public UnitValue Value2 = new UnitValue.NA(); public override string ToString() { return string.Format("({0}){1}({2})", Value1, FormulaHelper.ToString(Op), Value2); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceUnit c1 = Value1.GetValue(api, args); InstanceUnit c2 = Value2.GetValue(api, args); return FormulaHelper.Compare(c1, Op, c2); } } [DescAttribute("物品比较", "比较")] public class ItemComparison : BooleanValue { [DescAttribute("物品1")] public ItemValue Value1 = new ItemValue.NA(); [DescAttribute("比较符")] public ObjectComparisonOP Op = ObjectComparisonOP.EQUAL; [DescAttribute("物品2")] public ItemValue Value2 = new ItemValue.NA(); public override string ToString() { return string.Format("({0}){1}({2})", Value1, FormulaHelper.ToString(Op), Value2); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceItem c1 = Value1.GetValue(api, args); InstanceItem c2 = Value2.GetValue(api, args); return FormulaHelper.Compare(c1, Op, c2); } } [DescAttribute("Flag比较", "比较")] public class FlagComparison : BooleanValue { [DescAttribute("Flag1")] public FlagValue Value1 = new FlagValue.NA(); [DescAttribute("比较符")] public ObjectComparisonOP Op = ObjectComparisonOP.EQUAL; [DescAttribute("Flag2")] public FlagValue Value2 = new FlagValue.NA(); public override string ToString() { return string.Format("({0}){1}({2})", Value1, FormulaHelper.ToString(Op), Value2); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceFlag c1 = Value1.GetValue(api, args); InstanceFlag c2 = Value2.GetValue(api, args); return FormulaHelper.Compare(c1, Op, c2); } } [DescAttribute("Flag是否开启", "Flag状态")] public class FlagEnabled : BooleanValue { [DescAttribute("Flag")] public FlagValue Flag = new FlagValue.NA(); public override string ToString() { return string.Format("({0}).Enable", Flag); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceFlag flag = Flag.GetValue(api, args); if (flag != null) { return flag.Enable; } return false; } } [DescAttribute("区域刷新点是否刷新完毕", "Flag状态")] public class FlagIsSpawnOver : BooleanValue { [DescAttribute("区域")] public FlagValue Region = new FlagValue.EditorRegion(); public override string ToString() { return string.Format("({0})刷新完毕", Region); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { ZoneRegion region = Region.GetValue(api, args) as ZoneRegion; if (region != null) { return region.IsSpawnOver; } return false; } } [DescAttribute("区域刷新点是否没有存活单位", "Flag状态")] public class FlagIsSpawnNoneAlive : BooleanValue { [DescAttribute("区域")] public FlagValue Region = new FlagValue.EditorRegion(); public override string ToString() { return string.Format("({0})没有存活单位", Region); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { ZoneRegion region = Region.GetValue(api, args) as ZoneRegion; if (region != null) { return region.IsSpawnNoneAlive; } return false; } } [DescAttribute("场景用户自定义属性", "场景")] public class ZoneBooleanAttribute : BooleanValue { [DescAttribute("键值")] public string Key; public override string ToString() { return string.Format("场景键值[{0}]", Key); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { try { return Boolean.Parse(api.ZoneAPI.GetAttribute(Key) as string); } catch (Exception err) { Console.WriteLine("ZoneBooleanAttribute : " + Key + ", catch: " + err); } return false; } } #region __UNIT__ [DescAttribute("单位用户自定义属性", "单位")] public class UnitBooleanAttribute : BooleanValue { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("键值")] public string Key; public override string ToString() { return string.Format("单位({0})键值[{1}]", Unit, Key); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if (unit != null) { try { return Boolean.Parse(unit.GetAttribute(Key) as string); } catch (Exception err) { Console.WriteLine("UnitBooleanAttribute : " + Key + ", catch: " + err); } } return false; } } [DescAttribute("单位存活", "单位")] public class UnitIsAlived : BooleanValue { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); public override string ToString() { return string.Format("单位({0})活着", Unit); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if (unit != null) { return !unit.IsDead(); } return false; } } [DescAttribute("单位是否在区域", "单位")] public class UnitIsInArea : BooleanValue { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("区域")] public FlagValue.EditorRegion Region = new FlagValue.EditorRegion(); public override string ToString() { return string.Format("单位({0})在区域({1})", Unit, Region); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); ZoneRegion region = Region.GetValue(api, args) as ZoneRegion; if (unit != null && region != null) { bool isIn = region.IsUnitInRegion(unit); //Console.WriteLine("IsInRegin : " + isIn + ", " + region.Name); return isIn; } return false; } } [DescAttribute("单位死亡", "单位")] public class UnitIsDead : BooleanValue { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); public override string ToString() { return string.Format("单位({0})死亡", Unit); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if (unit != null) { return unit.IsDead(); } //不存在则认为死亡 return true; } } [DescAttribute("单位存在", "单位")] public class UnitExist : BooleanValue { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); public override string ToString() { return string.Format("单位({0})存在", Unit); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); return (unit != null); } } [DescAttribute("单位是否拥有道具", "单位")] public class UnitHasInventoryItem : BooleanValue { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("物品ID")] public ItemTemplateValue Item = new ItemTemplateValue.Template(); public override string ToString() { return string.Format("单位({0})是否拥有道具{1}", Unit, Item); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); ItemTemplate temp = Item.GetValue(api, args); if (unit != null && temp != null) { return unit.ContainsItemInInventory(temp.ID); } return false; } } [DescAttribute("玩家是否自动战斗", "玩家")] public class PlayerIsGuard : BooleanValue { [DescAttribute("玩家单位")] public UnitValue Unit = new UnitValue.Trigging(); public override string ToString() { return string.Format("玩家单位({0})是否自动战斗", Unit); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if (unit is InstancePlayer) { return (unit as InstancePlayer).IsGuard; } return false; } } #endregion #region __TRIGGER__ [DescAttribute("当前触发器是否已开启", "触发器")] public class CurrentEventTriggerIsActive : BooleanValue { public override string ToString() { return string.Format("当前触发器是否已开启"); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { return api.IsActive; } } [DescAttribute("指定触发器是否已开启", "触发器")] public class SpecifyEventTriggerIsActive : BooleanValue { [DescAttribute("事件触发器名字")] [SceneEventIDAttribute] public string EventName; public override string ToString() { return string.Format("触发器:({0})是否已开启", EventName); } public override Boolean GetValue(IEditorValueAdapter api, EventArguments args) { EventTriggerAdapter evt = api.Group.GetEditEvent(EventName); if (evt != null) { return evt.IsActive; } return false; } } #endregion } }