From e2e0343279a0e1e024e48a7f1d535a93d6f087eb Mon Sep 17 00:00:00 2001 From: wserver/wangdisen <1065498738@qq.com> Date: Thu, 18 Aug 2022 11:30:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E6=AD=A3=E5=9C=A8=E7=A7=8D=E6=A4=8D?= =?UTF-8?q?=EF=BC=8C=E6=AD=A3=E5=9C=A8=E6=94=B6=E5=89=B2=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Handler/C2M_FarmlandHarvestHandler.cs | 2 +- .../Handler/C2M_FarmlandPlantHandler.cs | 6 +- .../Hotfix/Demo/Helper/FarmlandHelper.cs | 63 ++++++++++++++++--- .../Codes/Hotfix/Demo/Helper/PeopleHelper.cs | 4 +- .../Hotfix/Demo/Operate/FarmlandOperate.cs | 19 +++--- .../Hotfix/Demo/Operate/PeopleOperate.cs | 2 +- Unity/Codes/Model/Demo/ConstValue.cs | 4 +- 7 files changed, 72 insertions(+), 28 deletions(-) diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs index 80cbf3a..80b4e97 100644 --- a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs @@ -17,7 +17,7 @@ namespace ET people = unit.GetComponent().GetChild(request.PeopleId); if (people != null) { - response.Error = FarmlandOperate.Harvest(unit, farmland, people); + response.Error = FarmlandOperate.FinishHarvest(unit, farmland, people); } else { diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs index 9c7cec1..661a53f 100644 --- a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs @@ -9,14 +9,14 @@ namespace ET { try { - People people; + Farmland farmland = unit.GetGrandChild(request.FarmlandId); if (farmland!=null) { - people = unit.GetComponent().GetChild(request.PeopleId); + People people = unit.GetComponent().GetChild(request.PeopleId); if (people != null) { - response.Error = FarmlandOperate.Plant(unit, farmland, people); + response.Error = FarmlandOperate.FinishPlant(unit, farmland, people); } else { diff --git a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs index 563aa41..da76ed3 100644 --- a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs +++ b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs @@ -29,12 +29,36 @@ namespace ET } } - public static async ETTask GoFarmlandPlant(Unit unit,People people,long farmlandId) + public static async ETTask GoFarmlandPlant(Unit unit,People people,Farmland farmland) { - return await PeopleHelper.ChangeBehave(unit, people, farmlandId, ConstBehaveType.BEHAVE_PREPARE_PLANT); + try + { + C2M_GoFarmlandPlant msg = new C2M_GoFarmlandPlant() { PeopleId = people.Id,FarmlandId = farmland.Id}; + M2C_GoFarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_GoFarmlandPlant; + if (resp.Error == ErrorCode.ERR_Success) + { + FarmlandOperate.GoPlant(unit, farmland,people); + } + else + { + Log.Error(resp.Error.ToString()); + } + + return resp.Error; + } + catch (Exception e) + { + Log.Error(e.ToString()); + throw; + } + } + + public static async ETTask StartFarmlandPlant(Unit unit, People people, Farmland farmland) + { + return await PeopleHelper.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PLANT,farmland.Id); } - public static async ETTask StartFarmlandPlant(Unit unit, Farmland farmland,People people) + public static async ETTask FinishFarmlandPlant(Unit unit, Farmland farmland,People people) { try { @@ -42,7 +66,7 @@ namespace ET M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandPlant; if (resp.Error == ErrorCode.ERR_Success) { - FarmlandOperate.Plant(unit, farmland,people); + FarmlandOperate.FinishPlant(unit, farmland,people); } else { @@ -57,14 +81,35 @@ namespace ET throw; } } - public static async ETTask FinishFarmlandPlant(Unit unit,People people) + + + public static async ETTask GoFarmlandHarvest(Unit unit,People people,Farmland farmland) { - return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE); + try + { + C2M_GoFarmlandHarvest msg = new C2M_GoFarmlandHarvest() { PeopleId = people.Id,FarmlandId = farmland.Id}; + M2C_GoFarmlandHarvest resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_GoFarmlandHarvest; + if (resp.Error == ErrorCode.ERR_Success) + { + FarmlandOperate.GoHarvest(unit, farmland,people); + } + else + { + Log.Error(resp.Error.ToString()); + } + + return resp.Error; + } + catch (Exception e) + { + Log.Error(e.ToString()); + throw; + } } - public static async ETTask GoFarmlandHarvest(Unit unit,People people) + public static async ETTask StartFarmlandHarvest(Unit unit, People people, Farmland farmland) { - return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_PREPARE_HARVEST); + return await PeopleHelper.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PREPARE_HARVEST,farmland.Id); } public static async ETTask FarmlandHarvest(Unit unit, Farmland farmland,People people) { @@ -74,7 +119,7 @@ namespace ET M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandPlant; if (resp.Error == ErrorCode.ERR_Success) { - FarmlandOperate.Harvest(unit, farmland,people); + FarmlandOperate.FinishHarvest(unit, farmland,people); } else { diff --git a/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs index 11cf1e2..17fcced 100644 --- a/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs +++ b/Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs @@ -28,7 +28,7 @@ namespace ET return ErrorCode.ERR_Success; } - public static async ETTask ChangeBehave(Unit unit, People people,long targetId, int behaveType) + public static async ETTask ChangeBehave(Unit unit, People people,int behaveType,long targetId ) { try { @@ -40,7 +40,7 @@ namespace ET return resp.Error; } - PeopleOperate.ChangeBehave(unit, people, targetId, behaveType); + PeopleOperate.ChangeBehave(unit, people, behaveType,targetId); } catch (Exception e) { diff --git a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs index d953fd1..c44db83 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs @@ -12,15 +12,13 @@ namespace ET { return ErrorCode.ERR_FarmlandNotSeed; } - - PeopleOperate.StopBehave(unit, people); - people.SetBehaveType(ConstBehaveType.BEHAVE_PREPARE_PLANT); - people.SetTargetId(farmland.Id); + + PeopleOperate.ChangeBehave(unit,people, ConstBehaveType.BEHAVE_PREPARE_PLANT, farmland.Id); farmland.PeopleId = people.Id; return ErrorCode.ERR_Success; } - public static int Plant(Unit unit, Farmland farmland, People people) + public static int FinishPlant(Unit unit, Farmland farmland, People people) { if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED) { @@ -28,7 +26,7 @@ namespace ET } farmland.Plant(); - PeopleOperate.ChangeBehave(unit, people, farmland.Id, ConstBehaveType.BEHAVE_IDLE); + PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_IDLE); return ErrorCode.ERR_Success; } @@ -40,14 +38,12 @@ namespace ET return ErrorCode.ERR_FarmlandNotSeed; } - PeopleOperate.StopBehave(unit, people); - people.SetBehaveType(ConstBehaveType.BEHAVE_PREPARE_HARVEST); - people.SetTargetId(farmland.Id); + PeopleOperate.ChangeBehave(unit,people,ConstBehaveType.BEHAVE_PREPARE_HARVEST,farmland.Id); farmland.PeopleId = people.Id; return ErrorCode.ERR_Success; } - public static int Harvest(Unit unit, Farmland farmland, People people) + public static int FinishHarvest(Unit unit, Farmland farmland, People people) { if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE) { @@ -60,10 +56,11 @@ namespace ET storeNc.Add(farmland.CropCfgId, farmland.Config.SeedProduce); farmland.Harvest(); + PeopleOperate.StopBehave(unit, people); return ErrorCode.ERR_Success; } - PeopleOperate.ChangeBehave(unit, people, farmland.Id, ConstBehaveType.BEHAVE_IDLE); + PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_IDLE); return ErrorCode.ERR_FarmlandNotRipe; } diff --git a/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs index c8b6724..7a75c3b 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs @@ -31,7 +31,7 @@ namespace ET return ErrorCode.ERR_Success; } - public static int ChangeBehave(Unit unit, People people,long targetId, int behaveType) + public static int ChangeBehave(Unit unit, People people,int behaveType,long targetId=0 ) { diff --git a/Unity/Codes/Model/Demo/ConstValue.cs b/Unity/Codes/Model/Demo/ConstValue.cs index a190171..3a292a5 100644 --- a/Unity/Codes/Model/Demo/ConstValue.cs +++ b/Unity/Codes/Model/Demo/ConstValue.cs @@ -32,7 +32,9 @@ namespace ET public const int BEHAVE_PREPARE_CONSTRUCT = 3; //去建造 public const int BEHAVE_CONSTRUCT = 4; //建造 public const int BEHAVE_PREPARE_PLANT = 5; //去种植 - public const int BEHAVE_PREPARE_HARVEST = 6;//去收割 + public const int BEHAVE_PLANT = 6; //正在种植 + public const int BEHAVE_PREPARE_HARVEST = 7;//去收割 + public const int BEHAVE_HARVEST = 8;//正在收割 }