2024-02-12 01:15:49 +00:00
|
|
|
|
using GameServer.Controllers.Attributes;
|
2024-02-17 13:49:28 +00:00
|
|
|
|
using GameServer.Controllers.Combat;
|
2024-02-24 12:37:52 +00:00
|
|
|
|
using GameServer.Models;
|
2024-02-12 01:15:49 +00:00
|
|
|
|
using GameServer.Network;
|
2024-02-24 12:37:52 +00:00
|
|
|
|
using GameServer.Systems.Entity;
|
|
|
|
|
using GameServer.Systems.Event;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-02-12 01:15:49 +00:00
|
|
|
|
using Protocol;
|
|
|
|
|
|
|
|
|
|
namespace GameServer.Controllers;
|
|
|
|
|
internal class CombatMessageController : Controller
|
|
|
|
|
{
|
2024-02-24 12:37:52 +00:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
public CombatMessageController(PlayerSession session, ILogger<CombatMessageController> logger) : base(session)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NetEvent(MessageId.MovePackagePush)]
|
|
|
|
|
public async Task OnMovePackagePush(MovePackagePush push, EntitySystem entitySystem, EventSystem eventSystem, ModelManager modelManager)
|
2024-02-12 01:15:49 +00:00
|
|
|
|
{
|
2024-02-24 12:37:52 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2024-02-12 01:15:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-24 12:37:52 +00:00
|
|
|
|
[NetEvent(MessageId.CombatSendPackRequest)]
|
2024-02-20 19:39:08 +00:00
|
|
|
|
public async Task<RpcResult> OnCombatSendPackRequest(CombatSendPackRequest request, CombatManager combatManager)
|
2024-02-17 13:49:28 +00:00
|
|
|
|
{
|
|
|
|
|
CombatReceivePackNotify combatPackNotify = new();
|
|
|
|
|
|
|
|
|
|
foreach (CombatSendData sendData in request.Data)
|
|
|
|
|
{
|
|
|
|
|
if (sendData.Request != null)
|
|
|
|
|
{
|
|
|
|
|
CombatRequestContext context = new(sendData.Request);
|
|
|
|
|
CombatResponseData? responseData = await combatManager.HandleRequest(context);
|
|
|
|
|
|
|
|
|
|
combatPackNotify.Data.AddRange(context.Notifies.Select(notify => new CombatReceiveData
|
|
|
|
|
{
|
|
|
|
|
CombatNotifyData = notify
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
if (responseData != null)
|
|
|
|
|
{
|
|
|
|
|
combatPackNotify.Data.Add(new CombatReceiveData
|
|
|
|
|
{
|
|
|
|
|
CombatResponseData = responseData
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Session.Push(MessageId.CombatReceivePackNotify, combatPackNotify);
|
|
|
|
|
return Response(MessageId.CombatSendPackResponse, new CombatSendPackResponse());
|
|
|
|
|
}
|
2024-02-12 01:15:49 +00:00
|
|
|
|
}
|