forked from Krasi2405/Dungeon-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.py
72 lines (61 loc) · 2.32 KB
/
item.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
import random
RARITY = ['Common', 'Uncommon', 'Rare', 'Epic', 'Legendary']
WEAPON_TYPES = ['Training', 'Stone', 'Iron', 'Steel', 'Silver', 'Dragonbone']
ARMOR_TYPES = ['Cloth', 'Leather', 'Iron', 'Steel', 'Silver', 'Dragonbone']
class Item:
def set_item_attr(self, **kwargs):
rarity_chance = random.randint(0, 100)
rarity_counter = 0
self.power = 0
for rarity_type in RARITY:
if rarity_chance <= round((100 - 10 * rarity_counter) * (rarity_counter + 1) / len(RARITY) + 10 * rarity_counter):
break
else:
self.power += 5
rarity_counter += 1
self.type = RARITY[rarity_counter]
for (key, value) in kwargs.items():
setattr(self, key, value)
def __str__(self):
if self.__class__.__name__ == "Armor":
stats = "Defense: {}".format(self.defense)
else:
stats = "Attack range: {} - {}".format(self.min_attack, self.max_attack)
return "{} {}\n {} ".format(self.type, self.name, stats)
class Weapon(Item):
def __init__(self, min_attack, max_attack, name, **kwargs):
self.set_item_attr(**kwargs)
self.name = name
self.min_attack = min_attack
self.max_attack = max_attack
combined_attack = self.min_attack + self.max_attack
type_counter = 0
for weapon_type in WEAPON_TYPES:
if combined_attack <= (100 * (type_counter + 1)) / len(WEAPON_TYPES):
break
else:
type_counter += 1
try:
type = WEAPON_TYPES[type_counter]
except:
type = WEAPON_TYPES[type_counter - 1]
self.type += " {}".format(type)
def attack(self):
attack = random.randint(self.min_attack, self.max_attack)
return attack
class Armor(Item):
def __init__(self, defense, name, **kwargs):
self.set_item_attr(**kwargs)
self.name = name
self.defense = defense
type_counter = 0
for armor in ARMOR_TYPES:
if defense <= (50 * (type_counter + 1)) / len(ARMOR_TYPES):
break
else:
type_counter += 1
try:
type = ARMOR_TYPES[type_counter]
except:
type = ARMOR_TYPES[type_counter - 1]
self.type += " {}".format(type)