using System; using System.Collections.Generic; namespace ET { public static class FarmlandHelper { public static async ETTask FarmlandSeed(Unit unit, List farmlandIds, List cropCfgIds) { try { C2M_FarmlandSeed msg = new C2M_FarmlandSeed() { FarmlandIds = farmlandIds, CropCfgIds = cropCfgIds }; M2C_FarmlandSeed resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandSeed; if (resp.Error == ErrorCode.ERR_Success) { FarmlandOperate.FarmlandSeed(unit, resp.FarmlandIds, resp.CropCfgIds); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask GoFarmlandPlant(Unit unit,People people,Farmland farmland) { try { C2M_GoFarmlandPlant msg = new C2M_GoFarmlandPlant() { PeopleId = people.Id,FarmlandId = farmland.Id}; M2C_GoFarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_GoFarmlandPlant; if (resp.Error == ErrorCode.ERR_Success) { FarmlandOperate.GoPlant(unit, farmland,people); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask StartFarmlandPlant(Unit unit, People people, Farmland farmland) { return await PeopleHelper.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PLANT,farmland.Id); } public static async ETTask FinishFarmlandPlant(Unit unit, Farmland farmland,People people) { try { C2M_FarmlandPlant msg = new C2M_FarmlandPlant() { FarmlandId = farmland.Id,PeopleId = people.Id}; M2C_FarmlandPlant resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandPlant; if (resp.Error == ErrorCode.ERR_Success) { FarmlandOperate.FinishPlant(unit, farmland,people); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask GoFarmlandHarvest(Unit unit,People people,Farmland farmland) { try { C2M_GoFarmlandHarvest msg = new C2M_GoFarmlandHarvest() { PeopleId = people.Id,FarmlandId = farmland.Id}; M2C_GoFarmlandHarvest resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_GoFarmlandHarvest; if (resp.Error == ErrorCode.ERR_Success) { FarmlandOperate.GoHarvest(unit, farmland,people); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask StartFarmlandHarvest(Unit unit, People people, Farmland farmland) { return await PeopleHelper.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_HARVEST,farmland.Id); } public static async ETTask FarmlandHarvest(Unit unit, Farmland farmland,People people) { try { C2M_FarmlandHarvest msg = new C2M_FarmlandHarvest() { FarmlandId = farmland.Id, PeopleId = people.Id}; M2C_FarmlandHarvest resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandHarvest; if (resp.Error == ErrorCode.ERR_Success) { FarmlandOperate.FinishHarvest(unit, farmland,people); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask FinishFarmlandHarvest(Unit unit,People people) { return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE); } public static async ETTask FarmlandRipe(Unit unit,long farmlandId) { try { C2M_FarmlandRipe msg = new C2M_FarmlandRipe() { FarmlandId = farmlandId }; M2C_FarmlandRipe resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_FarmlandRipe; return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } } }