using Yuanshen.Gameserver.Controllers.Attributes; using Yuanshen.Gameserver.Controllers.Result; using Yuanshen.Gameserver.Game; using Yuanshen.Gameserver.Network.Session; using Yuanshen.Protocol; using Microsoft.Extensions.Logging; namespace Yuanshen.Gameserver.Controllers; [NetController] internal sealed class AbilityController : ControllerBase { [NetCommand(CmdType.AbilityInvocationsNotify)] public async ValueTask OnAbilityInvocationsNotify(NetSession session) { AbilityInvocationsNotify notify = Packet!.DecodeBody(); await ForwardAsync(session, notify.Invokes); return Ok(); } [NetCommand(CmdType.ClientAbilityInitFinishNotify)] public async ValueTask OnClientAbilityInitFinishNotify(NetSession session, Player player, SceneManager scene, ILogger logger) { ClientAbilityInitFinishNotify notify = Packet!.DecodeBody(); foreach (AbilityInvokeEntry entry in notify.Invokes) { logger.LogDebug("AbilityInit entity={e} arg={arg} fwd={fwd} instAbility={ia} instModifier={im} localId={l} target={t}", notify.EntityId, entry.ArgumentType, entry.ForwardType, entry.Head?.InstancedAbilityId, entry.Head?.InstancedModifierId, entry.Head?.LocalId, entry.Head?.TargetId); } await ForwardAsync(session, notify.Invokes); GameMonster? monster = player.Monsters.FirstOrDefault(m => m.EntityId == notify.EntityId); if (monster is not null) await scene.SyncMonsterLevelAsync(monster); return Ok(); } [NetCommand(CmdType.ClientAbilityChangeNotify)] public async ValueTask OnClientAbilityChangeNotify(NetSession session) { ClientAbilityChangeNotify notify = Packet!.DecodeBody(); await ForwardAsync(session, notify.Invokes); return Ok(); } [NetCommand(CmdType.EvtDoSkillSuccNotify)] public ValueTask OnEvtDoSkillSuccNotify(ILogger logger) { logger.LogDebug("DoSkillSucc raw={body}", Convert.ToHexString(Packet!.Body.Span)); return ValueTask.FromResult(Ok()); } internal static async ValueTask ForwardAsync(NetSession session, IEnumerable invokes) { AbilityInvocationsNotify forward = new(); foreach (AbilityInvokeEntry entry in invokes) { if (entry.ForwardType is ForwardType.ForwardLocal) continue; forward.Invokes.Add(entry); } if (forward.Invokes.Count != 0) await session.NotifyAsync(CmdType.AbilityInvocationsNotify, forward); } }