Fix avatar entities on server side

This commit is contained in:
xeon 2024-01-25 15:14:47 +03:00
parent 4d182852e5
commit b623e3bd0f
9 changed files with 36 additions and 8 deletions

View file

@ -32,6 +32,11 @@ internal class EntityManager
return null;
}
public void NotifyMove(EntityBase entity)
{
_listener.OnEntityMoveByServer(entity.Id, new MotionInfo { Pos = entity.Position, Rot = entity.Rotation });
}
public void NotifyUpdate(EntityBase entity)
{
_listener.OnUpdateEntity(entity.SceneEntityInfo);

View file

@ -9,4 +9,5 @@ internal interface IEntityEventListener
Task OnRemoveEntities(IEnumerable<uint> ids);
Task OnUpdateEntity(SceneEntityInfo entity);
Task OnEntityMoveByServer(uint entityId, MotionInfo motion);
}

View file

@ -3,7 +3,6 @@ using RPG.GameCore.Level;
using RPG.GameCore.Level.Floor;
using RPG.GameCore.Level.Group;
using RPG.GameCore.Level.Objects;
using RPG.GameCore.Util;
using RPG.Network.Proto;
using RPG.Services.Gameserver.Game.Entity;
using RPG.Services.Gameserver.Game.Entity.Factory;
@ -47,7 +46,7 @@ internal class MazeManager
if (entity != null)
{
entity.SetMotion(CreateInitialAvatarMotion());
EntityManager.NotifyUpdate(entity);
EntityManager.NotifyMove(entity);
}
}
}

View file

@ -45,6 +45,9 @@ internal class AdventureModule : BaseModule
public override Task OnLogin()
{
ModuleManager.Get<TeamModule>().InitStartingLineup();
_mazeManager.SetPlayerUid(ModuleManager.PlayerUID);
_mazeManager.EnterMaze(StartingEntryId, ModuleManager.Get<TeamModule>().Team);
return Task.CompletedTask;

View file

@ -30,12 +30,12 @@ internal class BattleModule : BaseModule
{
PVEBattleResultCsReq req = PVEBattleResultCsReq.Parser.ParseFrom(body.Span);
AdventureModule adventureModule = ModuleManager.Get<AdventureModule>();
switch (req.EndStatus)
{
case BattleEndStatus.BattleEndWin:
adventureModule.OnBattleWin(_battleMonsterEntityId, _battleMonsterAssists!);
break;
case BattleEndStatus.BattleEndQuit:
case BattleEndStatus.BattleEndLose:
adventureModule.OnBattleLost();
break;

View file

@ -19,7 +19,7 @@ internal class LoginModule : BaseModule
PlayerLoginCsReq req = PlayerLoginCsReq.Parser.ParseFrom(body.Span);
_mazeEventListener.Session = session;
await ModuleManager.OnLogin();
await ModuleManager.OnLogin(session.PlayerUid);
Send(session, CmdType.CmdPlayerLoginScRsp, new PlayerLoginScRsp
{

View file

@ -21,6 +21,8 @@ internal class ModuleManager
private readonly IServiceProvider _serviceProvider;
private readonly ILogger _logger;
public uint PlayerUID { get; private set; }
static ModuleManager()
{
s_moduleTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsAssignableTo(typeof(BaseModule)) && !t.IsAbstract);
@ -39,8 +41,10 @@ internal class ModuleManager
return _serviceProvider.GetRequiredService<TModule>();
}
public async Task OnLogin()
public async Task OnLogin(uint gameUID)
{
PlayerUID = gameUID;
foreach (Type moduleType in s_moduleTypes)
{
if (_serviceProvider.GetRequiredService(moduleType) is BaseModule module)

View file

@ -14,14 +14,12 @@ internal class TeamModule : BaseModule
{
}
public override Task OnLogin()
public void InitStartingLineup()
{
for (uint i = 0; i < StartingLineup.Length; i++)
{
Team.Join(StartingLineup[i], AvatarType.AvatarFormalType, i);
}
return Task.CompletedTask;
}
[OnCommand(CmdType.CmdChangeLineupLeaderCsReq)]

View file

@ -37,4 +37,22 @@ internal class SessionEntityEventListener : IEntityEventListener
return Task.CompletedTask;
}
public Task OnEntityMoveByServer(uint entityId, MotionInfo motion)
{
SceneEntityMoveScNotify notify = new()
{
EntityId = entityId,
Motion = motion
};
Session?.SendToService(RPGServiceType.Gateserver, ServiceCommandType.ForwardGameMessage, new CmdForwardGameMessage
{
SessionId = Session.SessionId,
CmdType = (uint)CmdType.CmdSceneEntityMoveScNotify,
Payload = notify.ToByteString()
});
return Task.CompletedTask;
}
}