Directors

As a rogue-lite game, 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 interactibles 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 a total of 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 interactibles.

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


 * The Scene Director is active during map setup. It is responsible for spawning all interactibles, as well as 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, but 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 depends on the Director itself, though all directors use the same costs to spawn entities.

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 interactible 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 selected.
 * The Credit Cost represents how many credits a Director must spend to spawn the entity listed on the card.
 * 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, but the weight of the categories themselves varies 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 interactibles 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  category is selected. The same thing then happens within the category every item puts in tickets equal to its weight, and then a random ticket is drawn to determine which spawn card is selected from that category.

The Scene Director
When active during the start of a stage, 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 interactibles, then monsters. Finally, during cleanup, if at least one player has a, it will spawn a Rusty Lockbox for each player who has keys. The items within the Lockboxes are determined when they spawn, so changing the number of Rusted Keys during the stage won't affect the contents of the Lockboxes.

Credit Income
The Scene Director holds 2 credit budgets, one for its interactibles and one for its monsters. The base amount of credits given to the Scene Director when the stage starts depends on the environment.

The amount of interactible credits is then 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 Scene Director will have to work with.

Note that whenever the "vault" of Abyssal Depths is open, the Scene Director is granted 160 additional interactible credits. 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, entering Abandoned Aqueduct in 2 player mode at the start of "Medium" (which is a coefficient of 2.3) will give the Scene Director 230 credits to work with. The only exception to this rule is the first stage, which always has a monster credit amount of 0.

Spawning Interactibles
When spawning interactibles, the Scene Director will repeatedly select a spawn card from its deck, only selecting between cards it can currently afford. 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 Scene Director's credit count reaches 0 or less.
 * The Scene Director has no interactible it can afford.

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 interactibles have a cost of 1 and a rather high weight. It is likely they'll be selected a few times when the Scene Director has few credits remaining (less than 10).

Spawning Monsters
When spawning monsters, the Scene Director will use the same routine as when spawning interactibles, with one main difference a limit of 40 monsters. When this limit is reached, the Scene 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 initially 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've 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 :

Credits per second = creditMultiplier * (1 + 0.4 * coeff) * (playerCount + 1) / 2

Here, creditMultiplier is the "credit multiplier" attribute of the Director, playerCount refers to the number 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 random active Director and discards the rest. If there are no other active Directors (such as when the Teleporter has been charged), these credits are lost.

When activating the Teleporter, the Teleporter Directors activate before the standard Directors deactivate, so receive some credits from 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 credit 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 the 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 only affects the and.

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, so if the first spawn fails, the second one will not use these mechanics again.

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


 * The card is valid.
 * The card's value is lower than the Shrine of Combat Director's credits.
 * The Shrine of Combat 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, 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," which is a random value between 1 and 10 seconds. At the end of that timer, it will pick a random living player again as its next target (which may be the same player 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 value, dictating how close or far they can be from 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, so 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. The Teleporter Boss and Combat Shrine Directors bypass this restriction, however.

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 that card.

If the Director has not pre-selected a card, or the last spawn 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 (as in, the value of the corresponding Elite monster is less than or equal to the Director's current credits). Once the tier has been chosen, a random affix is then picked from its tier (unless the chosen tier 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 (i.e. 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 spent if the spawn is a FAILURE.

Too cheap?
A monster is deemed too cheap for the Director if all three of these conditions are met:


 * The amount of credits the Director has is more than 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 third 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, and therefore did not spawn anything.)

Prepare the spawn
enemyXPReward = coeff * monsterValue * rewardMultiplier enemyGoldReward = 2 * coeff * monsterValue * rewardMultiplier where the reward multiplier is an attribute of that Director, and coeff is the difficulty coefficient.
 * 1) The Director prepares the monster matching the spawn card.
 * 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 so that  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. These are invisible items that increase the monster's 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 again, however.

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' spawn rates have changed as of the Skills 2.0 update. However, the same concepts still stand, so the old values will be used.

Scenario
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 have received 4 waves of credits. 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 difficulty coefficient every second to make calculations clearer). 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 Fast's last spawn FAILED, it picks a spawn card - 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.

With the 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, and 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 adjustments 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 choose another monster card or Elite tier/affix.

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 that had been the case, that Elite would also have been Glacial since the affix has not changed. Fast only pays 8 credits and spawns a T0 Beetle, which leaves it with 4 credits.

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 them, so they are still the target.

Fast also keeps its card/elite yet again.

This time, however, Fast no longer has enough credits to pay for any Beetles (4 credits versus 8 cost) 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.