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.
61 lines
2.0 KiB
61 lines
2.0 KiB
using System; |
|
|
|
namespace ET |
|
{ |
|
public static class ResourceHelper |
|
{ |
|
public static async ETTask<int> RootOutResource(Unit unit, long resourceId) |
|
{ |
|
try |
|
{ |
|
M2C_RootOutResource resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session |
|
.Call(new C2M_RootOutResource() { ResourceId = resourceId }) as M2C_RootOutResource; |
|
|
|
if (resp.Error != ErrorCode.ERR_Success) |
|
{ |
|
Log.Error(resp.Error.ToString()); |
|
return resp.Error; |
|
} |
|
|
|
ResourceOperate.RootOutResource(unit, resourceId); |
|
} |
|
catch (Exception e) |
|
{ |
|
Log.Error(e); |
|
throw; |
|
} |
|
|
|
return ErrorCode.ERR_Success; |
|
} |
|
|
|
// 直接创建一个资源,不消耗任何东西,暂时不用,可以以后放在GM命令里 |
|
public static async ETTask<int> CreateResource(Unit unit, int configId, float posX, float posY) |
|
{ |
|
try |
|
{ |
|
M2C_CreateResource resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_CreateResource() |
|
{ |
|
ResourceConfigId = configId, |
|
X = posX, |
|
Y = posY |
|
}) as M2C_CreateResource; |
|
|
|
if (resp.Error != ErrorCode.ERR_Success) |
|
{ |
|
Log.Error(resp.Error.ToString()); |
|
return resp.Error; |
|
} |
|
|
|
var res = ResourceOperate.CreateResource(unit, configId, posX, posY, resp.ResourceId); |
|
Game.EventSystem.Publish(new EventType.AfterCreateResource(){Unit = unit, Resource = res}); |
|
} |
|
catch (Exception e) |
|
{ |
|
Log.Error(e); |
|
throw; |
|
} |
|
|
|
return ErrorCode.ERR_Success; |
|
} |
|
} |
|
} |