Browse Source

加正在种植,正在收割两个状态

master
wserver/wangdisen 3 years ago
parent
commit
e2e0343279
  1. 2
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandHarvestHandler.cs
  2. 6
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs
  3. 63
      Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs
  4. 4
      Unity/Codes/Hotfix/Demo/Helper/PeopleHelper.cs
  5. 19
      Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs
  6. 2
      Unity/Codes/Hotfix/Demo/Operate/PeopleOperate.cs
  7. 4
      Unity/Codes/Model/Demo/ConstValue.cs

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

@ -17,7 +17,7 @@ namespace ET
people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId); people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId);
if (people != null) if (people != null)
{ {
response.Error = FarmlandOperate.Harvest(unit, farmland, people); response.Error = FarmlandOperate.FinishHarvest(unit, farmland, people);
} }
else else
{ {

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

@ -9,14 +9,14 @@ namespace ET
{ {
try try
{ {
People people;
Farmland farmland = unit.GetGrandChild<Farmland>(request.FarmlandId); Farmland farmland = unit.GetGrandChild<Farmland>(request.FarmlandId);
if (farmland!=null) if (farmland!=null)
{ {
people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId); People people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId);
if (people != null) if (people != null)
{ {
response.Error = FarmlandOperate.Plant(unit, farmland, people); response.Error = FarmlandOperate.FinishPlant(unit, farmland, people);
} }
else else
{ {

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

@ -29,12 +29,36 @@ namespace ET
} }
} }
public static async ETTask<int> GoFarmlandPlant(Unit unit,People people,long farmlandId) public static async ETTask<int> GoFarmlandPlant(Unit unit,People people,Farmland farmland)
{ {
return await PeopleHelper.ChangeBehave(unit, people, farmlandId, ConstBehaveType.BEHAVE_PREPARE_PLANT); try
{
C2M_GoFarmlandPlant msg = new C2M_GoFarmlandPlant() { PeopleId = people.Id,FarmlandId = farmland.Id};
M2C_GoFarmlandPlant resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_GoFarmlandPlant;
if (resp.Error == ErrorCode.ERR_Success)
{
FarmlandOperate.GoPlant(unit, farmland,people);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> StartFarmlandPlant(Unit unit, People people, Farmland farmland)
{
return await PeopleHelper.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PLANT,farmland.Id);
} }
public static async ETTask<int> StartFarmlandPlant(Unit unit, Farmland farmland,People people) public static async ETTask<int> FinishFarmlandPlant(Unit unit, Farmland farmland,People people)
{ {
try try
{ {
@ -42,7 +66,7 @@ namespace ET
M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_FarmlandPlant; M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_FarmlandPlant;
if (resp.Error == ErrorCode.ERR_Success) if (resp.Error == ErrorCode.ERR_Success)
{ {
FarmlandOperate.Plant(unit, farmland,people); FarmlandOperate.FinishPlant(unit, farmland,people);
} }
else else
{ {
@ -57,14 +81,35 @@ namespace ET
throw; throw;
} }
} }
public static async ETTask<int> FinishFarmlandPlant(Unit unit,People people)
public static async ETTask<int> GoFarmlandHarvest(Unit unit,People people,Farmland farmland)
{ {
return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE); try
{
C2M_GoFarmlandHarvest msg = new C2M_GoFarmlandHarvest() { PeopleId = people.Id,FarmlandId = farmland.Id};
M2C_GoFarmlandHarvest resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_GoFarmlandHarvest;
if (resp.Error == ErrorCode.ERR_Success)
{
FarmlandOperate.GoHarvest(unit, farmland,people);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
} }
public static async ETTask<int> GoFarmlandHarvest(Unit unit,People people) public static async ETTask<int> StartFarmlandHarvest(Unit unit, People people, Farmland farmland)
{ {
return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_PREPARE_HARVEST); return await PeopleHelper.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PREPARE_HARVEST,farmland.Id);
} }
public static async ETTask<int> FarmlandHarvest(Unit unit, Farmland farmland,People people) public static async ETTask<int> FarmlandHarvest(Unit unit, Farmland farmland,People people)
{ {
@ -74,7 +119,7 @@ namespace ET
M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_FarmlandPlant; M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_FarmlandPlant;
if (resp.Error == ErrorCode.ERR_Success) if (resp.Error == ErrorCode.ERR_Success)
{ {
FarmlandOperate.Harvest(unit, farmland,people); FarmlandOperate.FinishHarvest(unit, farmland,people);
} }
else else
{ {

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

@ -28,7 +28,7 @@ namespace ET
return ErrorCode.ERR_Success; return ErrorCode.ERR_Success;
} }
public static async ETTask<int> ChangeBehave(Unit unit, People people,long targetId, int behaveType) public static async ETTask<int> ChangeBehave(Unit unit, People people,int behaveType,long targetId )
{ {
try try
{ {
@ -40,7 +40,7 @@ namespace ET
return resp.Error; return resp.Error;
} }
PeopleOperate.ChangeBehave(unit, people, targetId, behaveType); PeopleOperate.ChangeBehave(unit, people, behaveType,targetId);
} }
catch (Exception e) catch (Exception e)
{ {

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

@ -12,15 +12,13 @@ namespace ET
{ {
return ErrorCode.ERR_FarmlandNotSeed; return ErrorCode.ERR_FarmlandNotSeed;
} }
PeopleOperate.StopBehave(unit, people); PeopleOperate.ChangeBehave(unit,people, ConstBehaveType.BEHAVE_PREPARE_PLANT, farmland.Id);
people.SetBehaveType(ConstBehaveType.BEHAVE_PREPARE_PLANT);
people.SetTargetId(farmland.Id);
farmland.PeopleId = people.Id; farmland.PeopleId = people.Id;
return ErrorCode.ERR_Success; return ErrorCode.ERR_Success;
} }
public static int Plant(Unit unit, Farmland farmland, People people) public static int FinishPlant(Unit unit, Farmland farmland, People people)
{ {
if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED) if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED)
{ {
@ -28,7 +26,7 @@ namespace ET
} }
farmland.Plant(); farmland.Plant();
PeopleOperate.ChangeBehave(unit, people, farmland.Id, ConstBehaveType.BEHAVE_IDLE); PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_IDLE);
return ErrorCode.ERR_Success; return ErrorCode.ERR_Success;
} }
@ -40,14 +38,12 @@ namespace ET
return ErrorCode.ERR_FarmlandNotSeed; return ErrorCode.ERR_FarmlandNotSeed;
} }
PeopleOperate.StopBehave(unit, people); PeopleOperate.ChangeBehave(unit,people,ConstBehaveType.BEHAVE_PREPARE_HARVEST,farmland.Id);
people.SetBehaveType(ConstBehaveType.BEHAVE_PREPARE_HARVEST);
people.SetTargetId(farmland.Id);
farmland.PeopleId = people.Id; farmland.PeopleId = people.Id;
return ErrorCode.ERR_Success; return ErrorCode.ERR_Success;
} }
public static int Harvest(Unit unit, Farmland farmland, People people) public static int FinishHarvest(Unit unit, Farmland farmland, People people)
{ {
if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE) if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE)
{ {
@ -60,10 +56,11 @@ namespace ET
storeNc.Add(farmland.CropCfgId, farmland.Config.SeedProduce); storeNc.Add(farmland.CropCfgId, farmland.Config.SeedProduce);
farmland.Harvest(); farmland.Harvest();
PeopleOperate.StopBehave(unit, people);
return ErrorCode.ERR_Success; return ErrorCode.ERR_Success;
} }
PeopleOperate.ChangeBehave(unit, people, farmland.Id, ConstBehaveType.BEHAVE_IDLE); PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_IDLE);
return ErrorCode.ERR_FarmlandNotRipe; return ErrorCode.ERR_FarmlandNotRipe;
} }

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

@ -31,7 +31,7 @@ namespace ET
return ErrorCode.ERR_Success; return ErrorCode.ERR_Success;
} }
public static int ChangeBehave(Unit unit, People people,long targetId, int behaveType) public static int ChangeBehave(Unit unit, People people,int behaveType,long targetId=0 )
{ {

4
Unity/Codes/Model/Demo/ConstValue.cs

@ -32,7 +32,9 @@ namespace ET
public const int BEHAVE_PREPARE_CONSTRUCT = 3; //去建造 public const int BEHAVE_PREPARE_CONSTRUCT = 3; //去建造
public const int BEHAVE_CONSTRUCT = 4; //建造 public const int BEHAVE_CONSTRUCT = 4; //建造
public const int BEHAVE_PREPARE_PLANT = 5; //去种植 public const int BEHAVE_PREPARE_PLANT = 5; //去种植
public const int BEHAVE_PREPARE_HARVEST = 6;//去收割 public const int BEHAVE_PLANT = 6; //正在种植
public const int BEHAVE_PREPARE_HARVEST = 7;//去收割
public const int BEHAVE_HARVEST = 8;//正在收割
} }

Loading…
Cancel
Save