Directors

As a Rogue-lite, Risk of Rain 2 features a lot of random generation as part of its gameplay - unlike many other action games, enemies and most items are randomized between different runs, both in their nature and location. The systems that manage these are called the Directors. Their main purpose is to manage spawning of Monsters and Interactables while keeping a balance between variety and consistency to ensure a fun experience and ever-different playthroughs.

Risk of Rain 2 uses two sets of Directors : The Scene Director, which is responsible for setting up the map when entering an Environment, and the Combat Directors, which are responsible for spawning enemies while players explore the map.

Basics and Terminology
Although both Directors work differently, they share some similar concepts. Understanding them is important to understand the finer details of their inner workings.

List of Directors
The number of Directors used by the game is equal to 6. Note however that not all of these Directors are active at the same time. Directors are classified into Instantaneous and Continuous Directors. Only active Directors can spawn monsters and interactables.

Instantaneous
Instantaneous Directors have a simple behavior : Once activated, they perform their spawns then immediately disable themselves.


 * The Scene Director is active during map setup. It is responsible for spawning all interactables as well as spawning the initial monsters present on the map when players teleport in.
 * The Teleporter Boss Director is active 3 seconds after players activate the Teleporter. It is responsible for spawning Teleporter Bosses.
 * The Shrine of Combat Director is active whenever a player activates a Shrine of Combat. It is responsible for spawning enemies that appear as parts of its activation.

Continuous
Continuous Directors activate and deactivate themselves based on various conditions. While active, these Directors will regularly receive credits and attempt spawns until they are disabled.


 * The two Standard Directors activate when players enter the map and deactivate 3 seconds after players activate the Teleporter. They are responsible for spawning most of the monsters players will encounter when exploring the map. Both Directors have very similar characteristics, however, they differ in their spawn rates. They will be called the Fast and Slow Directors in the rest of the article.
 * The Teleporter Director activates 3 seconds after players activate the Teleporter and deactivates when the Teleporter is fully charged. It is responsible for spawning enemies while the Teleporter is charging.

Director Credits
Just as players use money to purchase items, the Directors make use of a special, invisible currency called "credits". Instantaneous Directors gain a burst of credits which they immediately spend, while Continuous Directors accumulate and spend them over time while active. The number of credits received depend on the Director itself, though all directors use the same costs.

Spawn Cards
In order to determine what to spawn and at which frequencies, the Directors make use of a concept called Spawn Cards. A Spawn Card represents a single entity and has a Weight, a Credit Cost and Conditions. Every monster and non-static interactable in the game has a spawn card.


 * The Entity represents what will be spawned if the card is selected
 * The Weight represents the relative chance of the card to be picked
 * The Credit Cost represents how many credits a Director must spend to spawn the entity
 * The Conditions represent any additional conditions that must be fulfilled before the card can be used

Categories
All spawn cards belong to one of several Categories, which are simply a collection of spawn cards with a weight. Every map uses the same set of categories, however, the weight of the categories themselves vary depending on the map, and not all maps use all spawn cards. Some maps can also override the weight or cost of individual spawn cards although this is rare. Note that no interactables are spawned by the Scene Director on Gilded Coast, which is omitted from the table.

Weighting
Whenever a Director picks a spawn card, it does not do so completely randomly - it takes into account the computed weight of the element. The computed weight of the element depends on two things :


 * The relative weight of the category (Equal to the weight of the category divided by the sum of the weights of all categories)
 * The relative weight of the card (Equal to the weight of the element divided by the sum of the weights of all elements that can spawn on this map and within that category)

The final chance to be picked is equal to the product of these ratios.

Think of it like a lottery : First, every category puts in tickets equal to their weight (A category with a weight of 10 has 5 times more tickets than a category with a weight of 2). Then, a random ticket is picked : Its category is selected. The same thing then happens within the category : Every item puts in tickets equal to its weight, the winning spawn card is selected.

