46 changed files with 978 additions and 165 deletions
Binary file not shown.
@ -0,0 +1,51 @@
|
||||
using System; |
||||
|
||||
namespace ET |
||||
{ |
||||
public class C2M_ArriveCabinHandler: AMActorLocationRpcHandler<Unit, C2M_ArriveCabin, M2C_ArriveCabin> |
||||
{ |
||||
protected async override ETTask Run(Unit unit, C2M_ArriveCabin request, M2C_ArriveCabin response, Action reply) |
||||
{ |
||||
try |
||||
{ |
||||
|
||||
var people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId); |
||||
if (people == null) |
||||
{ |
||||
response.Error = ErrorCode.ERR_PeopleNotFound; |
||||
} |
||||
else |
||||
{ |
||||
var cabin = unit.GetGrandChild<Cabin>(request.CabinId); |
||||
if (cabin == null) |
||||
{ |
||||
response.Error = ErrorCode.ERR_CabinNotFound; |
||||
} |
||||
else |
||||
{ |
||||
|
||||
if (cabin.PeopleArrive(request.PeopleId)) |
||||
{ |
||||
people.SetBehaveType(ConstBehaveType.BEHAVE_CABIN); |
||||
response.Error = ErrorCode.ERR_Success; |
||||
} |
||||
else |
||||
{ |
||||
response.Error = ErrorCode.ERR_ArriveCabinFail; |
||||
} |
||||
|
||||
} |
||||
} |
||||
reply(); |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
response.Message = e.ToString(); |
||||
response.Error = ErrorCode.ERR_OperateFail; |
||||
reply(); |
||||
} |
||||
|
||||
await ETTask.CompletedTask; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@
|
||||
using System; |
||||
|
||||
namespace ET |
||||
{ |
||||
|
||||
public class C2M_CabinAddFarmlandHandler: AMActorLocationRpcHandler<Unit, C2M_CabinAddFarmland, M2C_CabinAddFarmland> |
||||
{ |
||||
protected async override ETTask Run(Unit unit, C2M_CabinAddFarmland request, M2C_CabinAddFarmland response, Action reply) |
||||
{ |
||||
try |
||||
{ |
||||
|
||||
var farmland = unit.GetGrandChild<Farmland>(request.FarmlandId); |
||||
if (farmland == null) |
||||
{ |
||||
response.Error = ErrorCode.ERR_FarmlandNotFound; |
||||
} |
||||
else |
||||
{ |
||||
var cabin = unit.GetGrandChild<Cabin>(request.CabinId); |
||||
if (cabin == null) |
||||
{ |
||||
response.Error = ErrorCode.ERR_CabinNotFound; |
||||
} |
||||
else |
||||
{ |
||||
|
||||
if (cabin.AddFarmland(request.FarmlandId)) |
||||
{ |
||||
farmland.SetCabinId(request.CabinId); |
||||
response.Error = ErrorCode.ERR_Success; |
||||
} |
||||
else |
||||
{ |
||||
response.Error = ErrorCode.ERR_OperateFail; |
||||
} |
||||
|
||||
} |
||||
} |
||||
reply(); |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
response.Message = e.ToString(); |
||||
response.Error = ErrorCode.ERR_OperateFail; |
||||
reply(); |
||||
} |
||||
|
||||
await ETTask.CompletedTask; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
using System; |
||||
|
||||
namespace ET |
||||
{ |
||||
[FriendClass(typeof (Farmland))] |
||||
[FriendClass(typeof (Cabin))] |
||||
public class C2M_CabinSeedHandler: AMActorLocationRpcHandler<Unit, C2M_CabinSeed, M2C_CabinSeed> |
||||
{ |
||||
protected async override ETTask Run(Unit unit, C2M_CabinSeed request, M2C_CabinSeed res, Action reply) |
||||
{ |
||||
try |
||||
{ |
||||
res.Error = ErrorCode.ERR_Success; |
||||
var farmland = unit.GetGrandChild<Farmland>(request.FarmlandId); |
||||
if (GameUtil.IsErrorSuc(res.Error) && farmland == null) |
||||
{ |
||||
res.Error = ErrorCode.ERR_PeopleNotFound; |
||||
} |
||||
|
||||
var cabin = unit.GetGrandChild<Cabin>(farmland.CabinId); |
||||
if (GameUtil.IsErrorSuc(res.Error) && cabin == null) |
||||
{ |
||||
res.Error = ErrorCode.ERR_CabinNotFound; |
||||
} |
||||
|
||||
if (GameUtil.IsErrorSuc(res.Error) && cabin.ResidentState == 0) |
||||
{ |
||||
res.Error = ErrorCode.ERR_CabinNotPeople; |
||||
} |
||||
|
||||
if (GameUtil.IsErrorSuc(res.Error) && farmland.FarmlandState != FarmlandState.FARMLAND_STATE_FREE) |
||||
{ |
||||
res.Error = ErrorCode.ERR_FarmlandNotFree; |
||||
} |
||||
|
||||
if (GameUtil.IsErrorSuc(res.Error)) |
||||
{ |
||||
res.Error = FarmlandOperate.FarmlandSeed(unit, farmland, request.CropCfgId); |
||||
} |
||||
|
||||
reply(); |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
res.Message = e.ToString(); |
||||
res.Error = ErrorCode.ERR_OperateFail; |
||||
reply(); |
||||
} |
||||
|
||||
await ETTask.CompletedTask; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
using System; |
||||
|
||||
namespace ET |
||||
{ |
||||
public class C2M_GoCabinHandler: AMActorLocationRpcHandler<Unit, C2M_GoCabin, M2C_GoCabin> |
||||
{ |
||||
protected async override ETTask Run(Unit unit, C2M_GoCabin request, M2C_GoCabin response, Action reply) |
||||
{ |
||||
try |
||||
{ |
||||
var people = unit.GetComponent<PeopleComponent>().GetChild<People>(request.PeopleId); |
||||
if (people == null) |
||||
{ |
||||
response.Error = ErrorCode.ERR_PeopleNotFound; |
||||
} |
||||
else |
||||
{ |
||||
var cabin = unit.GetGrandChild<Cabin>(request.CabinId); |
||||
if (cabin == null) |
||||
{ |
||||
response.Error = ErrorCode.ERR_CabinNotFound; |
||||
} |
||||
else |
||||
{ |
||||
PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PREPARE_CABIN, request.CabinId); |
||||
cabin.PeoplePrepare(request.PeopleId); |
||||
response.Error = ErrorCode.ERR_Success; |
||||
} |
||||
} |
||||
|
||||
reply(); |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
response.Message = e.ToString(); |
||||
response.Error = ErrorCode.ERR_OperateFail; |
||||
reply(); |
||||
} |
||||
|
||||
await ETTask.CompletedTask; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
namespace ET |
||||
{ |
||||
[FriendClass(typeof(Cabin))] |
||||
public static class CabinSystem |
||||
{ |
||||
public static void FromMessage(this Cabin self, CabinProto proto) |
||||
{ |
||||
self.Id = proto.Id; |
||||
self.PeopleId = proto.PeopleId; |
||||
self.FarmlandIds = proto.FarmlandIds; |
||||
} |
||||
|
||||
public static CabinProto ToMessage(this Cabin self) |
||||
{ |
||||
var proto = new CabinProto(); |
||||
proto.Id = self.Id; |
||||
proto.PeopleId = self.PeopleId; |
||||
proto.FarmlandIds = self.FarmlandIds; |
||||
return proto; |
||||
} |
||||
|
||||
public static void PeoplePrepare(this Cabin self,long peopleId) |
||||
{ |
||||
self.PeopleId = peopleId; |
||||
} |
||||
|
||||
public static bool PeopleArrive(this Cabin self,long peopleId) |
||||
{ |
||||
if (self.PeopleId != peopleId) |
||||
{ |
||||
return false; |
||||
} |
||||
self.ResidentState = 1; |
||||
return true; |
||||
} |
||||
public static void PeopleLeave(this Cabin self) |
||||
{ |
||||
self.ResidentState = 0; |
||||
self.PeopleId = 0; |
||||
} |
||||
|
||||
public static bool AddFarmland(this Cabin self,long farmlandId) |
||||
{ |
||||
if (self.FarmlandIds.Contains(farmlandId)) |
||||
{ |
||||
return false; |
||||
} |
||||
self.FarmlandIds.Add(farmlandId); |
||||
return true; |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
@ -0,0 +1,107 @@
|
||||
using System; |
||||
|
||||
namespace ET |
||||
{ |
||||
public static class CabinHelper |
||||
{ |
||||
public static async ETTask<int> GoCabin(Unit unit,People people,Cabin cabin) |
||||
{ |
||||
try |
||||
{ |
||||
C2M_GoCabin msg = new C2M_GoCabin() { PeopleId = people.Id,CabinId = cabin.Id}; |
||||
M2C_GoCabin resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_GoCabin; |
||||
if (resp.Error == ErrorCode.ERR_Success) |
||||
{ |
||||
cabin.PeoplePrepare(people.Id); |
||||
PeopleOperate.ChangeBehave(unit, people, ConstBehaveType.BEHAVE_PREPARE_CABIN, cabin.Id); |
||||
} |
||||
else |
||||
{ |
||||
Log.Error(resp.Error.ToString()); |
||||
} |
||||
|
||||
return resp.Error; |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
Log.Error(e.ToString()); |
||||
throw; |
||||
} |
||||
} |
||||
|
||||
public static async ETTask<int> ArriveCabin(Unit unit,People people,Cabin cabin) |
||||
{ |
||||
try |
||||
{ |
||||
C2M_ArriveCabin msg = new C2M_ArriveCabin() { PeopleId = people.Id,CabinId = cabin.Id}; |
||||
M2C_ArriveCabin resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_ArriveCabin; |
||||
if (resp.Error == ErrorCode.ERR_Success) |
||||
{ |
||||
cabin.PeopleArrive(people.Id); |
||||
people.SetBehaveType(ConstBehaveType.BEHAVE_CABIN); |
||||
} |
||||
else |
||||
{ |
||||
Log.Error(resp.Error.ToString()); |
||||
} |
||||
|
||||
return resp.Error; |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
Log.Error(e.ToString()); |
||||
throw; |
||||
} |
||||
|
||||
|
||||
} |
||||
public static async ETTask<int> AddFarmland(Unit unit,Cabin cabin,Farmland farmland) |
||||
{ |
||||
try |
||||
{ |
||||
C2M_CabinAddFarmland msg = new C2M_CabinAddFarmland() { CabinId = cabin.Id,FarmlandId = farmland.Id}; |
||||
M2C_CabinAddFarmland resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinAddFarmland; |
||||
if (resp.Error == ErrorCode.ERR_Success) |
||||
{ |
||||
cabin.AddFarmland(farmland.Id); |
||||
farmland.SetCabinId(cabin.Id); |
||||
} |
||||
else |
||||
{ |
||||
Log.Error(resp.Error.ToString()); |
||||
} |
||||
|
||||
return resp.Error; |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
Log.Error(e.ToString()); |
||||
throw; |
||||
} |
||||
} |
||||
|
||||
public static async ETTask<int> CabinSeed(Unit unit,Farmland farmland,int cropCfgId) |
||||
{ |
||||
try |
||||
{ |
||||
C2M_CabinSeed msg = new C2M_CabinSeed() { CropCfgId = cropCfgId,FarmlandId = farmland.Id}; |
||||
M2C_CabinSeed resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinSeed; |
||||
if (resp.Error == ErrorCode.ERR_Success) |
||||
{ |
||||
FarmlandOperate.FarmlandSeed(unit, farmland, cropCfgId); |
||||
} |
||||
else |
||||
{ |
||||
Log.Error(resp.Error.ToString()); |
||||
} |
||||
|
||||
return resp.Error; |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
Log.Error(e.ToString()); |
||||
throw; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,9 @@
|
||||
namespace ET |
||||
{ |
||||
[FriendClass(typeof(People))] |
||||
[FriendClass(typeof(Cabin))] |
||||
public static class CabinOperate |
||||
{ |
||||
|
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic; |
||||
using MongoDB.Bson.Serialization.Attributes; |
||||
|
||||
namespace ET |
||||
{ |
||||
public class Cabin: Entity,IAwake,IUpdate, IDestroy,ISerializeToEntity |
||||
{ |
||||
public long PeopleId; |
||||
public List<long> FarmlandIds = new List<long>(); |
||||
public int ResidentState; //是不是有居民常驻 0表示没有,1表示有 |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue