Browse Source

增加farmland马上成熟的接口,增加同步成熟进度的接口

master
wserver/wangdisen 3 years ago
parent
commit
4a545bf7d8
  1. 25
      Proto/OuterMessage.proto
  2. 1
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs
  3. 38
      Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandRipeHandler.cs
  4. 2
      Server/Hotfix/Demo/Helper/ConstructHelper.cs
  5. 24
      Server/Hotfix/Demo/Helper/FarmlandHelper.cs
  6. 49
      Server/Model/Generate/Message/OuterMessage.cs
  7. 4
      Server/Model/Generate/Message/OuterOpcode.cs
  8. 2
      Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs
  9. 11
      Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs
  10. 18
      Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeHandler.cs
  11. 19
      Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeProgressHandler.cs
  12. 16
      Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs
  13. 2
      Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs
  14. 28
      Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs
  15. 49
      Unity/Codes/Model/Generate/Message/OuterMessage.cs
  16. 4
      Unity/Codes/Model/Generate/Message/OuterOpcode.cs

25
Proto/OuterMessage.proto

@ -1316,3 +1316,28 @@ message M2C_GoFarmlandHarvest // IActorLocationResponse
int32 Error = 91;
string Message = 92;
}
//ResponseType M2C_FarmlandRipe
message C2M_FarmlandRipe // IActorLocationRequest
{
int32 RpcId = 90;
int64 FarmlandId = 1 ;
}
message M2C_FarmlandRipe // IActorLocationResponse
{
int32 RpcId = 90;
int32 Error = 91;
string Message = 92;
}
message M2C_NtfFarmlandRipe // IActorMessage
{
repeated int64 FarmlandIds = 1;
}
message M2C_NtfFarmlandRipeProgress // IActorMessage
{
repeated int64 FarmlandIds = 1;
repeated int32 Progresses = 2;
}

1
Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandPlantHandler.cs

@ -35,6 +35,7 @@ namespace ET
response.Message = e.ToString();
response.Error = ErrorCode.ERR_OperateFail;
reply();
throw;
}
await ETTask.CompletedTask;

38
Server/Hotfix/Demo/Farmland/Handler/C2M_FarmlandRipeHandler.cs

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
namespace ET
{
[FriendClass(typeof(Farmland))]
public class C2M_FarmlandRipeHandler: AMActorLocationRpcHandler<Unit, C2M_FarmlandRipe, M2C_FarmlandRipe>
{
protected override async ETTask Run(Unit unit, C2M_FarmlandRipe request, M2C_FarmlandRipe response, Action reply)
{
try
{
Farmland farmland = unit.GetGrandChild<Farmland>(request.FarmlandId);
if (farmland != null)
{
farmland.FarmlandState = FarmlandState.FARMLAND_STATE_RIPE;
response.Error = ErrorCode.ERR_Success;
FarmlandHelper.NotifyFarmlandRipe(unit,new List<long>{farmland.Id});
}
else
{
response.Error = ErrorCode.ERR_FarmlandNotFound;
}
reply();
}
catch (Exception e)
{
response.Message = e.ToString();
response.Error = ErrorCode.ERR_OperateFail;
reply();
throw;
}
await ETTask.CompletedTask;
}
}
}

2
Server/Hotfix/Demo/Helper/ConstructHelper.cs

@ -21,7 +21,7 @@ namespace ET
}
}
public static void NofityConstructFinish(Unit unit, long id, long buildingId)
public static void NotifyConstructFinish(Unit unit, long id, long buildingId)
{
MessageHelper.SendToClient(unit,new M2C_NotifyConstructFinish(){ConstructId = id, BuildingId = buildingId});
}

24
Server/Hotfix/Demo/Helper/FarmlandHelper.cs

@ -0,0 +1,24 @@
using System.Collections.Generic;
namespace ET
{
public static class FarmlandHelper
{
public static void M2C_NtfFarmlandRipeProgress(Unit unit, List<long> farmlandIds, List<int> progresses)
{
if (farmlandIds.Count == 0)
{
return;
}
MessageHelper.SendToClient(unit,new M2C_NtfFarmlandRipeProgress(){ FarmlandIds = farmlandIds,Progresses = progresses});
}
public static void NotifyFarmlandRipe(Unit unit, List<long> farmlandIds)
{
if (farmlandIds.Count == 0)
{
return;
}
MessageHelper.SendToClient(unit,new M2C_NtfFarmlandRipe(){FarmlandIds =farmlandIds });
}
}
}

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

