Browse Source

调整种植接口

master
wserver/wangdisen 3 years ago
parent
commit
efeb40abc2
  1. 10
      Proto/OuterMessage.proto
  2. 21
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs
  3. 24
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs
  4. 14
      Server/Model/Generate/Message/OuterMessage.cs
  5. 16
      Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs
  6. 21
      Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs
  7. 6
      Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs
  8. 21
      Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs
  9. 8
      Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs
  10. 14
      Unity/Codes/Model/Generate/Message/OuterMessage.cs

10
Proto/OuterMessage.proto

@ -1201,10 +1201,10 @@ message FarmlandProto
{
int64 id = 1;
int32 SeedCfgId = 2;
int32 plantCfgId = 3;
int32 duration = 4;
int32 exProduct = 5;
int32 farmlandState = 6;
int32 PlantCfgId = 3;
int32 Duration = 4;
int32 ExProduct = 5;
int32 FarmlandState = 6;
}
//ResponseType M2C_FarmlandPlant
@ -1212,6 +1212,7 @@ message C2M_FarmlandPlant // IActorLocationRequest
{
int32 RpcId = 90;
int64 FarmlandId = 1;
int64 PeopleId = 2;
}
message M2C_FarmlandPlant // IActorLocationResponse
@ -1226,6 +1227,7 @@ message C2M_FarmlandHarvest // IActorLocationRequest
{
int32 RpcId = 90;
int64 FarmlandId = 1;
int64 PeopleId = 2;
}
message M2C_FarmlandHarvest // IActorLocationResponse

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

@ -3,14 +3,31 @@
namespace ET
{
[FriendClass(typeof (Unit))]
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();
People people;
Farmland farmland;
if (unit.FarmlandDic.TryGetValue(request.FarmlandId, out farmland))
{
people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId);
if (people != null)
{
response.Error = FarmlandOperate.Harvest(unit, farmland, people);
}
else
{
response.Error = ErrorCode.ERR_PeopleNotFound;
}
}
else
{
response.Error = ErrorCode.ERR_FarmlandNotFound;
}
}
catch (Exception e)
{

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

@ -2,14 +2,32 @@
namespace ET
{
[FriendClass(typeof (Unit))]
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);
People people;
Farmland farmland;
if (unit.FarmlandDic.TryGetValue(request.FarmlandId, out farmland))
{
people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId);
if (people != null)
{
response.Error = FarmlandOperate.Plant(unit, farmland, people);
}
else
{
response.Error = ErrorCode.ERR_PeopleNotFound;
}
}
else
{
response.Error = ErrorCode.ERR_FarmlandNotFound;
}
reply();
}
catch (Exception e)
@ -22,6 +40,4 @@ namespace ET
await ETTask.CompletedTask;
}
}
}

14
Server/Model/Generate/Message/OuterMessage.cs

@ -2504,16 +2504,16 @@ namespace ET
public int SeedCfgId { get; set; }
[ProtoMember(3)]
public int plantCfgId { get; set; }
public int PlantCfgId { get; set; }
[ProtoMember(4)]
public int duration { get; set; }
public int Duration { get; set; }
[ProtoMember(5)]
public int exProduct { get; set; }
public int ExProduct { get; set; }
[ProtoMember(6)]
public int farmlandState { get; set; }
public int FarmlandState { get; set; }
}
@ -2528,6 +2528,9 @@ namespace ET
[ProtoMember(1)]
public long FarmlandId { get; set; }
[ProtoMember(2)]
public long PeopleId { get; set; }
}
[Message(OuterOpcode.M2C_FarmlandPlant)]
@ -2556,6 +2559,9 @@ namespace ET
[ProtoMember(1)]
public long FarmlandId { get; set; }
[ProtoMember(2)]
public long PeopleId { get; set; }
}
[Message(OuterOpcode.M2C_FarmlandHarvest)]

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

@ -30,10 +30,10 @@
{
self.Id = farmlandProto.id;
self.CropCfgId = farmlandProto.SeedCfgId;
self.Duration = farmlandProto.duration;
self.ExProduct = farmlandProto.exProduct;
self.PlanCropCfgId = farmlandProto.plantCfgId;
self.FarmlandState = farmlandProto.farmlandState;
self.Duration = farmlandProto.Duration;
self.ExProduct = farmlandProto.ExProduct;
self.PlanCropCfgId = farmlandProto.PlantCfgId;
self.FarmlandState = farmlandProto.FarmlandState;
}
public static FarmlandProto ToMessage(this Farmland self)
@ -41,10 +41,10 @@
FarmlandProto proto = new FarmlandProto();
proto.id = self.Id;
proto.SeedCfgId = self.CropCfgId;
proto.duration = self.Duration;
proto.exProduct = self.ExProduct;
proto.plantCfgId = self.PlanCropCfgId;
proto.farmlandState = self.FarmlandState;
proto.Duration = self.Duration;
proto.ExProduct = self.ExProduct;
proto.PlantCfgId = self.PlanCropCfgId;
proto.FarmlandState = self.FarmlandState;
return proto;
}

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

