From d6d7ca6e76db2a5ee88a9a0a0b6b5cb0395c6746 Mon Sep 17 00:00:00 2001 From: xeon Date: Sat, 24 Feb 2024 15:37:52 +0300 Subject: [PATCH] Handle movement (fixes position reset after formation change) --- .../Controllers/CombatMessageController.cs | 33 +++++++++++++++++-- GameServer/Controllers/CreatureController.cs | 9 +++++ GameServer/Systems/Event/GameEventType.cs | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/GameServer/Controllers/CombatMessageController.cs b/GameServer/Controllers/CombatMessageController.cs index 7005149..9fd2ae9 100644 --- a/GameServer/Controllers/CombatMessageController.cs +++ b/GameServer/Controllers/CombatMessageController.cs @@ -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 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(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 OnCombatSendPackRequest(CombatSendPackRequest request, CombatManager combatManager) { CombatReceivePackNotify combatPackNotify = new(); diff --git a/GameServer/Controllers/CreatureController.cs b/GameServer/Controllers/CreatureController.cs index 3bbff68..5af5a54 100644 --- a/GameServer/Controllers/CreatureController.cs +++ b/GameServer/Controllers/CreatureController.cs @@ -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(); } diff --git a/GameServer/Systems/Event/GameEventType.cs b/GameServer/Systems/Event/GameEventType.cs index 1a0d856..0bef25b 100644 --- a/GameServer/Systems/Event/GameEventType.cs +++ b/GameServer/Systems/Event/GameEventType.cs @@ -6,6 +6,7 @@ internal enum GameEventType PushDataDone, // Actions + PlayerPositionChanged, FormationUpdated, VisionSkillChanged,