Browse Source

种植功能

master
star\zhenghan 3 years ago
parent
commit
1d560b8bad
  1. 4
      Excel/Json/s/StartSceneConfig.txt
  2. BIN
      Excel/StartSceneConfig@s.xlsx
  3. 39
      Proto/OuterMessage.proto
  4. 1
      Server/Hotfix/Demo/C2G_EnterMapHandler.cs
  5. 3
      Server/Hotfix/Server.Hotfix.csproj
  6. 85
      Server/Model/Generate/Message/OuterMessage.cs
  7. 5
      Server/Model/Generate/Message/OuterOpcode.cs
  8. 4
      Server/Model/Server.Model.csproj
  9. 9
      Unity/Animancer.FSM.csproj
  10. 9
      Unity/Animancer.csproj
  11. 5
      Unity/Codes/Hotfix/Demo/Building/BuildingComponentSystem.cs
  12. 25
      Unity/Codes/Hotfix/Demo/Building/BuildingSystem.cs
  13. 12
      Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs
  14. 99
      Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs
  15. 2
      Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs
  16. 55
      Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs
  17. 66
      Unity/Codes/Hotfix/Demo/Item/StoreComponentSystem.cs
  18. 15
      Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs
  19. 50
      Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs
  20. 21
      Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs
  21. 3
      Unity/Codes/Model/Demo/Building/Building.cs
  22. 11
      Unity/Codes/Model/Demo/ConstValue.cs
  23. 20
      Unity/Codes/Model/Demo/Farmland/Farmland.cs
  24. 5
      Unity/Codes/Model/Demo/Unit/Unit.cs
  25. 85
      Unity/Codes/Model/Generate/Message/OuterMessage.cs
  26. 5
      Unity/Codes/Model/Generate/Message/OuterOpcode.cs
  27. 6
      Unity/Codes/Model/Module/Message/ErrorCode.cs

4
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},

BIN
Excel/StartSceneConfig@s.xlsx

Binary file not shown.

39
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;
}

1
Server/Hotfix/Demo/C2G_EnterMapHandler.cs

@ -5,6 +5,7 @@ namespace ET
{
[FriendClass(typeof(GateMapComponent))]
[MessageHandler]
//此函数已经放弃了
public class C2G_EnterMapHandler : AMRpcHandler<C2G_EnterMap, G2C_EnterMap>
{
protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response, Action reply)

3
Server/Hotfix/Server.Hotfix.csproj

@ -40,6 +40,9 @@
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Construct\ConstructSystem.cs">
<Link>Demo\Construct\ConstructSystem.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Farmland\FarmlandSystem.cs">
<Link>Demo\Farmland\FarmlandSystem.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Fighter\FighterComponentSystem.cs">
<Link>Demo\Fighter\FighterComponentSystem.cs</Link>
</Compile>

85
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; }
}
}

5
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;
}
}

4
Server/Model/Server.Model.csproj

@ -70,6 +70,10 @@
<Link>Demo\ConstValue.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Model\Demo\Farmland\Farmland.cs">
<Link>Demo\Farmland\Farmland.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Model\Demo\Fighter\Fighter.cs">
<Link>Demo\Fighter\Fighter.cs</Link>
</Compile>

9
Unity/Animancer.FSM.csproj

@ -310,6 +310,9 @@
<Reference Include="UnityEditor.Graphs">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\Managed\UnityEditor.Graphs.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Android.Extensions">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\UnityEditor.Android.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.WindowsStandalone.Extensions">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\WindowsStandaloneSupport\UnityEditor.WindowsStandalone.Extensions.dll</HintPath>
</Reference>
@ -346,6 +349,12 @@
<Reference Include="NCalc">
<HintPath>Assets\ThirdParty\NCalc\NCalc.dll</HintPath>
</Reference>
<Reference Include="Unity.Android.Types">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Unity.Android.Types.dll</HintPath>
</Reference>
<Reference Include="Unity.Android.Gradle">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Unity.Android.Gradle.dll</HintPath>
</Reference>
<Reference Include="mscorlib">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\UnityReferenceAssemblies\unity-4.8-api\mscorlib.dll</HintPath>
</Reference>

9
Unity/Animancer.csproj

