yuanshen/Yuanshen.Gameserver/Controllers/CombatController.cs
wisedev 49450270db World drops, group based spawning and a pile of fixes
Drops now land on the ground as gadgets and are picked up with F instead of
appearing in the bag out of nowhere. Chests, ore, crystals and plants all spawn
and can be interacted with.

Monsters load by scene group rather than by a radius around each one, so a camp
shows up as a camp and nothing pops into existence mid fight. The group anchors
come out of the scene Lua, which also killed four invented tuning constants.

The gateway was creating a whole new session for every handshake datagram, and
the client retransmits those until it gets an answer. That is where the piles of
duplicated monsters and the chests coming back from the dead were coming from.

Also: monster level scales to the party now, path queries return an actual two
point path instead of an empty one, NpcTalk closes properly, and the ability and
combat invocations are no longer echoed back to the client that sent them.
2026-09-04 17:44:02 +03:00

90 lines
3.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 Google.Protobuf;
using Microsoft.Extensions.Logging;
namespace Yuanshen.Gameserver.Controllers;
[NetController]
internal sealed class CombatController : ControllerBase
{
[NetCommand(CmdType.UnionCmdNotify)]
public async ValueTask<IResult> OnUnionCmdNotify(GameState state, Player player, NetSession session, CombatManager combat, WorldSpawner worldSpawner, ILogger<CombatController> logger)
{
UnionCmdNotify notify = Packet!.DecodeBody<UnionCmdNotify>();
foreach (UnionCmd cmd in notify.CmdList)
{
if (cmd.MessageId == (uint)CmdType.CombatInvocationsNotify)
await ProcessCombatInvocationsAsync(CombatInvocationsNotify.Parser.ParseFrom(cmd.Body), state, player, combat, worldSpawner, logger, session);
}
return Ok();
}
[NetCommand(CmdType.CombatInvocationsNotify)]
public async ValueTask<IResult> OnCombatInvocationsNotify(GameState state, Player player, CombatManager combat, WorldSpawner worldSpawner, ILogger<CombatController> logger, NetSession session)
{
await ProcessCombatInvocationsAsync(Packet!.DecodeBody<CombatInvocationsNotify>(), state, player, combat, worldSpawner, logger, session);
return Ok();
}
[NetCommand(CmdType.EvtBeingHitNotify)]
public async ValueTask<IResult> OnEvtBeingHitNotify(CombatManager combat)
{
EvtBeingHitNotify notify = Packet!.DecodeBody<EvtBeingHitNotify>();
if (notify.BeingHitInfo?.AttackResult is not null)
await combat.HandleAttackAsync(notify.BeingHitInfo.AttackResult);
return Ok();
}
[NetCommand(CmdType.EvtBeingHitsCombineNotify)]
public async ValueTask<IResult> OnEvtBeingHitsCombineNotify(CombatManager combat)
{
EvtBeingHitsCombineNotify notify = Packet!.DecodeBody<EvtBeingHitsCombineNotify>();
foreach (EvtBeingHitInfo hit in notify.EvtBeingHitInfoList)
{
if (hit.AttackResult is not null)
await combat.HandleAttackAsync(hit.AttackResult);
}
return Ok();
}
private static async ValueTask ProcessCombatInvocationsAsync(CombatInvocationsNotify notify, GameState state, Player player, CombatManager combat, WorldSpawner worldSpawner, ILogger logger, NetSession session)
{
uint activeEntityId = player.ActiveAvatar?.EntityId ?? 0;
foreach (CombatInvokeEntry entry in notify.InvokeList)
{
switch (entry.ArgumentType)
{
case CombatTypeArgument.EntityMove:
EntityMoveInfo move = EntityMoveInfo.Parser.ParseFrom(entry.CombatData);
if (move.EntityId == activeEntityId && move.MotionInfo?.Pos is not null)
{
state.UpdatePosition(move.MotionInfo.Pos);
await worldSpawner.StreamAsync(move.MotionInfo.Pos);
}
break;
case CombatTypeArgument.CombatEvtBeingHit:
EvtBeingHitInfo hit = EvtBeingHitInfo.Parser.ParseFrom(entry.CombatData);
logger.LogInformation("HIT defense={d} damage={dmg} forward={f}",
hit.AttackResult?.DefenseId, hit.AttackResult?.Damage, entry.ForwardType);
if (hit.AttackResult is not null)
await combat.HandleAttackAsync(hit.AttackResult);
break;
default:
logger.LogDebug("combat arg={arg} fwd={f}", entry.ArgumentType, entry.ForwardType);
break;
}
}
}
}