diff --git a/Excel/Json/s/StartSceneConfig.txt b/Excel/Json/s/StartSceneConfig.txt index 7b3de1e..92083b6 100644 --- a/Excel/Json/s/StartSceneConfig.txt +++ b/Excel/Json/s/StartSceneConfig.txt @@ -3,8 +3,8 @@ {"_t":"StartSceneConfig","_id":2,"Process":1,"Zone":1,"SceneType":"Gate","Name":"Gate1","OuterPort":10003}, {"_t":"StartSceneConfig","_id":3,"Process":1,"Zone":1,"SceneType":"Gate","Name":"Gate2","OuterPort":10004}, {"_t":"StartSceneConfig","_id":4,"Process":1,"Zone":1,"SceneType":"Location","Name":"Location","OuterPort":0}, -{"_t":"StartSceneConfig","_id":5,"Process":3,"Zone":1,"SceneType":"Map","Name":"Game_1","OuterPort":0}, -{"_t":"StartSceneConfig","_id":6,"Process":1,"Zone":1,"SceneType":"Map","Name":"Game_2","OuterPort":0}, +{"_t":"StartSceneConfig","_id":5,"Process":1,"Zone":1,"SceneType":"Map","Name":"Game_1","OuterPort":0}, +{"_t":"StartSceneConfig","_id":6,"Process":3,"Zone":1,"SceneType":"Map","Name":"Game_2","OuterPort":0}, {"_t":"StartSceneConfig","_id":7,"Process":1,"Zone":1,"SceneType":"Account","Name":"Account","OuterPort":10005}, {"_t":"StartSceneConfig","_id":8,"Process":1,"Zone":1,"SceneType":"LoginCenter","Name":"LoginCenter","OuterPort":0}, {"_t":"StartSceneConfig","_id":9,"Process":1,"Zone":1,"SceneType":"UnitCache","Name":"UnitCache","OuterPort":0}, diff --git a/Excel/StartSceneConfig@s.xlsx b/Excel/StartSceneConfig@s.xlsx index 27b6c88..02f2ac2 100644 Binary files a/Excel/StartSceneConfig@s.xlsx and b/Excel/StartSceneConfig@s.xlsx differ diff --git a/Proto/OuterMessage.proto b/Proto/OuterMessage.proto index d5ebe96..a1b169d 100644 --- a/Proto/OuterMessage.proto +++ b/Proto/OuterMessage.proto @@ -65,7 +65,8 @@ message BuildingProto float X = 3; float Y = 4; int32 Durable = 5; - int32 State = 6; //1.建造中 2.完成 3.维修中 + FarmlandProto Farmland = 6; + } message PeopleProto @@ -1195,5 +1196,41 @@ message M2C_GMAddItem // IActorLocationResponse string Message = 92; } +message FarmlandProto +{ + int64 id = 1; + int32 SeedCfgId = 2; + int32 plantCfgId = 3; + int32 duration = 4; + int32 exProduct = 5; + int32 farmlandState = 6; +} + +//ResponseType M2C_FarmlandPlant +message C2M_FarmlandPlant // IActorLocationRequest +{ + int32 RpcId = 90; + int64 FarmlandId = 1; + int32 CropCfgId = 2; +} + +message M2C_FarmlandPlant // IActorLocationResponse +{ + int32 RpcId = 90; + int32 Error = 91; + string Message = 92; +} +//ResponseType M2C_FarmlandHarvest +message C2M_FarmlandHarvest // IActorLocationRequest +{ + int32 RpcId = 90; + int64 FarmlandId = 1; +} +message M2C_FarmlandHarvest // IActorLocationResponse +{ + int32 RpcId = 90; + int32 Error = 91; + string Message = 92; +} \ No newline at end of file diff --git a/Server/Hotfix/Demo/C2G_EnterMapHandler.cs b/Server/Hotfix/Demo/C2G_EnterMapHandler.cs index 1284d48..83bfc06 100644 --- a/Server/Hotfix/Demo/C2G_EnterMapHandler.cs +++ b/Server/Hotfix/Demo/C2G_EnterMapHandler.cs @@ -5,6 +5,7 @@ namespace ET { [FriendClass(typeof(GateMapComponent))] [MessageHandler] + //此函数已经放弃了 public class C2G_EnterMapHandler : AMRpcHandler { protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response, Action reply) diff --git a/Server/Hotfix/Server.Hotfix.csproj b/Server/Hotfix/Server.Hotfix.csproj index a2ad759..39e2171 100644 --- a/Server/Hotfix/Server.Hotfix.csproj +++ b/Server/Hotfix/Server.Hotfix.csproj @@ -40,6 +40,9 @@ Demo\Construct\ConstructSystem.cs + + Demo\Farmland\FarmlandSystem.cs + Demo\Fighter\FighterComponentSystem.cs diff --git a/Server/Model/Generate/Message/OuterMessage.cs b/Server/Model/Generate/Message/OuterMessage.cs index ec6e88e..4d918db 100644 --- a/Server/Model/Generate/Message/OuterMessage.cs +++ b/Server/Model/Generate/Message/OuterMessage.cs @@ -141,7 +141,7 @@ namespace ET public int Durable { get; set; } [ProtoMember(6)] - public int State { get; set; } + public FarmlandProto Farmland { get; set; } } @@ -2490,4 +2490,87 @@ namespace ET } + [Message(OuterOpcode.FarmlandProto)] + [ProtoContract] + public partial class FarmlandProto: Object + { + [ProtoMember(1)] + public long id { get; set; } + + [ProtoMember(2)] + public int SeedCfgId { get; set; } + + [ProtoMember(3)] + public int plantCfgId { get; set; } + + [ProtoMember(4)] + public int duration { get; set; } + + [ProtoMember(5)] + public int exProduct { get; set; } + + [ProtoMember(6)] + public int farmlandState { get; set; } + + } + + [ResponseType(nameof(M2C_FarmlandPlant))] + [Message(OuterOpcode.C2M_FarmlandPlant)] + [ProtoContract] + public partial class C2M_FarmlandPlant: Object, IActorLocationRequest + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(1)] + public long FarmlandId { get; set; } + + [ProtoMember(2)] + public int CropCfgId { get; set; } + + } + + [Message(OuterOpcode.M2C_FarmlandPlant)] + [ProtoContract] + public partial class M2C_FarmlandPlant: Object, IActorLocationResponse + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(91)] + public int Error { get; set; } + + [ProtoMember(92)] + public string Message { get; set; } + + } + + [ResponseType(nameof(M2C_FarmlandHarvest))] + [Message(OuterOpcode.C2M_FarmlandHarvest)] + [ProtoContract] + public partial class C2M_FarmlandHarvest: Object, IActorLocationRequest + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(1)] + public long FarmlandId { get; set; } + + } + + [Message(OuterOpcode.M2C_FarmlandHarvest)] + [ProtoContract] + public partial class M2C_FarmlandHarvest: Object, IActorLocationResponse + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(91)] + public int Error { get; set; } + + [ProtoMember(92)] + public string Message { get; set; } + + } + } diff --git a/Server/Model/Generate/Message/OuterOpcode.cs b/Server/Model/Generate/Message/OuterOpcode.cs index acd513c..2639765 100644 --- a/Server/Model/Generate/Message/OuterOpcode.cs +++ b/Server/Model/Generate/Message/OuterOpcode.cs @@ -147,5 +147,10 @@ namespace ET public const ushort M2C_BuildingDurable = 10144; public const ushort C2M_GMAddItem = 10145; public const ushort M2C_GMAddItem = 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; } } diff --git a/Server/Model/Server.Model.csproj b/Server/Model/Server.Model.csproj index 182f0e6..f384074 100644 --- a/Server/Model/Server.Model.csproj +++ b/Server/Model/Server.Model.csproj @@ -70,6 +70,10 @@ Demo\ConstValue.cs + + Demo\Farmland\Farmland.cs + + Demo\Fighter\Fighter.cs diff --git a/Unity/Animancer.FSM.csproj b/Unity/Animancer.FSM.csproj index 4432b1b..8c724c1 100644 --- a/Unity/Animancer.FSM.csproj +++ b/Unity/Animancer.FSM.csproj @@ -310,6 +310,9 @@ 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 @@ -346,6 +349,12 @@ 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 7017be2..779372b 100644 --- a/Unity/Animancer.csproj +++ b/Unity/Animancer.csproj @@ -447,6 +447,9 @@ 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 @@ -483,6 +486,12 @@ 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/Building/BuildingComponentSystem.cs b/Unity/Codes/Hotfix/Demo/Building/BuildingComponentSystem.cs index 31aa2a1..5fb37d5 100644 --- a/Unity/Codes/Hotfix/Demo/Building/BuildingComponentSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Building/BuildingComponentSystem.cs @@ -21,7 +21,6 @@ namespace ET building.ConfigId = ConfigId; building.Position = new Vector2(X, Y); building.Durable = building.Config.Durable; - building.State = (int) BuildingState.Built; return building; } @@ -31,7 +30,7 @@ namespace ET foreach (var v in self.Children) { Building building = (Building) v.Value; - if (Array.IndexOf(StructureID, building.ConfigId) != -1 && building.State == (int) BuildingState.Built) + if (Array.IndexOf(StructureID, building.ConfigId) != -1 ) { hasBuilding = true; break; @@ -47,7 +46,7 @@ namespace ET foreach (var v in self.Children) { Building building = (Building) v.Value; - if (special == building.Config.Special && building.State == (int) BuildingState.Built) + if (special == building.Config.Special) { hasBuilding = true; break; diff --git a/Unity/Codes/Hotfix/Demo/Building/BuildingSystem.cs b/Unity/Codes/Hotfix/Demo/Building/BuildingSystem.cs index 9839549..1eab3ae 100644 --- a/Unity/Codes/Hotfix/Demo/Building/BuildingSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Building/BuildingSystem.cs @@ -10,12 +10,33 @@ namespace ET self.Id = buildingProto.Id; self.Position = new Vector2(buildingProto.X, buildingProto.Y); self.ConfigId = buildingProto.ConfigId; - self.State = buildingProto.State; + self.Durable = buildingProto.Durable; + if (buildingProto.Farmland != null) + { + var farmland = self.AddChildWithId(buildingProto.Farmland.id); + farmland.FromMessage(buildingProto.Farmland); + } } public static BuildingProto ToMessage(this Building self) { - return new BuildingProto() { Id = self.Id, ConfigId = self.ConfigId, X = self.Position.x, Y = self.Position.y,State = self.State}; + var proto= new BuildingProto() { Id = self.Id, + ConfigId = self.ConfigId, + X = self.Position.x, + Y = self.Position.y, + Durable = self.Durable}; + if (self.Config.Special == (int) StructureSpecialEnum.FARMLAND) + { + foreach (var v in self.Children.Values) + { + if (v.GetType() == typeof (Farmland)) + { + proto.Farmland = ((Farmland) v).ToMessage(); + } + } + } + + return proto; } public static void DurableReduce(this Building self) diff --git a/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs b/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs index 73316d5..2608b5e 100644 --- a/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs @@ -3,9 +3,10 @@ namespace ET { [FriendClass(typeof(Construct))] + [FriendClass(typeof(Building))] public static class ConstructComponentSystem { - public static Construct CreateConstruct( this ConstructComponent self,int configId, float x, float y,long id=0,long buildingId =0) + public static Construct CreateConstruct( this ConstructComponent self,Unit unit,int configId, float x, float y,long id=0,long buildingId =0) { Construct construct ; if (id == 0) @@ -21,6 +22,15 @@ namespace ET construct.X = x; construct.Y = y; construct.BuildingId = buildingId; + if (buildingId > 0) + { + var building = unit.GetComponent().GetChild(buildingId); + if (building != null) + { + building.IsUpgrade = 1; + } + } + return construct; } diff --git a/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs b/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs new file mode 100644 index 0000000..d3bc434 --- /dev/null +++ b/Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs @@ -0,0 +1,99 @@ +namespace ET +{ + public class FarmlandDestroySystem : DestroySystem + { + public override void Destroy(Farmland self) + { + self.Parent.Parent.GetParent().RemoveFarmland(self); + } + } + + public class FarmlandAwakeSystem : AwakeSystem + { + public override void Awake(Farmland self) + { + self.Parent.Parent.GetParent().AddFarmland(self); + } + } + + public class FarmlandUpdateSystem: UpdateSystem + { + public override void Update(Farmland self) + { + + } + } + [FriendClass(typeof(Farmland))] + public static class FarmlandSystem + { + public static void FromMessage(this Farmland self, FarmlandProto farmlandProto) + { + self.Id = farmlandProto.id; + self.SeedCfgId = farmlandProto.SeedCfgId; + self.Duration = farmlandProto.duration; + self.ExProduct = farmlandProto.exProduct; + self.PlanSeedCfgId = farmlandProto.plantCfgId; + self.FarmlandState = farmlandProto.farmlandState; + } + + public static FarmlandProto ToMessage(this Farmland self) + { + FarmlandProto proto = new FarmlandProto(); + proto.id = self.Id; + proto.SeedCfgId = self.SeedCfgId; + proto.duration = self.Duration; + proto.exProduct = self.ExProduct; + proto.plantCfgId = self.PlanSeedCfgId; + proto.farmlandState = self.FarmlandState; + return proto; + } + + public static int Plant(this Farmland self, int cropId,int seedId) + { + 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; + + } + + public static void Update(this Farmland self) + { + if (self.FarmlandState != FarmlandState.FARMLAND_STATE_GROW) + { + return; + } + self.Duration += 1; + if (self.Duration >= self.Config.GrowthCycle) + { + self.FarmlandState = FarmlandState.FARMLAND_STATE_RIPE; + } + } + + public static int 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; + + } + + } + + +} \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs index 7909294..2557a7c 100644 --- a/Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs +++ b/Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs @@ -13,7 +13,7 @@ namespace ET M2C_CreateConstruct resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_CreateConstruct; if (resp.Error == ErrorCode.ERR_Success) { - var construct = unit.GetOrAddComponent().CreateConstruct(configId, x, y, resp.Id); + var construct = unit.GetOrAddComponent().CreateConstruct(unit,configId, x, y, resp.Id); Game.EventSystem.Publish(new EventType.AfterCreateConstruct(){Unit = unit, Construct = construct, IsNew = true}); } else diff --git a/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs new file mode 100644 index 0000000..ec77f41 --- /dev/null +++ b/Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs @@ -0,0 +1,55 @@ +using System; + +namespace ET +{ + public static class PlantHelper + { + public static async ETTask FarmlandPlant(Unit unit, long farmlandId, int cropId) + { + try + { + C2M_FarmlandPlant msg = new C2M_FarmlandPlant() { FarmlandId = farmlandId, CropCfgId = cropId }; + M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandPlant; + if (resp.Error == ErrorCode.ERR_Success) + { + FarmlandOperate.Plant(unit, farmlandId, cropId); + } + else + { + Log.Error(resp.Error.ToString()); + } + + return resp.Error; + } + catch (Exception e) + { + Log.Error(e.ToString()); + throw; + } + } + + public static async ETTask FarmlandHarvest(Unit unit, long farmlandId) + { + try + { + C2M_FarmlandHarvest msg = new C2M_FarmlandHarvest() { FarmlandId = farmlandId }; + M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandPlant; + if (resp.Error == ErrorCode.ERR_Success) + { + FarmlandOperate.Harvest(unit, farmlandId); + } + else + { + Log.Error(resp.Error.ToString()); + } + + return resp.Error; + } + catch (Exception e) + { + Log.Error(e.ToString()); + throw; + } + } + } +} \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Item/StoreComponentSystem.cs b/Unity/Codes/Hotfix/Demo/Item/StoreComponentSystem.cs index 9c23c4c..71a3360 100644 --- a/Unity/Codes/Hotfix/Demo/Item/StoreComponentSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Item/StoreComponentSystem.cs @@ -3,19 +3,17 @@ using System.Linq; namespace ET { - public class StoreComponentSystemDestroySystem : DestroySystem + public class StoreComponentSystemDestroySystem: DestroySystem { public override void Destroy(StoreComponent self) { - } } - - [FriendClass(typeof(Item))] - public static class StoreComponentSystem + + [FriendClass(typeof (Item))] + public static class StoreComponentSystem { - - public static void Add(this StoreComponent self,int configId,long amount,long id=0,bool bUpdateTime=false) + public static void Add(this StoreComponent self, int configId, long amount, long id = 0, bool bUpdateTime = false) { var config = AllItemConfigCategory.Instance.Get(configId); if (config.SuperpositionMax > 1) @@ -25,7 +23,7 @@ namespace ET var tempItem = (Item) v; if (tempItem.ConfigId == configId) { - tempItem.Amount+= amount; + tempItem.Amount += amount; return; } } @@ -39,20 +37,18 @@ namespace ET { item = self.AddChildWithId(id); } - + item.Amount = amount; item.ConfigId = configId; if (bUpdateTime) { item.CreateTime = TimeHelper.ServerUnix(); } - } else { for (int i = 0; i < amount; i++) { - Item item; if (id == 0) { @@ -62,6 +58,7 @@ namespace ET { item = self.AddChildWithId(id); } + item.Amount = 1; item.ConfigId = configId; if (bUpdateTime) @@ -69,9 +66,7 @@ namespace ET item.CreateTime = TimeHelper.ServerUnix(); } } - } - } public static long GetItemNum(this StoreComponent self, int configId) @@ -93,7 +88,7 @@ namespace ET long num = 0; foreach (var v in self.Children.Values) { - if (((Item)v).Config == config) + if (((Item) v).Config == config) { num++; } @@ -111,12 +106,13 @@ namespace ET { return false; } + var config = AllItemConfigCategory.Instance.Get(configId); if (config.SuperpositionMax > 1) { foreach (var v in self.Children.Values) { - var item = (Item)v; + var item = (Item) v; if (item.ConfigId == configId) { item.Amount -= amount; @@ -124,6 +120,7 @@ namespace ET { item.Dispose(); } + return true; } } @@ -133,7 +130,7 @@ namespace ET List removeList = new List(); foreach (var v in self.Children) { - var item = (Item)v.Value; + var item = (Item) v.Value; if (item.ConfigId == configId) { removeList.Add(item); @@ -147,13 +144,10 @@ namespace ET foreach (var v in removeList) { self.RemoveChildWithId(v.Id); - } - } return true; - } /// @@ -165,14 +159,14 @@ namespace ET /// public static List GetItemsWithType(this StoreComponent self, int mainType, int subType = -1) { - if (mainType == 0) return null; + if (mainType == 0) return null; var result = new List(); foreach (var v in self.Children.Values) { - var item = (Item)v; + var item = (Item) v; var config = AllItemConfigCategory.Instance.Get(item.ConfigId); - if(config.RelatedTable != mainType) continue; - if(subType == -1) + if (config.RelatedTable != mainType) continue; + if (subType == -1) { result.Add(item); } @@ -181,19 +175,20 @@ namespace ET switch (mainType) { case 1: + { + MaterialConfig materialConfig = MaterialConfigCategory.Instance.Get(config.RelatedId); + if (materialConfig == null) continue; + var types = materialConfig.Type.ToList(); + if (types.Contains(subType)) { - MaterialConfig materialConfig = MaterialConfigCategory.Instance.Get(config.RelatedId); - if (materialConfig == null) continue; - var types = materialConfig.Type.ToList(); - if (types.Contains(subType)) - { - result.Add(item); - } + result.Add(item); } + } break; } } } + return result; } @@ -209,6 +204,15 @@ namespace ET return true; } - + + public static bool IsEnoughItem(this StoreComponent self, int configId, int amount) + { + if (self.GetItemNum(configId) < amount) + { + return false; + } + + return true; + } } } \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs index f5aa5d3..73ef218 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs @@ -5,6 +5,7 @@ namespace ET { [FriendClass(typeof (Construct))] [FriendClass(typeof (Building))] + [FriendClass(typeof (Farmland))] public static class ConstructOperate { public static Construct CreateConstruct(Unit unit, int configId, float x, float y, long id = 0, long buildingId = 0) @@ -13,7 +14,7 @@ namespace ET // { // return null; // } - var construct = unit.GetOrAddComponent().CreateConstruct(configId, x, y, id, buildingId); + var construct = unit.GetOrAddComponent().CreateConstruct(unit,configId, x, y, id, buildingId); return construct; } @@ -150,17 +151,19 @@ namespace ET if (construct.IsUpgrade) { build = unit.GetOrAddComponent().GetChild(construct.BuildingId); - if (build == null) - { - Log.Error($"Can't find building:{construct.BuildingId} for construct:{construct.Id}"); - } + build.IsUpgrade = 0; } else { build = unit.GetOrAddComponent().AddChild(); build.Position.x = construct.X; build.Position.y = construct.Y; - build.State = (int) BuildingState.Built; + //如果是农场 + if (build.Config.Special == (int)StructureSpecialEnum.FARMLAND) + { + var farmland = build.AddChild(); + farmland.FarmlandState = FarmlandState.FARMLAND_STATE_FREE; + } } build.ConfigId = construct.Config.MixtureID; diff --git a/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs new file mode 100644 index 0000000..4726720 --- /dev/null +++ b/Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs @@ -0,0 +1,50 @@ +namespace ET +{ + [FriendClass(typeof(Unit))] + [FriendClass(typeof(Farmland))] + public static class FarmlandOperate + { + public static int Plant(Unit unit,long farmlandId, int cropId) + { + if (!unit.FarmlandDic.ContainsKey(farmlandId)) + { + return ErrorCode.ERR_FarmlandNotFound; + } + + var farmland = unit.FarmlandDic[farmlandId]; + if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_FREE) + { + return ErrorCode.ERR_FarmlandNotFree; + } + //检查种子数量 + var cropConfig = CropConfigCategory.Instance.Get(cropId); + if (cropConfig == null) + { + return ErrorCode.ERR_CropConfigNotFound; + } + + if (!unit.GetComponent().Remove(cropConfig.SeedNeed, cropConfig.SeedNum)) + { + return ErrorCode.ERR_SeedNotEnough; + } + + farmland.Plant(cropId,cropConfig.SeedNeed); + + return ErrorCode.ERR_Success; + } + + public static int Harvest(Unit unit, long farmlandId) + { + var farmland = unit.FarmlandDic[farmlandId]; + 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; + } + } +} \ 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 c88f5e4..cb7b5b6 100644 --- a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs @@ -21,6 +21,7 @@ namespace ET var now = TimeHelper.ServerNow(); var nowSec = now / 1000; var dt = now - self.UpdateTime; + //更新桃谷时间 var timeRate = WorldParametersConfigCategory.Instance.Get(WorldParam.TimeShift).Value[0]; if (dt > timeRate) { @@ -211,11 +212,29 @@ namespace ET return true; } - //每分钟的更新 + //耐久度的更新 public static void DurableReduce(this Unit self) { self.GetComponent()?.DurableReduce(); } + + public static void AddFarmland(this Unit self,Farmland farmland) + { + self.FarmlandDic[farmland.Id] = farmland; + } + + public static void RemoveFarmland(this Unit self, Farmland farmland) + { + self.FarmlandDic.Remove(farmland.Id); + } + + public static void UpdateGameTime(this Unit self) + { + foreach (var v in self.FarmlandDic.Values) + { + ((Farmland)v).Update(); + } + } } } \ No newline at end of file diff --git a/Unity/Codes/Model/Demo/Building/Building.cs b/Unity/Codes/Model/Demo/Building/Building.cs index 2278007..7ff618f 100644 --- a/Unity/Codes/Model/Demo/Building/Building.cs +++ b/Unity/Codes/Model/Demo/Building/Building.cs @@ -11,12 +11,13 @@ namespace ET Upgrade = 3, } + [ChildType(typeof(Farmland))] public class Building: Entity, IAwake, ISerializeToEntity { public int ConfigId; public Vector2 Position; public int Durable; - public int State; //1.正在建造,2.建造完成,3.维修 + public int IsUpgrade; [BsonIgnore] public StructureConfig Config => StructureConfigCategory.Instance.Get(this.ConfigId); diff --git a/Unity/Codes/Model/Demo/ConstValue.cs b/Unity/Codes/Model/Demo/ConstValue.cs index d405235..49e7f03 100644 --- a/Unity/Codes/Model/Demo/ConstValue.cs +++ b/Unity/Codes/Model/Demo/ConstValue.cs @@ -1,3 +1,5 @@ +using System; + namespace ET { public static class ConstValue @@ -116,4 +118,13 @@ namespace ET public const int CONSTRUCT_TYPE_NEW = 1; //创建新的建筑 public const int CONSTRUCT_TYPE_UPGRADE = 2; //升级建筑 } + + 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;//收割 + } } \ No newline at end of file diff --git a/Unity/Codes/Model/Demo/Farmland/Farmland.cs b/Unity/Codes/Model/Demo/Farmland/Farmland.cs new file mode 100644 index 0000000..5266eb5 --- /dev/null +++ b/Unity/Codes/Model/Demo/Farmland/Farmland.cs @@ -0,0 +1,20 @@ +using System; +using MongoDB.Bson.Serialization.Attributes; + +namespace ET +{ + public class Farmland: Entity, IAwake,IUpdate, IDestroy,ISerializeToEntity + { + public int SeedCfgId; //农作物configid + public int Duration; //种植时间 + public int ExProduct; //额外产量 + public int FarmlandState; //农田状态 + public int PlanSeedCfgId; //计划种植的东西 + public int ConfigId; + + [BsonIgnore] + public CropConfig Config =>CropConfigCategory.Instance.Get(this.ConfigId); + + + } +} \ No newline at end of file diff --git a/Unity/Codes/Model/Demo/Unit/Unit.cs b/Unity/Codes/Model/Demo/Unit/Unit.cs index 3c55ab5..8adf0e4 100644 --- a/Unity/Codes/Model/Demo/Unit/Unit.cs +++ b/Unity/Codes/Model/Demo/Unit/Unit.cs @@ -67,5 +67,10 @@ namespace ET [BsonIgnore] public long BattleId; + [BsonIgnore] + public Dictionary FarmlandDic = new Dictionary(); + + + } } \ No newline at end of file diff --git a/Unity/Codes/Model/Generate/Message/OuterMessage.cs b/Unity/Codes/Model/Generate/Message/OuterMessage.cs index ec6e88e..4d918db 100644 --- a/Unity/Codes/Model/Generate/Message/OuterMessage.cs +++ b/Unity/Codes/Model/Generate/Message/OuterMessage.cs @@ -141,7 +141,7 @@ namespace ET public int Durable { get; set; } [ProtoMember(6)] - public int State { get; set; } + public FarmlandProto Farmland { get; set; } } @@ -2490,4 +2490,87 @@ namespace ET } + [Message(OuterOpcode.FarmlandProto)] + [ProtoContract] + public partial class FarmlandProto: Object + { + [ProtoMember(1)] + public long id { get; set; } + + [ProtoMember(2)] + public int SeedCfgId { get; set; } + + [ProtoMember(3)] + public int plantCfgId { get; set; } + + [ProtoMember(4)] + public int duration { get; set; } + + [ProtoMember(5)] + public int exProduct { get; set; } + + [ProtoMember(6)] + public int farmlandState { get; set; } + + } + + [ResponseType(nameof(M2C_FarmlandPlant))] + [Message(OuterOpcode.C2M_FarmlandPlant)] + [ProtoContract] + public partial class C2M_FarmlandPlant: Object, IActorLocationRequest + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(1)] + public long FarmlandId { get; set; } + + [ProtoMember(2)] + public int CropCfgId { get; set; } + + } + + [Message(OuterOpcode.M2C_FarmlandPlant)] + [ProtoContract] + public partial class M2C_FarmlandPlant: Object, IActorLocationResponse + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(91)] + public int Error { get; set; } + + [ProtoMember(92)] + public string Message { get; set; } + + } + + [ResponseType(nameof(M2C_FarmlandHarvest))] + [Message(OuterOpcode.C2M_FarmlandHarvest)] + [ProtoContract] + public partial class C2M_FarmlandHarvest: Object, IActorLocationRequest + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(1)] + public long FarmlandId { get; set; } + + } + + [Message(OuterOpcode.M2C_FarmlandHarvest)] + [ProtoContract] + public partial class M2C_FarmlandHarvest: Object, IActorLocationResponse + { + [ProtoMember(90)] + public int RpcId { get; set; } + + [ProtoMember(91)] + public int Error { get; set; } + + [ProtoMember(92)] + public string Message { get; set; } + + } + } diff --git a/Unity/Codes/Model/Generate/Message/OuterOpcode.cs b/Unity/Codes/Model/Generate/Message/OuterOpcode.cs index acd513c..2639765 100644 --- a/Unity/Codes/Model/Generate/Message/OuterOpcode.cs +++ b/Unity/Codes/Model/Generate/Message/OuterOpcode.cs @@ -147,5 +147,10 @@ namespace ET public const ushort M2C_BuildingDurable = 10144; public const ushort C2M_GMAddItem = 10145; public const ushort M2C_GMAddItem = 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; } } diff --git a/Unity/Codes/Model/Module/Message/ErrorCode.cs b/Unity/Codes/Model/Module/Message/ErrorCode.cs index afe5c0d..58866e1 100644 --- a/Unity/Codes/Model/Module/Message/ErrorCode.cs +++ b/Unity/Codes/Model/Module/Message/ErrorCode.cs @@ -88,5 +88,11 @@ namespace ET public const int ERR_FighterSilence = 210205;//玩家被沉默了 public const int ERR_FighterConstraint = 210206; //玩家被禁锢了 public const int ERR_SkillNotFound = 210207; //没有该技能 + //210201-210322 种植相关 + public const int ERR_FarmlandNotFree = 210201; //农场不是空闲 + public const int ERR_PlantNotRipe = 210202; //农作物没有成熟 + public const int ERR_FarmlandNotFound = 210203;// 农场没有找到 + public const int ERR_CropConfigNotFound = 210204;// 农场没有找到 + public const int ERR_SeedNotEnough = 210205;// 农场没有找到 } } \ No newline at end of file