Documentation Update. Part 2.
[asgard.git] / party.py
blobb957f88a8b8dfe0c113113a99eee5bdaea7d4f44
1 ########################################################
2 #Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors
3 #This file is part of Asgard.
5 #Asgard is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Asgard is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Asgard; if not, write to the Free Software
17 #Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 ########################################################
19 from event import *
21 class Party:
23 def __init__(self,name):
24 """Constructor."""
25 self.__fighters = []
26 self.__name = name
28 def getName(self):
29 return self.__name
31 def setName(self,name):
32 self.__name = name
34 def isAlive(self):
35 """Is party alive?"""
36 for f in self.__fighters:
37 if f.isAlive():
38 return True
40 return False
42 def getNextEvent(self, enemy, ctime, cont):
43 """Check moves for enemy."""
45 ffWithHighestDex = None
46 efWithHighestDex = None
48 # The Party should be alive - you never know.
49 if not self.isAlive():
50 return None
52 # find the enemy that's ready that has the highest dex
53 for f in enemy.getFighters():
54 if f.getStat("tom").getCurrent() <= ctime:
55 if efWithHighestDex == None:
56 efWithHighestDex = f
57 elif efWithHighestDex.getStat("dex").getCurrent() < f.getStat("dex").getCurrent():
58 efWithHighestDex = f
60 #find the friendly fighter that's ready that has the highest dex
61 for f in self.__fighters:
62 if f.getStat("tom").getCurrent() <= ctime:
63 if ffWithHighestDex == None:
64 ffWithHighestDex = f
65 elif ffWithHighestDex.getStat("dex").getCurrent() < f.getStat("dex").getCurrent():
66 ffWithHighestDex = f
68 # does the friendly or the enemy have the highest dex
69 # if friendly, make event
70 if ffWithHighestDex == None:
71 return None
72 elif ffWithHighestDex.isAlive():
74 if efWithHighestDex == None:
75 # create the event
76 event = ffWithHighestDex.makeEvent(enemy,self,ctime,cont)
78 # recompute the next time they get to move
79 tom = ffWithHighestDex.getStat("tom").getMax() + round((1/float(ffWithHighestDex.getStat("spd").getMax()))*100)
80 ffWithHighestDex.getStat("tom").setCurrent(tom)
81 ffWithHighestDex.getStat("tom").setMax(tom)
83 return event
84 elif ffWithHighestDex.getStat("dex").getCurrent() < efWithHighestDex.getStat("dex").getCurrent():
86 # create the event
87 event = ffWithHighestDex.makeEvent(enemy,self,ctime,cont)
89 # compute the next time they get to move
90 tom = ffWithHighestDex.getStat("tom").getMax() + round((1/float(ffWithHighestDex.getStat("spd").getMax()))*100)
91 ffWithHighestDex.getStat("tom").setCurrent(tom)
92 ffWithHighestDex.getStat("tom").setMax(tom)
94 return event
96 else:
97 # recompute the next time they get to move
98 # this is so that the dead still know when their next turn is
99 tom = ffWithHighestDex.getStat("tom").getMax() + round((1/float(ffWithHighestDex.getStat("spd").getMax()))*100)
100 ffWithHighestDex.getStat("tom").setCurrent(tom)
101 ffWithHighestDex.getStat("tom").setMax(tom)
103 return None
105 def addFighter(self,fighter):
106 if self.sizeOfParty() != 6:
107 self.__fighters.append(fighter)
108 return True
109 return False
111 def getFighter(self, n):
112 """Return fighter."""
113 return self.__fighters[n]
115 def getFighters(self):
116 return self.__fighters
118 def sizeOfParty(self):
119 """Compute party's size."""
120 return len(self.__fighters)
122 def giveExp(self, exp):
123 """Divy up battle experience among living fighters in party."""
124 fighters = self.getFighters()
126 numLeft = 0
127 for f in fighters:
128 if f.isAlive():
129 numLeft += 1
131 exp = exp/numLeft
133 for f in fighters:
134 f.receiveExp(exp)