diff --git a/Proto/OuterMessage.proto b/Proto/OuterMessage.proto index ae34ad2..bce92c1 100644 --- a/Proto/OuterMessage.proto +++ b/Proto/OuterMessage.proto @@ -1316,3 +1316,28 @@ message M2C_GoFarmlandHarvest // IActorLocationResponse int32 Error = 91; string Message = 92; } + +//ResponseType M2C_FarmlandRipe +message C2M_FarmlandRipe // IActorLocationRequest +{ + int32 RpcId = 90; + int64 FarmlandId = 1 ; +} + +message M2C_FarmlandRipe // IActorLocationResponse +{ + int32 RpcId = 90; + int32 Error = 91; + string Message = 92; +} + +message M2C_NtfFarmlandRipe // IActorMessage +{ + repeated int64 FarmlandIds = 1; +} + +message M2C_NtfFarmlandRipeProgress // IActorMessage +{ + repeated int64 FarmlandIds = 1; + repeated int32 Progresses = 2; +} diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs index 661a53f..3fdb439 100644 --- a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs @@ -35,6 +35,7 @@ namespace ET response.Message = e.ToString(); response.Error = ErrorCode.ERR_OperateFail; reply(); + throw; } await ETTask.CompletedTask; diff --git a/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandRipeHandler.cs b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandRipeHandler.cs new file mode 100644 index 0000000..ccfac5f --- /dev/null +++ b/Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandRipeHandler.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +namespace ET +{ + [FriendClass(typeof(Farmland))] + public class C2M_FarmlandRipeHandler: AMActorLocationRpcHandler + { + protected override async ETTask Run(Unit unit, C2M_FarmlandRipe request, M2C_FarmlandRipe response, Action reply) + { + try + { + Farmland farmland = unit.GetGrandChild(request.FarmlandId); + if (farmland != null) + { + farmland.FarmlandState = FarmlandState.FARMLAND_STATE_RIPE; + response.Error = ErrorCode.ERR_Success; + FarmlandHelper.NotifyFarmlandRipe(unit,new List{farmland.Id}); + } + else + { + response.Error = ErrorCode.ERR_FarmlandNotFound; + } + + reply(); + } + catch (Exception e) + { + response.Message = e.ToString(); + response.Error = ErrorCode.ERR_OperateFail; + reply(); + throw; + } + + await ETTask.CompletedTask; + } + } +} \ No newline at end of file diff --git a/Server/Hotfix/Demo/Helper/ConstructHelper.cs b/Server/Hotfix/Demo/Helper/ConstructHelper.cs index 3165457..241ec39 100644 --- a/Server/Hotfix/Demo/Helper/ConstructHelper.cs +++ b/Server/Hotfix/Demo/Helper/ConstructHelper.cs @@ -21,7 +21,7 @@ namespace ET } } - public static void NofityConstructFinish(Unit unit, long id, long buildingId) + public static void NotifyConstructFinish(Unit unit, long id, long buildingId) { MessageHelper.SendToClient(unit,new M2C_NotifyConstructFinish(){ConstructId = id, BuildingId = buildingId}); } diff --git a/Server/Hotfix/Demo/Helper/FarmlandHelper.cs b/Server/Hotfix/Demo/Helper/FarmlandHelper.cs new file mode 100644 index 0000000..70fc1e5 --- /dev/null +++ b/Server/Hotfix/Demo/Helper/FarmlandHelper.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace ET +{ + public static class FarmlandHelper + { + public static void M2C_NtfFarmlandRipeProgress(Unit unit, List farmlandIds, List progresses) + { + if (farmlandIds.Count == 0) + { + return; + } + MessageHelper.SendToClient(unit,new M2C_NtfFarmlandRipeProgress(){ FarmlandIds = farmlandIds,Progresses = progresses}); + } + public static void NotifyFarmlandRipe(Unit unit, List farmlandIds) + { + if (farmlandIds.Count == 0) + { + return; + } + MessageHelper.SendToClient(unit,new M2C_NtfFarmlandRipe(){FarmlandIds =farmlandIds }); + } + } +} \ No newline at end of file diff --git a/Server/Model/Generate/Message/OuterMessage.cs b/Server/Model/Generate/Message/OuterMessage.cs index c317318..e9817f5 100644 --- a/Server/Model/Generate/Message/OuterMessage.cs +++ b/Server/Model/Generate/Message/OuterMessage.cs @@ -2746,4 +2746,53 @@ namespace ET } + [ResponseType(nameof(M2C_FarmlandRipe))] + [Message(OuterOpcode.C2M_FarmlandRipe)] + [ProtoContract] + public partial class C2M_FarmlandRipe: Object, IActorLocationRequest + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(1)] + public long FarmlandId { get; set; } + + } + + [Message(OuterOpcode.M2C_FarmlandRipe)] + [ProtoContract] + public partial class M2C_FarmlandRipe: Object, IActorLocationResponse + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(91)] + public int Error { get; set; } + + [ProtoMember(92)] + public string Message { get; set; } + + } + + [Message(OuterOpcode.M2C_NtfFarmlandRipe)] + [ProtoContract] + public partial class M2C_NtfFarmlandRipe: Object, IActorMessage + { + [ProtoMember(1)] + public List FarmlandIds = new List(); + + } + + [Message(OuterOpcode.M2C_NtfFarmlandRipeProgress)] + [ProtoContract] + public partial class M2C_NtfFarmlandRipeProgress: Object, IActorMessage + { + [ProtoMember(1)] + public List FarmlandIds = new List(); + + [ProtoMember(2)] + public List Progresses = new List(); + + } + } diff --git a/Server/Model/Generate/Message/OuterOpcode.cs b/Server/Model/Generate/Message/OuterOpcode.cs index 723aa68..539d4ca 100644 --- a/Server/Model/Generate/Message/OuterOpcode.cs +++ b/Server/Model/Generate/Message/OuterOpcode.cs @@ -162,5 +162,9 @@ namespace ET public const ushort M2C_GoFarmlandPlant = 10159; public const ushort C2M_GoFarmlandHarvest = 10160; public const ushort M2C_GoFarmlandHarvest = 10161; + public const ushort C2M_FarmlandRipe = 10162; + public const ushort M2C_FarmlandRipe = 10163; + public const ushort M2C_NtfFarmlandRipe = 10164; + public const ushort M2C_NtfFarmlandRipeProgress = 10165; } } diff --git a/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs b/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs index 09a2c44..b4432e1 100644 --- a/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs @@ -58,7 +58,7 @@ namespace ET foreach (var v in finishConstructs) { var building = ConstructOperate.ConstructFinish(unit, v.Id); - ConstructHelper.NofityConstructFinish(unit,v.Id, building.Id); + ConstructHelper.NotifyConstructFinish(unit,v.Id, building.Id); } if (finishConstructs.Count > 0) diff --git a/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs b/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs index 506e4be..d3e8a9f 100644 --- a/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs @@ -60,16 +60,17 @@ } - public static void Update(this Farmland self) + public static void Update(this Farmland self,Unit unit) { - if (self.FarmlandState != FarmlandState.FARMLAND_STATE_GROW) - { - return; - } + self.Duration += 1; if (self.Duration >= self.Config.GrowthCycle) { self.FarmlandState = FarmlandState.FARMLAND_STATE_RIPE; + +#if SERVER + +#endif } } diff --git a/Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeHandler.cs b/Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeHandler.cs new file mode 100644 index 0000000..1d24f29 --- /dev/null +++ b/Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeHandler.cs @@ -0,0 +1,18 @@ +namespace ET.Handler +{ + [FriendClass(typeof(Farmland))] + public class M2C_NtfFarmlandRipeHandler:AMHandler + { + protected override void Run(Session session, M2C_NtfFarmlandRipe message) + { + foreach (var v in message.FarmlandIds) + { + Farmland farmland=UnitComponent.unit.GetGrandChild(v); + if ( farmland!= null) + { + farmland.FarmlandState = FarmlandState.FARMLAND_STATE_RIPE; + } + } + } + } +} \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeProgressHandler.cs b/Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeProgressHandler.cs new file mode 100644 index 0000000..c156382 --- /dev/null +++ b/Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeProgressHandler.cs @@ -0,0 +1,19 @@ +namespace ET.Handler +{ + + [FriendClass(typeof(Farmland))] + public class M2C_NtfFarmlandRipeProgressHandler:AMHandler + { + protected override void Run(Session session, M2C_NtfFarmlandRipeProgress message) + { + for (int i=0;i(message.FarmlandIds[i]); + if ( farmland!= null) + { + farmland.Duration = message.Progresses[i]; + } + } + } + } +} \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs index da76ed3..35616fb 100644 --- a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs +++ b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs @@ -142,7 +142,21 @@ namespace ET return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE); } - + public static async ETTask FarmlandRipe(Unit unit,long farmlandId) + { + try + { + C2M_FarmlandRipe msg = new C2M_FarmlandRipe() { FarmlandId = farmlandId }; + M2C_FarmlandRipe resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandRipe; + + return resp.Error; + } + catch (Exception e) + { + Log.Error(e.ToString()); + throw; + } + } diff --git a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs index 53862e6..3dc3be7 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs @@ -92,5 +92,7 @@ namespace ET return (sucFarmlandList, sucCropList); } + + } } \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs index a1a514d..e5b6bf6 100644 --- a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs @@ -45,6 +45,7 @@ namespace ET #endif [FriendClass(typeof (Unit))] + [FriendClass(typeof (Farmland))] public static class UnitSystem { public static void AddTime(this Unit self, int tick) @@ -224,19 +225,36 @@ namespace ET self.GetComponent()?.DurableReduce(); } - - public static void UpdateGameTime(this Unit self) { //update farmland + List farmlandIds = new List(); + List progresses = new List(); + List ripeIds = new List(); foreach (var v in self.GrandChildren.Values) { if (v.GetType() == typeof (Farmland)) { - ((Farmland) v).Update(); - + Farmland farmland = (Farmland) v; + if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_GROW) + { + farmland.Update(self); + if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE) + { + ripeIds.Add(farmland.Id); + } + else + { + farmlandIds.Add(farmland.Id); + progresses.Add(farmland.Duration); + } + } } } +#if SERVER + FarmlandHelper.NotifyFarmlandRipe(unit,ripeIds); + FarmlandHelper.M2C_NtfFarmlandRipeProgress(unit,farmlandIds,ripeIds) +#endif } public static void AddAge(this Unit self) @@ -280,7 +298,7 @@ namespace ET self.GrandChildren[entity.Id] = entity; } - public static void RemoveGrandChild(this Unit self,long id) + public static void RemoveGrandChild(this Unit self, long id) { self.GrandChildren.Remove(id); } diff --git a/Unity/Codes/Model/Generate/Message/OuterMessage.cs b/Unity/Codes/Model/Generate/Message/OuterMessage.cs index c317318..e9817f5 100644 --- a/Unity/Codes/Model/Generate/Message/OuterMessage.cs +++ b/Unity/Codes/Model/Generate/Message/OuterMessage.cs @@ -2746,4 +2746,53 @@ namespace ET } + [ResponseType(nameof(M2C_FarmlandRipe))] + [Message(OuterOpcode.C2M_FarmlandRipe)] + [ProtoContract] + public partial class C2M_FarmlandRipe: Object, IActorLocationRequest + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(1)] + public long FarmlandId { get; set; } + + } + + [Message(OuterOpcode.M2C_FarmlandRipe)] + [ProtoContract] + public partial class M2C_FarmlandRipe: Object, IActorLocationResponse + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(91)] + public int Error { get; set; } + + [ProtoMember(92)] + public string Message { get; set; } + + } + + [Message(OuterOpcode.M2C_NtfFarmlandRipe)] + [ProtoContract] + public partial class M2C_NtfFarmlandRipe: Object, IActorMessage + { + [ProtoMember(1)] + public List FarmlandIds = new List(); + + } + + [Message(OuterOpcode.M2C_NtfFarmlandRipeProgress)] + [ProtoContract] + public partial class M2C_NtfFarmlandRipeProgress: Object, IActorMessage + { + [ProtoMember(1)] + public List FarmlandIds = new List(); + + [ProtoMember(2)] + public List Progresses = new List(); + + } + } diff --git a/Unity/Codes/Model/Generate/Message/OuterOpcode.cs b/Unity/Codes/Model/Generate/Message/OuterOpcode.cs index 723aa68..539d4ca 100644 --- a/Unity/Codes/Model/Generate/Message/OuterOpcode.cs +++ b/Unity/Codes/Model/Generate/Message/OuterOpcode.cs @@ -162,5 +162,9 @@ namespace ET public const ushort M2C_GoFarmlandPlant = 10159; public const ushort C2M_GoFarmlandHarvest = 10160; public const ushort M2C_GoFarmlandHarvest = 10161; + public const ushort C2M_FarmlandRipe = 10162; + public const ushort M2C_FarmlandRipe = 10163; + public const ushort M2C_NtfFarmlandRipe = 10164; + public const ushort M2C_NtfFarmlandRipeProgress = 10165; } }