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.
102 lines
3.3 KiB
102 lines
3.3 KiB
using System; |
|
using UnityEngine; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(Building))] |
|
public static class BuildingHelper |
|
{ |
|
public static async ETTask<int> RemoveBuilding(Unit unit, Building buildingInfo) |
|
{ |
|
try |
|
{ |
|
C2M_RemoveBuilding msg = new C2M_RemoveBuilding() { Id = buildingInfo.Id }; |
|
M2C_RemoveBuilding resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_RemoveBuilding; |
|
if (resp.Error != ErrorCode.ERR_Success) |
|
{ |
|
Log.Error(resp.Error.ToString()); |
|
return resp.Error; |
|
} |
|
|
|
BuildingComponent buildingComponent = unit.GetComponent<BuildingComponent>(); |
|
// buildingComponent.Remove(buildingInfo); |
|
buildingInfo.Dispose(); |
|
|
|
Game.EventSystem.Publish(new EventType.AfterRemoveBuilding() { Building = buildingInfo, Unit = unit }); |
|
} |
|
catch (Exception e) |
|
{ |
|
Log.Error(e); |
|
throw; |
|
} |
|
|
|
await ETTask.CompletedTask; |
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
public static async ETTask<int> RepairBuilding(Unit unit, Building buildingInfo) |
|
{ |
|
try |
|
{ |
|
C2M_RepairBuilding msg = new C2M_RepairBuilding() { Id = buildingInfo.Id }; |
|
M2C_RepairBuilding resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_RepairBuilding; |
|
if (resp.Error != ErrorCode.ERR_Success) |
|
{ |
|
Log.Error(resp.Error.ToString()); |
|
return resp.Error; |
|
} |
|
|
|
buildingInfo.Repair(); |
|
} |
|
catch (Exception e) |
|
{ |
|
Log.Error(e); |
|
throw; |
|
} |
|
|
|
await ETTask.CompletedTask; |
|
|
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
//buildingId 0表示所有建筑,其他表示具体的某个建筑 |
|
public static async ETTask<int> GetBuildingDurable(Unit unit, long buildingId=0) |
|
{ |
|
try |
|
{ |
|
C2M_BuildingDurable msg = new C2M_BuildingDurable() { BuildingId = buildingId }; |
|
M2C_BuildingDurable resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_BuildingDurable; |
|
if (resp.Error != ErrorCode.ERR_Success) |
|
{ |
|
Log.Error(resp.Error.ToString()); |
|
return resp.Error; |
|
} |
|
var bc = unit.GetComponent<BuildingComponent>(); |
|
|
|
if (bc == null) |
|
{ |
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
for (int i=0; i< resp.IdList.Count;i++) |
|
{ |
|
var building = bc.GetChild<Building>(resp.IdList[i]); |
|
if (building != null) |
|
{ |
|
building.Durable = resp.Vs[i]; |
|
} |
|
} |
|
|
|
} |
|
catch (Exception e) |
|
{ |
|
Log.Error(e); |
|
throw; |
|
} |
|
|
|
await ETTask.CompletedTask; |
|
|
|
return ErrorCode.ERR_Success; |
|
} |
|
} |
|
} |