-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawn.py
More file actions
55 lines (40 loc) · 1.42 KB
/
spawn.py
File metadata and controls
55 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import classes
import enemies
import items
import random
import copy
def spawn_low_level_enemy() -> classes.Enemy:
"""
Creates a new, battle-ready low-level enemy with unique, random loot.
"""
enemy_template = random.choice(enemies.low_lvl_ene)
# CRITICAL: Create a deep copy of the template.
spawned_enemy = copy.deepcopy(enemy_template)
loot_to_add = []
# 50% chance to get an item from the main 'treasure' list
if random.randint(1, 100) <= 50:
loot_to_add.append(random.choice(items.treasure))
unique_items_db = {}
for item in loot_to_add:
# handling duplicates
unique_items_db[item.id] = item
spawned_enemy.loot = list(unique_items_db.values())
return spawned_enemy
def spawn_mid_level_enemy() -> classes.Enemy:
"""
Creates a new, battle-ready mid-level enemy with unique, random loot.
"""
enemy_template = random.choice(enemies.mid_lvl_ene)
spawned_enemy = copy.deepcopy(enemy_template)
loot_to_add = []
# 100% chance for one treasure
loot_to_add.append(random.choice(items.treasure))
# 25% chance for a *second* treasure
if random.randint(1, 100) <= 25:
loot_to_add.append(random.choice(items.treasure))
# handling duplicates
unique_items_db = {}
for item in loot_to_add:
unique_items_db[item.id] = item
spawned_enemy.loot = list(unique_items_db.values())
return spawned_enemy