-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Criticals into CriticalEffects and ComponentCriticals to remove Lazy<>. Moved some criticals-related classes into own files. Changed some logs from Trace to Debug.
- Loading branch information
Showing
7 changed files
with
174 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using BattleTech; | ||
using CustomComponents; | ||
|
||
namespace MechEngineer.Features.CriticalEffects; | ||
|
||
internal readonly struct ComponentCriticals | ||
{ | ||
internal readonly MechComponent component; | ||
private AbstractActor actor => component.parent; | ||
|
||
internal ComponentCriticals(MechComponent component) | ||
{ | ||
this.component = component; | ||
if (actor == null) | ||
{ | ||
throw new NullReferenceException($"{nameof(actor)} is null"); | ||
} | ||
} | ||
|
||
internal int ComponentHittableCount() | ||
{ | ||
return ComponentHitMax() - ComponentHitCount(); | ||
} | ||
|
||
internal int ComponentHitMax() | ||
{ | ||
var inventorySize = component.componentDef.Is<CriticalChanceCustom>(out var chance) ? chance.Size : component.componentDef.InventorySize; | ||
// TODO fix size correctly for location: | ||
// introduce fake items for overflow location that is crit linked and overwrite component hit max for original + crit linked | ||
var additionalSize = component.componentDef.Is<DynamicSlots.DynamicSlots>(out var slot) && slot.InnerAdjacentOnly ? slot.ReservedSlots : 0; | ||
return inventorySize + additionalSize; | ||
} | ||
|
||
internal int ComponentHitCount(int? setHits = null) | ||
{ | ||
var stat = component.StatCollection.MECriticalSlotsHit(); | ||
stat.CreateIfMissing(); // move to Mech.init and remove "CreateIfMissing" from StatAdapter | ||
if (setHits.HasValue) | ||
{ | ||
stat.SetValue(setHits.Value); | ||
} | ||
return stat.Get(); | ||
} | ||
|
||
internal int ComponentHitArmoredCount(int? setHits = null) | ||
{ | ||
var stat = component.StatCollection.MECriticalSlotsHitArmored(); | ||
stat.CreateIfMissing(); // move to Mech.init and remove "CreateIfMissing" from StatAdapter | ||
if (setHits.HasValue) | ||
{ | ||
stat.SetValue(setHits.Value); | ||
} | ||
return stat.Get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Linq; | ||
using BattleTech; | ||
using MechEngineer.Features.CriticalEffects.Patches; | ||
using MechEngineer.Features.PlaceholderEffects; | ||
|
||
namespace MechEngineer.Features.CriticalEffects; | ||
|
||
internal class EffectIdUtil | ||
{ | ||
private readonly string templateEffectId; | ||
private readonly string resolvedEffectId; | ||
private readonly MechComponent mechComponent; | ||
|
||
internal EffectIdUtil(string templateEffectId, string resolvedEffectId, MechComponent mechComponent) | ||
{ | ||
this.templateEffectId = templateEffectId; | ||
this.resolvedEffectId = $"MECriticalHitEffect_{resolvedEffectId}_{mechComponent.parent.GUID}"; | ||
this.mechComponent = mechComponent; | ||
} | ||
|
||
internal static void CreateEffect(MechComponent component, EffectData effectData, string effectId) | ||
{ | ||
var actor = component.parent; | ||
|
||
Log.Main.Debug?.Log($"Creating id={effectId} statName={effectData.statisticData.statName}"); | ||
|
||
EffectManager_GetTargetStatCollections_Patch.SetContext(component, effectData); | ||
try | ||
{ | ||
actor.Combat.EffectManager.CreateEffect(effectData, effectId, -1, actor, actor, default, 0); | ||
} | ||
finally | ||
{ | ||
EffectManager_GetTargetStatCollections_Patch.ClearContext(); | ||
} | ||
} | ||
|
||
internal void CreateCriticalEffect() | ||
{ | ||
var effectData = CriticalEffectsFeature.GetEffectData(templateEffectId); | ||
if (effectData == null) | ||
{ | ||
return; | ||
} | ||
if (effectData.targetingData.effectTriggerType != EffectTriggerType.Passive) // we only support passive for now | ||
{ | ||
Log.Main.Warning?.Log($"Effect templateEffectId={templateEffectId} is not passive"); | ||
return; | ||
} | ||
|
||
PlaceholderEffectsFeature.ProcessLocationalEffectData(ref effectData, mechComponent); | ||
|
||
CreateEffect(mechComponent, effectData, resolvedEffectId); | ||
} | ||
|
||
internal void CancelCriticalEffect() | ||
{ | ||
var actor = mechComponent.parent; | ||
var statusEffects = actor.Combat.EffectManager | ||
.GetAllEffectsWithID(resolvedEffectId) | ||
.Where(e => e.Target == actor); | ||
|
||
Log.Main.Debug?.Log($"Canceling id={resolvedEffectId}"); | ||
foreach (var statusEffect in statusEffects) | ||
{ | ||
Log.Main.Debug?.Log($"Canceling statName={statusEffect.EffectData.statisticData.statName}"); | ||
actor.CancelEffect(statusEffect); | ||
} | ||
} | ||
} |
Oops, something went wrong.