Browse Source

增加编辑器‘替换单位模板’动作

大爷 1 year ago
parent
commit
5cb12583a1

+ 12 - 8
Common/CommonAI/Zone/Instance/InstanceZone.cs

@@ -567,8 +567,7 @@ namespace CommonAI.Zone.Instance
 
 
         internal uint genObjectID()
         internal uint genObjectID()
         {
         {
-            mObjectIDIndexer++;
+            return ++mObjectIDIndexer;
-            return mObjectIDIndexer;
         }
         }
 
 
         // 获取一个单位
         // 获取一个单位
@@ -808,12 +807,12 @@ namespace CommonAI.Zone.Instance
 
 
         //-------------------------------------------------------------------------------------------
         //-------------------------------------------------------------------------------------------
 
 
-        public InstanceUnit AddUnit(int unitTemplateID, string name, int force, int level, float x, float y, float direction, bool pointLv = false)
+        public InstanceUnit AddUnit(int unitTemplateID, string name, int force, int level, float x, float y, float direction, bool pointLv = false, uint CustomId = 0)
         {
         {
             UnitInfo info = Templates.getUnit(unitTemplateID);
             UnitInfo info = Templates.getUnit(unitTemplateID);
             if (info != null)
             if (info != null)
             {
             {
-                return AddUnit(info, name, force, level, x, y, direction, null, "", 0, pointLv);
+                return AddUnit(info, name, force, level, x, y, direction, null, "", 0, pointLv, CustomId);
             }
             }
             return null;
             return null;
         }
         }
@@ -831,10 +830,10 @@ namespace CommonAI.Zone.Instance
         /// <param name="summoner">召唤者</param>
         /// <param name="summoner">召唤者</param>
         /// <returns></returns>
         /// <returns></returns>
         public InstanceUnit AddUnit(UnitInfo info, string name, int force, int level, float x, float y, float direction,
         public InstanceUnit AddUnit(UnitInfo info, string name, int force, int level, float x, float y, float direction,
-            InstanceUnit summoner = null, String clientShowName = "", int gsFlag = 0, bool pointLv = false)
+            InstanceUnit summoner = null, String clientShowName = "", int gsFlag = 0, bool pointLv = false, uint CustomId = 0)
         {
         {
             AddUnitEvent add;
             AddUnitEvent add;
-            return AddUnit(info, name, force, level, x, y, direction, out add, summoner, clientShowName, gsFlag, 0, pointLv);
+            return AddUnit(info, name, force, level, x, y, direction, out add, summoner, clientShowName, gsFlag, 0, pointLv, CustomId);
         }
         }
         /// <summary>
         /// <summary>
         /// 添加一个单位
         /// 添加一个单位
@@ -854,7 +853,7 @@ namespace CommonAI.Zone.Instance
         private long mAddUnitPrintTime = 0;
         private long mAddUnitPrintTime = 0;
 
 
         public InstanceUnit AddUnit(UnitInfo info, string name, int force, int level, float x, float y, float direction,
         public InstanceUnit AddUnit(UnitInfo info, string name, int force, int level, float x, float y, float direction,
-            out AddUnitEvent add, InstanceUnit summoner = null, String clientShowName = "", int gsFlag = 0, int alliesForce = 0, bool pointLv = false)
+            out AddUnitEvent add, InstanceUnit summoner = null, String clientShowName = "", int gsFlag = 0, int alliesForce = 0, bool pointLv = false, uint CustomId = 0)
         {
         {
             add = null;
             add = null;
             if (mObjects.UnitsCount >= mMaxUnitCount)
             if (mObjects.UnitsCount >= mMaxUnitCount)
@@ -882,8 +881,13 @@ namespace CommonAI.Zone.Instance
                 InstanceUnit unit = ret as InstanceUnit;
                 InstanceUnit unit = ret as InstanceUnit;
                 //unit.Name = name;
                 //unit.Name = name;
                 unit.gameServerFlag = gsFlag;
                 unit.gameServerFlag = gsFlag;
+                if(CustomId > 0 && mObjects.ContainsObjectByKey(CustomId))
+                {
+                    log.Warn(string.Format("--Zone AddUnit failed, ID Exist: id:{0} template:{1}", CustomId, info.TemplateID));
+                    return null;
+                }
                 // 存入单位列表
                 // 存入单位列表
-                if (unit.tryAdd(x, y, direction))
+                if (unit.tryAdd(x, y, direction, CustomId))
                 {
                 {
                     mObjects.AddObject(unit);
                     mObjects.AddObject(unit);
                     this.LastAddedUnit = unit;
                     this.LastAddedUnit = unit;

+ 2 - 2
Common/CommonAI/Zone/Instance/InstanceZoneObject.cs

@@ -161,13 +161,13 @@ namespace CommonAI.Zone.Instance
         }
         }
 
 
         // 返回结果表示当前是否可以添加
         // 返回结果表示当前是否可以添加
-        internal bool tryAdd(float x, float y, float direction)
+        internal bool tryAdd(float x, float y, float direction, uint customid = 0)
         {
         {
             if (mAdded == false)
             if (mAdded == false)
             {
             {
                 this.mAdded = true;
                 this.mAdded = true;
                 this.mMarkRemoved = false;
                 this.mMarkRemoved = false;
-                this.mID = mZone.genObjectID();
+                this.mID = customid > 0 ? customid : mZone.genObjectID();
                 this.mPos.SetX(x);
                 this.mPos.SetX(x);
                 this.mPos.SetY(y);
                 this.mPos.SetY(y);
                 this.mPosPrevFrame.SetX(x);
                 this.mPosPrevFrame.SetX(x);

+ 27 - 0
Common/CommonAI/Zone/ZoneEditor/EventTrigger/Actions.Units.cs

@@ -114,6 +114,33 @@ namespace CommonAI.Zone.ZoneEditor.EventTrigger
         }
         }
     }
     }
 
 
+    [DescAttribute("替换单位模板", "单位")]
+    public class ReplaceUnitAction : AbstractAction
+    {
+        [DescAttribute("单位")]
+        public UnitValue Unit = new UnitValue.Trigging();
+        [DescAttribute("新单位模板ID与旧模板的差值")]
+        public IntegerValue IDDiff = new IntegerValue.VALUE(0);
+
+        public override string ToString()
+        {
+            return string.Format("替换单位({0})模板(ID Diff:{1})", Unit, IDDiff);
+        }
+        override public void DoAction(EventTriggerAdapter api, EventArguments args)
+        {
+            InstanceUnit unit = Unit.GetValue(api, args);
+            if (unit != null)
+            {
+                int newid = unit.Info.TemplateID + IDDiff.GetValue(api, args);
+                UnitInfo info = api.ZoneAPI.Templates.getUnit(newid);
+                if (info != null)
+                {
+                    api.ZoneAPI.RemoveObject(unit);
+                    api.ZoneAPI.AddUnit(newid, unit.Name, unit.Force, unit.Level, unit.X, unit.Y, unit.Direction, false, unit.ID);
+                }
+            }
+        }
+    }
 
 
     [DescAttribute("单位增加金钱", "单位")]
     [DescAttribute("单位增加金钱", "单位")]
     public class UnitAddMoneyAction : AbstractAction
     public class UnitAddMoneyAction : AbstractAction