Handle movement (fixes position reset after formation change)
This commit is contained in:
parent
e20c69f465
commit
d6d7ca6e76
3 changed files with 40 additions and 3 deletions
|
@ -1,17 +1,44 @@
|
||||||
using GameServer.Controllers.Attributes;
|
using GameServer.Controllers.Attributes;
|
||||||
using GameServer.Controllers.Combat;
|
using GameServer.Controllers.Combat;
|
||||||
|
using GameServer.Models;
|
||||||
using GameServer.Network;
|
using GameServer.Network;
|
||||||
|
using GameServer.Systems.Entity;
|
||||||
|
using GameServer.Systems.Event;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Protocol;
|
using Protocol;
|
||||||
|
|
||||||
namespace GameServer.Controllers;
|
namespace GameServer.Controllers;
|
||||||
internal class CombatMessageController : Controller
|
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)
|
public async Task<RpcResult> OnCombatSendPackRequest(CombatSendPackRequest request, CombatManager combatManager)
|
||||||
{
|
{
|
||||||
CombatReceivePackNotify combatPackNotify = new();
|
CombatReceivePackNotify combatPackNotify = new();
|
||||||
|
|
|
@ -130,6 +130,12 @@ internal class CreatureController : Controller
|
||||||
await UpdateAiHate();
|
await UpdateAiHate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GameEvent(GameEventType.PlayerPositionChanged)]
|
||||||
|
public void OnPlayerPositionChanged()
|
||||||
|
{
|
||||||
|
_modelManager.Player.Position.MergeFrom(GetPlayerEntity()!.Pos);
|
||||||
|
}
|
||||||
|
|
||||||
[GameEvent(GameEventType.VisionSkillChanged)]
|
[GameEvent(GameEventType.VisionSkillChanged)]
|
||||||
public async Task OnVisionSkillChanged()
|
public async Task OnVisionSkillChanged()
|
||||||
{
|
{
|
||||||
|
@ -174,6 +180,9 @@ internal class CreatureController : Controller
|
||||||
_modelManager.Creature.PlayerEntityId = newEntity.Id;
|
_modelManager.Creature.PlayerEntityId = newEntity.Id;
|
||||||
newEntity.IsCurrentRole = true;
|
newEntity.IsCurrentRole = true;
|
||||||
|
|
||||||
|
newEntity.Pos.MergeFrom(prevEntity.Pos);
|
||||||
|
newEntity.Rot.MergeFrom(prevEntity.Rot);
|
||||||
|
|
||||||
await UpdateAiHate();
|
await UpdateAiHate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ internal enum GameEventType
|
||||||
PushDataDone,
|
PushDataDone,
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
PlayerPositionChanged,
|
||||||
FormationUpdated,
|
FormationUpdated,
|
||||||
VisionSkillChanged,
|
VisionSkillChanged,
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue