From fa79f84c38c28f04bfd6346677e0187294f94875 Mon Sep 17 00:00:00 2001 From: wserver/wangdisen <1065498738@qq.com> Date: Mon, 15 Aug 2022 16:04:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=A7=8D=E6=A4=8D=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Proto/OuterMessage.proto | 44 ++++++++--- .../Handler/C2M_FarmlandHarvestHandler.cs | 25 ++++++ .../Handler/C2M_FarmlandPlantHandler.cs | 27 +++++++ .../Handler/C2M_FarmlandSeedHandler.cs | 25 ++++++ .../Demo/Gm/Handler/M2C_GMAddItemHandler.cs | 28 ------- Server/Hotfix/Server.Hotfix.csproj | 4 + Server/Model/Generate/Message/OuterMessage.cs | 76 +++++++++++++----- Server/Model/Generate/Message/OuterOpcode.cs | 10 ++- Unity/Animancer.FSM.csproj | 9 --- Unity/Animancer.csproj | 9 --- .../Hotfix/Demo/Farmland/FarmlandSystem.cs | 26 +++---- .../Hotfix/Demo/Helper/FarmlandHelper.cs | 32 +++++++- Unity/Codes/Hotfix/Demo/Helper/GmHelper.cs | 38 --------- .../Codes/Hotfix/Demo/Helper/PeopleHelper.cs | 24 ++++++ .../Hotfix/Demo/Operate/FarmlandOperate.cs | 77 +++++++++++++------ .../Hotfix/Demo/Operate/PeopleOperate.cs | 20 +++++ .../Codes/Hotfix/Demo/People/PeopleSystem.cs | 8 +- Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs | 8 ++ Unity/Codes/Model/Demo/ConstValue.cs | 11 ++- Unity/Codes/Model/Demo/People/People.cs | 2 + .../Model/Generate/Message/OuterMessage.cs | 76 +++++++++++++----- .../Model/Generate/Message/OuterOpcode.cs | 10 ++- Unity/Codes/Model/Module/Message/ErrorCode.cs | 2 + 23 files changed, 395 insertions(+), 196 deletions(-) create mode 100644 Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs create mode 100644 Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs create mode 100644 Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandSeedHandler.cs delete mode 100644 Server/Hotfix/Demo/Gm/Handler/M2C_GMAddItemHandler.cs delete mode 100644 Unity/Codes/Hotfix/Demo/Helper/GmHelper.cs diff --git a/Proto/OuterMessage.proto b/Proto/OuterMessage.proto index 9de46c7..d255a19 100644 --- a/Proto/OuterMessage.proto +++ b/Proto/OuterMessage.proto @@ -1182,22 +1182,21 @@ message M2C_BuildingDurable // IActorLocationResponse repeated int32 Vs = 2; } -//ResponseType M2C_GMAddItem -message C2M_GMAddItem // IActorLocationRequest +//ResponseType M2C_ConstructFinish +message C2M_ConstructFinish // IActorLocationRequest { int32 RpcId = 90; - int64 PeopleId = 1; - repeated int32 Ks = 2; - repeated int32 Vs = 3; + int64 ConstructId = 1; } -message M2C_GMAddItem // IActorLocationResponse +message M2C_ConstructFinish // IActorLocationResponse { int32 RpcId = 90; int32 Error = 91; string Message = 92; } + message FarmlandProto { int64 id = 1; @@ -1213,7 +1212,6 @@ message C2M_FarmlandPlant // IActorLocationRequest { int32 RpcId = 90; int64 FarmlandId = 1; - int32 CropCfgId = 2; } message M2C_FarmlandPlant // IActorLocationResponse @@ -1237,16 +1235,38 @@ message M2C_FarmlandHarvest // IActorLocationResponse string Message = 92; } -//ResponseType M2C_ConstructFinish -message C2M_ConstructFinish // IActorLocationRequest +//ResponseType M2C_FarmlandSeed +message C2M_FarmlandSeed // IActorLocationRequest { int32 RpcId = 90; - int64 ConstructId = 1; + repeated int64 FarmlandIds = 1; + repeated int32 CropCfgIds = 2; } -message M2C_ConstructFinish // IActorLocationResponse +message M2C_FarmlandSeed // IActorLocationResponse { int32 RpcId = 90; int32 Error = 91; string Message = 92; -} \ No newline at end of file + repeated int64 FarmlandIds = 1; + repeated int32 CropCfgIds = 2; +} + +//ResponseType M2C_ChangeBehave +message C2M_ChangeBehave // IActorLocationRequest +{ + int32 RpcId = 90; + int64 TargetId = 1; + int32 BehaveType = 2; + int64 PeopleId = 3; +} + +message M2C_ChangeBehave // IActorLocationResponse +{ + int32 RpcId = 90; + int32 Error = 91; + string Message = 92; + +} + + diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs new file mode 100644 index 0000000..63c6471 --- /dev/null +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs @@ -0,0 +1,25 @@ +using System; + +namespace ET +{ + + 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(); + } + catch (Exception e) + { + response.Message = e.ToString(); + response.Error = ErrorCode.ERR_OperateFail; + reply(); + } + + await ETTask.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs new file mode 100644 index 0000000..04fed52 --- /dev/null +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs @@ -0,0 +1,27 @@ +using System; + +namespace ET +{ + + 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); + reply(); + } + catch (Exception e) + { + response.Message = e.ToString(); + response.Error = ErrorCode.ERR_OperateFail; + reply(); + } + + await ETTask.CompletedTask; + } + } + + +} \ No newline at end of file diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandSeedHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandSeedHandler.cs new file mode 100644 index 0000000..208196e --- /dev/null +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandSeedHandler.cs @@ -0,0 +1,25 @@ +using System; + +namespace ET +{ + public class C2M_FarmlandSeedHandler: AMActorLocationRpcHandler + { + protected override async ETTask Run(Unit unit, C2M_FarmlandSeed request, M2C_FarmlandSeed response, Action reply) + { + try + { + (response.FarmlandIds, response.CropCfgIds) = FarmlandOperate.FarmlandSeed(unit, request.FarmlandIds, request.CropCfgIds); + response.Error = ErrorCode.ERR_Success; + reply(); + } + catch (Exception e) + { + response.Message = e.ToString(); + response.Error = ErrorCode.ERR_OperateFail; + reply(); + } + + await ETTask.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Server/Hotfix/Demo/Gm/Handler/M2C_GMAddItemHandler.cs b/Server/Hotfix/Demo/Gm/Handler/M2C_GMAddItemHandler.cs deleted file mode 100644 index bd1a64f..0000000 --- a/Server/Hotfix/Demo/Gm/Handler/M2C_GMAddItemHandler.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace ET.Gm.Handler -{ - public class M2C_GMAddItemHandler:AMActorLocationRpcHandler - { - protected override async ETTask Run(Unit unit, C2M_GMAddItem request, M2C_GMAddItem response, Action reply) - { - try - { - var storeNc = unit.GetComponent(); - for (int i = 0; i < request.Ks.Count; i++) - { - storeNc.Add(request.Ks[i], request.Vs[i]); - } - response.Error = ErrorCode.ERR_Success; - reply(); - } - catch (Exception e) - { - response.Message = e.ToString(); - reply(); - } - - await ETTask.CompletedTask; - } - } -} \ No newline at end of file diff --git a/Server/Hotfix/Server.Hotfix.csproj b/Server/Hotfix/Server.Hotfix.csproj index 157ba76..4c39e2e 100644 --- a/Server/Hotfix/Server.Hotfix.csproj +++ b/Server/Hotfix/Server.Hotfix.csproj @@ -94,6 +94,10 @@ Demo\Operate\DropOperate.cs + + + Demo\Operate\FarmlandOperate.cs + Demo\Operate\GatherOperate.cs diff --git a/Server/Model/Generate/Message/OuterMessage.cs b/Server/Model/Generate/Message/OuterMessage.cs index 275ee7f..fd00f80 100644 --- a/Server/Model/Generate/Message/OuterMessage.cs +++ b/Server/Model/Generate/Message/OuterMessage.cs @@ -2465,28 +2465,22 @@ namespace ET } - [ResponseType(nameof(M2C_GMAddItem))] - [Message(OuterOpcode.C2M_GMAddItem)] + [ResponseType(nameof(M2C_ConstructFinish))] + [Message(OuterOpcode.C2M_ConstructFinish)] [ProtoContract] - public partial class C2M_GMAddItem: Object, IActorLocationRequest + public partial class C2M_ConstructFinish: Object, IActorLocationRequest { [ProtoMember(90)] public int RpcId { get; set; } [ProtoMember(1)] - public long PeopleId { get; set; } - - [ProtoMember(2)] - public List Ks = new List(); - - [ProtoMember(3)] - public List Vs = new List(); + public long ConstructId { get; set; } } - [Message(OuterOpcode.M2C_GMAddItem)] + [Message(OuterOpcode.M2C_ConstructFinish)] [ProtoContract] - public partial class M2C_GMAddItem: Object, IActorLocationResponse + public partial class M2C_ConstructFinish: Object, IActorLocationResponse { [ProtoMember(90)] public int RpcId { get; set; } @@ -2534,9 +2528,6 @@ namespace ET [ProtoMember(1)] public long FarmlandId { get; set; } - [ProtoMember(2)] - public int CropCfgId { get; set; } - } [Message(OuterOpcode.M2C_FarmlandPlant)] @@ -2582,22 +2573,65 @@ namespace ET } - [ResponseType(nameof(M2C_ConstructFinish))] - [Message(OuterOpcode.C2M_ConstructFinish)] + [ResponseType(nameof(M2C_FarmlandSeed))] + [Message(OuterOpcode.C2M_FarmlandSeed)] [ProtoContract] - public partial class C2M_ConstructFinish: Object, IActorLocationRequest + public partial class C2M_FarmlandSeed: Object, IActorLocationRequest { [ProtoMember(90)] public int RpcId { get; set; } [ProtoMember(1)] - public long ConstructId { get; set; } + public List FarmlandIds = new List(); + + [ProtoMember(2)] + public List CropCfgIds = new List(); } - [Message(OuterOpcode.M2C_ConstructFinish)] + [Message(OuterOpcode.M2C_FarmlandSeed)] [ProtoContract] - public partial class M2C_ConstructFinish: Object, IActorLocationResponse + public partial class M2C_FarmlandSeed: Object, IActorLocationResponse + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(91)] + public int Error { get; set; } + + [ProtoMember(92)] + public string Message { get; set; } + + [ProtoMember(1)] + public List FarmlandIds = new List(); + + [ProtoMember(2)] + public List CropCfgIds = new List(); + + } + + [ResponseType(nameof(M2C_ChangeBehave))] + [Message(OuterOpcode.C2M_ChangeBehave)] + [ProtoContract] + public partial class C2M_ChangeBehave: Object, IActorLocationRequest + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(1)] + public long TargetId { get; set; } + + [ProtoMember(2)] + public int BehaveType { get; set; } + + [ProtoMember(3)] + public long PeopleId { get; set; } + + } + + [Message(OuterOpcode.M2C_ChangeBehave)] + [ProtoContract] + public partial class M2C_ChangeBehave: Object, IActorLocationResponse { [ProtoMember(90)] public int RpcId { get; set; } diff --git a/Server/Model/Generate/Message/OuterOpcode.cs b/Server/Model/Generate/Message/OuterOpcode.cs index d2e3bbd..cc51059 100644 --- a/Server/Model/Generate/Message/OuterOpcode.cs +++ b/Server/Model/Generate/Message/OuterOpcode.cs @@ -145,14 +145,16 @@ namespace ET public const ushort M2C_NotifyResourceAttri = 10142; public const ushort C2M_BuildingDurable = 10143; public const ushort M2C_BuildingDurable = 10144; - public const ushort C2M_GMAddItem = 10145; - public const ushort M2C_GMAddItem = 10146; + public const ushort C2M_ConstructFinish = 10145; + public const ushort M2C_ConstructFinish = 10146; public const ushort FarmlandProto = 10147; public const ushort C2M_FarmlandPlant = 10148; public const ushort M2C_FarmlandPlant = 10149; public const ushort C2M_FarmlandHarvest = 10150; public const ushort M2C_FarmlandHarvest = 10151; - public const ushort C2M_ConstructFinish = 10152; - public const ushort M2C_ConstructFinish = 10153; + public const ushort C2M_FarmlandSeed = 10152; + public const ushort M2C_FarmlandSeed = 10153; + public const ushort C2M_ChangeBehave = 10154; + public const ushort M2C_ChangeBehave = 10155; } } diff --git a/Unity/Animancer.FSM.csproj b/Unity/Animancer.FSM.csproj index 8c724c1..4432b1b 100644 --- a/Unity/Animancer.FSM.csproj +++ b/Unity/Animancer.FSM.csproj @@ -310,9 +310,6 @@ C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\Managed\UnityEditor.Graphs.dll - - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\UnityEditor.Android.Extensions.dll - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\WindowsStandaloneSupport\UnityEditor.WindowsStandalone.Extensions.dll @@ -349,12 +346,6 @@ Assets\ThirdParty\NCalc\NCalc.dll - - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Unity.Android.Types.dll - - - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Unity.Android.Gradle.dll - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\UnityReferenceAssemblies\unity-4.8-api\mscorlib.dll diff --git a/Unity/Animancer.csproj b/Unity/Animancer.csproj index 779372b..7017be2 100644 --- a/Unity/Animancer.csproj +++ b/Unity/Animancer.csproj @@ -447,9 +447,6 @@ C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\Managed\UnityEditor.Graphs.dll - - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\UnityEditor.Android.Extensions.dll - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\WindowsStandaloneSupport\UnityEditor.WindowsStandalone.Extensions.dll @@ -486,12 +483,6 @@ Assets\ThirdParty\NCalc\NCalc.dll - - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Unity.Android.Types.dll - - - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Unity.Android.Gradle.dll - C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\UnityReferenceAssemblies\unity-4.8-api\mscorlib.dll diff --git a/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs b/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs index d3bc434..055970d 100644 --- a/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs @@ -48,20 +48,11 @@ return proto; } - public static int Plant(this Farmland self, int cropId,int seedId) + public static void Plant(this Farmland self) { - if (self.FarmlandState != FarmlandState.FARMLAND_STATE_FREE) - { - return ErrorCode.ERR_FarmlandNotFree; - } - - self.ConfigId = cropId; self.Duration = 0; - self.SeedCfgId = seedId; - self.PlanSeedCfgId = seedId; self.FarmlandState = FarmlandState.FARMLAND_STATE_GROW; self.ExProduct = 0; - return ErrorCode.ERR_Success; } @@ -78,18 +69,21 @@ } } - public static int Harvest(this Farmland self) + public static void Harvest(this Farmland self) { - if (self.FarmlandState != FarmlandState.FARMLAND_STATE_RIPE) - { - return ErrorCode.ERR_PlantNotRipe; - } self.Duration = 0; self.SeedCfgId = 0; self.PlanSeedCfgId = 0; self.ExProduct = 0; self.FarmlandState = FarmlandState.FARMLAND_STATE_FREE; - return ErrorCode.ERR_Success; + + } + + public static void Seed(this Farmland self,int seedCfgId) + { + self.SeedCfgId = seedCfgId; + self.FarmlandState = FarmlandState.FARMLAND_STATE_SEED; + self.PlanSeedCfgId = seedCfgId; } diff --git a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs index ec77f41..87f4344 100644 --- a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs +++ b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs @@ -1,18 +1,42 @@ using System; +using System.Collections.Generic; namespace ET { public static class PlantHelper { + public static async ETTask FarmlandSeed(Unit unit, List farmlandIds, List cropCfgIds) + { + try + { + C2M_FarmlandSeed msg = new C2M_FarmlandSeed() { FarmlandIds = farmlandIds, CropCfgIds = cropCfgIds }; + M2C_FarmlandSeed resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandSeed; + if (resp.Error == ErrorCode.ERR_Success) + { + FarmlandOperate.FarmlandSeed(unit, resp.FarmlandIds, resp.CropCfgIds); + } + else + { + Log.Error(resp.Error.ToString()); + } + + return resp.Error; + } + catch (Exception e) + { + Log.Error(e.ToString()); + throw; + } + } public static async ETTask FarmlandPlant(Unit unit, long farmlandId, int cropId) { try { - C2M_FarmlandPlant msg = new C2M_FarmlandPlant() { FarmlandId = farmlandId, CropCfgId = cropId }; + C2M_FarmlandPlant msg = new C2M_FarmlandPlant() { FarmlandId = farmlandId}; M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandPlant; if (resp.Error == ErrorCode.ERR_Success) { - FarmlandOperate.Plant(unit, farmlandId, cropId); + FarmlandOperate.Plant(unit, farmlandId); } else { @@ -27,7 +51,7 @@ namespace ET throw; } } - + public static async ETTask FarmlandHarvest(Unit unit, long farmlandId) { try @@ -51,5 +75,7 @@ namespace ET throw; } } + + } } \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Helper/GmHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/GmHelper.cs deleted file mode 100644 index ee93bdd..0000000 --- a/Unity/Codes/Hotfix/Demo/Helper/GmHelper.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace ET -{ - public static class GmHelper - { - public static async ETTask AddItem(Unit unit, List Ks, List Vs) - { - try - { - M2C_GMAddItem resp = - await unit.ZoneScene().GetComponent().Session.Call(new C2M_GMAddItem() { Ks = Ks, Vs = Vs }) as - M2C_GMAddItem; - if (resp.Error != ErrorCode.ERR_Success) - { - Log.Error(resp.Error.ToString()); - return resp.Error; - } - - var storeNc = unit.GetComponent(); - for (int i = 0; i < Ks.Count; i++) - { - storeNc.Add(Ks[i], Vs[i]); - } - } - catch (Exception e) - { - Console.WriteLine(e); - throw; - } - - await ETTask.CompletedTask; - return ErrorCode.ERR_Success; - - } - } -} \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs index 4102baa..6ec9972 100644 --- a/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs +++ b/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs @@ -27,5 +27,29 @@ namespace ET return ErrorCode.ERR_Success; } + + public static async ETTask ChangeBehave(Unit unit, long peopleId,long targetId, int behaveType) + { + try + { + C2M_ChangeBehave msg = new C2M_ChangeBehave(){PeopleId = peopleId,TargetId = targetId,BehaveType = behaveType}; + M2C_ChangeBehave resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_ChangeBehave; + if (resp.Error != ErrorCode.ERR_Success) + { + Log.Error(resp.Error.ToString()); + return resp.Error; + } + + PeopleOperate.ChangeBehave(unit, peopleId, targetId, behaveType); + } + catch (Exception e) + { + Log.Error(e); + throw; + } + await ETTask.CompletedTask; + + return ErrorCode.ERR_Success; + } } } \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs index 4726720..dea82cd 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs @@ -1,10 +1,12 @@ -namespace ET +using System.Collections.Generic; + +namespace ET { - [FriendClass(typeof(Unit))] - [FriendClass(typeof(Farmland))] + [FriendClass(typeof (Unit))] + [FriendClass(typeof (Farmland))] public static class FarmlandOperate { - public static int Plant(Unit unit,long farmlandId, int cropId) + public static int Plant(Unit unit, long farmlandId) { if (!unit.FarmlandDic.ContainsKey(farmlandId)) { @@ -12,39 +14,64 @@ } var farmland = unit.FarmlandDic[farmlandId]; - if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_FREE) + if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED) { return ErrorCode.ERR_FarmlandNotFree; } - //检查种子数量 - var cropConfig = CropConfigCategory.Instance.Get(cropId); - if (cropConfig == null) - { - return ErrorCode.ERR_CropConfigNotFound; - } + farmland.Plant(); - if (!unit.GetComponent().Remove(cropConfig.SeedNeed, cropConfig.SeedNum)) + return ErrorCode.ERR_Success; + } + + public static int Harvest(Unit unit, long farmlandId) + { + Farmland farmland; + if (unit.FarmlandDic.TryGetValue(farmlandId, out farmland)) { - return ErrorCode.ERR_SeedNotEnough; + if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE) + { + var storeNc = unit.GetComponent(); + storeNc.Add(farmland.Config.ProductID, farmland.Config.BasicProduction); + if (farmland.Config.ByProduct > 0) + { + storeNc.Add(farmland.Config.ByProduct, farmland.Config.ByProductNum); + } + + storeNc.Add(farmland.SeedCfgId, farmland.Config.SeedProduce); + farmland.Harvest(); + return ErrorCode.ERR_Success; + } + + return ErrorCode.ERR_FarmlandNotRipe; } - farmland.Plant(cropId,cropConfig.SeedNeed); - - return ErrorCode.ERR_Success; + return ErrorCode.ERR_FarmlandNotFound; } - public static int Harvest(Unit unit, long farmlandId) + public static (List, List) FarmlandSeed(Unit unit, List farmlandIds, List CropCfgIds) { - var farmland = unit.FarmlandDic[farmlandId]; - var storeNc = unit.GetComponent(); - storeNc.Add(farmland.Config.ProductID, farmland.Config.BasicProduction); - if (farmland.Config.ByProduct > 0) + List sucFarmlandList = new List(); + List sucCropList = new List(); + for (int i = 0; i < farmlandIds.Count; i++) { - storeNc.Add(farmland.Config.ByProduct,farmland.Config.ByProductNum); + Farmland farmland; + if (unit.FarmlandDic.TryGetValue(farmlandIds[i], out farmland)) + { + if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_FREE) + { + var cropCfg = CropConfigCategory.Instance.Get(CropCfgIds[i]); + var sc = unit.GetComponent(); + if (sc.Remove(cropCfg.SeedNeed, cropCfg.SeedNum)) + { + farmland.Seed(cropCfg.SeedNeed); + sucCropList.Add(cropCfg.SeedNeed); + sucFarmlandList.Add(farmlandIds[i]); + } + } + } } - storeNc.Add(farmland.SeedCfgId,farmland.Config.SeedProduce); - farmland.Harvest(); - return ErrorCode.ERR_Success; + + return (sucFarmlandList, sucCropList); } } } \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs index a26533f..6b18686 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs @@ -2,6 +2,7 @@ namespace ET { + [FriendClass(typeof(People))] public static class PeopleOperate { public static int StopBehave(Unit unit, People people) @@ -29,5 +30,24 @@ namespace ET people.SetTargetId(0); return ErrorCode.ERR_Success; } + + public static int ChangeBehave(Unit unit, long peopleId,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) + { + return result; + } + + people.TargetId = targetId; + people.BehaveType = behaveType; + return ErrorCode.ERR_Success; + } } } \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/People/PeopleSystem.cs b/Unity/Codes/Hotfix/Demo/People/PeopleSystem.cs index 01e74b1..d4aaa9f 100644 --- a/Unity/Codes/Hotfix/Demo/People/PeopleSystem.cs +++ b/Unity/Codes/Hotfix/Demo/People/PeopleSystem.cs @@ -153,15 +153,19 @@ namespace ET int laborCoefficientBuild = WorldParametersConfigCategory.Instance.Get(WorldParam.LaborCoefficientBuild).Value[0]; return labor * laborCoefficientBuild; } - - //农民类型才会成长 + + //农民类型才会成长,年龄增加 public static void GrowUp(this People self) { if (self.PeopleType != (int)RoleTypeEnum.VILLAGERS) { return; } + + self.Age += 1; + } + //public static void Add } diff --git a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs index 69d38db..e9543ed 100644 --- a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs @@ -237,6 +237,14 @@ namespace ET ((Farmland)v).Update(); } } + + public static void AddAge(this Unit self) + { + foreach (var v in self.GetComponent().Children.Values) + { + ((People) v).GrowUp(); + } + } } } \ No newline at end of file diff --git a/Unity/Codes/Model/Demo/ConstValue.cs b/Unity/Codes/Model/Demo/ConstValue.cs index 49e7f03..4800116 100644 --- a/Unity/Codes/Model/Demo/ConstValue.cs +++ b/Unity/Codes/Model/Demo/ConstValue.cs @@ -31,6 +31,8 @@ namespace ET public const int BEHAVE_GATHER = 2; //正在采集 public const int BEHAVE_PREPARE_CONSTRUCT = 3; //去建造 public const int BEHAVE_CONSTRUCT = 4; //建造 + public const int BEHAVE_PLANT = 5; //种植 + public const int BEHAVE_Harvest = 6;//收获 } public static class ConstPeopleType @@ -122,9 +124,10 @@ namespace ET public static class FarmlandState { public const int FARMLAND_STATE_FREE = 1;//空闲 - public const int FARMLAND_STATE_PLANT = 2; //种植 - public const int FARMLAND_STATE_GROW = 3; //生长 - public const int FARMLAND_STATE_RIPE = 4; //成熟 - public const int FARMLAND_STATE_HARVEST = 5;//收割 + public const int FARMLAND_STATE_SEED = 2; //已经播种 + public const int FARMLAND_STATE_PLANT = 3; //种植 + public const int FARMLAND_STATE_GROW = 4; //生长 + public const int FARMLAND_STATE_RIPE = 5; //成熟 + public const int FARMLAND_STATE_HARVEST = 6;//收割 } } \ No newline at end of file diff --git a/Unity/Codes/Model/Demo/People/People.cs b/Unity/Codes/Model/Demo/People/People.cs index df458bb..83ef42a 100644 --- a/Unity/Codes/Model/Demo/People/People.cs +++ b/Unity/Codes/Model/Demo/People/People.cs @@ -14,6 +14,8 @@ namespace ET public int ConfigId; public int Labor; //劳力值,受年龄段限制 public int LaborExp; //劳力经验 + public int Physique; //体质 + public int PhysiqueExp; //体质经验 public int Exp; public int Level; public int Age; diff --git a/Unity/Codes/Model/Generate/Message/OuterMessage.cs b/Unity/Codes/Model/Generate/Message/OuterMessage.cs index 275ee7f..fd00f80 100644 --- a/Unity/Codes/Model/Generate/Message/OuterMessage.cs +++ b/Unity/Codes/Model/Generate/Message/OuterMessage.cs @@ -2465,28 +2465,22 @@ namespace ET } - [ResponseType(nameof(M2C_GMAddItem))] - [Message(OuterOpcode.C2M_GMAddItem)] + [ResponseType(nameof(M2C_ConstructFinish))] + [Message(OuterOpcode.C2M_ConstructFinish)] [ProtoContract] - public partial class C2M_GMAddItem: Object, IActorLocationRequest + public partial class C2M_ConstructFinish: Object, IActorLocationRequest { [ProtoMember(90)] public int RpcId { get; set; } [ProtoMember(1)] - public long PeopleId { get; set; } - - [ProtoMember(2)] - public List Ks = new List(); - - [ProtoMember(3)] - public List Vs = new List(); + public long ConstructId { get; set; } } - [Message(OuterOpcode.M2C_GMAddItem)] + [Message(OuterOpcode.M2C_ConstructFinish)] [ProtoContract] - public partial class M2C_GMAddItem: Object, IActorLocationResponse + public partial class M2C_ConstructFinish: Object, IActorLocationResponse { [ProtoMember(90)] public int RpcId { get; set; } @@ -2534,9 +2528,6 @@ namespace ET [ProtoMember(1)] public long FarmlandId { get; set; } - [ProtoMember(2)] - public int CropCfgId { get; set; } - } [Message(OuterOpcode.M2C_FarmlandPlant)] @@ -2582,22 +2573,65 @@ namespace ET } - [ResponseType(nameof(M2C_ConstructFinish))] - [Message(OuterOpcode.C2M_ConstructFinish)] + [ResponseType(nameof(M2C_FarmlandSeed))] + [Message(OuterOpcode.C2M_FarmlandSeed)] [ProtoContract] - public partial class C2M_ConstructFinish: Object, IActorLocationRequest + public partial class C2M_FarmlandSeed: Object, IActorLocationRequest { [ProtoMember(90)] public int RpcId { get; set; } [ProtoMember(1)] - public long ConstructId { get; set; } + public List FarmlandIds = new List(); + + [ProtoMember(2)] + public List CropCfgIds = new List(); } - [Message(OuterOpcode.M2C_ConstructFinish)] + [Message(OuterOpcode.M2C_FarmlandSeed)] [ProtoContract] - public partial class M2C_ConstructFinish: Object, IActorLocationResponse + public partial class M2C_FarmlandSeed: Object, IActorLocationResponse + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(91)] + public int Error { get; set; } + + [ProtoMember(92)] + public string Message { get; set; } + + [ProtoMember(1)] + public List FarmlandIds = new List(); + + [ProtoMember(2)] + public List CropCfgIds = new List(); + + } + + [ResponseType(nameof(M2C_ChangeBehave))] + [Message(OuterOpcode.C2M_ChangeBehave)] + [ProtoContract] + public partial class C2M_ChangeBehave: Object, IActorLocationRequest + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(1)] + public long TargetId { get; set; } + + [ProtoMember(2)] + public int BehaveType { get; set; } + + [ProtoMember(3)] + public long PeopleId { get; set; } + + } + + [Message(OuterOpcode.M2C_ChangeBehave)] + [ProtoContract] + public partial class M2C_ChangeBehave: Object, IActorLocationResponse { [ProtoMember(90)] public int RpcId { get; set; } diff --git a/Unity/Codes/Model/Generate/Message/OuterOpcode.cs b/Unity/Codes/Model/Generate/Message/OuterOpcode.cs index d2e3bbd..cc51059 100644 --- a/Unity/Codes/Model/Generate/Message/OuterOpcode.cs +++ b/Unity/Codes/Model/Generate/Message/OuterOpcode.cs @@ -145,14 +145,16 @@ namespace ET public const ushort M2C_NotifyResourceAttri = 10142; public const ushort C2M_BuildingDurable = 10143; public const ushort M2C_BuildingDurable = 10144; - public const ushort C2M_GMAddItem = 10145; - public const ushort M2C_GMAddItem = 10146; + public const ushort C2M_ConstructFinish = 10145; + public const ushort M2C_ConstructFinish = 10146; public const ushort FarmlandProto = 10147; public const ushort C2M_FarmlandPlant = 10148; public const ushort M2C_FarmlandPlant = 10149; public const ushort C2M_FarmlandHarvest = 10150; public const ushort M2C_FarmlandHarvest = 10151; - public const ushort C2M_ConstructFinish = 10152; - public const ushort M2C_ConstructFinish = 10153; + public const ushort C2M_FarmlandSeed = 10152; + public const ushort M2C_FarmlandSeed = 10153; + public const ushort C2M_ChangeBehave = 10154; + public const ushort M2C_ChangeBehave = 10155; } } diff --git a/Unity/Codes/Model/Module/Message/ErrorCode.cs b/Unity/Codes/Model/Module/Message/ErrorCode.cs index 58866e1..8366e96 100644 --- a/Unity/Codes/Model/Module/Message/ErrorCode.cs +++ b/Unity/Codes/Model/Module/Message/ErrorCode.cs @@ -94,5 +94,7 @@ namespace ET public const int ERR_FarmlandNotFound = 210203;// 农场没有找到 public const int ERR_CropConfigNotFound = 210204;// 农场没有找到 public const int ERR_SeedNotEnough = 210205;// 农场没有找到 + public const int ERR_FarmlandNotRipe = 210206;//没有成熟 + public const int ERR_FarmlandNotSeed = 210206;//没有播种 } } \ No newline at end of file