Browse Source

增加小屋收割的接口,修改小屋播种的BUG

master
wserver/wangdisen 3 years ago
parent
commit
fa3ec6f467
  1. 13
      Proto/OuterMessage.proto
  2. 35
      Server/Hotfix/Demo/Cabin/Handler/C2M_CabinHarvestHandler.cs
  3. 2
      Server/Model/Base/MongoRegister.cs
  4. 28
      Server/Model/Generate/Message/OuterMessage.cs
  5. 2
      Server/Model/Generate/Message/OuterOpcode.cs
  6. 4
      Server/Model/Server.Model.csproj
  7. 26
      Unity/Codes/Hotfix/Demo/Helper/CabinHelper.cs
  8. 33
      Unity/Codes/Hotfix/Demo/Operate/CabinOperate.cs
  9. 1
      Unity/Codes/Hotfix/Demo/Operate/FarmlandOperate.cs
  10. 2
      Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs
  11. 28
      Unity/Codes/Model/Demo/Weather/Weather.cs
  12. 28
      Unity/Codes/Model/Generate/Message/OuterMessage.cs
  13. 2
      Unity/Codes/Model/Generate/Message/OuterOpcode.cs

13
Proto/OuterMessage.proto

@ -1429,3 +1429,16 @@ message M2C_CabinUpdateFarmlands // IActorLocationResponse
}
//ResponseType M2C_CabinHarvest
message C2M_CabinHarvest // IActorLocationRequest
{
int32 RpcId = 90;
int64 FarmlandId = 1;
}
message M2C_CabinHarvest // IActorLocationResponse
{
int32 RpcId = 90;
int32 Error = 91;
string Message = 92;
}

35
Server/Hotfix/Demo/Cabin/Handler/C2M_CabinHarvestHandler.cs

@ -0,0 +1,35 @@
using System;
namespace ET
{
public class C2M_CabinHarvestHandler: AMActorLocationRpcHandler<Unit, C2M_CabinHarvest, M2C_CabinHarvest>
{
protected async override ETTask Run(Unit unit, C2M_CabinHarvest request, M2C_CabinHarvest response, Action reply)
{
try
{
Farmland farmland = unit.GetGrandChild<Farmland>(request.FarmlandId);
if (farmland == null)
{
response.Error = ErrorCode.ERR_FarmlandNotFound;
}
else
{
response.Error = CabinOperate.CabinHarvest(unit, farmland);
reply();
}
}
catch (Exception e)
{
response.Message = e.ToString();
response.Error = ErrorCode.ERR_OperateFail;
reply();
}
await ETTask.CompletedTask;
}
}
}

2
Server/Model/Base/MongoRegister.cs

@ -22,11 +22,13 @@ namespace ET
BsonSerializer.RegisterSerializer(typeof(Quaternion), new StructBsonSerialize<Quaternion>());
BsonSerializer.RegisterSerializer(typeof(ResourceAttri), new StructBsonSerialize<ResourceAttri>());
BsonSerializer.RegisterSerializer(typeof(ExtraOut), new StructBsonSerialize<ExtraOut>());
BsonSerializer.RegisterSerializer(typeof(WatherInfo), new StructBsonSerialize<WatherInfo>());
#elif ROBOT
BsonSerializer.RegisterSerializer(typeof(Quaternion), new StructBsonSerialize<Quaternion>());
BsonSerializer.RegisterSerializer(typeof(Vector3), new StructBsonSerialize<Vector3>());
BsonSerializer.RegisterSerializer(typeof(Vector4), new StructBsonSerialize<Vector4>());
BsonSerializer.RegisterSerializer(typeof(ResourceAttri), new StructBsonSerialize<ResourceAttri>());
BsonSerializer.RegisterSerializer(typeof(ExtraOut), new StructBsonSerialize<ExtraOut>());
#else
BsonSerializer.RegisterSerializer(typeof (Vector4), new StructBsonSerialize<Vector4>());
BsonSerializer.RegisterSerializer(typeof (Vector3), new StructBsonSerialize<Vector3>());

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

@ -2971,4 +2971,32 @@ namespace ET
}
[ResponseType(nameof(M2C_CabinHarvest))]
[Message(OuterOpcode.C2M_CabinHarvest)]
[ProtoContract]
public partial class C2M_CabinHarvest: Object, IActorLocationRequest
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(1)]
public long FarmlandId { get; set; }
}
[Message(OuterOpcode.M2C_CabinHarvest)]
[ProtoContract]
public partial class M2C_CabinHarvest: 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

@ -177,5 +177,7 @@ namespace ET
public const ushort M2C_CabinSeed = 10174;
public const ushort C2M_CabinUpdateFarmlands = 10175;
public const ushort M2C_CabinUpdateFarmlands = 10176;
public const ushort C2M_CabinHarvest = 10177;
public const ushort M2C_CabinHarvest = 10178;
}
}

