Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save markekraus/1d596e5a6ac808638ae75c801a874b0a to your computer and use it in GitHub Desktop.
Save markekraus/1d596e5a6ac808638ae75c801a874b0a to your computer and use it in GitHub Desktop.
Blue Prince Luck Calculator FSM [SPOILERS]

Blue Prince Luck Calculator FSM [SPOILERS]

This documents the Luck calculator Finite-State Machine (FSM) the Blue Prince uses for determining the number of items to spawn in rooms.

This was made for Blue Prince version 1.0.13, Patch 1.04, April 30, 2025.

Note

The words "Guarenteed" and "dows" are misspelled in the game's code. I have preserved the misspellings here.

            ██████╗ ██╗     ██╗   ██╗███████╗               
            ██╔══██╗██║     ██║   ██║██╔════╝               
            ██████╔╝██║     ██║   ██║█████╗                 
            ██╔══██╗██║     ██║   ██║██╔══╝                 
            ██████╔╝███████╗╚██████╔╝███████╗               
            ╚═════╝ ╚══════╝ ╚═════╝ ╚══════╝               
        ██████╗ ██████╗ ██╗███╗   ██╗ ██████╗███████╗       
        ██╔══██╗██╔══██╗██║████╗  ██║██╔════╝██╔════╝       
        ██████╔╝██████╔╝██║██╔██╗ ██║██║     █████╗         
        ██╔═══╝ ██╔══██╗██║██║╚██╗██║██║     ██╔══╝         
        ██║     ██║  ██║██║██║ ╚████║╚██████╗███████╗       
        ╚═╝     ╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝ ╚═════╝╚══════╝       
███████╗██████╗  ██████╗ ██╗██╗     ███████╗██████╗ ███████╗
██╔════╝██╔══██╗██╔═══██╗██║██║     ██╔════╝██╔══██╗██╔════╝
███████╗██████╔╝██║   ██║██║██║     █████╗  ██████╔╝███████╗
╚════██║██╔═══╝ ██║   ██║██║██║     ██╔══╝  ██╔══██╗╚════██║
███████║██║     ╚██████╔╝██║███████╗███████╗██║  ██║███████║
╚══════╝╚═╝      ╚═════╝ ╚═╝╚══════╝╚══════╝╚═╝  ╚═╝╚══════╝
         █████╗ ██╗  ██╗███████╗ █████╗ ██████╗ ██╗
        ██╔══██╗██║  ██║██╔════╝██╔══██╗██╔══██╗██║
        ███████║███████║█████╗  ███████║██║  ██║██║
        ██╔══██║██╔══██║██╔══╝  ██╔══██║██║  ██║╚═╝
        ██║  ██║██║  ██║███████╗██║  ██║██████╔╝██╗
        ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚═════╝ ╚═╝

Table of Contents

Where to Begin

The FSM remains in the Item Spawn state until it receives the "Luck Calculator" event and the it transitions to the Dowsing Check state.

Luck Defaults

Variable Default Value
LUCK 10
BalanceSubtraction -3
TempLuck 0
DowsLuck 0
Dowse False
Veranda Luck Bonus 0

Luck Mechanics

This is a collection of Luck mechanics that have been investigated.

Veranda Luck Bonus

Veranda luck bonus is an additional luck bonus granted to Green Rooms by drafting Verandas and Spare Verandas (a tier-2 upgrade to the Spare Room). This bonus is added to LUCK when drafting a Green Room to form the base luck for that Green Room.

  • The first Veranda drafted +12
  • Each additional Veranda is +6
  • Each Spare Veranda (including the first) is +6

If you draft a Veranda, a Spare Veranda, Chamber of Mirrors, a 2nd Veranda, a 2nd Spare Veranda, a Secret Passage, and a 3rd Veranda or Spare Veranda, the total Veranda Luck Bonus will be +36. If you have the base luck of 10 and draft a Green Room, the base luck for the Green Room will be 46. If you draft a Blue Room (or any thing other than a Green Room) your luck will only be the base 10.

Cloister of Rynna

Cloister of Rynna increases LUCK for the day by +6 for each Green Room you draft from the Cloister. This means each Cloister of Rynna can increase luck by up to +18. This will not carry over into future days.

Maid's Chamber

Drafting a Maid's Chamber decreases Luck by 7 each. If you draft a Maid's Chamber, a Chamber of Mirrors, and a 2nd Maid's Chamber, your LUCK will be decreased by -14. With a base luck of 10, your LUCK will be -4.

Lucky Rabbit's Foot

When the player has the Lucky Rabbit's Foot in their inventory, +3 is added to the room's luck.

Dowsing Rod

Further testing is needed to better understand how this works.

Room Item Spawn Logic

Each room has it's own logic as to how many and which items will be spawned. They all use the luck calculator to determine the room's luck and target items at drafting time. They then use that luck and items in their own logic. For example, even though te luck calculator might set 4 drop items for the room, the room may still have logic to limit to 3 items or decrease the chances of 4 items.

It is quite a task to try and decipher the logic for each room, so that has not yet been done.

Metal Detecting

It appears luck may be used in determining whether or not a room has Metal Detector items in it. Metal detecting is done at the same time as item spawning when the room is drafted. This means metal detecting will not proc for rooms that have already been drafted before obtaining the Metal Detector.

Trunks

Luck determines whether trunks spawn or not. Trunks are treated like any spawn item. In a room which can spawn a Trunk, and Apple, a Key, a Gem, 5 Coins, or a Metal detector, if the drop target is 2, then there is chance to spawn the Trunk and another item or just 2 other items.

Further investigation needs to be done on the influence of Luck on Trunk items.

Dirt Piles

Luck influences the number of dirt piles spawned in a room. The higher your luck, the higher the chance of spawning max dirt piles. Dirt piles are tracked separately from spawn items, so you can potentially spawn max items for a room and max dirt piles.

Luck plays no role on dirt pile items. Items looted from dirt piles are determined by what digging related items you have in your inventory and hard coded percentage chances.

Things Luck Does NOT Influence

So far, I have only found luck used in room item spawning. However, I have looked into several systems to explicitly determine that luck is not used or influenced.

Luck has been confirmed to have no influence on the following:

  • Rarity of drafted rooms
  • Casino slot machines
  • Trading Post Items
  • Commissary Items
  • Dirt Pile Items

Luck has been confirmed to be unaffected by the following:

  • Coins in the fountain
  • Being Cursed

States

0: Luck Check

  1. If this room's luck is less than 5 go to the "Set Bad Luck 2" state.
  2. If this room's luck is less than 11 go to the "Set Avg Luck 2" state.
  3. If this room's luck is less than 16 go to the "Set Kinda Lucky 2" state.
  4. If this room's luck is less than 19 go to the "Set Lucky 2" state.
  5. If this room's luck is less than 23 go to the "2 Items Guarenteed!" state.
  6. If this room's luck is less than 29 go to the "3 Items Guarenteed!" state.
  7. Got to state "4 out of 4"??

1: Item Spawn

When receiving the "Luck Calculator" event, go to the "Dowsing Check" state.

2: Loop Back

Wait 0.02 seconds then go to "Item Spawn" state.

3: VERANDA Check

  1. If veranda luck bonus is 0 go to the "Luck Balance Modifiers" state.
  2. If this is not a green room go to the "Luck Balance Modifiers" state.
  3. Add veranda luck bonus to this room's luck
  4. Go to the "Luck Balance Modifiers" state.

4: Set Bad Luck 2

Set DropTarget to 1.

ID Weight Target State
Bad Luck 93% 0 Items
Avg Luck 7% Dowse Correction

5: Set Avg Luck 2

ID Weight Target State
Bad Luck 85% 0 Items
Lucky 15% 1 Item Guarenteed!

6: Set Kinda Lucky 2

ID Weight Target State
Bad Luck 60% 0 Items
Lucky 40% 1 Item Guarenteed!

