using System; using System.Collections.Generic; namespace ET { public static class CabinHelper { public static async ETTask GoCabin(Unit unit, People people, Cabin cabin) { try { C2M_GoCabin msg = new C2M_GoCabin() { PeopleId = people.Id, CabinId = cabin.Id }; M2C_GoCabin resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_GoCabin; if (resp.Error == ErrorCode.ERR_Success) { cabin.PeoplePrepare(people.Id); PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PREPARE_CABIN, cabin.Id); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask ArriveCabin(Unit unit, People people, Cabin cabin) { try { C2M_ArriveCabin msg = new C2M_ArriveCabin() { PeopleId = people.Id, CabinId = cabin.Id }; M2C_ArriveCabin resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_ArriveCabin; if (resp.Error == ErrorCode.ERR_Success) { cabin.PeopleArrive(people.Id); people.SetBehaveType(ConstBehaveType.BEHAVE_CABIN); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask AddFarmland(Unit unit, Cabin cabin, List farmlandIds) { try { C2M_CabinAddFarmland msg = new C2M_CabinAddFarmland() { CabinId = cabin.Id, FarmlandIds = farmlandIds }; M2C_CabinAddFarmland resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_CabinAddFarmland; foreach (var v in resp.FarmlandIds) { cabin.AddFarmland(v); var farmland = unit.GetGrandChild(v); if (farmland != null) { farmland.SetCabinId(cabin.Id); } } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask CabinSeed(Unit unit, Farmland farmland, int cropCfgId) { try { C2M_CabinSeed msg = new C2M_CabinSeed() { CropCfgId = cropCfgId, FarmlandId = farmland.Id }; M2C_CabinSeed resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_CabinSeed; if (resp.Error == ErrorCode.ERR_Success) { CabinOperate.CabinSeed(unit, farmland, cropCfgId); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask CabinUpdateFarmlands(Unit unit, Cabin cabin, ListfarmlandIds) { try { C2M_CabinUpdateFarmlands msg = new C2M_CabinUpdateFarmlands() { CabinId = cabin.Id, FarmlandIds = farmlandIds }; M2C_CabinUpdateFarmlands resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_CabinUpdateFarmlands; if (resp.Error == ErrorCode.ERR_Success) { CabinOperate.CabinUpdateFarmlands(unit,cabin,farmlandIds); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask CabinHarvest(Unit unit, Farmland farmland) { try { C2M_CabinHarvest msg = new C2M_CabinHarvest() { FarmlandId = farmland.Id}; M2C_CabinHarvest resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_CabinHarvest; if (resp.Error == ErrorCode.ERR_Success) { CabinOperate.CabinHarvest(unit,farmland); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } } }