Browse Source

完善种植相关功能

master
wserver/wangdisen 3 years ago
parent
commit
fa79f84c38
  1. 44
      Proto/OuterMessage.proto
  2. 25
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs
  3. 27
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs
  4. 25
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandSeedHandler.cs
  5. 28
      Server/Hotfix/Demo/Gm/Handler/M2C_GMAddItemHandler.cs
  6. 4
      Server/Hotfix/Server.Hotfix.csproj
  7. 76
      Server/Model/Generate/Message/OuterMessage.cs
  8. 10
      Server/Model/Generate/Message/OuterOpcode.cs
  9. 9
      Unity/Animancer.FSM.csproj
  10. 9
      Unity/Animancer.csproj
  11. 26
      Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs
  12. 32
      Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs
  13. 38
      Unity/Codes/Hotfix/Demo/Helper/GmHelper.cs
  14. 24
      Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs
  15. 77
      Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs
  16. 20
      Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs
  17. 8
      Unity/Codes/Hotfix/Demo/People/PeopleSystem.cs
  18. 8
      Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs
  19. 11
      Unity/Codes/Model/Demo/ConstValue.cs
  20. 2
      Unity/Codes/Model/Demo/People/People.cs
  21. 76
      Unity/Codes/Model/Generate/Message/OuterMessage.cs
  22. 10
      Unity/Codes/Model/Generate/Message/OuterOpcode.cs
  23. 2
      Unity/Codes/Model/Module/Message/ErrorCode.cs

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

25
Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs

@ -0,0 +1,25 @@
using System;
namespace ET
{
public class C2M_FarmlandHarvestHandler: AMActorLocationRpcHandler<Unit, C2M_FarmlandHarvest, M2C_FarmlandHarvest>
{
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;
}
}
}

27
Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs

@ -0,0 +1,27 @@
using System;
namespace ET
{
public class C2M_FarmlandPlantHandler: AMActorLocationRpcHandler<Unit, C2M_FarmlandPlant, M2C_FarmlandPlant>
{
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;
}
}
}

25
Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandSeedHandler.cs

@ -0,0 +1,25 @@
using System;
namespace ET
{
public class C2M_FarmlandSeedHandler: AMActorLocationRpcHandler<Unit, C2M_FarmlandSeed, M2C_FarmlandSeed>
{
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;
}
}
}

28
Server/Hotfix/Demo/Gm/Handler/M2C_GMAddItemHandler.cs

@ -1,28 +0,0 @@
using System;
namespace ET.Gm.Handler
{
public class M2C_GMAddItemHandler:AMActorLocationRpcHandler<Unit, C2M_GMAddItem, M2C_GMAddItem>
{
protected override async ETTask Run(Unit unit, C2M_GMAddItem request, M2C_GMAddItem response, Action reply)
{
try
{
var storeNc = unit.GetComponent<StoreComponent>();
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;
}
}
}

4
Server/Hotfix/Server.Hotfix.csproj

@ -94,6 +94,10 @@
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Operate\DropOperate.cs">
<Link>Demo\Operate\DropOperate.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Operate\FarmlandOperate.cs">
<Link>Demo\Operate\FarmlandOperate.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Operate\GatherOperate.cs">
<Link>Demo\Operate\GatherOperate.cs</Link>
</Compile>

76
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<int> Ks = new List<int>();
[ProtoMember(3)]
public List<int> Vs = new List<int>();
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<long> FarmlandIds = new List<long>();
[ProtoMember(2)]
public List<int> CropCfgIds = new List<int>();
}
[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<long> FarmlandIds = new List<long>();
[ProtoMember(2)]
public List<int> CropCfgIds = new List<int>();
}
[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; }

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

9
Unity/Animancer.FSM.csproj

@ -310,9 +310,6 @@
<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>
@ -349,12 +346,6 @@
<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,9 +447,6 @@
<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>
@ -486,12 +483,6 @@
<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>

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

32
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<int> FarmlandSeed(Unit unit, List<long> farmlandIds, List<int> cropCfgIds)
{
try
{
C2M_FarmlandSeed msg = new C2M_FarmlandSeed() { FarmlandIds = farmlandIds, CropCfgIds = cropCfgIds };
M2C_FarmlandSeed resp = await unit.ZoneScene().GetComponent<SessionComponent>().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<int> 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<SessionComponent>().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<int> FarmlandHarvest(Unit unit, long farmlandId)
{
try
@ -51,5 +75,7 @@ namespace ET
throw;
}
}
}
}

38
Unity/Codes/Hotfix/Demo/Helper/GmHelper.cs

@ -1,38 +0,0 @@
using System;
using System.Collections.Generic;
namespace ET
{
public static class GmHelper
{
public static async ETTask<int> AddItem(Unit unit, List<int> Ks, List<int> Vs)
{
try
{
M2C_GMAddItem resp =
await unit.ZoneScene().GetComponent<SessionComponent>().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<StoreComponent>();
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;
}
}
}

24
Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs

@ -27,5 +27,29 @@ namespace ET
return ErrorCode.ERR_Success;
}
public static async ETTask<int> 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<SessionComponent>().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;
}
}
}

77
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<StoreComponent>().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<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;
}
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<long>, List<int>) FarmlandSeed(Unit unit, List<long> farmlandIds, List<int> CropCfgIds)
{
var farmland = unit.FarmlandDic[farmlandId];
var storeNc = unit.GetComponent<StoreComponent>();
storeNc.Add(farmland.Config.ProductID, farmland.Config.BasicProduction);
if (farmland.Config.ByProduct > 0)
List<long> sucFarmlandList = new List<long>();
List<int> sucCropList = new List<int>();
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<StoreComponent>();
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);
}
}
}

20
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<PeopleComponent>().GetChild<People>(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;
}
}
}

8
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
}

8
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<PeopleComponent>().Children.Values)
{
((People) v).GrowUp();
}
}
}
}

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

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

76
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<int> Ks = new List<int>();
[ProtoMember(3)]
public List<int> Vs = new List<int>();
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<long> FarmlandIds = new List<long>();
[ProtoMember(2)]
public List<int> CropCfgIds = new List<int>();
}
[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<long> FarmlandIds = new List<long>();
[ProtoMember(2)]
public List<int> CropCfgIds = new List<int>();
}
[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; }

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

2
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;//没有播种
}
}
Loading…
Cancel
Save