@ -2746,4 +2746,53 @@ namespace ET
}
[ResponseType(nameof(M2C_FarmlandRipe))]
[Message(OuterOpcode.C2M_FarmlandRipe)]
[ProtoContract]
public partial class C2M_FarmlandRipe: Object, IActorLocationRequest
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(1)]
public long FarmlandId { get; set; }
}
[Message(OuterOpcode.M2C_FarmlandRipe)]
[ProtoContract]
public partial class M2C_FarmlandRipe: Object, IActorLocationResponse
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(91)]
public int Error { get; set; }
[ProtoMember(92)]
public string Message { get; set; }
}
[Message(OuterOpcode.M2C_NtfFarmlandRipe)]
[ProtoContract]
public partial class M2C_NtfFarmlandRipe: Object, IActorMessage
{
[ProtoMember(1)]
public List<long> FarmlandIds = new List<long>();
}
[Message(OuterOpcode.M2C_NtfFarmlandRipeProgress)]
[ProtoContract]
public partial class M2C_NtfFarmlandRipeProgress: Object, IActorMessage
{
[ProtoMember(1)]
public List<long> FarmlandIds = new List<long>();
[ProtoMember(2)]
public List<int> Progresses = new List<int>();
}
}

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

@ -162,5 +162,9 @@ namespace ET
public const ushort M2C_GoFarmlandPlant = 10159;
public const ushort C2M_GoFarmlandHarvest = 10160;
public const ushort M2C_GoFarmlandHarvest = 10161;
public const ushort C2M_FarmlandRipe = 10162;
public const ushort M2C_FarmlandRipe = 10163;
public const ushort M2C_NtfFarmlandRipe = 10164;
public const ushort M2C_NtfFarmlandRipeProgress = 10165;
}
}

2
Unity/Codes/Hotfix/Demo/Construct/ConstructComponentSystem.cs

@ -58,7 +58,7 @@ namespace ET
foreach (var v in finishConstructs)
{
var building = ConstructOperate.ConstructFinish(unit, v.Id);
ConstructHelper.NofityConstructFinish(unit,v.Id, building.Id);
ConstructHelper.NotifyConstructFinish(unit,v.Id, building.Id);
}
if (finishConstructs.Count > 0)

11
Unity/Codes/Hotfix/Demo/Farmland/FarmlandSystem.cs

@ -60,16 +60,17 @@
}
public static void Update(this Farmland self)
public static void Update(this Farmland self,Unit unit)
{
if (self.FarmlandState != FarmlandState.FARMLAND_STATE_GROW)
{
return;
}
self.Duration += 1;
if (self.Duration >= self.Config.GrowthCycle)
{
self.FarmlandState = FarmlandState.FARMLAND_STATE_RIPE;
#if SERVER
#endif
}
}

18
Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeHandler.cs

@ -0,0 +1,18 @@
namespace ET.Handler
{
[FriendClass(typeof(Farmland))]
public class M2C_NtfFarmlandRipeHandler:AMHandler<M2C_NtfFarmlandRipe>
{
protected override void Run(Session session, M2C_NtfFarmlandRipe message)
{
foreach (var v in message.FarmlandIds)
{
Farmland farmland=UnitComponent.unit.GetGrandChild<Farmland>(v);
if ( farmland!= null)
{
farmland.FarmlandState = FarmlandState.FARMLAND_STATE_RIPE;
}
}
}
}
}

19
Unity/Codes/Hotfix/Demo/Farmland/Handler/M2C_NtfFarmlandRipeProgressHandler.cs

@ -0,0 +1,19 @@
namespace ET.Handler
{
[FriendClass(typeof(Farmland))]
public class M2C_NtfFarmlandRipeProgressHandler:AMHandler<M2C_NtfFarmlandRipeProgress>
{
protected override void Run(Session session, M2C_NtfFarmlandRipeProgress message)
{
for (int i=0;i<message.FarmlandIds.Count;i++)
{
Farmland farmland=UnitComponent.unit.GetGrandChild<Farmland>(message.FarmlandIds[i]);
if ( farmland!= null)
{
farmland.Duration = message.Progresses[i];
}
}
}
}
}

