(no commit message)
[asgard.git] / party.py
blob6f4a7d2870ddf40d3773ea38750eb104017a6b7d
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:
22 """ Model: Party Class """
24 __fighters = []
25 """ List of 1-6 fighters that represents a party. """
27 def __init__(self,name):
28 """ Instantiates Party object. """
30 self.__fighters = []
31 self.__name = name
33 def getName(self):
34 """ Gets name of party. """
36 return self.__name
38 def setName(self,name):
39 """ Sets name of party. """
41 self.__name = name
43 def isAlive(self):
44 """ Does the party have any live fighters? If so, the party is alive. """
46 for f in self.__fighters:
47 if f.isAlive():
48 return True
50 return False
52 def getNextEvent(self, enemy, ctime, cont):
53 """ Find the fighter in the party who is ready to generate an
54 event and whose dexterity stat is the highest. Return that event. If no events
55 are available, return the None object. """
57 ffWithHighestDex = None
58 efWithHighestDex = None
60 # The Party should be alive - you never know.
61 if not self.isAlive():
62 return None
64 # find the enemy that's ready that has the highest dex
65 for f in enemy.getFighters():
66 if f.getStat("tom").getCurrent() <= ctime:
67 if efWithHighestDex == None:
68 efWithHighestDex = f
69 elif efWithHighestDex.getStat("dex").getCurrent() < f.getStat("dex").getCurrent():
70 efWithHighestDex = f
72 #find the friendly fighter that's ready that has the highest dex
73 for f in self.__fighters:
74 if f.getStat("tom").getCurrent() <= ctime:
75 if ffWithHighestDex == None:
76 ffWithHighestDex = f
77 elif ffWithHighestDex.getStat("dex").getCurrent() < f.getStat("dex").getCurrent():
78 ffWithHighestDex = f
80 # does the friendly or the enemy have the highest dex
81 # if friendly, make event
82 if ffWithHighestDex == None:
83 return None
84 elif ffWithHighestDex.isAlive():
86 if efWithHighestDex == None:
87 # create the event
88 event = ffWithHighestDex.makeEvent(enemy,self,ctime,cont)
90 # recompute the next time they get to move
91 tom = ffWithHighestDex.getStat("tom").getMax() + round((1/float(ffWithHighestDex.getStat("spd").getMax()))*100)
92 ffWithHighestDex.getStat("tom").setCurrent(tom)
93 ffWithHighestDex.getStat("tom").setMax(tom)
95 return event
96 elif ffWithHighestDex.getStat("dex").getCurrent() < efWithHighestDex.getStat("dex").getCurrent():
98 # create the event
99 event = ffWithHighestDex.makeEvent(enemy,self,ctime,cont)
101 # compute the next time they get to move
102 tom = ffWithHighestDex.getStat("tom").getMax() + round((1/float(ffWithHighestDex.getStat("spd").getMax()))*100)
103 ffWithHighestDex.getStat("tom").setCurrent(tom)
104 ffWithHighestDex.getStat("tom").setMax(tom)
106 return event
108 else:
109 # recompute the next time they get to move
110 # this is so that the dead still know when their next turn is
111 tom = ffWithHighestDex.getStat("tom").getMax() + round((1/float(ffWithHighestDex.getStat("spd").getMax()))*100)
112 ffWithHighestDex.getStat("tom").setCurrent(tom)
113 ffWithHighestDex.getStat("tom").setMax(tom)
115 return None
117 def addFighter(self,fighter):
118 """ Add a fighter to the party. """
120 if self.sizeOfParty() != 6:
121 self.__fighters.append(fighter)
122 return True
123 return False
125 def getFighter(self, n):
126 """ Get a fighter from the party. """
128 return self.__fighters[n]
130 def getFighters(self):
131 """ Get list of all fighters from party. """
133 return self.__fighters
135 def sizeOfParty(self):
136 """ Computes the number of live AND dead fighters in the party. """
138 return len(self.__fighters)
140 def giveExp(self, exp):
141 """ Takes an amount of experience (presumably the total
142 experience of a defeated party), and divides it evenly among the party's
143 surviving fighters by calling Fighter.receiveExp(). """
145 fighters = self.getFighters()
147 numLeft = 0
148 for f in fighters:
149 if f.isAlive():
150 numLeft += 1
152 exp = exp/numLeft
154 for f in fighters:
155 f.receiveExp(exp)