From e4209cb4188d2b541492c5989c44003378929919 Mon Sep 17 00:00:00 2001 From: rustushki Date: Sun, 26 Nov 2006 23:54:53 +0000 Subject: [PATCH] Documentation Update. Part 2. Also, I removed job.py. Deprecated as of 0.2.2. --- consoleview.py | 1 + fighter.py | 84 +++++++++++++++++++--- job.py | 219 --------------------------------------------------------- statistic.py | 30 +++++++- 4 files changed, 105 insertions(+), 229 deletions(-) delete mode 100644 job.py diff --git a/consoleview.py b/consoleview.py index a8bc6d8..899acc3 100644 --- a/consoleview.py +++ b/consoleview.py @@ -130,6 +130,7 @@ class ConsoleView: print "=============================================================" def printStartupMenu(self): + """ Prints out the menu seen at startup and in-between battles. """ print "=============================================================" print "[1]. New Game" print "[2]. Load Game" diff --git a/fighter.py b/fighter.py index 9b85b18..0b3e0c8 100644 --- a/fighter.py +++ b/fighter.py @@ -27,9 +27,54 @@ import struct from utilities import * from struct import pack class Fighter: + """ This class represents a playable or non-playable fighter. """ + + name = "" + """ Name of the fighter. Let's keep it down to 15 characters. """ + + jobType = "" + """ Name of the Fighter's job type. """ + + playable = False + """ Whether the user gets to decide a fighter's course of action or not. """ + + timeOfMove = 0 + """ Time that the Fighter gets to move next. """ + + stat = [] + """ List of stats for a fighter, i.e. HP, MP, EXP ... """ + + equiption = None + """ All armor and weapons on the fighter's person. """ + + status = [] + """ Statuses that are afflicting this Fighter. Statuses are not saved + in the data files (at the moment). Generally, rpgs don't save statuses + after battle. This should be talked about in the future.""" + + elemMod = [] + """ A tuple-list. Each tuple contains the name of the element and how + it modifies the base change. If the element is not in this list, + modifier is assumed to be 0 (no modification). """ + + statusMod = [] + """ A tuple-list. Each tuple contains the name of the status and what + it's chance of being afflicted is. If the status is not in this list, + chance is assumed to be 100% (=1.0, always inflicts). """ + def __init__(self,fTree=None,binary=None): - """ Construct a Fighter object from a job type XML tree and either a fighter type XML tree or packed binary data. """ + """ Construct a Fighter object from a job type XML tree and either a fighter type XML tree or packed binary data. + * If "binary" specified: + Uses unpack() to instantiate the Fighter object based + off a string of binary data. Note that it needs a job class xml tree to + populate job class related stat members. + + * If "binary" is "": + Uses XPath queries to instantiate the Fighter object based off a given XML + document tree. Note that it needs a job class xml tree to populate job class + related stat members. + """ # If there was a fighter tree specified if fTree != None: @@ -190,7 +235,7 @@ class Fighter: self.__status = [] def toBinaryString(self): - """Convert Fighter data to binary string.""" + """Convert Fighter data to binary string, using struct's pack method.""" binStr = pack("!B20s20s20s20s20s20sB7I6B",0,self.__name,self.__jobType,self.__equiption.getHead(),self.__equiption.getArmor(),self.__equiption.getRight(),self.__equiption.getLeft(),self.getStat("level").getMax(),self.getStat("exp").getCurrent(),self.getStat("exptnl").getCurrent(),self.getStat("exptnl").getMax(),self.getStat("hp").getCurrent(),self.getStat("hp").getMax(),self.getStat("mp").getCurrent(),self.getStat("mp").getMax(),self.getStat("str").getMax(),self.getStat("dex").getMax(),self.getStat("agl").getMax(),self.getStat("spd").getMax(),self.getStat("wis").getMax(),self.getStat("wil").getMax()) return binStr @@ -227,22 +272,27 @@ class Fighter: self.__playable = plyble def getAttack(self): - """Compute value of attack.""" + """Computes value of attack, taking into account all modifiers.""" return self.getStat("str").getCurrent() + self.__equiption.computeAtkMod() def getDefense(self): - """Compute value of defense.""" + """Computes value of defense, taking into account all modifiers.""" return self.__equiption.computeDefMod() def getEvade(self): - """Compute value of evade.""" + """Computes value of evade, taking into account all modifiers.""" return self.getStat("agl").getCurrent() + self.__equiption.computeEvaMod() def makeEvent(self, eparty, fparty, currentTime, cont): - """ Check if ready to make move. - - If so, select random fighter from enemy party and return. + """ + This method does a lot of stuff. If the Fighter is not ready to move or is being prevented from making a move (i.e. canmove < 1), no event can be made. Fighters have an "ai" statistic: + ai = 0: playable fighter; user selects move. + ai = 1: monster fighter; move randomly decided and target(s) randomly decided from hero party. + ai = 2: fighter afflicted with madness; move and target(s) randomly select from either party. + + PerTurn status transactions are processed at the beginning of makeEvent. + PerTurnOnMove status transactions are processed when an event is generated. """ if self.getStat("tom").getCurrent() != currentTime: return None @@ -316,7 +366,7 @@ class Fighter: return (self.getStat("hp").getCurrent() > 0) def getEventTypes(self,eventTypes): - """Return list of events available to fighter.""" + """Return list of events available to fighter. Currently hard-coded.""" etypes = [] if self.__jobType == "blackmage": @@ -431,6 +481,13 @@ class Fighter: exptnl_s.setCurrent(int(exptnl_s.getMax() + exptnl_s.getCurrent())) def getElemModifier(self,elem): + """ Retrieves this information currently just from elemMod. If + the elemental name specified is found in the elemMod, and return the associated + modifier. The modifier is a float x where -2.0 <= x <= 2.0. If x is negative, + elemental effects hurt (remove hp). If x is positive, they cure (add hp). Some + Elementals may be innate to the Fighter, others might come from armor (armor + portion not yet implemented). """ + for elemMod in self.__elemMod: if elem == elemMod[0]: return elemMod[1] @@ -438,6 +495,12 @@ class Fighter: return 0.0 def getStatusModifier(self,stat): + """ Retrieves the status name specified, and return the + associated modifier. The modifier is a float x where 0 <= x <= 1.0. If x is 0, + Fighter is immune to stat. If x > 0, it represents the chance of being + afflicted with a stat. Some Status defenses may be innate to Fighter, others + might come from armor (armor portion not yet implemented). """ + for statusMod in self.__statusMod: if stat == statusMod[0]: return statusMod[1] @@ -481,14 +544,17 @@ class Fighter: print 'ERROR: Status was not in list!' def getStat(self,statName): + """ Get Statistic object for this Fighter by Statistic object name """ for stat in self.__stats: if stat.getName() == statName: return stat print 'ERROR: No such Fighter stat.' def getAllStats(self): + """ Get entire statistic object list """ return self.__stats def setAllStats(self,stats): + """ Set entire statistic object list """ self.__stats = stats diff --git a/job.py b/job.py deleted file mode 100644 index 133163f..0000000 --- a/job.py +++ /dev/null @@ -1,219 +0,0 @@ -######################################################## -#Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors -#This file is part of Asgard. -# -#Asgard 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 2 of the License, or -#(at your option) any later version. -# -#Asgard 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 Asgard; if not, write to the Free Software -#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -######################################################## -class Job: - - def __init__(self,n,expTill,hpp,mpp,strp,spdp,dexp,aglp,wisp,wp,hpch,mpch,strch,spdch,dexch,aglch,wisch,wch): - self.__name = n - self.__expTillLevelGR = expTill - self.__hpPlus = hpp - self.__mpPlus = mpp - self.__strPlus = strp - self.__speedPlus = spdp - self.__dexPlus = dexp - self.__agilityPlus = aglp - self.__wisdomPlus = wisp - self.__willPlus = wp - self.__hpChance = hpch - self.__mpChance = mpch - self.__strChance = strch - self.__speedChance = spdch - self.__dexChance = dexch - self.__agilityChance = aglch - self.__wisdomChance = wisch - self.__willChance = wch - - def getName(self): - """ Get Job Name. """ - - return self.__name - - def setName(self,n): - """ Set Job Name. """ - - self.__name = n - - def getExpTillLevelGR(self): - """ Get next level exp growth rate. """ - - return self.__expTillLevelGR - - def setExpTillLevelGR(self,expTill): - """ Set next level exp growth rate. """ - - self.__expTillLevelGR = expTill - - def getHpPlus(self): - """ Get hp increase for leveling up. """ - - return self.__hpPlus - - def setHpPlus(self, hpp): - """ Set hp increase for leveling up. """ - - self.__hpPlus = hpp - - def getMpPlus(self): - """ Get mp increase for leveling up. """ - - return self.__mpPlus - - def setMpPlus(self, mpp): - """ Set mp increase for leveling up. """ - - self.__mpPlus = mpp - - def getStrPlus(self): - """ Get strength increase for leveling up. """ - - return self.__strPlus - - def setStrPlus(self, strp): - """ Set strength increase for leveling up. """ - - self.__strPlus = strp - - def getSpeedPlus(self): - """ Get speed increase for leveling up. """ - - return self.__speedPlus - - def setSpeedPlus(self,spdp): - """ Set speed increase for leveling up. """ - - self.__speedPlus = spdp - - def getDexPlus(self): - """ Get dexterity increase for leveling up. """ - - return self.__dexPlus - - def setDexPlus(self, dexp): - """ Get dexterity increase for leveling up. """ - - self.dexPlus = dexp - - def getAgilityPlus(self): - """ Get agility increase for leveling up. """ - - return self.__agilityPlus - - def setAgilityPlus(self,aglp): - """ Set agility increase for leveling up. """ - - self.__agilityPlus = aglp - - def getWisdomPlus(self): - """ Get wisdom increase for leveling up. """ - - return self.__wisdomPlus - - def setWisdomPlus(self,wisp): - """ Set wisdom increase for leveling up. """ - - self.__wisdomPlus = wisp - - def getWillPlus(self): - """ Get will increase for leveling up. """ - - return self.__willPlus - - def setWillPlus(self,wp): - """ Set will increase for leveling up. """ - - self.__willPlus = wp - - def getHpChance(self): - """ Get hp increase chance. """ - - return self.__hpChance - - def setHpChance(self, hpch): - """ Set hp increase chance. """ - - self.__hpChance = hpch - - def getMpChance(self): - """ Get mp increase chance. """ - - return self.__mpChance - - def setMpChance(self, mpch): - """ Set mp increase chance. """ - - self.__mpChance = mpch - - def getStrChance(self): - """ Get strength increase chance. """ - - return self.__strChance - - def setStrChance(self, strch): - """ Set strength increase chance. """ - - self.__strChance = strch - - def getSpeedChance(self): - """ Get speed increase chance. """ - - return self.__speedChance - - def setSpeedChance(self,spdch): - """ Set speed increase chance. """ - - self.__speedChance = spdch - - def getDexChance(self): - """ Get dexterity increase chance. """ - - return self.__dexChance - - def setDexChance(self, dexch): - """ Set dexterity increase chance. """ - - self.__dexChance = dexch - - def getAgilityChance(self): - """ Get agility increase chance. """ - - return self.__agilityChance - - def setAgilityChance(self,aglch): - """ Set agility increase chance. """ - - self.__agilityChance = aglch - - def getWisdomChance(self): - """ Get wisdom increase chance. """ - - return self.__wisdomChance - - def setWisdomChance(self,wisch): - """ Set wisdom increase chance. """ - - self.__wisdomChance = wisch - - def getWillChance(self): - """ Get will increase chance. """ - - return self.__willChance - - def setWillChance(self,wch): - """ Set will increase chance. """ - - self.__willChance = wch diff --git a/statistic.py b/statistic.py index b74679e..f21ee2f 100644 --- a/statistic.py +++ b/statistic.py @@ -17,8 +17,36 @@ #Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ######################################################## class Statistic: + """ Represents a statistic associated with a Fighter object, along with + a number of statistic meta data. """ + + name = "" + """ Name of statistic. (i.e. "hp") """ + + current = 0 + """ Current value. (i.e. 350 points) """ + + max = 0 + """ Maximum value. (i.e. 500 points) If < 0, this statistic is deleted + from Fighter after the battle is over. """ + + afterBattle = True + """ Whether the statistic retains its "current" value after battle. """ + + plus = 0 + """ How much this stat goes up (maximally), on level up. """ + + chance = 0.0 + """ The chances that it will go up on level up. """ + + growthRate = 0.0 + """ Some things do not grow at a constant rate, i.e HP. This determines + how fast a stat grows with reference to it's previous value. For + example, HP = HP + (HP * growthRate). """ + + def __init__(self,name,current,max,afterBattle,plus,chance,growthRate): - """Constructor.""" + """Simple Constructor.""" self.__name = name self.__current = current self.__max = max -- 2.11.4.GIT