You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.6 KiB
137 lines
4.6 KiB
using System; |
|
using System.Collections.Generic; |
|
|
|
namespace ET |
|
{ |
|
public static class ConstructHelper |
|
{ |
|
public static async ETTask<int> 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<SessionComponent>().Session.Call(msg) as M2C_CreateConstruct; |
|
if (resp.Error == ErrorCode.ERR_Success) |
|
{ |
|
var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit, configId, x, y, resp.Id); |
|
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<int> CancelConstruct(Unit unit, long id) |
|
{ |
|
try |
|
{ |
|
M2C_CancelConstruct resp = |
|
await unit.ZoneScene().GetComponent<SessionComponent>().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<int> GoConstruct(Unit unit, long id, List<long> peopleIdList) |
|
{ |
|
try |
|
{ |
|
M2C_GoConstruct resp = |
|
await unit.ZoneScene().GetComponent<SessionComponent>().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<int> StartConstruct(Unit unit, long id, long peopleId) |
|
{ |
|
try |
|
{ |
|
M2C_StartConstruct resp = |
|
await unit.ZoneScene().GetComponent<SessionComponent>().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<int> StopConstruct(Unit unit, long id, long peopleId) |
|
{ |
|
try |
|
{ |
|
M2C_StopConstruct resp = |
|
await unit.ZoneScene().GetComponent<SessionComponent>().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<int> ConstructFinish(Unit unit, long id) |
|
{ |
|
try |
|
{ |
|
M2C_ConstructFinish resp = |
|
await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_ConstructFinish() { ConstructId = id }) as |
|
M2C_ConstructFinish; |
|
|
|
return resp.Error; |
|
} |
|
catch (Exception e) |
|
{ |
|
Log.Error(e.ToString()); |
|
throw; |
|
} |
|
} |
|
} |
|
} |