evilfactory / LuaCsForBarotrauma

Modification for Barotrauma that improves modding support.
http://www.barotraumagame.com/
77 stars 21 forks source link

Use `GetDerivedNonAbstract` for `CharacterAbilityGroup::ConstructCondition` #186

Open G-M-twostay opened 8 months ago

G-M-twostay commented 8 months ago

Disclaimers

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

evilfactory commented 8 months ago

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.

G-M-twostay commented 8 months ago

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

MapleWheels commented 3 weeks ago

This will be addressed in the Services Refactor.