Skip to content

Commit

Permalink
Fix Iceborg Self Shield shield on next turn if depleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheneq committed Jun 4, 2024
1 parent d34e95a commit e522ee2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
1 change: 1 addition & 0 deletions Assembly-CSharp/AbilityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public bool HasQueuedAction(ActionType actionType) // , checkExecutedForPve in
return result;
}

// TODO check it is used carefully as forced chase cancels queued abilities to free up movement
public bool HasQueuedAbilityOfType(Type abilityType) // , checkExecutedForPve in rogues
{
ActionType actionTypeOfAbility = GetActionTypeOfAbility(GetAbilityOfType(abilityType));
Expand Down
21 changes: 21 additions & 0 deletions Assembly-CSharp/IceborgSelfShield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class IceborgSelfShield : GenericAbility_Container
private AbilityMod_IceborgSelfShield m_abilityMod;
private Iceborg_SyncComponent m_syncComp;

#if SERVER
// custom
private Passive_Iceborg m_passive;
#endif

public override List<string> GetContextNamesForEditor()
{
List<string> contextNamesForEditor = base.GetContextNamesForEditor();
Expand All @@ -34,6 +39,15 @@ protected override void SetupTargetersAndCachedVars()
{
m_syncComp = GetComponent<Iceborg_SyncComponent>();
base.SetupTargetersAndCachedVars();

#if SERVER
// custom
PassiveData passiveData = GetComponent<PassiveData>();
if (passiveData != null)
{
m_passive = passiveData.GetPassiveOfType(typeof(Passive_Iceborg)) as Passive_Iceborg;
}
#endif
}

protected override void AddSpecificTooltipTokens(List<TooltipTokenEntry> tokens, AbilityMod modAsBase)
Expand Down Expand Up @@ -83,6 +97,13 @@ protected override void GenModImpl_ClearModRef()
}

#if SERVER
// custom
public override void Run(List<AbilityTarget> targets, ActorData caster, ServerAbilityUtils.AbilityRunData additionalData)
{
base.Run(targets, caster, additionalData);
m_passive?.OnSelfShieldCast();
}

// custom
protected override void PreProcessForCalcAbilityHits(
List<AbilityTarget> targets,
Expand Down
63 changes: 40 additions & 23 deletions Assembly-CSharp/Passive_Iceborg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Passive_Iceborg : Passive
Iceborg_SyncComponent m_syncComp;
private IceborgSelfShield m_shieldAbility;
private bool m_pendingShieldDepletionAnimation;
private int m_lastSelfShieldCastTurn;

protected override void OnStartup()
{
Expand All @@ -17,35 +18,30 @@ protected override void OnStartup()
m_syncComp = Owner.GetComponent<Iceborg_SyncComponent>();
m_shieldAbility = Owner.GetAbilityData().GetAbilityOfType(typeof(IceborgSelfShield)) as IceborgSelfShield;
}


public void OnSelfShieldCast()
{
m_lastSelfShieldCastTurn = GameFlowData.Get().CurrentTurn;
m_pendingShieldDepletionAnimation = true;
}

public override void OnTurnEnd()
{
base.OnTurnEnd();

AbilityData abilityData = Owner.GetAbilityData();
if (abilityData != null && abilityData.HasQueuedAbilityOfType(typeof(IceborgSelfShield)))
if (m_lastSelfShieldCastTurn == GameFlowData.Get().CurrentTurn)
{
m_pendingShieldDepletionAnimation = true;

if (Owner.AbsorbPoints == 0)
if (Owner.AbsorbPoints == 0) // or shieldEffect == null || shieldEffect.GetRemainingAbsorb() <= 0?
// Shorter shields like NanoSmithBlastShield will be consumed first anyway.
// Fellow two-turn shields are consumed in undefined order, so we need to define a consistent behaviour ourselves.
// And for e.g. NanoSmithWeaponsOfWar to be consistent with NanoSmithBlastShield, it makes sense to consume this shield first.
// The only longer shield is modded NanoSmithWeaponsOfWar but do we want to make it an exception to the pattern?
{
int shieldOnNextTurnIfDepleted = m_shieldAbility.GetShieldOnNextTurnIfDepleted();
if (shieldOnNextTurnIfDepleted > 0)
{
Log.Info($"ICEBORG PASSIVE {Owner.m_displayName} applying additional shielding");
StandardActorEffect shieldEffect = GenericAbility_Container.CreateShieldEffect(
m_shieldAbility,
Owner,
shieldOnNextTurnIfDepleted,
1);

ActorHitResults actorHitResults = new ActorHitResults(new ActorHitParameters(Owner, Owner.GetFreePos()));
actorHitResults.AddEffect(shieldEffect);
MovementResults.SetupAndExecuteAbilityResultsOutsideResolution(
Owner,
Owner,
actorHitResults,
m_shieldAbility);
ApplyAdditionalShieldEffect();
}
else
{
Expand Down Expand Up @@ -84,10 +80,7 @@ public override void OnTurnStart()
}
else
{
Effect activeEffect = ServerEffectManager.Get()
.GetEffectsOnTargetByCaster(Owner, Owner, typeof(StandardActorEffect))
.FirstOrDefault(eff => eff.Parent.Ability is IceborgSelfShield);
if (activeEffect is null)
if (GetActiveSelfShieldEffect() is null)
{
// play shield depletion animation
MovementResults.SetupAndExecuteAbilityResultsOutsideResolution(
Expand All @@ -102,5 +95,29 @@ public override void OnTurnStart()
}
}
}

private Effect GetActiveSelfShieldEffect()
{
return ServerEffectManager.Get()
.GetEffectsOnTargetByCaster(Owner, Owner, typeof(StandardActorEffect))
.FirstOrDefault(eff => eff.Parent.Ability is IceborgSelfShield);
}

private void ApplyAdditionalShieldEffect()
{
StandardActorEffect shieldEffect = GenericAbility_Container.CreateShieldEffect(
m_shieldAbility,
Owner,
m_shieldAbility.GetShieldOnNextTurnIfDepleted(),
1);

ActorHitResults actorHitResults = new ActorHitResults(new ActorHitParameters(Owner, Owner.GetFreePos()));
actorHitResults.AddEffect(shieldEffect);
MovementResults.SetupAndExecuteAbilityResultsOutsideResolution(
Owner,
Owner,
actorHitResults,
m_shieldAbility);
}
#endif
}

0 comments on commit e522ee2

Please sign in to comment.