Browse Source

增加ConstructFinish接口

master
wserver/wangdisen 3 years ago
parent
commit
558e231a38
  1. 14
      Proto/OuterMessage.proto
  2. 24
      Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs
  3. 4
      Server/Hotfix/Demo/Unit/UnitFactory.cs
  4. 28
      Server/Model/Generate/Message/OuterMessage.cs
  5. 2
      Server/Model/Generate/Message/OuterOpcode.cs
  6. 49
      Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs
  7. 4
      Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs
  8. 14
      Unity/Codes/Hotfix/Demo/People/PeopleSystem.cs
  9. 3
      Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs
  10. 13
      Unity/Codes/Model/Demo/People/People.cs
  11. 28
      Unity/Codes/Model/Generate/Message/OuterMessage.cs
  12. 2
      Unity/Codes/Model/Generate/Message/OuterOpcode.cs

14
Proto/OuterMessage.proto

@ -1230,6 +1230,20 @@ message C2M_FarmlandHarvest // IActorLocationRequest
}
message M2C_FarmlandHarvest // IActorLocationResponse
{
int32 RpcId = 90;
int32 Error = 91;
string Message = 92;
}
//ResponseType M2C_ConstructFinish
message C2M_ConstructFinish // IActorLocationRequest
{
int32 RpcId = 90;
int64 ConstructId = 1;
}
message M2C_ConstructFinish // IActorLocationResponse
{
int32 RpcId = 90;
int32 Error = 91;

24
Server/Hotfix/Demo/Construct/Handler/C2M_ConstructFinishHandler.cs

@ -0,0 +1,24 @@
using System;
namespace ET
{
public class C2M_ConstructFinishHandler: AMActorLocationRpcHandler<Unit, C2M_ConstructFinish, M2C_ConstructFinish>
{
protected async override ETTask Run(Unit unit, C2M_ConstructFinish request, M2C_ConstructFinish response, Action reply)
{
try
{
ConstructOperate.ConstructFinish(unit, request.ConstructId);
response.Error = ErrorCode.ERR_Success;
reply();
}
catch (Exception e)
{
response.Message = e.ToString();
response.Error = ErrorCode.ERR_OperateFail;
reply();
}
await ETTask.CompletedTask;
}
}
}

4
Server/Hotfix/Demo/Unit/UnitFactory.cs

@ -87,7 +87,7 @@ namespace ET
people.Name = role.Name;
people.Level = 1;
people.Exp = 0;
people.LaborLevel = 1;
people.Labor = 1;
people.LaborExp = 0;
people.Age = role.Age;
if (role.AttributesGroup > 0)
@ -109,7 +109,7 @@ namespace ET
hero.Name = roleInfo.Name;
hero.Level = 1;
hero.Exp = 0;
hero.LaborLevel = 1;
hero.Labor = 1;
hero.LaborExp = 0;
hero.Age = heroConfig.Age;
if (heroConfig.AttributesGroup > 0)

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

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

@ -152,5 +152,7 @@ namespace ET
public const ushort M2C_FarmlandPlant = 10149;
public const ushort C2M_FarmlandHarvest = 10150;
public const ushort M2C_FarmlandHarvest = 10151;
public const ushort C2M_ConstructFinish = 10152;
public const ushort M2C_ConstructFinish = 10153;
}
}

49
Unity/Codes/Hotfix/Demo/Helper/ConstructHelper.cs

@ -5,16 +5,16 @@ namespace ET
{
public static class ConstructHelper
{
public static async ETTask<int> CreateConstruct(Unit unit, int configId, float x, float y,long buildingId=0)
public static async ETTask<int> CreateConstruct(Unit unit, int configId, float x, float y, long buildingId = 0)
{
try
{
C2M_CreateConstruct msg = new C2M_CreateConstruct(){ConfigId = configId, X = x,Y = y,BuildingId = buildingId};
M2C_CreateConstruct resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CreateConstruct;
C2M_CreateConstruct msg = new C2M_CreateConstruct() { ConfigId = configId, X = x, Y = y, BuildingId = buildingId };
M2C_CreateConstruct resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CreateConstruct;
if (resp.Error == ErrorCode.ERR_Success)
{
var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit,configId, x, y, resp.Id);
Game.EventSystem.Publish(new EventType.AfterCreateConstruct(){Unit = unit, Construct = construct, IsNew = true});
var construct = unit.GetOrAddComponent<ConstructComponent>().CreateConstruct(unit, configId, x, y, resp.Id);
Game.EventSystem.Publish(new EventType.AfterCreateConstruct() { Unit = unit, Construct = construct, IsNew = true });
}
else
{
@ -28,7 +28,6 @@ namespace ET
Log.Error(e.ToString());
throw;
}
}
public static async ETTask<int> CancelConstruct(Unit unit, long id)
@ -51,17 +50,18 @@ namespace ET
throw;
}
}
public static async ETTask<int> GoConstruct(Unit unit, long id, List<long> peopleIdList)
{
try
{
M2C_GoConstruct resp =
await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_GoConstruct() { Id = id,PeopleIdList = peopleIdList}) as
await unit.ZoneScene().GetComponent<SessionComponent>().Session
.Call(new C2M_GoConstruct() { Id = id, PeopleIdList = peopleIdList }) as
M2C_GoConstruct;
if (resp.Error == ErrorCode.ERR_Success)
{
ConstructOperate.GoConstruct(unit,id,peopleIdList);
ConstructOperate.GoConstruct(unit, id, peopleIdList);
}
return resp.Error;
@ -78,12 +78,14 @@ namespace ET
try
{
M2C_StartConstruct resp =
await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_StartConstruct() { Id = id,peopleId = peopleId }) as
await unit.ZoneScene().GetComponent<SessionComponent>().Session
.Call(new C2M_StartConstruct() { Id = id, peopleId = peopleId }) as
M2C_StartConstruct;
if (resp.Error == ErrorCode.ERR_Success)
{
ConstructOperate.StartConstruct(unit,id,peopleId);
ConstructOperate.StartConstruct(unit, id, peopleId);
}
return resp.Error;
}
catch (Exception e)
@ -92,17 +94,18 @@ namespace ET
throw;
}
}
public static async ETTask<int> StopConstruct(Unit unit, long id, long peopleId)
{
try
{
M2C_StopConstruct resp =
await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_StopConstruct() { Id = id,peopleId = peopleId}) as
await unit.ZoneScene().GetComponent<SessionComponent>().Session
.Call(new C2M_StopConstruct() { Id = id, peopleId = peopleId }) as
M2C_StopConstruct;
if (resp.Error == ErrorCode.ERR_Success)
{
ConstructOperate.StopConstruct(unit,id,peopleId);
ConstructOperate.StopConstruct(unit, id, peopleId);
}
return resp.Error;
@ -113,6 +116,22 @@ namespace ET
throw;
}
}
public static async ETTask<int> ConstructFinish(Unit unit, long id)
{
try
{
M2C_ConstructFinish resp =
await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(new C2M_ConstructFinish() { ConstructId = id }) as
M2C_ConstructFinish;
return resp.Error;
}
catch (Exception e)
{
Log.Error(e.ToString());
throw;
}
}
}
}

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

