Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the new feature?
New sets for non wave-based invasions (goblin army, pirate, frost legion, martian madness), which take care of handling the invasion progress and music playback.
Added complementary sets for how much progress individual NPCs contribute and if an NPC should not play music despite being an event NPC.
The naming is based on the existing set
BelongsToInvasionOldOnesArmy
.Why should this be part of tModLoader?
Currently, modders have to write alot of boilerplate to make enemies work with invasions properly.
For playing music, since
ModNPC.Music
does not work on things that don't already have music by default (i.e. bosses), aModSceneEffect
is required which checks for alive NPCs.For handling invasion progress, code that handles that and the multiplayer side of it is required to be added to
ModNPC.OnKill/checkDead
hooks.If any mods need to identify which invasion an NPC belongs to (vanilla or modded), these sets become valuable.
Are there alternative designs?
Regarding patches, you could make the
NPC.GetNPCInvasionGroup
patches in a way where you don't touch the switch cases at all and instead re-assign the values, just need to use the magic numbers forInvasionID
.To minimize the patch associated with
InvasionSlotCount
I just kept the vanilla code the same and let tml overwrite the value.The patches that handle music are kept the same as the
NPC.GetNPCInvasionGroup
patches currently, you can make use of copied vanilla magic numbers forMusicID
otherwise.520 (Martian Walker)
doesn't get checked inNPC.GetNPCInvasionGroup
for the martian madness, this is probably a vanilla bug. I didn't include it in the set, so I had to leave the manual check for it in the music code.EDIT: This has been confirmed as a bug by CB, fixed on 1.4.5. This PR "backports" the fix for less maintenance when that update arrives.
The only use for
NoInvasionMusic
is for387 (Tesla Turret)
, I made it a set anyway because mods may add similar things that are temporary but contribute to progress.I named the set responsible for frost legion
BelongsToInvasionFrostLegion
instead of matchingInvasionID.SnowLegion
. Could be changed to match, but then you also would need to changeBelongsToInvasionPirate
toBelongsToInvasionPirateInvasion
to matchInvasionID.PirateInvasion
, which does look awkward, hence why I didn't match it either.InvasionSlotCount
has a default of1
which technically makes things that aren't in any invasions act as if they would decrease the count. If it were0
, you'd require alot more assignments in the set to match vanilla behavior. Since the set is only accessed if the NPC matches an invasion, it makes sense to keep it that way.Disclaimer: I have purposefully not touched anything related to wave-based invasions (frost moon, OOA), their code is handled differently. I suggest it should be a separate PR if the need arises.
Sample usage for the new feature
ExampleMod updates
Ideally an invasion enemy could be added but I personally don't have the time (or sprites) for this. It would need to include the set usage here, aswell as spawning only if an invasion is ongoing, and code (either ModNPC.AIType or custom) to make it "flee" if the invasion is over.
Porting Notes
NPCID.Sets.BelongsToInvasionX
sets for non wave-based invasion enemies. You can remove custom music code (i.e. from aModSceneEffect
) that sets the invasion music, and any code that handles wave progress throughMain.invasionSize
. To customize by how muchMain.invasionSize
would be previously decremented by, useNPCID.Sets.InvasionSlotCount