|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
[FriendClass(typeof (Unit))]
|
|
|
|
[FriendClass(typeof (Farmland))]
|
|
|
|
public static class FarmlandOperate
|
|
|
|
{
|
|
|
|
public static int Plant(Unit unit, long farmlandId)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int Harvest(Unit unit, long farmlandId)
|
|
|
|
{
|
|
|
|
Farmland farmland;
|
|
|
|
if (unit.FarmlandDic.TryGetValue(farmlandId, out farmland))
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
return ErrorCode.ERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ErrorCode.ERR_FarmlandNotRipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ErrorCode.ERR_FarmlandNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (unit.FarmlandDic.TryGetValue(farmlandIds[i], out farmland))
|
|
|
|
{
|
|
|
|
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.SeedNeed);
|
|
|
|
sucCropList.Add(cropCfg.SeedNeed);
|
|
|
|
sucFarmlandList.Add(farmlandIds[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (sucFarmlandList, sucCropList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|