-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loot_encounter.py
46 lines (37 loc) · 1.57 KB
/
loot_encounter.py
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
import random
import utilities
from items.item import Rarity
from item_factory import generate_random_item
from character import Character
class Loot:
def __init__(self, characters: [Character]):
self.characters = characters
self.level = int(sum([x.level for x in characters]) / len(characters))
self.description = random.choice(descs)
self.roll_item = generate_random_item(self.level, rarity=Rarity.rare)
self.roll_list = []
self.has_rolled = []
for character in self.characters:
item = generate_random_item(self.level, rarity=None)
character.add_to_inventory(item, True)
self.description += f'\n {character.name} found: {item.name} {utilities.get_rarity_symbol(item.rarity)}'
def add_to_roll_list(self, name: str):
if name not in self.has_rolled:
self.has_rolled.append(name)
roll = random.randint(1, 100)
self.roll_list.append((name, roll))
return roll
return False
def choose_winner(self):
if len(self.roll_list) < 1:
return None
winner = sorted(self.roll_list, key=lambda x: x[1], reverse=True)[0][0]
return winner
descs = [
'You discover an equipment cache.',
'You find some item_specs half-buried near unidentifiable remains.',
'An abandoned campsite here has some salvageable goods.',
'You find something useful on what appears to be a makeshift altar.',
'You almost trip over a partially buried chest.',
'A cave-in here has revealed some ancient artifacts.',
]