Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CM1101 Team Project
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Harry Wyatt
CM1101 Team Project
Commits
89473e43
Commit
89473e43
authored
2 years ago
by
Harry Wyatt
Browse files
Options
Downloads
Patches
Plain Diff
Placed spawn probabilities in probabilities.json to show off file loading
parent
34b792a0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
item_dist.py
+19
-2
19 additions, 2 deletions
item_dist.py
probabilities.json
+80
-0
80 additions, 0 deletions
probabilities.json
with
99 additions
and
2 deletions
item_dist.py
+
19
−
2
View file @
89473e43
...
...
@@ -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
"
:
...
...
This diff is collapsed.
Click to expand it.
probabilities.json
0 → 100644
+
80
−
0
View file @
89473e43
{
"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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment