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.EventTrigger; using CommonLang; using CommonAI.Zone.Helper; using CommonAI.data; namespace CommonAI.Zone.ZoneEditor.EventTrigger { [DescAttribute("激活单位事件触发器", "单位触发器")] public class UnitEventTriggerActive : AbstractAction { [DescAttribute("事件触发器名字")] [UnitEventIDAttribute] public string EventName; public override string ToString() { return string.Format("激活单位事件触发器({0})", EventName); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { api.Group.EventActive(EventName, args); } } [DescAttribute("关闭单位事件触发器", "单位触发器")] public class UnitEventTriggerDeactive : AbstractAction { [DescAttribute("事件触发器名字")] [UnitEventIDAttribute] public string EventName; public override string ToString() { return string.Format("关闭单位事件触发器({0})", EventName); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { api.Group.EventDeactive(EventName, args); } } //------------------------------------------------------------------------------------------- #region __单位动作__ [DescAttribute("添加单位", "单位")] public class AddUnitAction : AbstractAction { [DescAttribute("单位模板ID")] [TemplateIDAttribute(typeof(UnitInfo))] public int UnitTemplateID = 0; [DescAttribute("单位等级")] [TemplateLevelAttribute] public int UnitLevel = 0; [DescAttribute("单位阵营")] public IntegerValue Force = new IntegerValue.VALUE(1); [DescAttribute("用户定义名字(编辑器名字)")] public string UnitName; [DescAttribute("位置")] public PositionValue Position = new PositionValue.VALUE(); [DescAttribute("朝向")] public float Direction; [DescAttribute("开始寻路")] public FlagValue.EditorPoint StartPoint; [DescAttribute("场景内是否唯一")] public bool unique; [DescAttribute("初始当前生命百分比(0, 100)")] public int hpPrecent; public override string ToString() { return string.Format("添加单位({0})到({1})", UnitTemplateID, Position); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { if(this.unique) { InstanceUnit targetUnit = api.ZoneAPI.getUnitByTemplateID(UnitTemplateID); if (targetUnit != null) { return; } } Vector2 pos = Position.GetValue(api, args); if(pos != null) { InstanceUnit unit = api.ZoneAPI.AddUnit(UnitTemplateID, UnitName, (byte)Force.GetValue(api, args), UnitLevel, pos.X, pos.Y, Direction, false); if(unit is IGuardUnit && StartPoint != null) { IGuardUnit guard = unit as IGuardUnit; InstanceFlag flag = StartPoint.GetValue(api, args); if(flag != null) { guard.AttackTo(flag as ZoneWayPoint); } } if(0 < hpPrecent && hpPrecent < 100) { int reduceHP = (int)(unit.MaxHP * 0.01f * (100 -hpPrecent)); unit.ReduceHP(-reduceHP, null, true, null, false, Data.DamageSource.Def, true); } } } } [DescAttribute("单位增加金钱", "单位")] public class UnitAddMoneyAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("金钱")] public IntegerValue Money = new IntegerValue.VALUE(100); public override string ToString() { return string.Format("给({0})增加金钱({1})", Unit, Money); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { int money = Money.GetValue(api, args); InstanceUnit unit = Unit.GetValue(api, args); if(unit != null && money != 0) { unit.CurrentMoney += money; } } } [DescAttribute("单位隐身", "单位")] public class UnitStealthAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("隐身")] public IntegerValue stealth = new IntegerValue.VALUE(1); public IntegerValue flag = new IntegerValue.VALUE(0); public override string ToString() { return string.Format("设置({0})隐身状态({1}),标记:{2}", Unit, stealth, flag); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { int stealthState = stealth.GetValue(api, args); InstanceUnit unit = Unit.GetValue(api, args); if (unit != null) { if(stealthState > 0) { int extValue = flag.GetValue(api, args); unit.AddActionSubState(UnitActionSubStatus.Stealth, (short)extValue); } else { unit.RemoveActionSubState(UnitActionSubStatus.Stealth); } } } } [DescAttribute("杀死单位", "单位")] public class KillUnitAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); public override string ToString() { return string.Format("杀死({0})", Unit); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if(unit != null) { unit.kill(); } } } [DescAttribute("直接移除单位", "单位")] public class RemoveUnitAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); public override string ToString() { return string.Format("直接移除({0})", Unit); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if(unit != null) { api.ZoneAPI.RemoveObject(unit); } } } [DescAttribute("给单位添加BUFF(过时,请用TrggerEvent)", "单位")] public class UnitAddBuffAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("Buff模板ID")] [TemplateIDAttribute(typeof(BuffTemplate))] public int BuffTemplateID; public override string ToString() { return string.Format("给({0})添加BUFF({1})", Unit, BuffTemplateID); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { //Console.WriteLine("-----------------DoAction : " + TimeUtil.GetTimestampMS()/1000); InstanceUnit unit = Unit.GetValue(api, args); if(unit != null) { unit.AddBuff(BuffTemplateID); } } } [DescAttribute("单位触发TrggerEvent(Buff)", "单位")] public class UnitTriggerEventAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); public int TriggerID; public override string ToString() { return string.Format("单位({0})触发事件({1})", Unit, TriggerID); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { //单位事件,只允许自己触发,有攻击者的需要绑定攻击。 InstanceUnit unit = Unit.GetValue(api, args); if (unit != null) { BattleFunction.GetInstance().TriggrBattleFunction(TriggerID, unit.Virtual, unit.Virtual); } } } [DescAttribute("给单位删除BUFF", "单位")] public class UnitRemoveBuffAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("Buff")] public BuffTemplateValue Buff = new BuffTemplateValue.Template(); public override string ToString() { return string.Format("给({0})删除BUFF({1})", Unit, Buff); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { var unit = Unit.GetValue(api, args); var buff = Buff.GetValue(api, args); if(unit != null && buff != null) { unit.removeBuff(buff.ID); } } } [DescAttribute("单位直接使用物品", "单位")] public class UnitUseItemAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("物品")] public ItemTemplateValue Item = new ItemTemplateValue.Template(); public override string ToString() { return string.Format("给({0})使用物品({1})", Unit, Item); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { ItemTemplate item = Item.GetValue(api, args); InstanceUnit unit = Unit.GetValue(api, args); if(unit != null && item != null) { unit.UseItem(item, unit); } } } [DescAttribute("单位冻结技能", "单位")] public class UnitRemoveSkill : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("物品")] public int skillID; public override string ToString() { return string.Format("单位({0})冻结技能({1})", Unit, skillID); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if (unit != null) { unit.SetSkillActive(skillID, false); } } } [DescAttribute("单位激活技能", "单位")] public class UnitActiveSkill : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("物品")] public int skillID; public override string ToString() { return string.Format("单位({0})激活技能({1})", Unit, skillID); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if (unit != null) { unit.SetSkillActive(skillID, true); } } } [DescAttribute("设置单位(建筑)攻击目标", "单位")] public class SetUnitTragetAtkAction : AbstractAction { [DescAttribute("单位(建筑)")] public UnitValue Unit1 = new UnitValue.Trigging(); [DescAttribute("单位(攻击者)")] public UnitValue Unit2 = new UnitValue.Trigging(); public override string ToString() { return string.Format("设置({0})攻击目标为({1})", Unit1, Unit2); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceBuilding unit1 = Unit1.GetValue(api, args) as InstanceBuilding; InstanceUnit unit2 = Unit2.GetValue(api, args); if (unit1 != null && unit2 != null) { unit1.SetTracingTarget(unit2); } } } [DescAttribute("给单位背包添加道具", "单位 - 背包")] public class UnitAddInventoryItemAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("物品")] public ItemTemplateValue Item = new ItemTemplateValue.Template(); [DescAttribute("数量")] public IntegerValue Count = new IntegerValue.VALUE(1); public override string ToString() { return string.Format("给({0})背包添加{2}个物品({1})", Unit, Item, Count); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { ItemTemplate item = Item.GetValue(api, args); InstanceUnit unit = Unit.GetValue(api, args); int count = Count.GetValue(api, args); if(unit != null && item != null && count > 0) { unit.AddItemToEmptyInventory(item, count); } } } [DescAttribute("从单位背包丢弃道具", "单位 - 背包")] public class UnitDropInventoryItemAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("物品")] public ItemTemplateValue Item = new ItemTemplateValue.Template(); [DescAttribute("数量")] public IntegerValue Count = new IntegerValue.VALUE(1); public override string ToString() { return string.Format("从({0})背包丢弃{2}个物品({1})", Unit, Item, Count); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { ItemTemplate item = Item.GetValue(api, args); InstanceUnit unit = Unit.GetValue(api, args); int count = Count.GetValue(api, args); if(unit != null && item != null && count > 0) { unit.DropInventoryItemByType(item.ID, count); } } } [DescAttribute("从单位背包清除道具", "单位 - 背包")] public class UnitClearInventoryItemAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("物品")] public ItemTemplateValue Item = new ItemTemplateValue.Template(); public override string ToString() { return string.Format("从({0})背包清除物品({1})", Unit, Item); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { ItemTemplate item = Item.GetValue(api, args); InstanceUnit unit = Unit.GetValue(api, args); if(unit != null && item != null) { unit.ClearInventoryItemByType(item.ID); } } } [DescAttribute("使用背包内的道具", "单位 - 背包")] public class UnitUseInventoryItemAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("物品")] public ItemTemplateValue Item = new ItemTemplateValue.Template(); [DescAttribute("数量")] public IntegerValue Count = new IntegerValue.VALUE(1); public override string ToString() { return string.Format("使用({0})背包内的{2}个道具({1})", Unit, Item, Count); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { ItemTemplate item = Item.GetValue(api, args); InstanceUnit unit = Unit.GetValue(api, args); int count = Count.GetValue(api, args); if(unit != null && item != null && count > 0) { unit.UseInventoryItemByType(item.ID, count); } } } [DescAttribute("单位释放法术", "单位")] public class UnitLaunchSpellAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("释放法术")] public LaunchSpell Spell = new LaunchSpell(); public override string ToString() { return string.Format("({0})释放法术({1})", Unit, Spell); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if(unit != null && Spell != null) { api.ZoneAPI.unitLaunchSpell(XmdsSkillType.none, unit, Spell, unit.X, unit.Y); } } } [DescAttribute("单位释放技能", "单位")] public class UnitLaunchSkillAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("释放技能")] public LaunchSkill Skill = new LaunchSkill(); public override string ToString() { return string.Format("({0})释放技能({1})", Unit, Skill); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if(unit != null && Skill != null) { unit.launchSkill(Skill.SkillID, new InstanceUnit.LaunchSkillParam()); } } } [DescAttribute("给单位添加被动触发", "单位")] public class UnitAddTriggerAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("UnitTrigger模板ID")] [TemplateIDAttribute(typeof(UnitTriggerTemplate))] public int TriggerTemplateID; public override string ToString() { return string.Format("给({0})添加BUFF({1})", Unit, TriggerTemplateID); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args) as InstanceUnit; if(unit != null) { unit.addTrigger(TriggerTemplateID); } } } [DescAttribute("单位添加HP", "单位")] public class UnitAddHPAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("增加HP")] public IntegerValue AddHP = new IntegerValue.VALUE(); public override string ToString() { return string.Format("给({0})添加({1})HP", Unit, AddHP); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args) as InstanceUnit; if(unit != null) { int add_hp = AddHP.GetValue(api, args); unit.AddHP(add_hp, null); } } } [DescAttribute("单位添加HP百分比", "单位")] public class UnitAddHPPctAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("增加HP百分比")] public RealValue AddHPPct = new RealValue.VALUE(); public override string ToString() { return string.Format("给({0})添加({1})%HP", Unit, AddHPPct); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args) as InstanceUnit; if(unit != null) { float add_hp = AddHPPct.GetValue(api, args); unit.AddHP_Pct(add_hp, unit); } } } [DescAttribute("单位清除所有BUFF(Debuff)", "单位")] public class UnitCleanBuffAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); public override string ToString() { return string.Format("清理{0}所有的BUFF", Unit); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); if(unit != null) { unit.clearBuffs(); } } } [DescAttribute("单位传送", "单位")] public class UnitTransportAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("位置")] public PositionValue Pos = new PositionValue.VALUE(); public override string ToString() { return string.Format("{0}传送到{1}", Unit, Pos); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); Vector2 pos = Pos.GetValue(api, args); if(unit != null && pos != null) { unit.transport(pos.X, pos.Y); } } } [DescAttribute("单位暂停/继续逻辑", "单位")] public class UnitPauseAction : AbstractAction { [DescAttribute("单位")] public UnitValue Unit = new UnitValue.Trigging(); [DescAttribute("暂停/继续")] public BooleanValue Pause = new BooleanValue.VALUE(); [DescAttribute("暂停时长(毫秒)")] public IntegerValue PauseTimeMS = new IntegerValue.VALUE(0); public override string ToString() { return string.Format("{0}.暂停逻辑={1}", Unit, Pause); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { InstanceUnit unit = Unit.GetValue(api, args); Boolean pause = Pause.GetValue(api, args); int timeMS = PauseTimeMS.GetValue(api, args); if(unit != null) { unit.Pause(pause, timeMS); } } } [DescAttribute("克隆单位", "单位")] public class CloneUnitAction : AbstractAction { [DescAttribute("克隆原始体")] public UnitValue SrcUnit = new UnitValue.Trigging(); [DescAttribute("克隆单位类型")] public UnitInfo.UnitType NewType = UnitInfo.UnitType.TYPE_MANUAL; [DescAttribute("克隆单位名字")] public string NewName = "Clone"; [DescAttribute("克隆单位阵营")] public IntegerValue NewForce = new IntegerValue.VALUE(0); [DescAttribute("克隆单位等级")] public int NewLevel = 0; [DescAttribute("位置")] public PositionValue Position = new PositionValue.VALUE(); public override string ToString() { return string.Format("克隆单位({0})到({1})", SrcUnit, NewName); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { Vector2 pos = Position.GetValue(api, args); InstanceUnit src = SrcUnit.GetValue(api, args); if(pos != null && src != null) { UnitInfo info = (UnitInfo)src.Info.Clone(); info.UType = NewType; InstanceUnit u = api.ZoneAPI.AddUnit(info, NewName, (byte)NewForce.GetValue(api, args), NewLevel, pos.X, pos.Y, src.Direction); if(u != null) { u.SetVisibleInfo(src.VisibleInfo); } } } } [DescAttribute("单位开始逃跑", "单位")] public class UnitEscapeAction : AbstractAction { [DescAttribute("单位")] public UnitValue SrcUnit = new UnitValue.Trigging(); [DescAttribute("持续时间(ms)")] public IntegerValue KeepTimeMS = new IntegerValue.VALUE(10000); [DescAttribute("逃跑距离")] public RealValue EscapeDistance = new RealValue.VALUE(20); public override string ToString() { return string.Format("单位({0})开始逃跑", SrcUnit); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { var src = SrcUnit.GetValue(api, args); if(src != null) { var distance = EscapeDistance.GetValue(api, args); var time = KeepTimeMS.GetValue(api, args); src.startEscape(time, distance); } } } #endregion //------------------------------------------------------------------------------------------- #region __单组位动作__ [DescAttribute("遍历某个阵营所有单位", "遍历单位组")] public class EveryForceUnitDoAction : AbstractAction { [DescAttribute("阵营")] public IntegerValue SelectForce = new IntegerValue.VALUE(0); [DescAttribute("动作")] public AbstractAction Action = new DoNoting(); public override string ToString() { return string.Format("遍历所有阵营{0}的单位 DO {1}", SelectForce, Action); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { byte force = (byte)SelectForce.GetValue(api, args); using(var units = ListObjectPool.AllocAutoRelease()) { var args2 = args.Clone(); api.ZoneAPI.GetForceUnits(force, units); foreach(InstanceUnit u in units) { args2.IteratingUnit = (u); Action.DoAction(api, args2); args2.IteratingUnit = (null); } } } } [DescAttribute("遍历所有单位", "遍历单位组")] public class EveryUnitDoAction : AbstractAction { [DescAttribute("动作")] public AbstractAction Action = new DoNoting(); public override string ToString() { return string.Format("遍历所有单位 DO {0}", Action); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { using (var units = ListObjectPool.AllocAutoRelease()) { var args2 = args.Clone(); api.ZoneAPI.GetAllUnits(units); foreach (InstanceUnit u in units) { args2.IteratingUnit = (u); Action.DoAction(api, args2); args2.IteratingUnit = (null); } } } } [DescAttribute("遍历坐标半径范围内所有单位", "遍历单位组")] public class EveryRangedUnitDoAction : AbstractAction { [DescAttribute("坐标")] public PositionValue Position = new PositionValue.VALUE(); [DescAttribute("半径")] public float Range = 10f; [DescAttribute("动作")] public AbstractAction Action = new DoNoting(); public override string ToString() { return string.Format("遍历坐标({0})半径({1})范围内的单位 DO {2}", Position, Range, Action); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { Vector2 pos = Position.GetValue(api, args); if(pos != null) { using(var list = ListObjectPool.AllocAutoRelease()) { var args2 = args.Clone(); api.ZoneAPI.getObjectsRoundRange( Collider.Object_Pos_IncludeInRound, pos.X, pos.Y, Range, list , null); foreach(InstanceUnit u in list) { args2.IteratingUnit = (u); Action.DoAction(api, args2); args2.IteratingUnit = (null); } } } } } [DescAttribute("遍历区域内所有单位", "遍历单位组")] public class EveryUnitInRegionDoAction : AbstractAction { [DescAttribute("区域")] public FlagValue Region = new FlagValue.EditorRegion(); [DescAttribute("动作")] public AbstractAction Action = new DoNoting(); public override string ToString() { return string.Format("遍历区域({0})内的单位 DO {1}", Region, Action); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { ZoneRegion region = Region.GetValue(api, args) as ZoneRegion; if(region != null) { using(var list = ListObjectPool.AllocAutoRelease()) { var args2 = args.Clone(); region.getObjectsInRegion(list); foreach(InstanceUnit u in list) { args2.IteratingUnit = (u); Action.DoAction(api, args2); args2.IteratingUnit = (null); } } } } } [DescAttribute("遍历区域产生的所有单位", "遍历单位组")] public class EverySpawnedUnitInRegionDoAction : AbstractAction { [DescAttribute("区域")] public FlagValue Region = new FlagValue.EditorRegion(); [DescAttribute("动作")] public AbstractAction Action = new DoNoting(); public override string ToString() { return string.Format("遍历区域({0})产生的单位 DO {1}", Region, Action); } override public void DoAction(EventTriggerAdapter api, EventArguments args) { ZoneRegion region = Region.GetValue(api, args) as ZoneRegion; if(region != null) { using(var list = ListObjectPool.AllocAutoRelease()) { var args2 = args.Clone(); region.getSpawnedObjectsInRegion(list); foreach(InstanceUnit u in list) { args2.IteratingUnit = (u); Action.DoAction(api, args2); args2.IteratingUnit = (null); } } } } } #endregion }