Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding weapon base damage for purposes of flyovers #1275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BlackDog86
Copy link
Contributor

Fixes #1274

@BlackDog86 BlackDog86 added enhancement ready-to-review A pull request is ready to be reviewed labels Oct 22, 2023
@BlackDog86 BlackDog86 self-assigned this Oct 22, 2023
@BlackDog86 BlackDog86 added this to the 1.27.0 milestone Oct 22, 2023
@Iridar
Copy link
Contributor

Iridar commented Oct 28, 2023

I think the displayed damage type on the flyover for applied damage should match the damage type actually applied to the target.

The trick is that an ability can apply damage of several types at the same time, which are gathered from different sources in X2Effect_ApplyWeaponDamage.

The var array<name> DamageTypes; lives in X2Effect, and if the target is immune to one of the damage types listed in this array, then the effect cannot be applied.

This functions a bit differently for X2Effect_ApplyWeaponDamage. Normally it has the DamageTypes array empty, and instead its various functions keep a local array of applied damage types going. It does start with AppliedDamageTypes = DamageTypes, and is then gradually appended by damage values gathered from different sources, unless the target is immune to that particular damage type.

I assume the rule of "effect won't be applied if the target is immune to a damage type listed in DamageTypes" still holds true for X2Effect_ApplyWeaponDamage, but once that threshold is passed, the effect can gather applied damage types from different sources, ignoring sources that add damage types the target is immune to.

For example, let's take an X2Effect_ApplyWeaponDamage that is set up to apply weapon damage, attached to a sword, and also its own EffectDamageValue, that has the fire damage type. Then the effect will normally apply both sources of damage summed up together, but if the target is immune to one of these, then only the other one will be applied.

And even if the target is immune to both, the effect will still be applied, the target just won't take any damage.

Unless, of course, either of these damage types is manually added to effect's DamageTypes array.

To summarize, an X2Effect_AWD can potentially apply damage of multiple types, and has its own logic for gathering the damage types.

Then the question is: which of the damage types should be displayed in flyover?

Well let's think about what the flyover can actually display, which is either generic damage or psionic damage.

So I think the task boils down to checking whether the effect is applying psionic damage or not. If yes, then display the psionic flyover. If not, then we don't care what other damage types are, the flyover will be the same either way.

All that said, to determine whether the effect applies psionic damage or not, we have to repeat the effect's process of gathering the damage type either way.

One huge huge caveat is that a custom X2Effect_ApplyWeaponDamage can have completely arbitrary logic for gathering applied damage types, so we can't reliably make a universal solution by copying vanilla logic from X2Effect_AWD.

What we can do is check what damage types have actually been applied to the unit. Visualization happens after the effect has already been applied by state code, so we can examine the var() array<DamageResult> DamageResults; on the XComGameState_Unit we're visualizing taking damage.

struct native DamageResult
{
	var int DamageAmount, MitigationAmount, ShieldHP, Shred;
	var bool bImmuneToAllDamage;	//	if ALL of the damage being dealt was 0'd out due to immunity, it will be tracked here
	var bool bFreeKill;     //  free kill weapon upgrade forced death of the unit
	var name FreeKillAbilityName;
	var EffectAppliedData SourceEffect;
	var XComGameStateContext Context;
	var array<DamageModifierInfo> SpecialDamageFactors;
	var array<name> DamageTypes;
};

Of particular interest are SourceEffect - this is how we'll find the DamageResults entry relevant to the instance of damage we're visualizing and DamageTypes - the bingo we're looking for.

Therefore, the task is:

  1. Get the visualized Unit State.
  2. Get the originating X2Effect.
  3. Iterate over DamageResults array on the Unit State until you find the entry the originating effect is responsible for.
  4. Check if the DamageTypes array on the Damage Result has psionic damage type in it or not. If yes, show psionic damage flyover. If not, show default damage flyover.

I think this is the optimal solution that covers all bases, but discussion is welcome.

@Iridar Iridar modified the milestones: 1.27.0, 1.28.0 Oct 29, 2023
@BlackDog86
Copy link
Contributor Author

Seems reasonable to me - I'll try to tackle this over the next few days :)

@Iridar Iridar changed the title Allow over-riding weapon base damage for purposes of flyovers Allow overriding weapon base damage for purposes of flyovers Mar 1, 2024
@Iridar Iridar modified the milestones: 1.28.0, 1.27.1, 1.29.0 May 1, 2024
@BlackDog86 BlackDog86 force-pushed the 1274-Ignore-Weapon-Base-Damage-For-Flyover branch from cd85a8f to 8cc3b7b Compare October 28, 2024 22:10
@BlackDog86 BlackDog86 force-pushed the 1274-Ignore-Weapon-Base-Damage-For-Flyover branch from 09ecbdf to d42c4b4 Compare October 28, 2024 23:26
@BlackDog86 BlackDog86 added waiting-on-author A pull request is waiting on changes from the author and removed ready-to-review A pull request is ready to be reviewed labels Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement waiting-on-author A pull request is waiting on changes from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

X2Effects which modify a weapon's base damage type do not visualise correctly
2 participants