-
Notifications
You must be signed in to change notification settings - Fork 0
/
weapon_generator.py
103 lines (75 loc) · 2.63 KB
/
weapon_generator.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/local/opt/python/bin/python3.7
import random
import string
weapon_map = {0: "rifle",
1: "sniper",
2: "cannon",
3: "handgun"}
class Weapon:
def __init__(self, weapon_type=None):
self.type = get_random_weapon_type() \
if weapon_type is None else weapon_map[int(weapon_type)]
self.dmg_type = get_random_dmg_type()
self.cooldown = 0
self.traits = get_random_traits()
self.name = ' '.join(
(' '.join(trait for trait in self.traits
if trait is not None),
self.dmg_type,
string.capwords(self.type)))
self.power, \
self.accuracy, \
self.speed = globals()["generate_" + self.type]()
def _describe(self):
print(f'{self.name}')
print(f'Power: {self.power}')
print(f'Speed: {self.speed}')
print(f'Accuracy: {self.accuracy}')
def get_random_traits():
weapon_traits = [random.choice(['High-speed',
'Long-range',
'Rapid-fire',
'Multi-shot',
'Charging'])]
weapon_traits.append(random.choice(['Piercing',
'Destroyer',
'Obliterating',
'Annihilating',
None]))
return weapon_traits
def get_random_weapon_type():
# weapon_type = ['rifle', 'sniper', 'cannon', 'handgun']
# return random.choice(weapon_type)
return weapon_map[random.randint(0, 3)]
def get_random_dmg_type():
"""Refer to the docstring @ mechanics.apply_status_effects()"""
dmg_type = ['Lava',
'Frost',
'Shock',
'Laser']
return random.choice(dmg_type)
def generate_rifle():
power = random.randint(15, 20)
accuracy = random.randint(3, 3)
speed = 4
return power, accuracy, speed
def generate_sniper():
power = random.randint(25, 30)
accuracy = random.randint(4, 5)
speed = 1
return power, accuracy, speed
def generate_cannon():
power = random.randint(30, 40)
accuracy = random.randint(1, 2)
speed = 1
return power, accuracy, speed
def generate_handgun():
power = random.randint(18, 23)
accuracy = random.randint(3, 3)
speed = 3
return power, accuracy, speed
if __name__ == '__main__':
Weapon(0)._describe()
Weapon(1)._describe()
Weapon(2)._describe()
Weapon(3)._describe()