7: Set Lucky 2

ID Weight Target State
Bad Luck 20% 0 Items
Lucky 80% 1 Item Guarenteed!

8: 3 Items Guarenteed!

  1. Set DropTarget to 2.
  2. If this room's luck is less than 17, go to the "Send Drop Target" state.
  3. Set DropTarget to 3.
  4. Subtract 2 from BalanceSubtraction.
  5. Go to the "Send Drop Target" state.

9: 4 out of 4

  1. Set DropTarget to 4
  2. Subtract 3 from BalanceSubtraction.
  3. Go to the "Send Drop Target" state.

10: 1 Item Guarenteed!

Set DropTarget to 1

ID Weight Target State
Avg Luck 96% Dowse Correction
Very Lucky 4% 2 Items Guarenteed!

11: 2 Items Guarenteed!

  1. Set DropTarget to 1.
  2. If this room's luck is less than 11 go to the "Send Drop Target" state.
  3. Set DropTarget to 2.
  4. Subtract 1 from BalanceSubtraction.
ID Weight Target State
Avg Luck 95% Send Drop Target
Very Lucky 5% 3 Items Guarenteed!

12: 0 Items

  1. Set DropTarget to 0.
  2. Go to the "Dowse Correction" state.

13: Send Drop Target

  1. Set Dowse to False.
  2. Set DropTarget in this room's Item management FSM to this FSM's DropTarget.
  3. Send "Items Go" event to this room's Item management FSM.
  4. Go to the "Loop Back" state.

14: Rabbit's Foot

  1. If player inventory contains Lucky Rabbit's Foot go to the "+3" state.
  2. If player inventory contains Lucky Purse go to the "+3" state. If not go to the "VERANDA Check" state.

15: +3

  1. Add 3 to this room's luck.
  2. Go to the "VERANDA Check" state.

16: SET INT LUCK

  1. Set this room's luck to the luck calculator's LUCK.
  2. go to the "Rabbit's Foot" state.

17: Set Dowsed Luck

  1. Set dowse to True.
  2. Add 32 to LUCK and set the result in TempLuck.
  3. Go to the "Rabbit's Foot" state.

18: Dowse Correction

  1. If dowse is False go to the "Send Drop Target" state.
  2. Set DropTarget to 1
  3. go to the "Send Drop Target" state.

19: Luck Balance Modifiers

  1. If dowse is True go to "Dows Check" state.
  2. Subtract SubtractionBalance from this room's luck.
  3. Go to the "Luck Check" state.

20: Dowsing Check

  1. If dowse is True go to the "Set Dowsed Luck" state.
  2. If dowse is False go to the "SET INT LUCK" state.

21: Dowsing Rod

  1. If this room's luck is less than 19 then go to the "Luck Check" state.
  2. Set DropTarget to 1
ID Weight Target State
Avg Luck 85% 1 Item Guarenteed!
Very Lucky 10% Dows +1
Extremely Lucky 5% Dows +2

22: Check Dowsing Array

  1. If the current room is in the Drafting manager's DopTarget 1 rooms list go to the "2 Items Guarenteed!" state.
  2. If the current room is not in the Drafting manager's DopTarget 1 rooms list go to the "Dowsing Rod" state.

23: Dows +1

  1. add 1 to dows luck.
  2. Go to the "3 Items Guarenteed!" state

24: Dows +2

  1. add 2 to dows luck.
  2. Go to the "4 out of 4" state

25: Dows Check

  1. If dows luck is greater than 5 go to the "State 2" state.
  2. If dows luck is greater than 2 go to the "State 1" state.
  3. Go to the "Check Dowsing Array" state.

26: State 1

ID Weight Target State
Avg Luck 60% State 2
Very Lucky 20% Check Dowsing Array
Bad Luck 20% 1 Item Guarenteed!

27: State 2

ID Weight Target State
Avg Luck 50% 2 Items Guarenteed!
Bad Luck 50% 1 Item Guarenteed!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment