From ca8bffe31ff4c888fe8494dbf8b600b68a381ad6 Mon Sep 17 00:00:00 2001 From: wserver/wangdisen <1065498738@qq.com> Date: Fri, 26 Aug 2022 17:42:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=96=E5=AE=8C=E5=BB=BA?= =?UTF-8?q?=E7=AD=91=E5=90=8E=E7=9A=84=E5=AD=90=E4=BA=A7=E5=93=81id?= =?UTF-8?q?=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Proto/OuterMessage.proto | 1 + .../Handler/C2M_ConstructFinishHandler.cs | 4 +- Server/Hotfix/Demo/Helper/ConstructHelper.cs | 4 +- Server/Model/Generate/Message/OuterMessage.cs | 3 ++ .../Construct/ConstructComponentSystem.cs | 4 +- .../M2C_NofityConstructFinishHandler.cs | 2 +- .../Hotfix/Demo/Operate/ConstructOperate.cs | 38 ++++++++----------- .../Model/Generate/Message/OuterMessage.cs | 3 ++ 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Proto/OuterMessage.proto b/Proto/OuterMessage.proto index 0b6130b..e77a226 100644 --- a/Proto/OuterMessage.proto +++ b/Proto/OuterMessage.proto @@ -774,6 +774,7 @@ message M2C_NotifyConstructFinish // IActorMessage { int64 ConstructId = 1; int64 BuildingId = 2; + int64 ChildId = 3; } message M2C_NotifyUpdateValley // IActorMessage diff --git a/Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs b/Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs index bce6620..02d61d3 100644 --- a/Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs +++ b/Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs @@ -7,10 +7,10 @@ namespace ET { try { - var building = ConstructOperate.ConstructFinish(unit, request.ConstructId); + var (building,childId) = ConstructOperate.ConstructFinish(unit, request.ConstructId); response.Error = ErrorCode.ERR_Success; reply(); - ConstructHelper.NotifyConstructFinish(unit,request.ConstructId, building.Id); + ConstructHelper.NotifyConstructFinish(unit,request.ConstructId, building.Id,0); } catch (Exception e) { diff --git a/Server/Hotfix/Demo/Helper/ConstructHelper.cs b/Server/Hotfix/Demo/Helper/ConstructHelper.cs index 241ec39..6c4983e 100644 --- a/Server/Hotfix/Demo/Helper/ConstructHelper.cs +++ b/Server/Hotfix/Demo/Helper/ConstructHelper.cs @@ -21,9 +21,9 @@ namespace ET } } - public static void NotifyConstructFinish(Unit unit, long id, long buildingId) + public static void NotifyConstructFinish(Unit unit, long id, long buildingId,long childId) { - MessageHelper.SendToClient(unit,new M2C_NotifyConstructFinish(){ConstructId = id, BuildingId = buildingId}); + MessageHelper.SendToClient(unit,new M2C_NotifyConstructFinish(){ConstructId = id, BuildingId = buildingId,ChildId = childId}); } } } \ No newline at end of file diff --git a/Server/Model/Generate/Message/OuterMessage.cs b/Server/Model/Generate/Message/OuterMessage.cs index 1614fc7..d3f4acd 100644 --- a/Server/Model/Generate/Message/OuterMessage.cs +++ b/Server/Model/Generate/Message/OuterMessage.cs @@ -1613,6 +1613,9 @@ namespace ET [ProtoMember(2)] public long BuildingId { get; set; } + [ProtoMember(3)] + public long ChildId { get; set; } + } [Message(OuterOpcode.M2C_NotifyUpdateValley)] diff --git a/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs b/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs index b4432e1..7b19007 100644 --- a/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs @@ -57,8 +57,8 @@ namespace ET ConstructHelper.NtfUpdateConstructProgress(unit, self); foreach (var v in finishConstructs) { - var building = ConstructOperate.ConstructFinish(unit, v.Id); - ConstructHelper.NotifyConstructFinish(unit,v.Id, building.Id); + var (building,childId) = ConstructOperate.ConstructFinish(unit, v.Id); + ConstructHelper.NotifyConstructFinish(unit,v.Id, building.Id,childId); } if (finishConstructs.Count > 0) diff --git a/Unity/Codes/Hotfix/Demo/Construct/Handler/M2C_NofityConstructFinishHandler.cs b/Unity/Codes/Hotfix/Demo/Construct/Handler/M2C_NofityConstructFinishHandler.cs index d6a0393..4585bd3 100644 --- a/Unity/Codes/Hotfix/Demo/Construct/Handler/M2C_NofityConstructFinishHandler.cs +++ b/Unity/Codes/Hotfix/Demo/Construct/Handler/M2C_NofityConstructFinishHandler.cs @@ -5,7 +5,7 @@ { protected override void Run(Session session, M2C_NotifyConstructFinish message) { - var building = ConstructOperate.ConstructFinish(UnitComponent.unit,message.ConstructId, message.BuildingId); + var (building,childId) = ConstructOperate.ConstructFinish(UnitComponent.unit,message.ConstructId, message.BuildingId,message.ChildId); UnitOperate.InitProsperity(UnitComponent.unit); if (building != null) { diff --git a/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs index 2727587..092f4c7 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs @@ -6,7 +6,7 @@ namespace ET [FriendClass(typeof (Construct))] [FriendClass(typeof (Building))] [FriendClass(typeof (Farmland))] - [FriendClass(typeof(Unit))] + [FriendClass(typeof (Unit))] public static class ConstructOperate { public static Construct CreateConstruct(Unit unit, int configId, float x, float y, long id = 0, long buildingId = 0) @@ -15,7 +15,7 @@ namespace ET // { // return null; // } - var construct = unit.GetOrAddComponent().CreateConstruct(unit,configId, x, y, id, buildingId); + var construct = unit.GetOrAddComponent().CreateConstruct(unit, configId, x, y, id, buildingId); return construct; } @@ -140,13 +140,14 @@ namespace ET return ErrorCode.ERR_Success; } - public static Building ConstructFinish(Unit unit, long constructId, long buildingId = 0) + public static (Building,long) ConstructFinish(Unit unit, long constructId, long buildingId = 0, long childId = 0) { + var construct = unit.GetComponent().GetChild(constructId); Building build; if (construct == null) { - return null; + return (null,0); } if (construct.IsUpgrade) @@ -157,40 +158,33 @@ namespace ET { Log.Error($"Can't find building:{construct.BuildingId} for construct:{construct.Id}"); } + build.IsUpgrade = 0; build.ConfigId = construct.Config.MixtureID; } else { - if (buildingId > 0) - { - build = unit.GetOrAddComponent().AddChildWithId(buildingId); - } - else - { - build = unit.GetOrAddComponent().AddChild(); - } - + build = unit.GetOrAddComponent().AddChildWithNotZeroId(buildingId); + build.Position.x = construct.X; build.Position.y = construct.Y; build.ConfigId = construct.Config.MixtureID; switch (build.Config.Special) { - case (int)StructureSpecialEnum.FARMLAND: //如果是农场 - var farmland = build.AddChild(); + case (int) StructureSpecialEnum.FARMLAND: //如果是农场 + var farmland = build.AddChildWithNotZeroId(childId); farmland.SetFarmlandState(FarmlandState.FARMLAND_STATE_FREE); + childId = farmland.Id; unit.AddGrandChild(farmland); break; - case (int)StructureSpecialEnum.FARM_CABIN : - var cabin = build.AddChild(); + case (int) StructureSpecialEnum.FARM_CABIN: + var cabin = build.AddChildWithNotZeroId(childId); + childId = cabin.Id; unit.AddGrandChild(cabin); break; } - - - } - + StructureConfig structureConfig = StructureConfigCategory.Instance.Get(build.ConfigId); if (structureConfig != null) { @@ -206,7 +200,7 @@ namespace ET } construct.Dispose(); - return build; + return (build,childId); } public static bool CheckOutBuildingByIds(Unit unit, int[] StructureID) diff --git a/Unity/Codes/Model/Generate/Message/OuterMessage.cs b/Unity/Codes/Model/Generate/Message/OuterMessage.cs index 1614fc7..d3f4acd 100644 --- a/Unity/Codes/Model/Generate/Message/OuterMessage.cs +++ b/Unity/Codes/Model/Generate/Message/OuterMessage.cs @@ -1613,6 +1613,9 @@ namespace ET [ProtoMember(2)] public long BuildingId { get; set; } + [ProtoMember(3)] + public long ChildId { get; set; } + } [Message(OuterOpcode.M2C_NotifyUpdateValley)]