forked from Stals/PythonRPG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hero.py
195 lines (164 loc) · 7.23 KB
/
Hero.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
from Entity import Entity
from Inventory import Inventory
from Equipment import *
from Potion import PotionsPocket
from Elements import *
from Stats import *
#Класс хранит Имя рассы и те бонусы которые она даёт
import utils.getChoice as utils
## Расса
class Race:
def __init__(self,name="",stats=Stats()):
self.name = name
self.stats = stats
## Возвращает название рассы
def name(self):
return self.name
## Возвращает описание Рассы в виде строки
def __str__(self):
return "{0}\n{1}".format(self.name,self.stats)
#TODO Сдлеать чтобы маны было меньше , и также как и hp примерно для среднего класса Human Может для human все статы по 5 ?
races=[ #TODO! Переписать дома с листочка + можно тоже сделать и для Классов
Race( "Dwarf", Stats(7,7,4,4,4,4) ),
Race( "Wood Elf", Stats(5,4,3,4,7,7) ),
Race( "Human", Stats(5,5,5,5,5,5) ),
Race( "High Elf", Stats(3,4,8,8,3,4) ),
Race( "Orc", Stats(7,6,3,4,4,5) )
]
## Герой
class Hero(Entity):
def __init__(self):
self.heroRace = Race()
self.heroClass = ""
#Получаем Данные от пользователя
self.getName()
self.getClass()
self.getRace()
super().__init__(self.name,self.heroRace.stats,Elements(),0)
## Инвентарь героя
self.inventory = Inventory()
## Обмундирование героя
self.equipment = Equipment()
## Карман с Лечебками героя
self.potionsPocket = PotionsPocket()
## Получает имя Персонажа
def getName(self): #TODO! Не получать пустую строку , и чтобы ввод был норм.
while True:
self.name = input("Input you name:")
if self.name:
# Если что-то было введено - прекратить цикл
break
## Получает Рассу
def getRace(self):
#Получаем Расу
self.heroRace = utils.getChoice("Choose your Race:",races) #TODOlater Сделать вывод по горизонтали
## Получает Класс
def getClass(self): #TODO Сдлеать сразу содание класса, при выборе одного из классов(вызывается создание класса) http://stackoverflow.com/questions/8141165/how-to-dynamically-select-a-method-call-in-python
self.heroClass = utils.getChoice("Choose Your Class:",[
"Warrior",
"Ranger",
"Mage"
])
## Выводит полный перечень Того что есть у Персонажа:
## Уровень Опыт Класс Рассу
## Статистики (stats, hp, mp, money)
## Урон
## Вещи в inventory (инвентаре)
## Вещи в equipment (обмундировании)
## Лечебки в potionsPocket
## Резисты Персонажа
## Квесты в QuestJournal
## Заклинания в SpellBook
def showStats(self):
#TODO showStats() в hero делать с переносом на новую строку при выводе каждого объекта. При этом с использованием \n и дальше на новой строке код
# -Level exp
# +Race Class
# +Stats
# +Damage
# +inventory
# +equipment
# +potionsPocket
# +resists
# -questJournal
# -spellbook
#
pass
## восстанавливает hp и mp
def heal(self):
self.stats.hp = self.stats.maxHp
self.stats.mp = self.stats.maxMp
## Кастует Заклинание
def castSpell(self, spell): #TODOlater Сделать когда будет готов класс Spell и SpellBook
pass
#TODO Переименовать на action? или еще что-то
def castSpellChoice(self, hero, enemies):
pass
def usePotionChoice(self, hero, enemies):
choosedPotion = utils.getChoice("What potion to use?", self.potionsPocket.items(), cancel=True)
if choosedPotion:
# Если было выбрано одно из зелий
self.use(choosedPotion)
else:
#TODO! Выбрали отмену
return False
#вызывает simpleAttack для выбранного монстра
def attackChoice(self, hero, enemies):
if len(enemies) > 1:
choosedEnemy = utils.getChoice("Choose your target:", enemies, cancel=True)
if choosedEnemy == 0:
#TODO! Выбрана отмена
return False
else:
# Если один противник - его бьёт автоматически
choosedEnemy = enemies[0]
self.simpleAttack(choosedEnemy)
def doTurn(self, hero, enemies):
availableBattleChoices = self.getAvailableBattleChoices()
selectedBattleChoice = utils.getChoice("What would you do?", list(availableBattleChoices.keys()))
availableBattleChoices[selectedBattleChoice](hero, enemies)
## Возвращает Словарь с возможными вариантами хода и методом за них отвечающим
def getAvailableBattleChoices(self):
battleChoices = {}
# Simple attack is always available
battleChoices["Attack with \"{0}\"".format(self.equipment.weapon())] = self.attackChoice
#if not self.spellBook.isEmpty():
# battleChoices["Cast Spell"] = self.castSpellChoice
if not self.potionsPocket.isEmpty():
battleChoices["Use Potion"] = self.usePotionChoice
return battleChoices
## Одевает item в equipment и убирает из inventory
def equip(self, item):
if self.equipment.equipment[item.piece] != "empty":#if there is an item
self.unequip(self.equipment.equipment[item.piece])
#now the slot is empty
self.equipment.equipment[item.piece]=item
#Если вещь в инвентаре - убрать её оттуда
self.inventory.removeItem(item)
#give items Stats bonus and damage/defence
self.stats.addStats(item.bonusStats)
if item.isWeapon():
self.stats.damage.addDamage(item.damage)
if item.isArmor():
self.defence+=item.defence
#Think Нужен ли equipList() - который будет просто вызывать equip для каждой вещи
## Снимает item из equipment и кладёт в inventory
def unequip(self, item):
#remove Stats that this item added
self.stats.removeStats(self.equipment.equipment[item.piece].bonusStats)
if item.isWeapon():
self.stats.damage.removeDamage(item.damage)
if item.isArmor():
self.defence-=item.defence
#add it to inventory
self.inventory.addItem(self.equipment.equipment[item.piece])
#make this slot empty
self.equipment.equipment[item.piece] = "empty"
## Использует вещь на героя (например Зелье)
def use(self, item):
item.use(self)
## Возвращает true Если герой может использовать это (Spell, weapon, armor и т.п.)
def canUse(self, object):
return object.canUse(hero)
def __str__(self):
#return '"{0}" Health: {1}/{2} Mana: {3}/{4} {5} Defence: {6}'.format(self.name,self.hp,self.maxHp,self.mp,self.maxMp,self.stats.damage,self.defence)
return '"{0}" Health: {1.hp}/{1.maxHp} Mana: {1.mp}/{1.maxMp} {1.damage} Defence: {2}'.format(self.name, self.stats, self.defence)