LuaCsForBarotrauma icon indicating copy to clipboard operation
LuaCsForBarotrauma copied to clipboard

Use `GetDerivedNonAbstract` for `CharacterAbilityGroup::ConstructCondition`

Open G-M-twostay opened this issue 7 months ago • 2 comments

Disclaimers

  • [X] I have searched the issue tracker to check if the issue has already been reported.
  • [ ] My issue happened while using mods.

What happened?

In the current implementation it uses conditionType = Type.GetType("Barotrauma.Abilities." + type + "", false, true); to find the type of AbilityCondition. However, this is very hard coded and makes extending AbilityConditions, for example adding own new types of AbilityConditions, extremely hard. This is also not consistent with other places like AfflictionPrefab and ItemComponent, where both uses ReflectionUtils.GetDerivedNonAbstract. You may search "GetDerivedNonAbstract" to verify its usages. Given that lua for baro modifies this method to also include modded assemblies with the purposes of making the game more extendable, AbilityCondition should also be constructed using this method.

Therefore the change I propose to change the hard coded Type.GetType line to ReflectionUtils.GetDerivedNonAbstract<AbilityCondition>().First() (or smth like this). This should not change XML behaviors as all vanilla AbilityConditions are subclasses of AbilityCondition with the benefit of making creating new ones way more easier.

Reproduction steps

Problem described above.

Bug prevalence

Just once

Single player or multiplayer?

Single player

-

No response

Version

v1.2.8.0 (Winter Update hotfix 2)

-

No response

Which operating system did you encounter this bug on?

Windows

Relevant error messages and crash reports

No response

G-M-twostay avatar Jan 24 '24 03:01 G-M-twostay

If you could make a PR with the changes and do some basic QA (make sure it doesn't break anything), it would be nice.

evilfactory avatar Jan 24 '24 03:01 evilfactory

i will try to do some qa, but I haven't compiled baro before.

G-M-twostay avatar Jan 26 '24 01:01 G-M-twostay