4
Server/Model/Server.Model.csproj

@ -191,6 +191,10 @@
<Link>Demo\ValleyRandom.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Model\Demo\Weather\Weather.cs">
<Link>Weather\Weather.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Codes\Model\Generate\ConfigPartial\SkillUpConfig.cs">
<Link>Generate\ConfigPartial\SkillUpConfig.cs</Link>
</Compile>

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

@ -88,7 +88,7 @@ namespace ET
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);
CabinOperate.CabinSeed(unit, farmland, cropCfgId);
}
else
{
@ -127,5 +127,29 @@ namespace ET
throw;
}
}
public static async ETTask<int> CabinHarvest(Unit unit, Farmland farmland)
{
try
{
C2M_CabinHarvest msg = new C2M_CabinHarvest() { FarmlandId = farmland.Id};
M2C_CabinHarvest resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CabinHarvest;
if (resp.Error == ErrorCode.ERR_Success)
{
CabinOperate.CabinHarvest(unit,farmland);
}
else
{
Log.Error(resp.Error.ToString());
}
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
}
}

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

@ -4,6 +4,7 @@ namespace ET
{
[FriendClass(typeof(People))]
[FriendClass(typeof(Cabin))]
[FriendClass(typeof(Farmland))]
public static class CabinOperate
{
public static void CabinUpdateFarmlands(Unit unit,Cabin cabin, List<long> farmlandIds)
@ -28,5 +29,37 @@ namespace ET
cabin.FarmlandIds = farmlandIds;
}
public static int CabinSeed(Unit unit, Farmland farmland, int CropCfgId)
{
var cropCfg = CropConfigCategory.Instance.Get(CropCfgId);
var sc = unit.GetComponent<StoreComponent>();
if (sc.Remove(cropCfg.SeedNeed, cropCfg.SeedNum))
{
farmland.Seed(cropCfg.Id);
farmland.Plant();
return ErrorCode.ERR_Success;
}
return ErrorCode.ERR_OperateFail;
}
public static int CabinHarvest(Unit unit, Farmland farmland)
{
if (farmland.FarmlandState == FarmlandState.FARMLAND_STATE_RIPE)
{
var storeNc = unit.GetComponent<StoreComponent>();
storeNc.Add(farmland.Config.ProductID, farmland.Config.BasicProduction);
if (farmland.Config.ByProduct > 0)
{
storeNc.Add(farmland.Config.ByProduct, farmland.Config.ByProductNum);
}
storeNc.Add(farmland.CropCfgId, farmland.Config.SeedProduce);
farmland.Harvest();
return ErrorCode.ERR_Success;
}
return ErrorCode.ERR_FarmlandNotRipe;
}
}
}

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

@ -77,5 +77,6 @@ namespace ET
return ErrorCode.ERR_OperateFail;
}
}
}

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

@ -103,7 +103,7 @@ namespace ET
Log.Info($"----------------day: {self.Day}, nightTime: {nightTime}");
self.Day++;
self.updateSeason();
time -= self.SeasonConfig.DayTime[0];
time = self.SeasonConfig.DayTime[0];
self.EventSeed = 1;
UnitOperate.NightEvent(self, nightTime, time);
//每天长大一岁

28
Unity/Codes/Model/Demo/Weather/Weather.cs

@ -0,0 +1,28 @@
using System.Collections.Generic;
namespace ET
{
public struct WatherInfo
{
public int ConfigId;
public int Cd;
public int StartTime; //game day
}
public class Weather:Entity,IAwake,ISerializeToEntity
{
public int ConfigId;
public int Times; //当前季节触发次数
public int Cd;
public List<int> SpringList; //春天列表
public List<int> SummerList;
public List<int> AutumnList;
public List<int> WinterList;
public int StartTime;//开始时间,游戏时间
public int RealStartTime; //实际时间
public int Duration; //持续
}
}

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

@ -2971,4 +2971,32 @@ namespace ET
}
[ResponseType(nameof(M2C_CabinHarvest))]
[Message(OuterOpcode.C2M_CabinHarvest)]
[ProtoContract]
public partial class C2M_CabinHarvest: Object, IActorLocationRequest
{
[ProtoMember(90)]
public int RpcId { get; set; }
[ProtoMember(1)]
public long FarmlandId { get; set; }
}
[Message(OuterOpcode.M2C_CabinHarvest)]
[ProtoContract]
public partial class M2C_CabinHarvest: 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

@ -177,5 +177,7 @@ namespace ET
public const ushort M2C_CabinSeed = 10174;
public const ushort C2M_CabinUpdateFarmlands = 10175;
public const ushort M2C_CabinUpdateFarmlands = 10176;
public const ushort C2M_CabinHarvest = 10177;
public const ushort M2C_CabinHarvest = 10178;
}
}

Loading…
Cancel
Save