forked from Feyorsh/iQuHack_2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.py
158 lines (125 loc) · 4.56 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding: utf-8 -*-
#
# Item.py, Ice Emblem's item class.
#
# Copyright 2015 Elia Argentieri <elia.argentieri@openmailbox.org>
# Copyright 2015 Luca Argentieri <luca99.argentieri@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
class Item(object):
"""Generic item class"""
def __init__(self, name, worth, uses, description=""):
self.name = name
self.descr = description
self.worth = int(worth) # Price
self.muses = int(uses) # max number of uses
self.uses = int(uses) # number of remaining uses
def use(self):
self.uses -= 1
if self.uses <= 0:
self.uses = 0
print("%s is broken" % self.name)
return self.uses
def __str__(self):
return f'{self.name} ({self.uses}/{self.muses})'
def __repr__(self):
return (
f'Item:\n\tName: "{self.name}"\n\tDescription: "{self.descr}"\n'
f'\tWorth: "{self.worth}₤"\n\tUses: {self.uses}/{self.muses}'
)
class Weapon(Item):
bonus_weapons = []
bonus_units = []
"""Swords, Lances, Axes, Bows, Tomes, Staffs"""
def __init__(self, name, rank, might, weight, hit, critical, range,
uses, worth, experience, effective, description=""):
super().__init__(name, worth, uses, description)
self.rank = rank # rank necessary to use it
self.might = int(might) # damage
self.weight = int(weight) # weight affects on speed
self.hit = int(hit) # probability to hit the enemy
self.crit = int(critical) # probability of triple damage
self.min_range = int(range['min']) # min attack distance
self.max_range = int(range['max']) # max attack distancez
self.exp = int(experience) # exp increases unit's weapon rank
self.effective = effective
def __repr__(self):
return (
'Weapon:\n\tName: "{name}"\n'
'Description: "{descr}"\n'
'Rank: {rank}\n'
'Might: {might}\n'
'Weight: {weight}\n'
'Hit: {hit}\n'
'Crit: {crit}\n'
'Range: {min_range}-{max_range}\n'
'Uses: {uses}/{muses}\n'
'Worth: {worth}\n'
'Exp: {experience}\n'
.format_map(self.__dict__)
)
def get_might(self, enemy):
if isinstance(enemy, self.bonus_class):
might = self.might + (self.might / 10)
print("%s is advantaged over %s" % (self.bonus_class.__name__, enemy.__class__.__name__))
else:
might = self.might
for effect in self.effective:
if isinstance(effect, enemy):
might += might / 10
return might
class Sword(Weapon):
pass
class Lance(Weapon):
pass
class Axe(Weapon):
pass
Sword.bonus_weapons.append(Axe)
Lance.bonus_weapons.append(Sword)
Axe.bonus_weapons.append(Lance)
class Bow(Weapon):
pass
class LightTome(Weapon):
pass
class DarkTome(Weapon):
pass
class AnimaTome(Weapon):
pass
class Staff(Weapon):
pass
class Armour(Item):
"""
Not used yet.
"""
def __init__(self, name, rank, defence, weight, uses, worth, exp, effective, descr=""):
super().__init__(name, worth, descr)
self.rank = rank # rank necessary to use it
self.defence = int(defence)# damage
self.weight = int(weight) # weight affects on speed
self.exp = int(exp) # exp increases unit's weapon rank
self.effective = effective
def __str__(self):
return """
Armour "%s":
Description: "%s"
Rank: %c
Defence: %d
Weight: %d
Uses: %d/%d
Worth: %d
Exp: %d
""" % (self.name, self.descr, self.rank, self.defence, self.weight,
self.uses, self.muses, self.worth, self.exp)