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(); 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, List) FarmlandSeed(Unit unit, List farmlandIds, List CropCfgIds) { List sucFarmlandList = new List(); List sucCropList = new List(); for (int i = 0; i < farmlandIds.Count; i++) { Farmland farmland = unit.GetGrandChild(farmlandIds[i]); if (farmland == null) { continue; } if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_FREE) { var cropCfg = CropConfigCategory.Instance.Get(CropCfgIds[i]); var sc = unit.GetComponent(); if (sc.Remove(cropCfg.SeedNeed, cropCfg.SeedNum)) { farmland.Seed(cropCfg.Id); sucCropList.Add(cropCfg.Id); sucFarmlandList.Add(farmlandIds[i]); } } } return (sucFarmlandList, sucCropList); } } }