yuanshen/Yuanshen.Gameserver/Controllers/AbilityController.cs
wisedev 61cc2055cf First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:06:53 +03:00

72 lines
2.7 KiB
C#

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<IResult> OnAbilityInvocationsNotify(NetSession session)
{
AbilityInvocationsNotify notify = Packet!.DecodeBody<AbilityInvocationsNotify>();
await ForwardAsync(session, notify.Invokes);
return Ok();
}
[NetCommand(CmdType.ClientAbilityInitFinishNotify)]
public async ValueTask<IResult> OnClientAbilityInitFinishNotify(NetSession session, Player player, SceneManager scene, ILogger<AbilityController> logger)
{
ClientAbilityInitFinishNotify notify = Packet!.DecodeBody<ClientAbilityInitFinishNotify>();
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<IResult> OnClientAbilityChangeNotify(NetSession session)
{
ClientAbilityChangeNotify notify = Packet!.DecodeBody<ClientAbilityChangeNotify>();
await ForwardAsync(session, notify.Invokes);
return Ok();
}
[NetCommand(CmdType.EvtDoSkillSuccNotify)]
public ValueTask<IResult> OnEvtDoSkillSuccNotify(ILogger<AbilityController> logger)
{
logger.LogDebug("DoSkillSucc raw={body}", Convert.ToHexString(Packet!.Body.Span));
return ValueTask.FromResult(Ok());
}
internal static async ValueTask ForwardAsync(NetSession session, IEnumerable<AbilityInvokeEntry> 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);
}
}