From efeb40abc2149f930b091b1d8431e0bcfad922e5 Mon Sep 17 00:00:00 2001 From: wserver/wangdisen <1065498738@qq.com> Date: Tue, 16 Aug 2022 09:43:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=A7=8D=E6=A4=8D=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Proto/OuterMessage.proto | 10 ++++---- .../Handler/C2M_FarmlandHarvestHandler.cs | 21 ++++++++++++++-- .../Handler/C2M_FarmlandPlantHandler.cs | 24 +++++++++++++++---- Server/Model/Generate/Message/OuterMessage.cs | 14 +++++++---- .../Hotfix/Demo/Farmland/FarmlandSystem.cs | 16 ++++++------- .../Hotfix/Demo/Helper/FarmlandHelper.cs | 21 ++++++++-------- .../Codes/Hotfix/Demo/Helper/PeopleHelper.cs | 6 ++--- .../Hotfix/Demo/Operate/FarmlandOperate.cs | 21 ++++++---------- .../Hotfix/Demo/Operate/PeopleOperate.cs | 8 ++----- .../Model/Generate/Message/OuterMessage.cs | 14 +++++++---- 10 files changed, 96 insertions(+), 59 deletions(-) diff --git a/Proto/OuterMessage.proto b/Proto/OuterMessage.proto index d255a19..fb8077a 100644 --- a/Proto/OuterMessage.proto +++ b/Proto/OuterMessage.proto @@ -1201,10 +1201,10 @@ message FarmlandProto { int64 id = 1; int32 SeedCfgId = 2; - int32 plantCfgId = 3; - int32 duration = 4; - int32 exProduct = 5; - int32 farmlandState = 6; + int32 PlantCfgId = 3; + int32 Duration = 4; + int32 ExProduct = 5; + int32 FarmlandState = 6; } //ResponseType M2C_FarmlandPlant @@ -1212,6 +1212,7 @@ message C2M_FarmlandPlant // IActorLocationRequest { int32 RpcId = 90; int64 FarmlandId = 1; + int64 PeopleId = 2; } message M2C_FarmlandPlant // IActorLocationResponse @@ -1226,6 +1227,7 @@ message C2M_FarmlandHarvest // IActorLocationRequest { int32 RpcId = 90; int64 FarmlandId = 1; + int64 PeopleId = 2; } message M2C_FarmlandHarvest // IActorLocationResponse diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs index 63c6471..52c75f2 100644 --- a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs @@ -3,14 +3,31 @@ namespace ET { + [FriendClass(typeof (Unit))] public class C2M_FarmlandHarvestHandler: AMActorLocationRpcHandler { protected override async ETTask Run(Unit unit, C2M_FarmlandHarvest request, M2C_FarmlandHarvest response, Action reply) { try { - response.Error = FarmlandOperate.Harvest(unit, request.FarmlandId); - reply(); + People people; + Farmland farmland; + if (unit.FarmlandDic.TryGetValue(request.FarmlandId, out farmland)) + { + people = unit.GetComponent().GetChild(request.PeopleId); + if (people != null) + { + response.Error = FarmlandOperate.Harvest(unit, farmland, people); + } + else + { + response.Error = ErrorCode.ERR_PeopleNotFound; + } + } + else + { + response.Error = ErrorCode.ERR_FarmlandNotFound; + } } catch (Exception e) { diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs index 04fed52..8aeb717 100644 --- a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs @@ -2,14 +2,32 @@ namespace ET { - + [FriendClass(typeof (Unit))] public class C2M_FarmlandPlantHandler: AMActorLocationRpcHandler { protected override async ETTask Run(Unit unit, C2M_FarmlandPlant request, M2C_FarmlandPlant response, Action reply) { try { - response.Error=FarmlandOperate.Plant(unit, request.FarmlandId); + People people; + Farmland farmland; + if (unit.FarmlandDic.TryGetValue(request.FarmlandId, out farmland)) + { + people = unit.GetComponent().GetChild(request.PeopleId); + if (people != null) + { + response.Error = FarmlandOperate.Plant(unit, farmland, people); + } + else + { + response.Error = ErrorCode.ERR_PeopleNotFound; + } + } + else + { + response.Error = ErrorCode.ERR_FarmlandNotFound; + } + reply(); } catch (Exception e) @@ -22,6 +40,4 @@ namespace ET await ETTask.CompletedTask; } } - - } \ No newline at end of file diff --git a/Server/Model/Generate/Message/OuterMessage.cs b/Server/Model/Generate/Message/OuterMessage.cs index fd00f80..f9d633c 100644 --- a/Server/Model/Generate/Message/OuterMessage.cs +++ b/Server/Model/Generate/Message/OuterMessage.cs @@ -2504,16 +2504,16 @@ namespace ET public int SeedCfgId { get; set; } [ProtoMember(3)] - public int plantCfgId { get; set; } + public int PlantCfgId { get; set; } [ProtoMember(4)] - public int duration { get; set; } + public int Duration { get; set; } [ProtoMember(5)] - public int exProduct { get; set; } + public int ExProduct { get; set; } [ProtoMember(6)] - public int farmlandState { get; set; } + public int FarmlandState { get; set; } } @@ -2528,6 +2528,9 @@ namespace ET [ProtoMember(1)] public long FarmlandId { get; set; } + [ProtoMember(2)] + public long PeopleId { get; set; } + } [Message(OuterOpcode.M2C_FarmlandPlant)] @@ -2556,6 +2559,9 @@ namespace ET [ProtoMember(1)] public long FarmlandId { get; set; } + [ProtoMember(2)] + public long PeopleId { get; set; } + } [Message(OuterOpcode.M2C_FarmlandHarvest)] diff --git a/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs b/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs index c3523c7..56e556b 100644 --- a/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs @@ -30,10 +30,10 @@ { self.Id = farmlandProto.id; self.CropCfgId = farmlandProto.SeedCfgId; - self.Duration = farmlandProto.duration; - self.ExProduct = farmlandProto.exProduct; - self.PlanCropCfgId = farmlandProto.plantCfgId; - self.FarmlandState = farmlandProto.farmlandState; + self.Duration = farmlandProto.Duration; + self.ExProduct = farmlandProto.ExProduct; + self.PlanCropCfgId = farmlandProto.PlantCfgId; + self.FarmlandState = farmlandProto.FarmlandState; } public static FarmlandProto ToMessage(this Farmland self) @@ -41,10 +41,10 @@ FarmlandProto proto = new FarmlandProto(); proto.id = self.Id; proto.SeedCfgId = self.CropCfgId; - proto.duration = self.Duration; - proto.exProduct = self.ExProduct; - proto.plantCfgId = self.PlanCropCfgId; - proto.farmlandState = self.FarmlandState; + proto.Duration = self.Duration; + proto.ExProduct = self.ExProduct; + proto.PlantCfgId = self.PlanCropCfgId; + proto.FarmlandState = self.FarmlandState; return proto; } diff --git a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs index 8dede60..631da26 100644 --- a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs +++ b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs @@ -28,15 +28,16 @@ namespace ET throw; } } - public static async ETTask FarmlandPlant(Unit unit, long farmlandId) + + public static async ETTask FarmlandPlant(Unit unit, Farmland farmland,People people) { try { - C2M_FarmlandPlant msg = new C2M_FarmlandPlant() { FarmlandId = farmlandId}; + C2M_FarmlandPlant msg = new C2M_FarmlandPlant() { FarmlandId = farmland.Id,PeopleId = people.Id}; M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandPlant; if (resp.Error == ErrorCode.ERR_Success) { - FarmlandOperate.Plant(unit, farmlandId); + FarmlandOperate.Plant(unit, farmland,people); } else { @@ -52,15 +53,15 @@ namespace ET } } - public static async ETTask FarmlandHarvest(Unit unit, long farmlandId) + public static async ETTask FarmlandHarvest(Unit unit, Farmland farmland,People people) { try { - C2M_FarmlandHarvest msg = new C2M_FarmlandHarvest() { FarmlandId = farmlandId }; + C2M_FarmlandHarvest msg = new C2M_FarmlandHarvest() { FarmlandId = farmland.Id }; M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandPlant; if (resp.Error == ErrorCode.ERR_Success) { - FarmlandOperate.Harvest(unit, farmlandId); + FarmlandOperate.Harvest(unit, farmland,people); } else { @@ -76,14 +77,14 @@ namespace ET } } - public static async ETTask FarmlandPlantFinish(Unit unit,long peopleId) + public static async ETTask FarmlandPlantFinish(Unit unit,People people) { - return await PeopleHelper.ChangeBehave(unit, peopleId, 0, ConstBehaveType.BEHAVE_IDLE); + return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE); } - public static async ETTask FarmlandHarvestFinish(Unit unit,long peopleId) + public static async ETTask FarmlandHarvestFinish(Unit unit,People people) { - return await PeopleHelper.ChangeBehave(unit, peopleId, 0, ConstBehaveType.BEHAVE_IDLE); + return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE); } diff --git a/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs index 6ec9972..11cf1e2 100644 --- a/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs +++ b/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs @@ -28,11 +28,11 @@ namespace ET return ErrorCode.ERR_Success; } - public static async ETTask ChangeBehave(Unit unit, long peopleId,long targetId, int behaveType) + public static async ETTask ChangeBehave(Unit unit, People people,long targetId, int behaveType) { try { - C2M_ChangeBehave msg = new C2M_ChangeBehave(){PeopleId = peopleId,TargetId = targetId,BehaveType = behaveType}; + C2M_ChangeBehave msg = new C2M_ChangeBehave(){PeopleId = people.Id,TargetId = targetId,BehaveType = behaveType}; M2C_ChangeBehave resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_ChangeBehave; if (resp.Error != ErrorCode.ERR_Success) { @@ -40,7 +40,7 @@ namespace ET return resp.Error; } - PeopleOperate.ChangeBehave(unit, peopleId, targetId, behaveType); + PeopleOperate.ChangeBehave(unit, people, targetId, behaveType); } catch (Exception e) { diff --git a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs index 0268d9e..933237a 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs @@ -6,28 +6,22 @@ namespace ET [FriendClass(typeof (Farmland))] public static class FarmlandOperate { - public static int Plant(Unit unit, long farmlandId) + public static int Plant(Unit unit, Farmland farmland,People people) { - if (!unit.FarmlandDic.ContainsKey(farmlandId)) - { - return ErrorCode.ERR_FarmlandNotFound; - } - - var farmland = unit.FarmlandDic[farmlandId]; + if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED) { return ErrorCode.ERR_FarmlandNotFree; } farmland.Plant(); + PeopleOperate.ChangeBehave(unit,people, farmland.Id, ConstBehaveType.BEHAVE_PLANT); return ErrorCode.ERR_Success; } - public static int Harvest(Unit unit, long farmlandId) + public static int Harvest(Unit unit, Farmland farmland,People people) { - Farmland farmland; - if (unit.FarmlandDic.TryGetValue(farmlandId, out farmland)) - { + if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE) { var storeNc = unit.GetComponent(); @@ -41,11 +35,10 @@ namespace ET farmland.Harvest(); return ErrorCode.ERR_Success; } + PeopleOperate.ChangeBehave(unit,people, farmland.Id, ConstBehaveType.BEHAVE_HARVEST); return ErrorCode.ERR_FarmlandNotRipe; - } - - return ErrorCode.ERR_FarmlandNotFound; + } public static (List, List) FarmlandSeed(Unit unit, List farmlandIds, List CropCfgIds) diff --git a/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs index 66f3edf..c8b6724 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs @@ -31,13 +31,9 @@ namespace ET return ErrorCode.ERR_Success; } - public static int ChangeBehave(Unit unit, long peopleId,long targetId, int behaveType) + public static int ChangeBehave(Unit unit, People people,long targetId, int behaveType) { - var people = unit.GetComponent().GetChild(peopleId); - if (people == null) - { - return ErrorCode.ERR_PeopleNotFound; - } + var result = StopBehave(unit, people); if (result != ErrorCode.ERR_Success) diff --git a/Unity/Codes/Model/Generate/Message/OuterMessage.cs b/Unity/Codes/Model/Generate/Message/OuterMessage.cs index fd00f80..f9d633c 100644 --- a/Unity/Codes/Model/Generate/Message/OuterMessage.cs +++ b/Unity/Codes/Model/Generate/Message/OuterMessage.cs @@ -2504,16 +2504,16 @@ namespace ET public int SeedCfgId { get; set; } [ProtoMember(3)] - public int plantCfgId { get; set; } + public int PlantCfgId { get; set; } [ProtoMember(4)] - public int duration { get; set; } + public int Duration { get; set; } [ProtoMember(5)] - public int exProduct { get; set; } + public int ExProduct { get; set; } [ProtoMember(6)] - public int farmlandState { get; set; } + public int FarmlandState { get; set; } } @@ -2528,6 +2528,9 @@ namespace ET [ProtoMember(1)] public long FarmlandId { get; set; } + [ProtoMember(2)] + public long PeopleId { get; set; } + } [Message(OuterOpcode.M2C_FarmlandPlant)] @@ -2556,6 +2559,9 @@ namespace ET [ProtoMember(1)] public long FarmlandId { get; set; } + [ProtoMember(2)] + public long PeopleId { get; set; } + } [Message(OuterOpcode.M2C_FarmlandHarvest)]