@ -151,6 +151,7 @@ namespace ET
if (construct.IsUpgrade)
{
build = unit.GetOrAddComponent<BuildingComponent>().GetChild<Building>(construct.BuildingId);
build.ConfigId = construct.Config.MixtureID;
build.IsUpgrade = 0;
}
else
@ -158,6 +159,7 @@ namespace ET
build = unit.GetOrAddComponent<BuildingComponent>().AddChild<Building>();
build.Position.x = construct.X;
build.Position.y = construct.Y;
build.ConfigId = construct.Config.MixtureID;
//如果是农场
if (build.Config.Special == (int)StructureSpecialEnum.FARMLAND)
{
@ -166,7 +168,7 @@ namespace ET
}
}
build.ConfigId = construct.Config.MixtureID;
StructureConfig structureConfig = StructureConfigCategory.Instance.Get(build.ConfigId);
if (structureConfig != null)
{

14
Unity/Codes/Hotfix/Demo/People/PeopleSystem.cs

@ -19,7 +19,7 @@ namespace ET
self.Id = peopleProto.Id;
self.Name = peopleProto.Name;
self.ConfigId = peopleProto.ConfigId;
self.LaborLevel = peopleProto.LaborLevel;
self.Labor = peopleProto.LaborLevel;
self.LaborExp = peopleProto.LaborExp;
self.Level = peopleProto.Level;
self.Exp = peopleProto.Exp;
@ -45,7 +45,7 @@ namespace ET
peopleProto.Id = self.Id;
peopleProto.Name = self.Name;
peopleProto.ConfigId = self.ConfigId;
peopleProto.LaborLevel = self.LaborLevel;
peopleProto.LaborLevel = self.Labor;
peopleProto.LaborExp = self.LaborExp;
peopleProto.Level = self.Level;
peopleProto.Exp = self.Exp;
@ -146,6 +146,7 @@ namespace ET
return nc.GetAsInt(NumericType.Labor);
}
//建造相关
public static int GetLaborWithCoefficient(this People self)
{
int labor = self.GetLabor();
@ -153,6 +154,15 @@ namespace ET
return labor * laborCoefficientBuild;
}
//农民类型才会成长
public static void GrowUp(this People self)
{
if (self.PeopleType != (int)RoleTypeEnum.VILLAGERS)
{
return;
}
}
}
}

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

@ -156,9 +156,8 @@ namespace ET
return;
}
self.Season = self.SeasonConfig.Id;
#if SERVER
UnitHelper.NofityUpdateValley(self, new List<int> { NumericType.Season }, new List<long> { self.Season });
#endif
//如果是春天,长大一岁
}
public static void SetEmbattle(this Unit self, Dictionary<int, long> FighterDic)

13
Unity/Codes/Model/Demo/People/People.cs

@ -11,9 +11,9 @@ namespace ET
public class People: Entity, IAwake<int>, ISerializeToEntity
{
public string Name;
public int ConfigId;
public int LaborLevel;
public int LaborExp;
public int ConfigId;
public int Labor; //劳力值,受年龄段限制
public int LaborExp; //劳力经验
public int Exp;
public int Level;
public int Age;
@ -22,6 +22,13 @@ namespace ET
public int CurrSkillId;
public float PosX;
public float PosY;
public int Disease; //疾病值
public int PeopleType; //主角,伙伴,村民
public int Gender; //性别
public int Life; //生命
public int Wisdom; //智慧
public int MoveSpeed; //移动速度
[BsonIgnore]
public RoleConfig Config => RoleConfigCategory.Instance.Get(this.ConfigId);

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

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

@ -152,5 +152,7 @@ namespace ET
public const ushort M2C_FarmlandPlant = 10149;
public const ushort C2M_FarmlandHarvest = 10150;
public const ushort M2C_FarmlandHarvest = 10151;
public const ushort C2M_ConstructFinish = 10152;
public const ushort M2C_ConstructFinish = 10153;
}
}

Loading…
Cancel
Save