Handle movement (fixes position reset after formation change)

This commit is contained in:
xeon 2024-02-24 15:37:52 +03:00
parent e20c69f465
commit d6d7ca6e76
3 changed files with 40 additions and 3 deletions

View file

@ -1,17 +1,44 @@
using GameServer.Controllers.Attributes;
using GameServer.Controllers.Combat;
using GameServer.Models;
using GameServer.Network;
using GameServer.Systems.Entity;
using GameServer.Systems.Event;
using Microsoft.Extensions.Logging;
using Protocol;
namespace GameServer.Controllers;
internal class CombatMessageController : Controller
{
public CombatMessageController(PlayerSession session) : base(session)
private readonly ILogger _logger;
public CombatMessageController(PlayerSession session, ILogger<CombatMessageController> logger) : base(session)
{
// CombatMessageController.
_logger = logger;
}
[NetEvent(MessageId.CombatSendPackRequest)] // TODO: CombatSendPackRequest is important
[NetEvent(MessageId.MovePackagePush)]
public async Task OnMovePackagePush(MovePackagePush push, EntitySystem entitySystem, EventSystem eventSystem, ModelManager modelManager)
{
foreach (MovingEntityData movingEntityData in push.MovingEntities)
{
EntityBase? entity = entitySystem.Get<EntityBase>(movingEntityData.EntityId);
if (entity == null)
{
_logger.LogWarning("OnMovePackagePush: moving entity not found! Id: {entityId}", movingEntityData.EntityId);
continue;
}
MoveReplaySample lastMoveReplay = movingEntityData.MoveInfos.Last();
entity.Pos.MergeFrom(lastMoveReplay.Location);
entity.Rot.MergeFrom(lastMoveReplay.Rotation);
if (entity.Id == modelManager.Creature.PlayerEntityId)
await eventSystem.Emit(GameEventType.PlayerPositionChanged);
}
}
[NetEvent(MessageId.CombatSendPackRequest)]
public async Task<RpcResult> OnCombatSendPackRequest(CombatSendPackRequest request, CombatManager combatManager)
{
CombatReceivePackNotify combatPackNotify = new();

View file

@ -130,6 +130,12 @@ internal class CreatureController : Controller
await UpdateAiHate();
}
[GameEvent(GameEventType.PlayerPositionChanged)]
public void OnPlayerPositionChanged()
{
_modelManager.Player.Position.MergeFrom(GetPlayerEntity()!.Pos);
}
[GameEvent(GameEventType.VisionSkillChanged)]
public async Task OnVisionSkillChanged()
{
@ -174,6 +180,9 @@ internal class CreatureController : Controller
_modelManager.Creature.PlayerEntityId = newEntity.Id;
newEntity.IsCurrentRole = true;
newEntity.Pos.MergeFrom(prevEntity.Pos);
newEntity.Rot.MergeFrom(prevEntity.Rot);
await UpdateAiHate();
}

View file

@ -6,6 +6,7 @@ internal enum GameEventType
PushDataDone,
// Actions
PlayerPositionChanged,
FormationUpdated,
VisionSkillChanged,