Skip to content

Exclusive Boss Rush Changes

Tien edited this page Aug 16, 2024 · 1 revision

Exclusive Boss Rush Changes

This page contains information about being able to change general behavior for bosses, their minions and projectiles when in Boss Rush Event.

Introduction

This is mostly possible thanks to tModLoader API. tModLoader API provides GlobalNPC and GlobalProjectile classes that can be used to modify behavior of existing NPCs and projectiles, be it vanilla or modded.

Example Code

using BossRushAPI;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using BRS = BossRushAPI.BossRushSystem;

namespace MyBossRushMod;

public class BossRushQueenBee : GlobalNPC
{
    public override bool AppliesToEntity(NPC entity, bool lateInstantiation)
    {
        return lateInstantiation && entity.type == NPCID.QueenBee;
    }

    public sealed override void PostAI(NPC npc)
    {
        if (BRS.I.IsBossRushActive)
        {
            DoSomething();
        }
    }

    private void DoSomething()
    {
        if (Main.netMode != NetmodeID.MultiplayerClient)
        {
            npc.life += 1; // Regenrate 1 life every frame. This is just an example.
            npc.netUpdate = true;
        }
    }
}

We can use the instance property IsBossRushActive from BossRushSystem to check if the Boss Rush Event is active. In this example, we allow Queen Bee to regenerate her life by 1 every frame only when the Boss Rush Event is active.

Exposed Events

The Boss Rush API contains public events that can be used to hook into the SetDefaults method of the API's GlobalNPC called BossAndMinions which is responsible for automatically computing stats based on ModifiedAttributes struct. The available events are as follows:

  1. static event Action<NPC, ModifiedAttributes> PreSetDefaults - Hook before the ModifiedAttributes struct is computed on the NPC's stats.
  2. static event Action<NPC, ModifiedAttributes> PostSetDefaults - Hook after the ModifiedAttributes struct is computed on the NPC's stats.

These are useful when there is a need to modify the stats, for example maybe according to custom tiers or difficulties. For example, below is the code to change the base Max HP of all bosses to 500,000 points.

public override void Load()
{
    BossAndMinions.PreSetDefaults += PreSetDefaults;
}

public override void Unload()
{
    BossAndMinions.PreSetDefaults -= PreSetDefaults;
}

private void PreSetDefaults(NPC npc, ModifiedAttributes attributes)
{
    npc.lifeMax = 500000;
    if (npc.type == NPCID.MoonLord)
    {
        npc.lifeMax = 1000000;
    }
}

In the example above, we also made an exception for Moon Lord to have 1,000,000 points of health instead.

Clone this wiki locally