You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.4 KiB
98 lines
3.4 KiB
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 (List<long>, List<int>) FarmlandSeed(Unit unit, List<long> farmlandIds, List<int> CropCfgIds) |
|
{ |
|
List<long> sucFarmlandList = new List<long>(); |
|
List<int> sucCropList = new List<int>(); |
|
for (int i = 0; i < farmlandIds.Count; i++) |
|
{ |
|
Farmland farmland = unit.GetGrandChild<Farmland>(farmlandIds[i]); |
|
if (farmland == null) |
|
{ |
|
continue; |
|
} |
|
|
|
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.Id); |
|
sucCropList.Add(cropCfg.Id); |
|
sucFarmlandList.Add(farmlandIds[i]); |
|
} |
|
} |
|
} |
|
|
|
return (sucFarmlandList, sucCropList); |
|
} |
|
|
|
|
|
} |
|
} |