Browse Source

修改增加小屋农场的接口

master
wserver/wangdisen 3 years ago
parent
commit
b69370cd53
  1. 3
      Proto/OuterMessage.proto
  2. 36
      Server/Hotfix/Demo/Cabin/Handler/C2M_CabinAddFarmlandHandler.cs
  3. 5
      Server/Model/Generate/Message/OuterMessage.cs
  4. 23
      Unity/Codes/Hotfix/Demo/Helper/CabinHelper.cs
  5. 6
      Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs
  6. 5
      Unity/Codes/Model/Generate/Message/OuterMessage.cs

3
Proto/OuterMessage.proto

@ -1384,7 +1384,7 @@ message M2C_ArriveCabin // IActorLocationResponse
message C2M_CabinAddFarmland // IActorLocationRequest message C2M_CabinAddFarmland // IActorLocationRequest
{ {
int32 RpcId = 90; int32 RpcId = 90;
int64 FarmlandId = 1 ; repeated int64 FarmlandIds = 1 ;
int64 CabinId = 2; int64 CabinId = 2;
} }
@ -1393,6 +1393,7 @@ message M2C_CabinAddFarmland // IActorLocationResponse
int32 RpcId = 90; int32 RpcId = 90;
int32 Error = 91; int32 Error = 91;
string Message = 92; string Message = 92;
repeated int64 FarmlandIds = 1 ;
} }
//ResponseType M2C_CabinSeed //ResponseType M2C_CabinSeed

36
Server/Hotfix/Demo/Cabin/Handler/C2M_CabinAddFarmlandHandler.cs

@ -1,42 +1,32 @@
using System; using System;
using System.Collections.Generic;
namespace ET namespace ET
{ {
public class C2M_CabinAddFarmlandHandler: AMActorLocationRpcHandler<Unit, C2M_CabinAddFarmland, M2C_CabinAddFarmland> 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) protected async override ETTask Run(Unit unit, C2M_CabinAddFarmland request, M2C_CabinAddFarmland response, Action reply)
{ {
try try
{ {
List<long> sucList = new List<long>();
var farmland = unit.GetGrandChild<Farmland>(request.FarmlandId); var cabin = unit.GetGrandChild<Cabin>(request.CabinId);
if (farmland == null) if (cabin != null)
{ {
response.Error = ErrorCode.ERR_FarmlandNotFound; for (int i = 0; i < request.FarmlandIds.Count; i++)
}
else
{
var cabin = unit.GetGrandChild<Cabin>(request.CabinId);
if (cabin == null)
{
response.Error = ErrorCode.ERR_CabinNotFound;
}
else
{ {
var farmland = unit.GetGrandChild<Farmland>(request.FarmlandIds[i]);
if (cabin.AddFarmland(request.FarmlandId)) if (farmland != null)
{
farmland.SetCabinId(request.CabinId);
response.Error = ErrorCode.ERR_Success;
}
else
{ {
response.Error = ErrorCode.ERR_OperateFail; if (cabin.AddFarmland(request.FarmlandIds[i]))
{
farmland.SetCabinId(request.CabinId);
response.FarmlandIds.Add(request.FarmlandIds[i]);
}
} }
} }
} }
reply(); reply();
} }
catch (Exception e) catch (Exception e)

5
Server/Model/Generate/Message/OuterMessage.cs

@ -2881,7 +2881,7 @@ namespace ET
public int RpcId { get; set; } public int RpcId { get; set; }
[ProtoMember(1)] [ProtoMember(1)]
public long FarmlandId { get; set; } public List<long> FarmlandIds = new List<long>();
[ProtoMember(2)] [ProtoMember(2)]
public long CabinId { get; set; } public long CabinId { get; set; }
@ -2901,6 +2901,9 @@ namespace ET
[ProtoMember(92)] [ProtoMember(92)]
public string Message { get; set; } public string Message { get; set; }
[ProtoMember(1)]
public List<long> FarmlandIds = new List<long>();
} }
[ResponseType(nameof(M2C_CabinSeed))] [ResponseType(nameof(M2C_CabinSeed))]

23
Unity/Codes/Hotfix/Demo/Helper/CabinHelper.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
namespace ET namespace ET
{ {
@ -55,21 +56,25 @@ namespace ET
} }
public static async ETTask<int> AddFarmland(Unit unit,Cabin cabin,Farmland farmland) public static async ETTask<int> AddFarmland(Unit unit,Cabin cabin,List<long> farmlandIds)
{ {
try try
{ {
C2M_CabinAddFarmland msg = new C2M_CabinAddFarmland() { CabinId = cabin.Id,FarmlandId = farmland.Id}; C2M_CabinAddFarmland msg = new C2M_CabinAddFarmland() { CabinId = cabin.Id,FarmlandIds = farmlandIds};
M2C_CabinAddFarmland resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinAddFarmland; M2C_CabinAddFarmland resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinAddFarmland;
if (resp.Error == ErrorCode.ERR_Success) foreach (var v in resp.FarmlandIds)
{
cabin.AddFarmland(farmland.Id);
farmland.SetCabinId(cabin.Id);
}
else
{ {
Log.Error(resp.Error.ToString()); cabin.AddFarmland(v);
var farmland = unit.GetGrandChild<Farmland>(v);
if (farmland != null)
{
farmland.SetCabinId(cabin.Id);
}
} }
return resp.Error; return resp.Error;
} }

6
Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs

@ -181,9 +181,9 @@ namespace ET
farmland.SetFarmlandState(FarmlandState.FARMLAND_STATE_FREE); farmland.SetFarmlandState(FarmlandState.FARMLAND_STATE_FREE);
unit.AddGrandChild(farmland); unit.AddGrandChild(farmland);
break; break;
case 7 : case (int)StructureSpecialEnum.FARM_CABIN :
//var cabin = build.AddChild<Cabin>(); var cabin = build.AddChild<Cabin>();
// unit.AddGrandChild(cabin); unit.AddGrandChild(cabin);
break; break;
} }

5
Unity/Codes/Model/Generate/Message/OuterMessage.cs

@ -2881,7 +2881,7 @@ namespace ET
public int RpcId { get; set; } public int RpcId { get; set; }
[ProtoMember(1)] [ProtoMember(1)]
public long FarmlandId { get; set; } public List<long> FarmlandIds = new List<long>();
[ProtoMember(2)] [ProtoMember(2)]
public long CabinId { get; set; } public long CabinId { get; set; }
@ -2901,6 +2901,9 @@ namespace ET
[ProtoMember(92)] [ProtoMember(92)]
public string Message { get; set; } public string Message { get; set; }
[ProtoMember(1)]
public List<long> FarmlandIds = new List<long>();
} }
[ResponseType(nameof(M2C_CabinSeed))] [ResponseType(nameof(M2C_CabinSeed))]

Loading…
Cancel
Save