Refactored to stop passing game around.
[realism.git] / engine / party.py
blobc4fdcc8ed7f2cf72e1296c2df7ee66ee1700f5e5
1 from character import character
2 from being import agility, zen
3 from spells import *
4 from items import *
5 from game import game
7 class Party(object):
8 def __init__(self, chars):
9 self.chars = chars
10 self.claim_chars()
12 def is_dead(self):
13 for char in self.chars:
14 if char.is_alive():
15 return False
16 return True
18 def living_chars(self):
19 return [char for char in self.chars if char.is_alive()]
21 def claim_chars(self):
22 for char in self.chars:
23 char.party = self
25 def find_max(self, ability):
26 max = -1
27 whose = None
28 for char in self.chars:
29 if char.stats[ability] > max:
30 max = char.stats[ability]
31 whose = char
33 return (max, whose)
35 def max_zen(self):
36 return self.find_max(zen)[1]
38 def zen_bleed(self):
39 max_zen = self.find_max(zen)[0]
40 return max(int(max_zen * .9), max_zen - 5)
42 def agility_bleed(self):
43 max_agility = self.find_max(agility)[0]
44 return max(int(max_agility * .9), max_agility - 5)
46 class HeroParty(Party):
47 def __init__(self):
48 self.gold = 1000
49 self.items = []
50 chars = [character(name="FM", level=1, character_number=0, pronoun="he")]
51 Party.__init__(self, chars)
53 def got_item(self, item):
54 for inv in self.items:
55 if inv == item:
56 inv.count += item.count
57 return
58 self.items.append(item)
60 def lost_item(self, item, num):
61 self.items[item].count -= num
62 if self.items[item].count <= 0:
63 del self.items[item]
65 def get_items(self):
66 return self.items
68 def get_spells(self):
69 spells = []
70 if healing_stone in self.items:
71 spells.append(heal)
72 return spells