96 lines
2.9 KiB
C#
96 lines
2.9 KiB
C#
using NeonSprawl.Server.Game.Items;
|
|
|
|
namespace NeonSprawl.Server.Game.Encounters;
|
|
|
|
/// <summary>
|
|
/// NEO-106: wires ability-cast combat outcomes to encounter activation, defeat progress, and completion grants.
|
|
/// Best-effort on the cast accept path — outcome does not change <c>AbilityCastResponse</c> JSON.
|
|
/// </summary>
|
|
public static class EncounterCombatWiring
|
|
{
|
|
/// <summary>
|
|
/// On damaging hits, activates encounter progress; on lethal hits, records defeat and may grant rewards.
|
|
/// </summary>
|
|
public static void TryProcessCastOutcome(
|
|
string playerId,
|
|
string targetNpcInstanceId,
|
|
int damageDealt,
|
|
bool targetDefeated,
|
|
IEncounterDefinitionRegistry encounterRegistry,
|
|
IRewardTableDefinitionRegistry rewardTableRegistry,
|
|
IEncounterProgressStore progressStore,
|
|
IEncounterCompletionStore completionStore,
|
|
IItemDefinitionRegistry itemRegistry,
|
|
IPlayerInventoryStore inventoryStore,
|
|
TimeProvider timeProvider,
|
|
ILogger? logger = null)
|
|
{
|
|
if (damageDealt > 0)
|
|
{
|
|
EncounterProgressOperations.TryActivateOnFirstEngagement(
|
|
playerId,
|
|
targetNpcInstanceId,
|
|
encounterRegistry,
|
|
progressStore,
|
|
completionStore);
|
|
}
|
|
|
|
if (!targetDefeated)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!EncounterProgressOperations.TryMarkTargetDefeated(
|
|
playerId,
|
|
targetNpcInstanceId,
|
|
encounterRegistry,
|
|
progressStore,
|
|
completionStore))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!EncounterProgressOperations.TryResolveEncounterForNpc(
|
|
targetNpcInstanceId,
|
|
encounterRegistry,
|
|
out var encounterId,
|
|
out _))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!EncounterProgressOperations.IsAllRequiredTargetsDefeated(
|
|
playerId,
|
|
encounterId,
|
|
encounterRegistry,
|
|
progressStore))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var completion = EncounterCompletionOperations.TryCompleteAndGrant(
|
|
playerId,
|
|
encounterId,
|
|
encounterRegistry,
|
|
rewardTableRegistry,
|
|
progressStore,
|
|
completionStore,
|
|
itemRegistry,
|
|
inventoryStore,
|
|
timeProvider);
|
|
|
|
if (!completion.Success)
|
|
{
|
|
logger?.LogDebug(
|
|
"Encounter completion grant skipped for player {PlayerId} encounter {EncounterId} ({ReasonCode})",
|
|
playerId,
|
|
encounterId,
|
|
completion.ReasonCode);
|
|
return;
|
|
}
|
|
|
|
// --- Telemetry hook site (NEO-109): future E9.M1 catalog event `encounter_complete` ---
|
|
// TODO(E9.M1): catalog emit — once per player+encounter when grants commit (NEO-106 cast path).
|
|
}
|
|
}
|