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.
65 lines
2.1 KiB
65 lines
2.1 KiB
using System.Collections.Generic; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(People))] |
|
[FriendClass(typeof(Cabin))] |
|
[FriendClass(typeof(Farmland))] |
|
public static class CabinOperate |
|
{ |
|
public static void CabinUpdateFarmlands(Unit unit,Cabin cabin, List<long> farmlandIds) |
|
{ |
|
foreach (var v in cabin.FarmlandIds) |
|
{ |
|
var farmland = unit.GetGrandChild<Farmland>(v); |
|
if (farmland != null) |
|
{ |
|
farmland.SetCabinId(0); |
|
} |
|
} |
|
|
|
foreach (var v in farmlandIds) |
|
{ |
|
var farmland = unit.GetGrandChild<Farmland>(v); |
|
if (farmland != null) |
|
{ |
|
farmland.SetCabinId(cabin.Id); |
|
} |
|
} |
|
|
|
cabin.FarmlandIds = farmlandIds; |
|
} |
|
|
|
public static int CabinSeed(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); |
|
farmland.Plant(); |
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
return ErrorCode.ERR_OperateFail; |
|
} |
|
|
|
public static int CabinHarvest(Unit unit, Farmland 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; |
|
} |
|
} |
|
} |