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

Increased the variety of names of keys and chests

parent 37a7218f
No related branches found
No related tags found
No related merge requests found
...@@ -594,7 +594,6 @@ def loadingbar(): ...@@ -594,7 +594,6 @@ def loadingbar():
# This is the entry point of our program # This is the entry point of our program
def main(): def main():
# Generate random items in each room before we start the game
clear() clear()
loading = ['Loading -', 'Loading \\', 'Loading |', 'Loading /'] loading = ['Loading -', 'Loading \\', 'Loading |', 'Loading /']
for i in range(10): for i in range(10):
...@@ -630,7 +629,7 @@ def main(): ...@@ -630,7 +629,7 @@ def main():
if player.current_room.cleared == False: if player.current_room.cleared == False:
# filler, for now # filler, for now
for enemy in player.current_room.enemies: for enemy in player.current_room.enemies:
combat(enemy) #combat(enemy)
if player.alive == False: if player.alive == False:
break break
......
...@@ -7,13 +7,26 @@ import random ...@@ -7,13 +7,26 @@ import random
import json import json
# Global vars to edit how chests may spawn in the game # 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 NO_CHESTS = range(1, 5) # 1-4 chests can spawn in the entire game
NEED_ITEM_PAIRING = 0.6 # 60% of chests will need a key or other to be opened NEED_ITEM_PAIRING = 0.6 # 60% of chests will need a key or other to be opened
ALLOW_MULTICHESTS = False # Can one room have more than one chest in it? 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 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! EXCLUDE_CHESTS = [spawn_room] # The rooms in which no chests can spawn - ever!
CHEST_NAMES = [] # This list goes [["id", "name"], ... ]
KEY_NAMES = [] CHEST_NAMES = [
["chest", "old chest"],
["chest", "treasure chest"],
["chest", "coffin chest"],
["chest", "brown chest"],
["chest", "metal chest"],
["chest", "modern chest"],
["suitcase", "black suitcase"],
["box", "jewelry box"],
["case", "business case"],
["crate", "woodern crate"],
["safe", "money safe"]
]
KEY_NAMES = ["rusty key", "old key", "trusty key", "antique key", "burned key", "tubular key", "paracentric key"]
# Item spawn probability file # Item spawn probability file
PROBABILITIES_FILE = "probabilities.json" PROBABILITIES_FILE = "probabilities.json"
...@@ -37,6 +50,7 @@ def read_probabilities(): ...@@ -37,6 +50,7 @@ def read_probabilities():
f = open(PROBABILITIES_FILE, "r") f = open(PROBABILITIES_FILE, "r")
data = json.load(f) data = json.load(f)
f.close() # Close the data file to avoid memory leaking
return data return data
...@@ -50,6 +64,8 @@ def create_chests(): ...@@ -50,6 +64,8 @@ def create_chests():
global EXCLUDE_CHESTS global EXCLUDE_CHESTS
global rooms global rooms
global ALLOW_MULTICHESTS global ALLOW_MULTICHESTS
global CHEST_NAMES
global KEY_NAMES
chests = [] chests = []
chest_no = random.choice(NO_CHESTS) # As it is a range, we must dedicate ourselves to a number (of chests) chest_no = random.choice(NO_CHESTS) # As it is a range, we must dedicate ourselves to a number (of chests)
...@@ -60,9 +76,12 @@ def create_chests(): ...@@ -60,9 +76,12 @@ def create_chests():
for i in range(0, chest_no + 1): for i in range(0, chest_no + 1):
needs_key = random.random() < NEED_ITEM_PAIRING needs_key = random.random() < NEED_ITEM_PAIRING
# Choose a name and id for the chest
info = random.choice(CHEST_NAMES)
new_chest = Chest( new_chest = Chest(
id="chest", id=info[0],
name="chest", name=info[1],
description="chest", description="chest",
contains=None contains=None
) )
...@@ -91,9 +110,12 @@ def create_chests(): ...@@ -91,9 +110,12 @@ def create_chests():
room_to_put.items.append(new_chest) room_to_put.items.append(new_chest)
if needs_key is True: if needs_key is True:
# Get a key name
name = random.choice(KEY_NAMES)
new_key = Unlocks( new_key = Unlocks(
id="key", id="key",
name="old key", name=name,
description=f"It's hard to read, but the tag seems to say \"{new_chest.id.upper()} IN {room_to_put.name.upper()}\"", description=f"It's hard to read, but the tag seems to say \"{new_chest.id.upper()} IN {room_to_put.name.upper()}\"",
perish_on_open=True perish_on_open=True
) )
......
...@@ -237,13 +237,14 @@ class Chest(GameObject): ...@@ -237,13 +237,14 @@ class Chest(GameObject):
contains = None # contains is expected to be a subclass of GameObject, a list or a NoneType contains = None # contains is expected to be a subclass of GameObject, a list or a NoneType
requires = None # None means no key or anything is needed, else this should be set to Unlocks class requires = None # None means no key or anything is needed, else this should be set to Unlocks class
opened = False opened = False
on_interaction_description = "to open the chest" on_interaction_description = "to open the {0}"
def __init__(self, id, name, description, contains, requires=None, pickup=False, place=False): def __init__(self, id, name, description, contains, requires=None, pickup=False, place=False):
super().__init__(id, name, description, pickup, place) super().__init__(id, name, description, pickup, place)
self.contains = contains self.contains = contains
self.requires = requires self.requires = requires
self.on_interaction_description.format(self.id)
def _interaction(self, player): def _interaction(self, player):
# Upon interacting with a chest item, the player should be awarded the items inside # Upon interacting with a chest item, the player should be awarded the items inside
......
...@@ -100,9 +100,12 @@ class Player: ...@@ -100,9 +100,12 @@ class Player:
for category in self.equipped: for category in self.equipped:
item = self.equipped[category] item = self.equipped[category]
if item.id == item_id:
item.inspect() # We must check is it a valid object, as we can also expect NoneType here
return if issubclass(type(item), GameObject):
if item.id == item_id:
item.inspect()
return
print("Could not find that item to inspect.") print("Could not find that item to inspect.")
......
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