|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
[FriendClass(typeof (Unit))]
|
|
|
|
[FriendClass(typeof (Farmland))]
|
|
|
|
public static class FarmlandOperate
|
|
|
|
{
|
|
|
|
public static int GoPlant(Unit unit, Farmland farmland, People people)
|
|
|
|
{
|
|
|
|
if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED)
|
|
|
|
{
|
|
|
|
return ErrorCode.ERR_FarmlandNotSeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PREPARE_PLANT, farmland.Id);
|
|
|
|
farmland.PeopleId = people.Id;
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int FinishPlant(Unit unit, Farmland farmland, People people)
|
|
|
|
{
|
|
|
|
if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_SEED)
|
|
|
|
{
|
|
|
|
return ErrorCode.ERR_FarmlandNotFree;
|
|
|
|
}
|
|
|
|
|
|
|
|
farmland.Plant();
|
|
|
|
PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_IDLE);
|
|
|
|
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int GoHarvest(Unit unit, Farmland farmland, People people)
|
|
|
|
{
|
|
|
|
if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_RIPE)
|
|
|
|
{
|
|
|
|
return ErrorCode.ERR_FarmlandNotSeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PREPARE_HARVEST, farmland.Id);
|
|
|
|
farmland.PeopleId = people.Id;
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int FinishHarvest(Unit unit, Farmland farmland, People people)
|
|
|
|
{
|
|
|
|
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.CropCfgId, farmland.Config.SeedProduce);
|
|
|
|
farmland.Harvest();
|
|
|
|
PeopleOperate.StopBehave(unit, people);
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_IDLE);
|
|
|
|
|
|
|
|
return ErrorCode.ERR_FarmlandNotRipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int FarmlandSeed(Unit unit, Farmland farmland, int CropCfgId)
|
|
|
|
{
|
|
|
|
var cropCfg = CropConfigCategory.Instance.Get(CropCfgId);
|
|
|
|
var sc = unit.GetComponent<StoreComponent>();
|
|
|
|
if (sc.Remove(cropCfg.SeedNeed, cropCfg.SeedNum))
|
|
|
|
{
|
|
|
|
farmland.Seed(cropCfg.Id);
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ErrorCode.ERR_OperateFail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|