45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using NeonSprawl.Server.Game.Npc;
|
|
|
|
namespace NeonSprawl.Server.Game.Combat;
|
|
|
|
/// <summary>Deterministic NPC telegraph-complete damage resolve (NEO-95).</summary>
|
|
public static class NpcAttackOperations
|
|
{
|
|
/// <summary>
|
|
/// Applies catalog <paramref name="attackDamage"/> to <paramref name="holderPlayerId"/> when
|
|
/// the threat row still names that holder for <paramref name="npcInstanceId"/>.
|
|
/// </summary>
|
|
public static bool TryResolveTelegraphComplete(
|
|
string npcInstanceId,
|
|
string holderPlayerId,
|
|
int attackDamage,
|
|
IPlayerCombatHealthStore playerHealthStore,
|
|
IThreatStateStore threatStore)
|
|
{
|
|
if (attackDamage <= 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(holderPlayerId) ||
|
|
!threatStore.TryGet(npcInstanceId, out var threat) ||
|
|
string.IsNullOrEmpty(threat.AggroHolderPlayerId) ||
|
|
!string.Equals(threat.AggroHolderPlayerId, holderPlayerId, StringComparison.Ordinal))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!playerHealthStore.TryApplyDamage(holderPlayerId, attackDamage, out var snapshot))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (snapshot.Defeated)
|
|
{
|
|
// TODO(E9.M1): player_death
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|