The Scene Director
When active during stage start, the Scene Director spawns everything at once. Once it has selected "reserved" spots for the Teleporter and player spawns, it starts populating the map with Interactables first then monsters. Finally, during clean-up, if at least one player has a Rusted Key, it will spawn a Lockbox. The item probabilities are determined at that time so changing the number of Rusted keys during the stage won't affect the contents of the Lockbox.

Credit Income
The Scene Director holds 2 credit budgets : One for its interactables and one for its monsters. The base amount of credits given to the Scene Director depends on the environment

The amount of interactable credits then gets increased by +50% per additional player beyond the first. For instance, on Abyssal Depths, the Scene Director will hold 400 credits in singleplayer, 600 with 2 players, 800 with 3 and a whopping 1000 with 4. This total represents how much the Director will have to work with.

The amount of monster credits is not increased by player count but rather multiplied by the Difficulty coefficient. For instance, this means that entering Abandoned Aqueduct in 2 player mode at the start of "Medium" (Which is a coeff of 2.3) will give the Director 230 credits to work with. The only exception to that rule is the first stage, which always has a credit amount set to 0.

Spawning Interactables
When spawning interactables, the Director will repeatedly select a spawn card from its deck, only selecting between cards it can pay for. It then pays for it, attempts to spawn it and starts again. The process is interrupted only if one of 2 conditions are met :


 * The Director credit count reaches 0 or less
 * The Director has no interactable it has credits for

Because there is no hard limit to the number of possible spawns, this means that almost all maps will hold at least one Barrel or Equipment Barrel since these interactables have a cost of 1 and a rather high weight - it is likely they'll be selected a few times when the Director has few credits remaining (Less than 10).

Spawning Monsters
When spawning monsters, the Director will the same routine as when spawning interactables, with one main difference : It has a limit of 40 monsters. When this limit is reached, the Director will discard its remaining credits and finish its setup. Monsters spawned this way do not use any of the checks used by the Combat Directors - they can never be ELite or too cheap for instance.

Monsters spawned by the Scene Director use their own reward coefficient of 0.667, which is one third of what an equivalent monster would give before the Teleporter Event. Details on how monster rewards are calculated are given in the Combat Director section.

The Combat Directors
The Combat Directors are responsible for spawning every monster that is not already spawned by the Scene Director.

Attributes
Every Combat Director has different attributes. They are summarized in the following tables. These attributes are referenced later.

Note that the Scene Director is only included for reference, it is not actually a Combat Director.

Instantaneous Directors
Instantaneous Directors receive a burst of credits when they are activated. The amount is specified on the "Income on activation" column. Once they spawned their wave, they deactivate.

Continuous Directors
Continuous Directors start at 0 credits, but have a credit generator attached. Every second, the generator grants some credits to its Director. The number of credits generated every second is equal to this formula :

$$Cps = creditMultiplier \times (1 + 0.4 \times coeff) \times (playerCount - 1) / 2$$

Here, creditMultiplier is the "Credit multiplier" attribute of the Director, playerCount refers to the amount of players in the game and coeff represents the current difficulty coefficient.

Director transfer
Whenever a Combat Director deactivates, it transfers 40% of its remaining credits to another randomly selected active director and discards the rest. If there are no other active Directors (such as when the Teleporter is charged), these credits are lost.

When activating the Teleporter, the activation of the Teleporter Directors precedes the deactivation of standard Directors, which means that they will receive the credits of the deactivating Directors. Which Director receives which one's credits is random however.

Spawn loop
While active, all Combat Directors, both instantaneous and continuous, will periodically attempt to spawn a monster. A spawn loop runs every frame and follows the following steps.

Pick a target
If the Director targets players, it selects one random living player as its target. When a player has been selected, the Director also sets a "retarget timer", random between 1 and 10 seconds. At the end of that timer, it will pick a random living player again as its next target (This may be the same as the previous one).

Directors that target an object will never switch to something else.

Check the timer
If the monster spawn timer is at 0 or less, the Director will attempt a spawn.

When they activate, all Directors start with a spawn timer of 0 which means they can immediately attempt a spawn. The Teleporter Boss Director starts with a spawn timer of -600 which means it will virtually never not attempt a spawn.

Attempt a spawn
If there are already 40 monsters or more on the map, the spawn will FAIL (Excepted the Teleporter Boss Director which bypasses this restriction)

If this is the first spawn attempt or the previous one was a FAIL, the Director picks a new spawn card from its deck. It also chooses an Elite type - these informations will be used to determine what monster spawns in the wave.

The Combat Shrine Director uses a special routine instead : It selects in advance (at the start of the map) a card which is valid and whose value is between 1/12 and 1/1 of its Director's credit. If it can't find such a card, it deactivates (spawning in an inactive state, as if already used).

The Teleporter Boss uses the standard routine but with one difference : When it activates, it decides randomly whether it only wants Champions (90% chance) or non-Champions (10%, this is a "Horde of Many" event). When it picks from the deck, it will only select cards that match this condition, also specifically excluding Golems. Curiously however, if the first spawn attempt fails, the standard selection mechanic is used from the 2nd one onwards.

Note that due to a bug, both of these special selection routines will always select Blazing - this is why Combat Shrine and Teleporter enemies spawn most of the time as Blazing.

Check the spawn card
The Director checks that the current card is valid for the spawn. It checks the 3 following conditions :


 * The spawn card conditions are met (i.e. a Hermit Crab was selected later than the first stage)
 * The Director can afford the monster (Its spawn cost is equal or lower than the Director's current credits)
 * The monster is not too cheap for the Director (The Director has less than 24 times the monster's cost in Credits, or 4 times the cost if the monster cannot spawn as an Elite) - this condition is ignored by the Combat Shrine Director

If all three conditions are met, the spawn will SUCCEED and the Director starts preparing the spawn - otherwise, it FAILS and the Director skips the spawn. Note that no credits are expended in this case.

Prepare the spawn
$$enemyXPReward = coeff * monsterValue * rewardMultiplier$$ $$enemyGoldReward = 2 * coeff * monsterValue * rewardMultiplier$$ where the Reward multiplier is a Director's attribute
 * 1) The Director prepares the monster matching the spawncard. It sets its HP and Damage multipliers at 1 and its value at its base cost.
 * 2) If the monster can spawn as an Elite and the Director has the credits for it (6 times its base cost), then it sets the monster as an Elite. Its HP multiplier is multiplied by 4.7, its Damage multiplier is multiplied by 2, its value is multiplied by 6 and it is granted the corresponding Elite buff selected previously.
 * 3) The Director pays for the monster : It spends an amount of credits equal to the monster's value
 * 4) If the monster is a Teleporter Boss, its HP multiplier is multiplied by the number of living players and it is set to that Armor-Piercing Rounds will deal bonus damage to it
 * 5) The Director applies the HP and Damage multiplier to the monster by giving it an appropriate amount of Boost items (Invisible items that increase HP and Damage)
 * 6) The Director sets the reward of the monster. They are calculated as follows :
 * 1) The Director spawns the monster

Check the spawn status
What happens now depends on whether the previous spawn was a SUCCESS or a FAIL

If the spawn failed
If the Director is an Instantaneous Director that already spawned at least one enemy, it deactivates.

The monster spawn timer increases by a random amount specified by the "Spawn Interval (Between waves)" attribute. This attribute is irrelevant for Instantaneous Directors because they will either try again immediately or never succeed.

The current monster card is destroyed, which means another one will be selected during the next attempt (The same card may be selected twice).

If the spawn succeeded
The monster spawn timer increases by a random amount specified by the "Spawn Interval (During a wave)" attribute.

The current monster card is kept. The next spawn will attempt to keep the same monster and elite index.

Example
Since the spawning method is rather complex, here is a concrete example to help understand the various concepts behind spawning.

