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().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(); 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; } } }