@ -28,15 +28,16 @@ namespace ET
throw;
}
}
public static async ETTask<int> FarmlandPlant(Unit unit, long farmlandId)
public static async ETTask<int> FarmlandPlant(Unit unit, Farmland farmland,People people)
{
try
{
C2M_FarmlandPlant msg = new C2M_FarmlandPlant() { FarmlandId = farmlandId};
C2M_FarmlandPlant msg = new C2M_FarmlandPlant() { FarmlandId = farmland.Id,PeopleId = people.Id};
M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_FarmlandPlant;
if (resp.Error == ErrorCode.ERR_Success)
{
FarmlandOperate.Plant(unit, farmlandId);
FarmlandOperate.Plant(unit, farmland,people);
}
else
{
@ -52,15 +53,15 @@ namespace ET
}
}
public static async ETTask<int> FarmlandHarvest(Unit unit, long farmlandId)
public static async ETTask<int> FarmlandHarvest(Unit unit, Farmland farmland,People people)
{
try
{
C2M_FarmlandHarvest msg = new C2M_FarmlandHarvest() { FarmlandId = farmlandId };
C2M_FarmlandHarvest msg = new C2M_FarmlandHarvest() { FarmlandId = farmland.Id };
M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_FarmlandPlant;
if (resp.Error == ErrorCode.ERR_Success)
{
FarmlandOperate.Harvest(unit, farmlandId);
FarmlandOperate.Harvest(unit, farmland,people);
}
else
{
@ -76,14 +77,14 @@ namespace ET
}
}
public static async ETTask<int> FarmlandPlantFinish(Unit unit,long peopleId)
public static async ETTask<int> FarmlandPlantFinish(Unit unit,People people)
{
return await PeopleHelper.ChangeBehave(unit, peopleId, 0, ConstBehaveType.BEHAVE_IDLE);
return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE);
}
public static async ETTask<int> FarmlandHarvestFinish(Unit unit,long peopleId)
public static async ETTask<int> FarmlandHarvestFinish(Unit unit,People people)
{
return await PeopleHelper.ChangeBehave(unit, peopleId, 0, ConstBehaveType.BEHAVE_IDLE);
return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE);
}

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

@ -28,11 +28,11 @@ namespace ET
return ErrorCode.ERR_Success;
}
public static async ETTask<int> ChangeBehave(Unit unit, long peopleId,long targetId, int behaveType)
public static async ETTask<int> ChangeBehave(Unit unit, People people,long targetId, int behaveType)
{
try
{
C2M_ChangeBehave msg = new C2M_ChangeBehave(){PeopleId = peopleId,TargetId = targetId,BehaveType = behaveType};
C2M_ChangeBehave msg = new C2M_ChangeBehave(){PeopleId = people.Id,TargetId = targetId,BehaveType = behaveType};
M2C_ChangeBehave resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_ChangeBehave;
if (resp.Error != ErrorCode.ERR_Success)
{
@ -40,7 +40,7 @@ namespace ET
return resp.Error;
}
PeopleOperate.ChangeBehave(unit, peopleId, targetId, behaveType);
PeopleOperate.ChangeBehave(unit, people, targetId, behaveType);
}
catch (Exception e)
{

21
Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs

@ -6,28 +6,22 @@ namespace ET
[FriendClass(typeof (Farmland))]
public static class FarmlandOperate
{
public static int Plant(Unit unit, long farmlandId)
public static int Plant(Unit unit, Farmland farmland,People people)
{
if (!unit.FarmlandDic.ContainsKey(farmlandId))
{
return ErrorCode.ERR_FarmlandNotFound;
}
var farmland = unit.FarmlandDic[farmlandId];
if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED)
{
return ErrorCode.ERR_FarmlandNotFree;
}
farmland.Plant();
PeopleOperate.ChangeBehave(unit,people, farmland.Id, ConstBehaveType.BEHAVE_PLANT);
return ErrorCode.ERR_Success;
}
public static int Harvest(Unit unit, long farmlandId)
public static int Harvest(Unit unit, Farmland farmland,People people)
{
Farmland farmland;
if (unit.FarmlandDic.TryGetValue(farmlandId, out farmland))
{
if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE)
{
var storeNc = unit.GetComponent<StoreComponent>();
@ -41,11 +35,10 @@ namespace ET
farmland.Harvest();
return ErrorCode.ERR_Success;
}
PeopleOperate.ChangeBehave(unit,people, farmland.Id, ConstBehaveType.BEHAVE_HARVEST);
return ErrorCode.ERR_FarmlandNotRipe;
}
return ErrorCode.ERR_FarmlandNotFound;
}
public static (List<long>, List<int>) FarmlandSeed(Unit unit, List<long> farmlandIds, List<int> CropCfgIds)

8
Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs

@ -31,13 +31,9 @@ namespace ET
return ErrorCode.ERR_Success;
}
public static int ChangeBehave(Unit unit, long peopleId,long targetId, int behaveType)
public static int ChangeBehave(Unit unit, People people,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)

14
Unity/Codes/Model/Generate/Message/OuterMessage.cs

@ -2504,16 +2504,16 @@ namespace ET
public int SeedCfgId { get; set; }
[ProtoMember(3)]
public int plantCfgId { get; set; }
public int PlantCfgId { get; set; }
[ProtoMember(4)]
public int duration { get; set; }
public int Duration { get; set; }
[ProtoMember(5)]
public int exProduct { get; set; }
public int ExProduct { get; set; }
[ProtoMember(6)]
public int farmlandState { get; set; }
public int FarmlandState { get; set; }
}
@ -2528,6 +2528,9 @@ namespace ET
[ProtoMember(1)]
public long FarmlandId { get; set; }
[ProtoMember(2)]
public long PeopleId { get; set; }
}
[Message(OuterOpcode.M2C_FarmlandPlant)]
@ -2556,6 +2559,9 @@ namespace ET
[ProtoMember(1)]
public long FarmlandId { get; set; }
[ProtoMember(2)]
public long PeopleId { get; set; }
}
[Message(OuterOpcode.M2C_FarmlandHarvest)]

Loading…
Cancel
Save