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.
50 lines
1.7 KiB
50 lines
1.7 KiB
3 years ago
|
namespace ET
|
||
|
{
|
||
|
[FriendClass(typeof(Unit))]
|
||
|
[FriendClass(typeof(Farmland))]
|
||
|
public static class FarmlandOperate
|
||
|
{
|
||
|
public static int Plant(Unit unit,long farmlandId, int cropId)
|
||
|
{
|
||
|
if (!unit.FarmlandDic.ContainsKey(farmlandId))
|
||
|
{
|
||
|
return ErrorCode.ERR_FarmlandNotFound;
|
||
|
}
|
||
|
|
||
|
var farmland = unit.FarmlandDic[farmlandId];
|
||
|
if (farmland.FarmlandState != FarmlandState.FARMLAND_STATE_FREE)
|
||
|
{
|
||
|
return ErrorCode.ERR_FarmlandNotFree;
|
||
|
}
|
||
|
//检查种子数量
|
||
|
var cropConfig = CropConfigCategory.Instance.Get(cropId);
|
||
|
if (cropConfig == null)
|
||
|
{
|
||
|
return ErrorCode.ERR_CropConfigNotFound;
|
||
|
}
|
||
|
|
||
|
if (!unit.GetComponent<StoreComponent>().Remove(cropConfig.SeedNeed, cropConfig.SeedNum))
|
||
|
{
|
||
|
return ErrorCode.ERR_SeedNotEnough;
|
||
|
}
|
||
|
|
||
|
farmland.Plant(cropId,cropConfig.SeedNeed);
|
||
|
|
||
|
return ErrorCode.ERR_Success;
|
||
|
}
|
||
|
|
||
|
public static int Harvest(Unit unit, long farmlandId)
|
||
|
{
|
||
|
var farmland = unit.FarmlandDic[farmlandId];
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|