9 changed files with 182 additions and 18 deletions
@ -0,0 +1,36 @@
|
||||
using System; |
||||
|
||||
namespace ET |
||||
{ |
||||
|
||||
|
||||
public class C2M_CabinUpdateFarmlandsHandler: AMActorLocationRpcHandler<Unit, C2M_CabinUpdateFarmlands, M2C_CabinUpdateFarmlands> |
||||
{ |
||||
protected async override ETTask Run(Unit unit, C2M_CabinUpdateFarmlands request, M2C_CabinUpdateFarmlands response, Action reply) |
||||
{ |
||||
try |
||||
{ |
||||
var cabin = unit.GetGrandChild<Cabin>(request.CabinId); |
||||
if (cabin == null) |
||||
{ |
||||
response.Error = ErrorCode.ERR_CabinNotFound; |
||||
} |
||||
else |
||||
{ |
||||
CabinOperate.CabinUpdateFarmlands(unit,cabin,request.FarmlandIds); |
||||
response.Error = ErrorCode.ERR_Success; |
||||
} |
||||
|
||||
reply(); |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
response.Message = e.ToString(); |
||||
response.Error = ErrorCode.ERR_OperateFail; |
||||
reply(); |
||||
} |
||||
|
||||
await ETTask.CompletedTask; |
||||
} |
||||
} |
||||
} |
@ -1,9 +1,32 @@
|
||||
namespace ET |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ET |
||||
{ |
||||
[FriendClass(typeof(People))] |
||||
[FriendClass(typeof(Cabin))] |
||||
public static class CabinOperate |
||||
{ |
||||
|
||||
public static void CabinUpdateFarmlands(Unit unit,Cabin cabin, List<long> farmlandIds) |
||||
{ |
||||
foreach (var v in cabin.FarmlandIds) |
||||
{ |
||||
var farmland = unit.GetGrandChild<Farmland>(v); |
||||
if (farmland != null) |
||||
{ |
||||
farmland.SetCabinId(0); |
||||
} |
||||
} |
||||
|
||||
foreach (var v in farmlandIds) |
||||
{ |
||||
var farmland = unit.GetGrandChild<Farmland>(v); |
||||
if (farmland != null) |
||||
{ |
||||
farmland.SetCabinId(cabin.Id); |
||||
} |
||||
} |
||||
|
||||
cabin.FarmlandIds = farmlandIds; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue