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

BelongsToInvasion NPC sets #3558

Merged
merged 10 commits into from
Jul 3, 2023

Conversation

direwolf420
Copy link
Contributor

@direwolf420 direwolf420 commented Jun 18, 2023

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), a ModSceneEffect 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?

  1. 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 for InvasionID.

  2. To minimize the patch associated with InvasionSlotCount I just kept the vanilla code the same and let tml overwrite the value.

  3. The patches that handle music are kept the same as the NPC.GetNPCInvasionGroup patches currently, you can make use of copied vanilla magic numbers for MusicID otherwise.

  4. 520 (Martian Walker) doesn't get checked in NPC.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.

  5. The only use for NoInvasionMusic is for 387 (Tesla Turret), I made it a set anyway because mods may add similar things that are temporary but contribute to progress.

  6. I named the set responsible for frost legion BelongsToInvasionFrostLegion instead of matching InvasionID.SnowLegion. Could be changed to match, but then you also would need to change BelongsToInvasionPirate to BelongsToInvasionPirateInvasion to match InvasionID.PirateInvasion, which does look awkward, hence why I didn't match it either.

  7. InvasionSlotCount has a default of 1 which technically makes things that aren't in any invasions act as if they would decrease the count. If it were 0, 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

NPCID.Sets.BelongsToInvasionGoblinArmy[NPC.type] = true; // Make it count towards goblin army for music playback and invasion progress
NPCID.Sets.InvasionSlotCount[NPC.type] = 5; // Make it count as 5 enemies defeated for the invasion progress
NPCID.Sets.NoInvasionMusic[NPC.type] = true; // Rarely used, for example a temporary enemy that is alive after the invasion ends but does not have InvasionSlotCount 0

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

  • Use the NPCID.Sets.BelongsToInvasionX sets for non wave-based invasion enemies. You can remove custom music code (i.e. from a ModSceneEffect) that sets the invasion music, and any code that handles wave progress through Main.invasionSize. To customize by how much Main.invasionSize would be previously decremented by, use NPCID.Sets.InvasionSlotCount

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants