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 game has six Directors. 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.

Note that whenever the "vault" of Abyssal Depths is opened, the game will grant 160 additional credits to the director. These credits are not increased by player count however, and this does not apply to the vault of Distant Roost either.

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, although they will always be valid and within the budget.

Monsters spawned by the Scene Director use their own reward coefficient of 0.0667, 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.

Monster & Elite tiers
Most monsters in the game can spawn in multiple variations of power level, called Tiers. Tier 0 monsters are the base version of the monster, while Tier 1 and higher have higher attributes and unique abilities - these monsters are called Elite monsters. Their HP bar outline is white instead of grey and they also have an "Elite item" granting them the abilities of their affix.

Elite monsters have a higher value than their normal counterparts. The value of a monster is equal to its base value multiplied by the value multiplier of its elite tier (e.g. a T0 Jellyfish is worth 10, a T1 Jellyfish is worth 60 and a T2 Jelllyfish is worth 360).

Some Elite tiers are not available until a certain number of stages have been completed. Whenever it is calculated, the maximum value of an elite monster only takes into account available tiers (e.g. the highest possible value for a Jellyfish is 60 in stages 1-4 and 360 from stage 5 onwards).

Similarly, some monsters can never be Elite - the maximum tier for them is always considered 0, regardless of the current stage. This currently affects the Magma Worm and Overloading Worm.

Card pre-selection
Before entering the spawn loop, some Directors prepare cards in a specific way, allowing them to match specific conditions the standard selection method may not match.

This is only applied to the first card, therefore if the first spawn fails, the second one will not use these mechanics again.

Combat Shrine
When the Combat Shrine picks its card, it does so in a way that will guarantee that it will work. As such, the Director only picks from cards that match the following conditions :

- The card is valid - The card value is lower than the Director's credits - The Director's credits are lower than the "too cheap" value for the card (See the next section for details)

If at least one card matches all these conditions, the Director picks one at random and uses it.

If no card matches all these conditions, the shrine deactivates, spawning in an inactive state as if already used.

Note that since these conditions mimic those used by the spawn loop, the Combat Shrine Director should always succeed when it actually attempts the spawn.

Teleporter Boss
When the Teleporter Boss Director picks its first card, it first decides whether it wants a Boss event (90% chance) or a Horde of Many (10% chance).

If a Boss event is selected, only cards in the "Champion" category will be selected. If a Horde of Many is selected, only cards not in the Champion category will be selected. In both cases, Golems are also specifically excluded.

A random card will then be selected. Do note however that since credits are never checked, it is quite possible that the spawn will fail due to the card being too cheap or too expensive.

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.

The Director uses the target to determine where the enemy will appear (All enemies have a minimum and maximum distance they have to their target when they spawn)

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.

Check for overcrowding
If there are already 40 monsters or more on the map, the spawn will FAIL (Excepted the Teleporter Boss and Combat Shrine Directors which bypass this restriction)

Prepare a wave
If the previous spawn was a SUCCESS, the wave parameters are kept and this section is skipped.

If the Director has pre-selected a monster card and no spawn has FAILED yet, it prepares the wave using this card.

If the Director has not pre-selected a wave or the last attempt was a FAIL, a random monster card is selected.

The Director then determines which Elite tier will be active. The chosen Elite tier is the highest available tier the Director can afford (The value of the corresponding Elite monster is lower than or equal to the Director's credits). Once the tier has been chosen, a random affix is then picked from its tier (Unless it is 0). All elites from the wave will use this tier and affix.

Finally, a spawn counter is created, starting at 0 and tracking how many monsters have been spawned with the current parameters.

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


 * The current wave has spawned 5 or less monsters
 * The spawn card conditions are met (i.e. if a Hermit Crab was selected, the stage must be 2nd or higher)
 * The Director can afford the monster (Its spawn cost is equal to or lower than the Director's current credits)
 * The monster is not too cheap for the Director (See below for details)

If all 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.

Too cheap ?
A monster is deemed too cheap for the Director if all three conditions are met :
 * The amount of credits the Director has exceeds 6 times the value of an Elite of the selected Tier.
 * The Director is not an Instantaneous Director
 * The selected monster is not the most expensive the Director could spawn (Defined as the highest value out of all monsters of the maximum available Tier)

The latter condition ensures that Directors will always have at least one possible enemy to spawn (Before build 3830295, the Director could gain so many credits that it considered every single monster in the game too cheap, therefore not spawning anything)

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.
 * 2) If the Director has enough credits to spawn an Elite of the selected Elite Tier, it sets the monster as Elite and raises its value accordingly - otherwise, the monster will be Tier 0
 * 3) The Director pays for the monster : It spends an amount of credits equal to the monster's value and increments the wave spawn counter by 1
 * 4) The Director calculates the HP and Damage multipliers of the monster according to its Tier
 * 5) 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
 * 6) 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)
 * 7) 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 prepared 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 and Elite tier/affix are kept.

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

Note that the Directors spawnrate have changed as of the Skills 2.0 update - however the concepts still stand, therefore the old values will be used.

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 - a Beetle, of base value 8.

Fast must then select an appropriate Elite tier. It tries Tier 1, which is always available, and finds that the value of a T1 Beetle would be 8 * 6 = 48 credits, which it can afford. It also tries Tier 2, which is available since players are in their second loop, getting a value of 8 * 36 = 288 credits, which is too much. Therefore, Tier 1 is selected.

Fast selects a random affix from the Tier 1 list. Glacial is selected. Finally, the Wave spawn counter is set to 0.

Our wave parameters set, Fast can now actually attempt a spawn.

Beetles have no special conditions and Fast's credit count (60) is higher than 8 but lower than 288 (The cost of 6 T1 Beetles), so the spawn will SUCCEED.

Fast notices that the cost of a T1 Beetle, 48 credits, is lower than its current budget. It therefore decides to spawn the Beetle as a Tier 1 Elite, raising its value to 48.

Fast pays for the Beetle, it has 12 credits remaining. Since the Beetle is Tier 1, its HP multiplier is set to 4.7 and its Damage multiplier to 2. It is also granted the Glacial buff. 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 T1/Glacial. 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 tier/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 T1 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 T0. 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 and almost enough to spawn a Tier 2 Beetle.