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
{
int32 RpcId = 90;
int64 FarmlandId = 1 ;
repeated int64 FarmlandIds = 1 ;
int64 CabinId = 2;
}
@ -1393,6 +1393,7 @@ message M2C_CabinAddFarmland // IActorLocationResponse
int32 RpcId = 90;
int32 Error = 91;
string Message = 92;
repeated int64 FarmlandIds = 1 ;
}
//ResponseType M2C_CabinSeed

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

@ -1,42 +1,32 @@
using System;
using System.Collections.Generic;
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)
List<long> sucList = new List<long>();
var cabin = unit.GetGrandChild<Cabin>(request.CabinId);
if (cabin != null)
{
response.Error = ErrorCode.ERR_FarmlandNotFound;
}
else
{
var cabin = unit.GetGrandChild<Cabin>(request.CabinId);
if (cabin == null)
{
response.Error = ErrorCode.ERR_CabinNotFound;
}
else
for (int i = 0; i < request.FarmlandIds.Count; i++)
{
if (cabin.AddFarmland(request.FarmlandId))
{
farmland.SetCabinId(request.CabinId);
response.Error = ErrorCode.ERR_Success;
}
else
var farmland = unit.GetGrandChild<Farmland>(request.FarmlandIds[i]);
if (farmland != null)
{
response.Error = ErrorCode.ERR_OperateFail;
if (cabin.AddFarmland(request.FarmlandIds[i]))
{
farmland.SetCabinId(request.CabinId);
response.FarmlandIds.Add(request.FarmlandIds[i]);
}
}
}
}
reply();
}
catch (Exception e)

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

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

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

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
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
{
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;
if (resp.Error == ErrorCode.ERR_Success)
{
cabin.AddFarmland(farmland.Id);
farmland.SetCabinId(cabin.Id);
}
else
foreach (var v in resp.FarmlandIds)
{
Log.Error(resp.Error.ToString());
cabin.AddFarmland(v);
var farmland = unit.GetGrandChild<Farmland>(v);
if (farmland != null)
{
farmland.SetCabinId(cabin.Id);
}
}
return resp.Error;
}

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

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

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

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

Loading…
Cancel
Save