16
Unity/Codes/Hotfix/Demo/Helper/FarmlandHelper.cs

@ -142,7 +142,21 @@ namespace ET
return await PeopleHelper.ChangeBehave(unit, people, 0, ConstBehaveType.BEHAVE_IDLE);
}
public static async ETTask<int> FarmlandRipe(Unit unit,long farmlandId)
{
try
{
C2M_FarmlandRipe msg = new C2M_FarmlandRipe() { FarmlandId = farmlandId };
M2C_FarmlandRipe resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_FarmlandRipe;
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}

2
Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs

@ -92,5 +92,7 @@ namespace ET
return (sucFarmlandList, sucCropList);
}
}
}

28
Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs

@ -45,6 +45,7 @@ namespace ET
#endif
[FriendClass(typeof (Unit))]
[FriendClass(typeof (Farmland))]
public static class UnitSystem
{
public static void AddTime(this Unit self, int tick)
@ -224,19 +225,36 @@ namespace ET
self.GetComponent<BuildingComponent>()?.DurableReduce();
}
public static void UpdateGameTime(this Unit self)
{
//update farmland
List<long> farmlandIds = new List<long>();
List<int> progresses = new List<int>();
List<long> ripeIds = new List<long>();
foreach (var v in self.GrandChildren.Values)
{
if (v.GetType() == typeof (Farmland))
{
((Farmland) v).Update();
Farmland farmland = (Farmland) v;
if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_GROW)
{
farmland.Update(self);
if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE)
{
ripeIds.Add(farmland.Id);
}
else
{
farmlandIds.Add(farmland.Id);
progresses.Add(farmland.Duration);
}
}
}
}
#if SERVER
FarmlandHelper.NotifyFarmlandRipe(unit,ripeIds);
FarmlandHelper.M2C_NtfFarmlandRipeProgress(unit,farmlandIds,ripeIds)
#endif
}
public static void AddAge(this Unit self)
@ -280,7 +298,7 @@ namespace ET
self.GrandChildren[entity.Id] = entity;
}
public static void RemoveGrandChild(this Unit self,long id)
public static void RemoveGrandChild(this Unit self, long id)
{
self.GrandChildren.Remove(id);
}

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

@ -2746,4 +2746,53 @@ namespace ET
}
[ResponseType(nameof(M2C_FarmlandRipe))]
[Message(OuterOpcode.C2M_FarmlandRipe)]
[ProtoContract]
public partial class C2M_FarmlandRipe: Object, IActorLocationRequest
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(1)]
public long FarmlandId { get; set; }
}
[Message(OuterOpcode.M2C_FarmlandRipe)]
[ProtoContract]
public partial class M2C_FarmlandRipe: Object, IActorLocationResponse
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(91)]
public int Error { get; set; }
[ProtoMember(92)]
public string Message { get; set; }
}
[Message(OuterOpcode.M2C_NtfFarmlandRipe)]
[ProtoContract]
public partial class M2C_NtfFarmlandRipe: Object, IActorMessage
{
[ProtoMember(1)]
public List<long> FarmlandIds = new List<long>();
}
[Message(OuterOpcode.M2C_NtfFarmlandRipeProgress)]
[ProtoContract]
public partial class M2C_NtfFarmlandRipeProgress: Object, IActorMessage
{
[ProtoMember(1)]
public List<long> FarmlandIds = new List<long>();
[ProtoMember(2)]
public List<int> Progresses = new List<int>();
}
}

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

@ -162,5 +162,9 @@ namespace ET
public const ushort M2C_GoFarmlandPlant = 10159;
public const ushort C2M_GoFarmlandHarvest = 10160;
public const ushort M2C_GoFarmlandHarvest = 10161;
public const ushort C2M_FarmlandRipe = 10162;
public const ushort M2C_FarmlandRipe = 10163;
public const ushort M2C_NtfFarmlandRipe = 10164;
public const ushort M2C_NtfFarmlandRipeProgress = 10165;
}
}

Loading…
Cancel
Save