Situation
4 players have just entered Abandoned Aqueduct, in their second loop. The difficulty is already past HAHAHAHA (Coeff of 17.5).

t = 0s | Attempt 1 : Condemned by poverty
Both Fast and Slow Directors activate, starting with 0 credits. They immediately target Player 2, choose a retarget timer of 6s, then attempt a spawn, which fails since they have no credits. Fast decides to attempt a spawn 4.01 seconds later while Slow chooses a delay of 18.33 seconds.

t = 4.01s | Attempt 2 : Now we're talking
After 4.01 seconds, both Directors has received 4 waves of credit. Each wave contains 0.75 * (1 + 0.4 * 17.5) * (4+1)/2 = 15 credits, so both Directors have 60 credits (We will ignore the very small increments of the coeff every second to make calculations more clear). Fast will now try another spawn since its monster timer has reached 0.

First, Fast keeps Player 2 as its spawn target since 1.99s remain on its retarget timer. There are only 12 monsters on the map (pre-placed by the Scene Director) so all is well.

Since his last spawn FAILED, Fast picks a spawncard and an Elite Index - this time it will be a Beetle and Glacial.

The cost of a Beetle is 8 and it can spawn as an Elite, so Fast knows that the maximum allowed credits it can hold before it deems Beetles too cheap is 8 * 24 = 192 credits.

Beetles have no special conditions and Fast's credit count (60) is higher than 8 but lower than 192, so the spawn will SUCCEED.

Fast notices that the cost of an Elite Beetle, 48 credits, is lower than its current budget. It decides to spawn the Beetle as an Elite - its base value rise to 48, its HP multiplier to 4.7 and its Damage multiplier to 2. It is also granted the Glacial buff.

Fast pays for the Beetle, it has 12 credits remaining. Since it is not a teleporter boss, no further adjustements are necessary.

Fast then calculates the base reward of its shiny new Beetle. Its base XP reward will be 0.2 * 17.5 * 48 = 168 XP, and its Gold reward will be double that, 336 Gold.

Finally, the Beetle spawns, not too far away from Player 2. With its higher HP and damage, we can only hope it will be a force to be reckoned with.

Since the spawn was a SUCCESS, Fast keeps Beetles and Glacial as its card and elite index. It decides to spawn the next monster 0.45s later.

t = 4.46s | Attempt 3 : They are billions
Shortly after our Elite beetle starts spawning, Fast decides to spawn another monster. It has not received any credit since, so its budget is still 12.

Our poor Player 2 is still targeted for 1.54s, so no change there.

Because the last spawn SUCCEEDED, Fast has no need to regenerate another card or elite index.

Just like before, 12 is higher than 8 and lower than 192 so the spawn will SUCCEED again.

This time however, Fast does not have enough credits to spawn another Elite - if it was the case, that Elite would also have been Glacial since the index has not changed. Fast only pays 8 credits, which leaves it with 4.

The base reward of this basic Beetle is only a mere 28 XP and 56 Gold since it is not an Elite. It spawns, also around Player 2.

Since this spawns SUCCEEDED, Fast keeps its card/elite again and decided to attempt the next spawn 0.23s later.

t = 4.69s | Attempt 4 : We shall stop for now
Once our second Beetle has started spawning, Fast decides yet again to try and spawn a Beetle.

Player 2 has still 1.31s going for it, so it is still the target.

Fast also keeps its card/elite yet again.

This time however, it no longer has enough credit to pay for a Beetle (4 vs 8) so the spawn FAILS.

Because of this, Fast must now wait much longer - 5.63s this time - before its next spawn. It will also select another card/elite combo - Player 2 is safe for now.

Past that
If we were to continue the simulation, we would keep generating random numbers and advance time to simulate a run. We would probably have Fast try another wave or two before Slow makes its first real attempt with the 15 * 18 = 270 credits it had accumulated, enough to spawn one Greater Wisp.