@ -447,6 +447,9 @@
<Reference Include="UnityEditor.Graphs">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\Managed\UnityEditor.Graphs.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Android.Extensions">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\UnityEditor.Android.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.WindowsStandalone.Extensions">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\WindowsStandaloneSupport\UnityEditor.WindowsStandalone.Extensions.dll</HintPath>
</Reference>
@ -483,6 +486,12 @@
<Reference Include="NCalc">
<HintPath>Assets\ThirdParty\NCalc\NCalc.dll</HintPath>
</Reference>
<Reference Include="Unity.Android.Types">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Unity.Android.Types.dll</HintPath>
</Reference>
<Reference Include="Unity.Android.Gradle">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\PlaybackEngines\AndroidPlayer\Unity.Android.Gradle.dll</HintPath>
</Reference>
<Reference Include="mscorlib">
<HintPath>C:\Program Files\Unity\Hub\Editor\2021.3.7f1c1\Editor\Data\UnityReferenceAssemblies\unity-4.8-api\mscorlib.dll</HintPath>
</Reference>

5
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;

25
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<Farmland>(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)

12
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<BuildingComponent>().GetChild<Building>(buildingId);
if (building != null)
{
building.IsUpgrade = 1;
}
}
return construct;
}

99
Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs

@ -0,0 +1,99 @@
namespace ET
{
public class FarmlandDestroySystem : DestroySystem<Farmland>
{
public override void Destroy(Farmland self)
{
self.Parent.Parent.GetParent<Unit>().RemoveFarmland(self);
}
}
public class FarmlandAwakeSystem : AwakeSystem<Farmland>
{
public override void Awake(Farmland self)
{
self.Parent.Parent.GetParent<Unit>().AddFarmland(self);
}
}
public class FarmlandUpdateSystem: UpdateSystem<Farmland>
{
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;
}
}
}

2
Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs

@ -13,7 +13,7 @@ namespace ET
M2C_CreateConstruct resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CreateConstruct;
if (resp.Error == ErrorCode.ERR_Success)
{
var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(configId, x, y, resp.Id);
var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit,configId, x, y, resp.Id);
Game.EventSystem.Publish(new EventType.AfterCreateConstruct(){Unit = unit, Construct = construct, IsNew = true});
}
else

55
Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs

@ -0,0 +1,55 @@
using System;
namespace ET
{
public static class PlantHelper
{
public static async ETTask<int> 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<SessionComponent>().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<int> FarmlandHarvest(Unit unit, long farmlandId)
{
try
{
C2M_FarmlandHarvest msg = new C2M_FarmlandHarvest() { FarmlandId = farmlandId };
M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent<SessionComponent>().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;
}
}
}
}

66
Unity/Codes/Hotfix/Demo/Item/StoreComponentSystem.cs

@ -3,19 +3,17 @@ using System.Linq;
namespace ET
{
public class StoreComponentSystemDestroySystem : DestroySystem<StoreComponent>
public class StoreComponentSystemDestroySystem: DestroySystem<StoreComponent>
{
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<Item>(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<Item>(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<Item> removeList = new List<Item>();
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;
}
/// <summary>
@ -165,14 +159,14 @@ namespace ET
/// <returns></returns>
public static List<Item> GetItemsWithType(this StoreComponent self, int mainType, int subType = -1)
{
if (mainType == 0) return null;
if (mainType == 0) return null;
var result = new List<Item>();
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;
}
}
}

15
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<ConstructComponent>().CreateConstruct(configId, x, y, id, buildingId);
var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit,configId, x, y, id, buildingId);
return construct;
}
@ -150,17 +151,19 @@ namespace ET
if (construct.IsUpgrade)
{
build = unit.GetOrAddComponent<BuildingComponent>().GetChild<Building>(construct.BuildingId);
if (build == null)
{
Log.Error($"Can't find building:{construct.BuildingId} for construct:{construct.Id}");
}
build.IsUpgrade = 0;
}
else
{
build = unit.GetOrAddComponent<BuildingComponent>().AddChild<Building>();
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>();
farmland.FarmlandState = FarmlandState.FARMLAND_STATE_FREE;
}
}
build.ConfigId = construct.Config.MixtureID;

50
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<StoreComponent>().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<StoreComponent>();
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;
}
}
}

21
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<BuildingComponent>()?.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();
}
}
}
}

3
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);

11
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;//收割
}
}

20
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);
}
}

5
Unity/Codes/Model/Demo/Unit/Unit.cs

@ -67,5 +67,10 @@ namespace ET
[BsonIgnore]
public long BattleId;
[BsonIgnore]
public Dictionary<long, Farmland> FarmlandDic = new Dictionary<long, Farmland>();
}
}

85
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; }
}
}

5
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;
}
}

6
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;// 农场没有找到
}
}
Loading…
Cancel
Save