using System; using System.Collections.Generic; namespace ET { public static class ConstructHelper { public static async ETTask CreateConstruct(Unit unit, int configId, float x, float y, long buildingId = 0) { try { C2M_CreateConstruct msg = new C2M_CreateConstruct() { ConfigId = configId, X = x, Y = y, BuildingId = buildingId }; M2C_CreateConstruct resp = await unit.ZoneScene().GetComponent().Session.Call(msg) as M2C_CreateConstruct; if (resp.Error == ErrorCode.ERR_Success) { var construct = unit.GetOrAddComponent().CreateConstruct(unit, configId, x, y, resp.Id, buildingId); Game.EventSystem.Publish(new EventType.AfterCreateConstruct() { Unit = unit, Construct = construct, IsNew = true }); } else { Log.Error(resp.Error.ToString()); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask CancelConstruct(Unit unit, long id) { try { M2C_CancelConstruct resp = await unit.ZoneScene().GetComponent().Session.Call(new C2M_CancelConstruct() { Id = id }) as M2C_CancelConstruct; if (resp.Error == ErrorCode.ERR_Success) { ConstructOperate.CancelConstruct(unit, id); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask GoConstruct(Unit unit, long id, List peopleIdList) { try { M2C_GoConstruct resp = await unit.ZoneScene().GetComponent().Session .Call(new C2M_GoConstruct() { Id = id, PeopleIdList = peopleIdList }) as M2C_GoConstruct; if (resp.Error == ErrorCode.ERR_Success) { ConstructOperate.GoConstruct(unit, id, peopleIdList); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask StartConstruct(Unit unit, long id, long peopleId) { try { M2C_StartConstruct resp = await unit.ZoneScene().GetComponent().Session .Call(new C2M_StartConstruct() { Id = id, peopleId = peopleId }) as M2C_StartConstruct; if (resp.Error == ErrorCode.ERR_Success) { ConstructOperate.StartConstruct(unit, id, peopleId); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask StopConstruct(Unit unit, long id, long peopleId) { try { M2C_StopConstruct resp = await unit.ZoneScene().GetComponent().Session .Call(new C2M_StopConstruct() { Id = id, peopleId = peopleId }) as M2C_StopConstruct; if (resp.Error == ErrorCode.ERR_Success) { ConstructOperate.StopConstruct(unit, id, peopleId); } return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } public static async ETTask ConstructFinish(Unit unit, long id) { try { M2C_ConstructFinish resp = await unit.ZoneScene().GetComponent().Session.Call(new C2M_ConstructFinish() { ConstructId = id }) as M2C_ConstructFinish; return resp.Error; } catch (Exception e) { Log.Error(e.ToString()); throw; } } } }