Add tutorial and QoL improvements
This commit is contained in:
@@ -21,6 +21,39 @@ namespace KernelPanic.Combat
|
||||
TrueDamage = trueDamage;
|
||||
CanCrit = canCrit;
|
||||
ApplySourceModifiers = applySourceModifiers;
|
||||
LazyMultiplierPercent = 100;
|
||||
CompilationPercent = 100;
|
||||
IsCardDamage = false;
|
||||
Cause = null;
|
||||
}
|
||||
|
||||
// Explicit provenance: DOT, package damage, enemy damage, recoil and spill use the
|
||||
// original constructor, so none can inherit a card's execution modifiers accidentally.
|
||||
public static DamageRequest FromCard(CombatContext context, CombatantState target, int amount,
|
||||
Language language, bool trueDamage, bool canCrit) => new(
|
||||
new DamageRequest(context.Source, target, amount, language, trueDamage, canCrit), context);
|
||||
|
||||
private DamageRequest(DamageRequest request, CombatContext context)
|
||||
: this(request.Source, request.Target, request.Amount, request.Language, request.TrueDamage, request.CanCrit)
|
||||
{
|
||||
IsCardDamage = true;
|
||||
LazyMultiplierPercent = context.LazyMultiplierPercent;
|
||||
CompilationPercent = context.CombatManager?.Compilation.DamagePercent ?? 100;
|
||||
}
|
||||
|
||||
// Preview requests retain card provenance without executing a card or constructing a
|
||||
// mutable combat context. Multipliers describe the prospective execution snapshot.
|
||||
public static DamageRequest PreviewCard(CombatantState source, CombatantState target, int amount,
|
||||
Language language, bool trueDamage, bool canCrit, int lazyPercent, int compilationPercent) =>
|
||||
new(source, target, amount, language, trueDamage, canCrit, lazyPercent, compilationPercent);
|
||||
|
||||
private DamageRequest(CombatantState source, CombatantState target, int amount,
|
||||
Language language, bool trueDamage, bool canCrit, int lazyPercent, int compilationPercent)
|
||||
: this(source, target, amount, language, trueDamage, canCrit)
|
||||
{
|
||||
IsCardDamage = true;
|
||||
LazyMultiplierPercent = lazyPercent;
|
||||
CompilationPercent = compilationPercent;
|
||||
}
|
||||
|
||||
public CombatantState Source { get; }
|
||||
@@ -30,6 +63,22 @@ namespace KernelPanic.Combat
|
||||
public bool TrueDamage { get; }
|
||||
public bool CanCrit { get; }
|
||||
public bool ApplySourceModifiers { get; }
|
||||
public bool IsCardDamage { get; }
|
||||
public int LazyMultiplierPercent { get; }
|
||||
public int CompilationPercent { get; }
|
||||
public string Cause { get; }
|
||||
|
||||
public DamageRequest WithCause(string cause) => new(this, cause);
|
||||
|
||||
private DamageRequest(DamageRequest request, string cause)
|
||||
: this(request.Source, request.Target, request.Amount, request.Language, request.TrueDamage,
|
||||
request.CanCrit, request.ApplySourceModifiers)
|
||||
{
|
||||
IsCardDamage = request.IsCardDamage;
|
||||
LazyMultiplierPercent = request.LazyMultiplierPercent;
|
||||
CompilationPercent = request.CompilationPercent;
|
||||
Cause = cause;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct DamageResult
|
||||
@@ -59,7 +108,34 @@ namespace KernelPanic.Combat
|
||||
/// </summary>
|
||||
public sealed class DamagePipeline
|
||||
{
|
||||
public System.Func<DamageRequest, int, int> ResistanceResolver { get; set; }
|
||||
private System.Func<DamageRequest, int, int> _resistanceResolver;
|
||||
public System.Func<DamageRequest, int, int> ResistanceResolver
|
||||
{
|
||||
get => _resistanceResolver;
|
||||
set
|
||||
{
|
||||
if (_resistanceResolver != value) PreviewResistanceResolver = null;
|
||||
_resistanceResolver = value;
|
||||
}
|
||||
}
|
||||
// Only explicitly pure resistance resolvers are usable by a read-only preview. Never
|
||||
// invoke the runtime delegate here: custom runtime hooks may consume resources.
|
||||
public System.Func<DamageRequest, int, int> PreviewResistanceResolver { get; set; }
|
||||
|
||||
public bool CanPreviewResistance => ResistanceResolver == null || PreviewResistanceResolver != null;
|
||||
|
||||
public int PreviewIncomingDamage(DamageRequest request, bool critical = false,
|
||||
int? archStacks = null, int? sourceMultiplierPercent = null, int? cardMultiplierPercent = null)
|
||||
{
|
||||
int amount = Mathf.Max(0, request.Amount);
|
||||
if (request.ApplySourceModifiers)
|
||||
{
|
||||
amount = ApplyFlatAdditions(amount, request, out _, archStacks);
|
||||
amount = ApplyMultipliers(amount, request, sourceMultiplierPercent, cardMultiplierPercent);
|
||||
if (critical && CanRollCritical(request, amount)) amount = ScaleCritical(amount);
|
||||
}
|
||||
return PreviewResistanceResolver == null ? amount : PreviewResistanceResolver(request, amount);
|
||||
}
|
||||
|
||||
public DamageResult DefeatCombatant(CombatantState target, CombatantState source, Language language)
|
||||
{
|
||||
@@ -98,7 +174,7 @@ namespace KernelPanic.Combat
|
||||
int finalAmount = ApplyShieldAndUptime(amount, request, out int absorbedAmount, out int shieldDamage, out int uptimeDamage);
|
||||
ApplyArchRollingReleaseSave(request);
|
||||
bool rollingReleaseSaveTriggered = request.Target != null && request.Target.ArchRollingReleaseRecoveredThisHit;
|
||||
GameEvents.RaiseDamageDealt(new DamageDealtEvent(request.Source, request.Target, finalAmount, request.Language, amount, absorbedAmount, wasCritical, shieldDamage, uptimeDamage, request.TrueDamage, archBtwBonus, rollingReleaseSaveTriggered));
|
||||
GameEvents.RaiseDamageDealt(new DamageDealtEvent(request.Source, request.Target, finalAmount, request.Language, amount, absorbedAmount, wasCritical, shieldDamage, uptimeDamage, request.TrueDamage, archBtwBonus, rollingReleaseSaveTriggered).WithCause(request.Cause));
|
||||
|
||||
bool defeated = false;
|
||||
if (request.Target.CurrentUptime <= 0 && !request.Target.IsDefeated)
|
||||
@@ -111,7 +187,8 @@ namespace KernelPanic.Combat
|
||||
return new DamageResult(finalAmount, defeated, wasCritical, absorbedAmount, shieldDamage, uptimeDamage, amount);
|
||||
}
|
||||
|
||||
private static int ApplyMultipliers(int amount, DamageRequest request)
|
||||
private static int ApplyMultipliers(int amount, DamageRequest request,
|
||||
int? sourceMultiplierPercent = null, int? cardMultiplierPercent = null)
|
||||
{
|
||||
if (amount == int.MaxValue)
|
||||
{
|
||||
@@ -125,12 +202,14 @@ namespace KernelPanic.Combat
|
||||
return amount;
|
||||
}
|
||||
|
||||
int multiplier = request.Source == null ? 100 : Mathf.Max(0, request.Source.DamageMultiplierPercent);
|
||||
int currentCardMultiplier = request.Source == null ? 100 : Mathf.Max(0, request.Source.CurrentCardDamageMultiplierPercent);
|
||||
int multiplier = Mathf.Max(0, sourceMultiplierPercent ?? request.Source?.DamageMultiplierPercent ?? 100);
|
||||
int currentCardMultiplier = Mathf.Max(0, cardMultiplierPercent ?? request.Source?.CurrentCardDamageMultiplierPercent ?? 100);
|
||||
if (request.IsCardDamage && (request.LazyMultiplierPercent != 100 || request.CompilationPercent != 100))
|
||||
return CardScaling.Scale(amount, request.LazyMultiplierPercent, request.CompilationPercent, multiplier, currentCardMultiplier);
|
||||
return Mathf.RoundToInt(amount * (multiplier / 100f) * (currentCardMultiplier / 100f));
|
||||
}
|
||||
|
||||
private static int ApplyFlatAdditions(int amount, DamageRequest request, out int archBtwBonus)
|
||||
private static int ApplyFlatAdditions(int amount, DamageRequest request, out int archBtwBonus, int? archStacks = null)
|
||||
{
|
||||
archBtwBonus = 0;
|
||||
if (amount == int.MaxValue)
|
||||
@@ -145,7 +224,7 @@ namespace KernelPanic.Combat
|
||||
|
||||
if (request.Source != null && (request.Language == Language.C || request.Language == Language.Rust))
|
||||
{
|
||||
archBtwBonus = Mathf.Max(0, request.Source.ArchBtwStacks) * Mathf.Max(1, request.Source.ArchBtwDamagePerStack);
|
||||
archBtwBonus = Mathf.Max(0, archStacks ?? request.Source.ArchBtwStacks) * Mathf.Max(1, request.Source.ArchBtwDamagePerStack);
|
||||
amount += archBtwBonus;
|
||||
}
|
||||
|
||||
@@ -155,16 +234,22 @@ namespace KernelPanic.Combat
|
||||
private static int ApplyCrit(int amount, DamageRequest request, out bool wasCritical)
|
||||
{
|
||||
wasCritical = false;
|
||||
if (!request.CanCrit || amount <= 0 || amount == int.MaxValue || request.Source != null && request.Source.ForceMaxRolls)
|
||||
if (!CanRollCritical(request, amount))
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
int critChance = request.Language == Language.C ? 50 : 25;
|
||||
wasCritical = RandomRoll.RollRange(1, 100, new RollContext(request.Source)) <= critChance;
|
||||
return wasCritical ? Mathf.CeilToInt(amount * 1.5f) : amount;
|
||||
return wasCritical ? ScaleCritical(amount) : amount;
|
||||
}
|
||||
|
||||
private static bool CanRollCritical(DamageRequest request, int amount) =>
|
||||
request.CanCrit && amount > 0 && amount != int.MaxValue && !(request.Source?.ForceMaxRolls ?? false);
|
||||
|
||||
private static int ScaleCritical(int amount) =>
|
||||
(int)System.Math.Min(int.MaxValue, ((long)amount * 3 + 1) / 2);
|
||||
|
||||
private static void ApplyArchRollingReleaseSave(DamageRequest request)
|
||||
{
|
||||
CombatantState target = request.Target;
|
||||
|
||||
Reference in New Issue
Block a user