Skip to content
Snippets Groups Projects
Commit 89473e43 authored by Harry Wyatt's avatar Harry Wyatt
Browse files

Placed spawn probabilities in probabilities.json to show off file loading

parent 34b792a0
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ each time they play the game
'''
from map import *
import random
import copy
import json
# Global vars to edit how chests may spawn in the game
NO_CHESTS = range(1, 4) # 1-3 chests can spawn in the entire game
......@@ -13,6 +13,9 @@ ALLOW_MULTICHESTS = False # Can one room have more than one chest in it?
CHANCE_NOTHING = 15 # The numbers of entries in the raffle that result in nothing being place into the chest
EXCLUDE_CHESTS = [spawn_room] # The rooms in which no chests can spawn - ever!
# Item spawn probability file
PROBABILITIES_FILE = "probabilities.json"
# HINT: Use ALL_ROOMS string keyword in spawnable to allow the item to spawn in all rooms at that base percentage
# Use the CHEST keyword to allow the item to spawn in a chest. Make an int as it is number of entries in raffle
......@@ -23,6 +26,18 @@ id_tracker = {
"key": 1
}
def read_probabilities():
'''
This function is designed to read the probabilities file.
Having the probabilties file allows us to claim you can mod our game
'''
f = open(PROBABILITIES_FILE, "r")
data = json.load(f)
return data
def create_chests():
'''
This function will create the (empty) chests of the game and place them in random rooms
......@@ -137,6 +152,8 @@ def populate_rooms():
global spawnable_items
global CHANCE_NOTHING
spawn_chances = read_probabilities()
# First, generate where the chests should be placed and whether they need a key
chests = create_chests()
possible_rewards = []
......@@ -149,7 +166,7 @@ def populate_rooms():
id_tracker[class_to_spawn.__name__.lower()] = 1
# Check what rooms this item can spawn in
spawn_information = spawn_chances[class_to_spawn]
spawn_information = spawn_chances[class_to_spawn.__name__.lower()]
for room_id in spawn_information:
# We can have either Room or the keyword ALL_ROOMS
if room_id == "ALL_ROOMS":
......
{
"giantsword": {
"CHEST": 4,
"dusty_bedroom": 0.1,
"observatory": 0.1
},
"worndagger": {
"CHEST": 5,
"ALL_ROOMS": 0.25,
"kitchen": 0.5
},
"plasticspoon": {
"ALL_ROOMS": 0.3,
"CHEST": 1,
"spawn_room": 1
},
"golfclub": {
"garage": 1
},
"handgun": {
"dusty_bedroom": 0.3,
"CHEST": 4
},
"whip": {
"ALL_ROOMS": 0.1,
"CHEST": 3,
"dusty_bedroom": 0.3,
"garage": 0.3
},
"crocs": {
"spawn_room": 0.3,
"CHEST": 4,
"first_hallway": 0.5,
"dusty_bedroom": 0.4
},
"sturdyshield": {
"first_hallway": 0.3,
"observatory": 0.25,
"CHEST": 5
},
"apron": {
"kitchen": 0.8,
"wine_cellar": 0.2,
"CHEST": 1
},
"suitofarmour": {
"high_tower": 0.1,
"basement": 0.1,
"garage": 0.1,
"CHEST": 5
},
"cookies": {
"high_tower": 0.1,
"basement": 0.1,
"garage": 0.1,
"CHEST": 5
},
"firstaidkit": {
"dusty_bedroom": 0.1,
"conservatory": 0.1,
"high_tower": 0.3,
"CHEST": 6
},
"apple": {
"ALL_ROOMS": 0.3,
"kitchen": 0.8
},
"strangepotion": {
"high_tower": 0.5,
"garden": 0.3,
"garage": 0.2,
"observatory": 0.2
},
"wine": {
"conservatory": 0.2,
"wine_cellar": 0.9,
"kitchen": 0.2,
"CHEST": 4
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment