Browse Source

增加小屋更新农场列表的接口

master
wserver/wangdisen 3 years ago
parent
commit
dd3a220873
  1. 17
      Proto/OuterMessage.proto
  2. 36
      Server/Hotfix/Demo/Cabin/Handler/C2M_CabinUpdateFarmlandsHandler.cs
  3. 3
      Server/Hotfix/Server.Hotfix.csproj
  4. 31
      Server/Model/Generate/Message/OuterMessage.cs
  5. 2
      Server/Model/Generate/Message/OuterOpcode.cs
  6. 51
      Unity/Codes/Hotfix/Demo/Helper/CabinHelper.cs
  7. 27
      Unity/Codes/Hotfix/Demo/Operate/CabinOperate.cs
  8. 31
      Unity/Codes/Model/Generate/Message/OuterMessage.cs
  9. 2
      Unity/Codes/Model/Generate/Message/OuterOpcode.cs

17
Proto/OuterMessage.proto

@ -1411,3 +1411,20 @@ message M2C_CabinSeed // IActorLocationResponse
string Message = 92;
}
//ResponseType M2C_CabinUpdateFarmlands
message C2M_CabinUpdateFarmlands // IActorLocationRequest
{
int32 RpcId = 90;
repeated int64 FarmlandIds = 1;
long CabinId = 2;
}
message M2C_CabinUpdateFarmlands // IActorLocationResponse
{
int32 RpcId = 90;
int32 Error = 91;
string Message = 92;
}

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

@ -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;
}
}
}

3
Server/Hotfix/Server.Hotfix.csproj

@ -85,6 +85,9 @@
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Menu\MenuSystem.cs">
<Link>Demo\Menu\MenuSystem.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Operate\CabinOperate.cs">
<Link>Demo\Operate\CabinOperate.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Hotfix\Demo\Operate\ConstructOperate.cs">
<Link>Demo\Operate\ConstructOperate.cs</Link>

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

@ -2937,4 +2937,35 @@ namespace ET
}
[ResponseType(nameof(M2C_CabinUpdateFarmlands))]
[Message(OuterOpcode.C2M_CabinUpdateFarmlands)]
[ProtoContract]
public partial class C2M_CabinUpdateFarmlands: Object, IActorLocationRequest
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(1)]
public List<long> FarmlandIds = new List<long>();
[ProtoMember(2)]
public long CabinId { get; set; }
}
[Message(OuterOpcode.M2C_CabinUpdateFarmlands)]
[ProtoContract]
public partial class M2C_CabinUpdateFarmlands: Object, IActorLocationResponse
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(91)]
public int Error { get; set; }
[ProtoMember(92)]
public string Message { get; set; }
}
}

2
Server/Model/Generate/Message/OuterOpcode.cs

@ -175,5 +175,7 @@ namespace ET
public const ushort M2C_CabinAddFarmland = 10172;
public const ushort C2M_CabinSeed = 10173;
public const ushort M2C_CabinSeed = 10174;
public const ushort C2M_CabinUpdateFarmlands = 10175;
public const ushort M2C_CabinUpdateFarmlands = 10176;
}
}

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

@ -5,11 +5,11 @@ namespace ET
{
public static class CabinHelper
{
public static async ETTask<int> GoCabin(Unit unit,People people,Cabin cabin)
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};
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)
{
@ -29,12 +29,12 @@ namespace ET
throw;
}
}
public static async ETTask<int> ArriveCabin(Unit unit,People people,Cabin cabin)
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};
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)
{
@ -53,14 +53,13 @@ namespace ET
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> AddFarmland(Unit unit,Cabin cabin,List<long> farmlandIds)
public static async ETTask<int> AddFarmland(Unit unit, Cabin cabin, List<long> farmlandIds)
{
try
{
C2M_CabinAddFarmland msg = new C2M_CabinAddFarmland() { CabinId = cabin.Id,FarmlandIds = farmlandIds};
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;
foreach (var v in resp.FarmlandIds)
{
@ -69,12 +68,8 @@ namespace ET
if (farmland != null)
{
farmland.SetCabinId(cabin.Id);
}
}
return resp.Error;
}
@ -84,12 +79,12 @@ namespace ET
throw;
}
}
public static async ETTask<int> CabinSeed(Unit unit,Farmland farmland,int cropCfgId)
public static async ETTask<int> CabinSeed(Unit unit, Farmland farmland, int cropCfgId)
{
try
{
C2M_CabinSeed msg = new C2M_CabinSeed() { CropCfgId = cropCfgId,FarmlandId = farmland.Id};
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)
{
@ -108,5 +103,29 @@ namespace ET
throw;
}
}
public static async ETTask<int> CabinUpdateFarmlands(Unit unit, Cabin cabin, List<long>farmlandIds)
{
try
{
C2M_CabinUpdateFarmlands msg = new C2M_CabinUpdateFarmlands() { CabinId = cabin.Id, FarmlandIds = farmlandIds };
M2C_CabinUpdateFarmlands resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinUpdateFarmlands;
if (resp.Error == ErrorCode.ERR_Success)
{
CabinOperate.CabinUpdateFarmlands(unit,cabin,farmlandIds);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
}
}

27
Unity/Codes/Hotfix/Demo/Operate/CabinOperate.cs

@ -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;
}
}
}

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

@ -2937,4 +2937,35 @@ namespace ET
}
[ResponseType(nameof(M2C_CabinUpdateFarmlands))]
[Message(OuterOpcode.C2M_CabinUpdateFarmlands)]
[ProtoContract]
public partial class C2M_CabinUpdateFarmlands: Object, IActorLocationRequest
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(1)]
public List<long> FarmlandIds = new List<long>();
[ProtoMember(2)]
public long CabinId { get; set; }
}
[Message(OuterOpcode.M2C_CabinUpdateFarmlands)]
[ProtoContract]
public partial class M2C_CabinUpdateFarmlands: Object, IActorLocationResponse
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(91)]
public int Error { get; set; }
[ProtoMember(92)]
public string Message { get; set; }
}
}

2
Unity/Codes/Model/Generate/Message/OuterOpcode.cs

@ -175,5 +175,7 @@ namespace ET
public const ushort M2C_CabinAddFarmland = 10172;
public const ushort C2M_CabinSeed = 10173;
public const ushort M2C_CabinSeed = 10174;
public const ushort C2M_CabinUpdateFarmlands = 10175;
public const ushort M2C_CabinUpdateFarmlands = 10176;
}
}

Loading…
Cancel
Save