Browse Source

修改盖完建筑后的子产品id不一致的BUG

master
wserver/wangdisen 3 years ago
parent
commit
ca8bffe31f
  1. 1
      Proto/OuterMessage.proto
  2. 4
      Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs
  3. 4
      Server/Hotfix/Demo/Helper/ConstructHelper.cs
  4. 3
      Server/Model/Generate/Message/OuterMessage.cs
  5. 4
      Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs
  6. 2
      Unity/Codes/Hotfix/Demo/Construct/Handler/M2C_NofityConstructFinishHandler.cs
  7. 38
      Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs
  8. 3
      Unity/Codes/Model/Generate/Message/OuterMessage.cs

1
Proto/OuterMessage.proto

@ -774,6 +774,7 @@ message M2C_NotifyConstructFinish // IActorMessage
{ {
int64 ConstructId = 1; int64 ConstructId = 1;
int64 BuildingId = 2; int64 BuildingId = 2;
int64 ChildId = 3;
} }
message M2C_NotifyUpdateValley // IActorMessage message M2C_NotifyUpdateValley // IActorMessage

4
Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs

@ -7,10 +7,10 @@ namespace ET
{ {
try try
{ {
var building = ConstructOperate.ConstructFinish(unit, request.ConstructId); var (building,childId) = ConstructOperate.ConstructFinish(unit, request.ConstructId);
response.Error = ErrorCode.ERR_Success; response.Error = ErrorCode.ERR_Success;
reply(); reply();
ConstructHelper.NotifyConstructFinish(unit,request.ConstructId, building.Id); ConstructHelper.NotifyConstructFinish(unit,request.ConstructId, building.Id,0);
} }
catch (Exception e) catch (Exception e)
{ {

4
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});
} }
} }
} }

3
Server/Model/Generate/Message/OuterMessage.cs

@ -1613,6 +1613,9 @@ namespace ET
[ProtoMember(2)] [ProtoMember(2)]
public long BuildingId { get; set; } public long BuildingId { get; set; }
[ProtoMember(3)]
public long ChildId { get; set; }
} }
[Message(OuterOpcode.M2C_NotifyUpdateValley)] [Message(OuterOpcode.M2C_NotifyUpdateValley)]

4
Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs

@ -57,8 +57,8 @@ namespace ET
ConstructHelper.NtfUpdateConstructProgress(unit, self); ConstructHelper.NtfUpdateConstructProgress(unit, self);
foreach (var v in finishConstructs) foreach (var v in finishConstructs)
{ {
var building = ConstructOperate.ConstructFinish(unit, v.Id); var (building,childId) = ConstructOperate.ConstructFinish(unit, v.Id);
ConstructHelper.NotifyConstructFinish(unit,v.Id, building.Id); ConstructHelper.NotifyConstructFinish(unit,v.Id, building.Id,childId);
} }
if (finishConstructs.Count > 0) if (finishConstructs.Count > 0)

2
Unity/Codes/Hotfix/Demo/Construct/Handler/M2C_NofityConstructFinishHandler.cs

@ -5,7 +5,7 @@
{ {
protected override void Run(Session session, M2C_NotifyConstructFinish message) 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); UnitOperate.InitProsperity(UnitComponent.unit);
if (building != null) if (building != null)
{ {

38
Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs

@ -6,7 +6,7 @@ namespace ET
[FriendClass(typeof (Construct))] [FriendClass(typeof (Construct))]
[FriendClass(typeof (Building))] [FriendClass(typeof (Building))]
[FriendClass(typeof (Farmland))] [FriendClass(typeof (Farmland))]
[FriendClass(typeof(Unit))] [FriendClass(typeof (Unit))]
public static class ConstructOperate public static class ConstructOperate
{ {
public static Construct CreateConstruct(Unit unit, int configId, float x, float y, long id = 0, long buildingId = 0) 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; // return null;
// } // }
var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit,configId, x, y, id, buildingId); var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit, configId, x, y, id, buildingId);
return construct; return construct;
} }
@ -140,13 +140,14 @@ namespace ET
return ErrorCode.ERR_Success; 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<ConstructComponent>().GetChild<Construct>(constructId); var construct = unit.GetComponent<ConstructComponent>().GetChild<Construct>(constructId);
Building build; Building build;
if (construct == null) if (construct == null)
{ {
return null; return (null,0);
} }
if (construct.IsUpgrade) if (construct.IsUpgrade)
@ -157,40 +158,33 @@ namespace ET
{ {
Log.Error($"Can't find building:{construct.BuildingId} for construct:{construct.Id}"); Log.Error($"Can't find building:{construct.BuildingId} for construct:{construct.Id}");
} }
build.IsUpgrade = 0; build.IsUpgrade = 0;
build.ConfigId = construct.Config.MixtureID; build.ConfigId = construct.Config.MixtureID;
} }
else else
{ {
if (buildingId > 0) build = unit.GetOrAddComponent<BuildingComponent>().AddChildWithNotZeroId<Building>(buildingId);
{
build = unit.GetOrAddComponent<BuildingComponent>().AddChildWithId<Building>(buildingId);
}
else
{
build = unit.GetOrAddComponent<BuildingComponent>().AddChild<Building>();
}
build.Position.x = construct.X; build.Position.x = construct.X;
build.Position.y = construct.Y; build.Position.y = construct.Y;
build.ConfigId = construct.Config.MixtureID; build.ConfigId = construct.Config.MixtureID;
switch (build.Config.Special) switch (build.Config.Special)
{ {
case (int)StructureSpecialEnum.FARMLAND: //如果是农场 case (int) StructureSpecialEnum.FARMLAND: //如果是农场
var farmland = build.AddChild<Farmland>(); var farmland = build.AddChildWithNotZeroId<Farmland>(childId);
farmland.SetFarmlandState(FarmlandState.FARMLAND_STATE_FREE); farmland.SetFarmlandState(FarmlandState.FARMLAND_STATE_FREE);
childId = farmland.Id;
unit.AddGrandChild(farmland); unit.AddGrandChild(farmland);
break; break;
case (int)StructureSpecialEnum.FARM_CABIN : case (int) StructureSpecialEnum.FARM_CABIN:
var cabin = build.AddChild<Cabin>(); var cabin = build.AddChildWithNotZeroId<Cabin>(childId);
childId = cabin.Id;
unit.AddGrandChild(cabin); unit.AddGrandChild(cabin);
break; break;
} }
} }
StructureConfig structureConfig = StructureConfigCategory.Instance.Get(build.ConfigId); StructureConfig structureConfig = StructureConfigCategory.Instance.Get(build.ConfigId);
if (structureConfig != null) if (structureConfig != null)
{ {
@ -206,7 +200,7 @@ namespace ET
} }
construct.Dispose(); construct.Dispose();
return build; return (build,childId);
} }
public static bool CheckOutBuildingByIds(Unit unit, int[] StructureID) public static bool CheckOutBuildingByIds(Unit unit, int[] StructureID)

3
Unity/Codes/Model/Generate/Message/OuterMessage.cs

@ -1613,6 +1613,9 @@ namespace ET
[ProtoMember(2)] [ProtoMember(2)]
public long BuildingId { get; set; } public long BuildingId { get; set; }
[ProtoMember(3)]
public long ChildId { get; set; }
} }
[Message(OuterOpcode.M2C_NotifyUpdateValley)] [Message(OuterOpcode.M2C_NotifyUpdateValley)]

Loading…
Cancel
Save