From 4ec96cf6a997504485b6a2968bade56e80629952 Mon Sep 17 00:00:00 2001 From: rustushki Date: Thu, 28 Sep 2006 19:06:18 +0000 Subject: [PATCH] --- COPYING | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 22 ++++ battle.py | 118 ++++++++++++++++++ consolecontroller.py | 217 +++++++++++++++++++++++++++++++++ consoleview.py | 101 +++++++++++++++ data/fighter/Jade | 20 +++ data/fighter/Kyle | 20 +++ data/fighter/Ryan | 20 +++ data/fighter/imp1 | 20 +++ data/fighter/imp2 | 20 +++ data/fighter/imp3 | 20 +++ data/fighter/imp4 | 20 +++ data/fighter/imp5 | 20 +++ data/fighter/imp6 | 20 +++ data/job/archer | 16 +++ data/job/npc | 16 +++ data/job/swordsman | 16 +++ data/job/thief | 16 +++ data/party/party1 | 2 + data/party/party2 | 2 + equiption.py | 110 +++++++++++++++++ event.py | 74 +++++++++++ fighter.py | 294 ++++++++++++++++++++++++++++++++++++++++++++ job.py | 197 ++++++++++++++++++++++++++++++ main.py | 30 +++++ party.py | 109 +++++++++++++++++ 26 files changed, 1859 insertions(+) create mode 100644 COPYING create mode 100644 Makefile create mode 100644 battle.py create mode 100644 consolecontroller.py create mode 100644 consoleview.py create mode 100644 data/fighter/Jade create mode 100644 data/fighter/Kyle create mode 100644 data/fighter/Ryan create mode 100644 data/fighter/imp1 create mode 100644 data/fighter/imp2 create mode 100644 data/fighter/imp3 create mode 100644 data/fighter/imp4 create mode 100644 data/fighter/imp5 create mode 100644 data/fighter/imp6 create mode 100644 data/job/archer create mode 100644 data/job/npc create mode 100644 data/job/swordsman create mode 100644 data/job/thief create mode 100644 data/party/party1 create mode 100644 data/party/party2 create mode 100644 equiption.py create mode 100644 event.py create mode 100644 fighter.py create mode 100644 job.py create mode 100755 main.py create mode 100644 party.py diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d511905 --- /dev/null +++ b/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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. + + This program 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 this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e4939b5 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +######################################################## +#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 +######################################################## +run: + - ./main.py +clean: + - rm *.pyc diff --git a/battle.py b/battle.py new file mode 100644 index 0000000..5bc5eec --- /dev/null +++ b/battle.py @@ -0,0 +1,118 @@ +######################################################## +#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 +######################################################## +from os import listdir +from time import * +from fighter import * +from party import * +from event import * +from job import * +class Battle: + + def __init__(self): + self.__currentTime = 0 + self.__party1 = None + self.__party2 = None + self.__jobList = [] + + def isOver(self): + """ Is battle over?""" + + return not self.__party1.isAlive() or not self.__party2.isAlive() + + def nextTurn(self): + """ Execute next iteration in gameloop.""" + + sleep(.1) + + wereEvents = False + + # execute all available events + while self.executeNextEvent(): + # if there was at least one event + wereEvents = True + continue + + self.__currentTime += 1 + + return wereEvents + + def executeNextEvent(self): + """ Execute next event in event queue. Return true if there were events. """ + + if self.isOver(): + return False + + # Try to get an event from party1 + event = self.__party1.getNextEvent(self.__party2,self.__currentTime,self.__controller) + + # If there was one, execute and return true + if event != None: + self.__view.printEvent(event) + event.execute() + return True + + # Try to get an event from party2 + event = self.__party2.getNextEvent(self.__party1,self.__currentTime,self.__controller) + + # If there was one, execute and return true + if event != None: + self.__view.printEvent(event) + event.execute() + return True + + # Otherwise, notify that there are no more events at this time. + return False + + def getCurrentTime(self): + """ Retrieve current time.""" + return self.__currentTime + + def setCurrentTime(self,t): + """ Establish current time.""" + self.__currentTime = t + + def getParty1(self): + """ Retrieve party1.""" + return self.__party1 + + def setParty1(self, p): + """ Set party1.""" + self.__party1 = p + + def getParty2(self): + """ Retrieve party2.""" + return self.__party2 + + def setParty2(self, p): + """ Set party2.""" + self.__party2 = p + + def setView(self,v): + """ Establish view.""" + self.__view = v + + def setController(self,c): + """ Establish controller.""" + self.__controller = c + + def getJobList(self): + return self.__jobList + + def setJobList(self,jobList): + self.__jobList = jobList diff --git a/consolecontroller.py b/consolecontroller.py new file mode 100644 index 0000000..a80142b --- /dev/null +++ b/consolecontroller.py @@ -0,0 +1,217 @@ +######################################################## +#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 +######################################################## +from os import listdir +from battle import * +from equiption import * +from fighter import * + +class ConsoleController: + def __init__(self,debug,battle,view): + self.__debug = debug + self.__battle = battle + self.__view = view + + battle.setController(self) + battle.setView(view) + view.setController(self) + view.setBattle(battle) + + self.load() + self.__gameLoop() + self.save() + + def getCommand(self,p,f): + + command = [] + + print "\033[1;34m[SELCT]\033[1;0m Turn:" + f.getName() + "; HP:" + str(f.getHpCurrent()) + "/" + str(f.getHpMax()) + + self.__view.printEnemySelectMenu(p) + n = raw_input("% ") + d = p.getFighter(int(n)-1) + + self.__view.printEventTypeMenu(f) + n = raw_input("% ") + t = f.getEventTypes()[int(n)-1] + + return [d,t] + + def getDebug(self): + return self.__debug + + def setDebug(self,d): + self.__debug = d + + def __gameLoop(self): + """Retrieves events from Parties and Executes all Events in queue per iteration""" + + print "Battle Starts." + self.__view.printState() + + # initialize the event checker boolean + wereEvents = False + + while not self.__battle.isOver(): + # next iteration + wereEvents = self.__battle.nextTurn() + + # only print out state if something actually happened + if wereEvents: + self.__view.printState() + + if self.__battle.getParty1().isAlive(): + # sum exp from enemy party + exp = 0 + for f in self.__battle.getParty2().getFighters(): + exp += f.getExp() + + # hero party gets exp + self.__battle.getParty1().giveExp(exp) + + print "Final Results" + print "=============================================================" + self.__view.printParty(self.__battle.getParty1()) + print "=============================================================" + print "Victory Fanfare. Heros win "+str(exp)+" exp!" + else: + print "Game Over. Imps win." + + + def load(self): + """Load game.""" + + ### Loading job classes ### + dir = listdir('./data/job') + self.__battle.setJobList([]) + for j in dir: + + if j[0] == ".": + continue + + j = './data/job/'+j + fptr = open(j,'r') + lines = fptr.readlines() + self.__battle.getJobList().append(Job(lines[0].strip(),float(lines[1]),int(lines[2]),int(lines[3]),int(lines[4]),int(lines[5]),int(lines[6]),int(lines[7]),int(lines[8]),float(lines[9]),float(lines[10]),float(lines[11]),float(lines[12]),float(lines[13]),float(lines[14]),float(lines[15]))) + fptr.close() + + ### Loading parties ### + self.__battle.setParty1(None) + self.__battle.setParty2(None) + dir = listdir('./data/party/') + for p in dir: + + if p[0] == ".": + continue + + p = './data/party/'+p + fptr = open(p,'r') + lines = fptr.readlines() + if int(lines[0]) == 1: + self.__battle.setParty1(Party(lines[1].strip())) + elif int(lines[0]) == 2: + self.__battle.setParty2(Party(lines[1].strip())) + fptr.close() + + ### Loading fighters ### + dir = listdir('./data/fighter/') + for f in dir: + # f cannot be a "." file + if f[0] == '.': + continue + # Change file into pathname + f = './data/fighter/'+f + # Open file f for 'r'eading + fptr = open(f,'r') + # Place lines in file f into list + lines = fptr.readlines() + + # chop up the lines + name = lines[0].strip() + jobname = lines[1].strip() + level = int(lines[2]) + exp = int(lines[3]) + exptnlm = int(lines[4]) + exptnl = int(lines[5]) + maxhp = int(lines[6]) + currenthp = int(lines[7]) + str = int(lines[8]) + speed = int(lines[9]) + dex = int(lines[10]) + agility = int(lines[11]) + wisdom = int(lines[12]) + will = int(lines[13]) + playable = bool(int(lines[14].strip())) + head = lines[15].strip() + body = lines[16].strip() + left = lines[17].strip() + right = lines[18].strip() + pn = int(lines[19]) + + #this tom calc. might should be moved to the fighter constructor + tom = round((1/float(speed))*100) + equip = Equiption(head,body,left,right) + + for job in self.__battle.getJobList(): + if job.getName() == jobname: + break + + # Create fighter(name,hp,str,dex,head,l,r,body) + fighter1 = Fighter(name,level,exp,exptnlm,exptnl,maxhp,currenthp,str,speed,dex,agility,wisdom,will,tom,playable,equip,job) + + + # Add fighter to respective party (1 or 2) + if pn == 1: + self.__battle.getParty1().addFighter(fighter1) + elif pn == 2: + self.__battle.getParty2().addFighter(fighter1) + # Close file f + fptr.close() + + + def save(self): + for f in self.__battle.getParty1().getFighters(): + fptr = open("./data/fighter/" + f.getName(),"w") + e = f.getEquiption() + j = f.getJob() + fptr.write(f.getName() + "\n") + fptr.write(j.getName() + "\n") + fptr.write(str(f.getLevel()) + "\n") + fptr.write(str(f.getExp()) + "\n") + fptr.write(str(f.getExpTillNextLevelMax()) + "\n") + fptr.write(str(f.getExpTillNextLevel()) + "\n") + fptr.write(str(f.getHpMax()) + "\n") + fptr.write(str(f.getHpCurrent()) + "\n") + fptr.write(str(f.getStrength()) + "\n") + fptr.write(str(f.getSpeed()) + "\n") + fptr.write(str(f.getDexterity()) + "\n") + fptr.write(str(f.getAgility()) + "\n") + fptr.write(str(f.getWisdom()) + "\n") + fptr.write(str(f.getWill()) + "\n") + + if f.getPlayable(): + fptr.write(str(1) + "\n") + else: + fptr.write(str(0) + "\n") + + fptr.write(e.getHead() + "\n") + fptr.write(e.getArmor() + "\n") + fptr.write(e.getLeft() + "\n") + fptr.write(e.getRight() + "\n") + fptr.write(str(1) + "\n") + fptr.close() diff --git a/consoleview.py b/consoleview.py new file mode 100644 index 0000000..6602bc5 --- /dev/null +++ b/consoleview.py @@ -0,0 +1,101 @@ +######################################################## +#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 ConsoleView: + """Viewer object for Asgard""" + + def __init__(self): + pass + + def printParty(self, p): + """Show party stats.""" + + print "\033[1;35m[PARTY]\033[1;0m NAME:"+p.getName() + + for f in p.getFighters(): + self.printFighter(f) + + def printFighter(self, f): + """Show fighter stats.""" + + job = f.getJob() + + print "\033[1;35m[FGHTR]\033[1;0m NAME:"+f.getName()+"\tJOB:"+job.getName()+"\tHP:"+str(f.getHpCurrent())+"/"+str(f.getHpMax())+"\tPOWR:"+str(f.getAttack())+"\tDFNS:"+str(f.getDefense())+"\tEVAD:"+str(f.getEvade()) + + #Uncomment this when getEquiption is implemented + #printEquiption(f.getEquiption()) + + def printEvent(self, e): + """Show Event data.""" + + print "\033[1;33m[EVENT]\033[1;0m EXECUTOR:" + e.getExecutor().getName() + "\tTarget:" + e.getTarget().getName() + "\tTYPE:" + e.getType() + + def printEquiption(self, eq): + """Show equiption for fighter.""" + + print "\033[1;36m[EQUIP]\033[1;0m HEAD:" + eq.getHead() + "\tARMR:" + eq.getArmor() + "\tLEFT:" + eq.getLeft() + "\tRGHT:" + eq.getRight() + + def printEventTypeMenu(self, f): + """Show battle menu options for fighter.""" + + i = 1 + menu = "" + for e in f.getEventTypes(): + menu += "("+str(i)+")"+" "+e+"\t" + i += 1 + print menu + + def printEnemySelectMenu(self, p): + """Show enemy selection options for fighter""" + + i = 1 + menu = "" + for f in p.getFighters(): + # Dead fighters tell no tales... + if not f.isAlive(): + i += 1 + continue + + # Create enemy selection menu + menu += "("+str(i)+")"+" "+f.getName()+" "+"HP: "+str(f.getHpCurrent())+"/"+str(f.getHpMax())+"\t" + + i += 1 + + print menu + + def printState(self): + """Show state.""" + + if self.__controller.getDebug(): + # Retrieve parties 1 and 2 + party1 = self.__battle.getParty1() + party2 = self.__battle.getParty2() + + # Print Party1 + self.printParty(party1) + + # Print Party2 + self.printParty(party2) + + print "=============================================================" + + def setBattle(self,b): + self.__battle = b + + def setController(self,c): + self.__controller = c diff --git a/data/fighter/Jade b/data/fighter/Jade new file mode 100644 index 0000000..47e79f6 --- /dev/null +++ b/data/fighter/Jade @@ -0,0 +1,20 @@ +Jade +Archer +1 +0 +200 +200 +60 +60 +20 +8 +25 +15 +7 +7 +1 +Helm +Chain Mail +Bow +Shield +1 diff --git a/data/fighter/Kyle b/data/fighter/Kyle new file mode 100644 index 0000000..9cb9bb9 --- /dev/null +++ b/data/fighter/Kyle @@ -0,0 +1,20 @@ +Kyle +Swordsman +1 +0 +350 +350 +200 +200 +25 +6 +10 +10 +7 +12 +1 +Helm +Cloak +Sword +Shield +1 diff --git a/data/fighter/Ryan b/data/fighter/Ryan new file mode 100644 index 0000000..2a3b8f2 --- /dev/null +++ b/data/fighter/Ryan @@ -0,0 +1,20 @@ +Ryan +Thief +1 +0 +100 +100 +150 +150 +12 +13 +30 +25 +7 +15 +1 +Helm +Cloak +Staff +Shield +1 diff --git a/data/fighter/imp1 b/data/fighter/imp1 new file mode 100644 index 0000000..280cb37 --- /dev/null +++ b/data/fighter/imp1 @@ -0,0 +1,20 @@ +Vrigka +Monster +4 +6000 +0 +0 +1 +1 +4 +3 +3 +3 +3 +3 +0 +Helm +Chain Mail +Sword +Shield +2 diff --git a/data/fighter/imp2 b/data/fighter/imp2 new file mode 100644 index 0000000..1fee887 --- /dev/null +++ b/data/fighter/imp2 @@ -0,0 +1,20 @@ +Rodagog +Monster +4 +50 +0 +0 +40 +40 +4 +5 +5 +5 +3 +3 +0 +Helm +Chain Mail +Sword +Shield +2 diff --git a/data/fighter/imp3 b/data/fighter/imp3 new file mode 100644 index 0000000..300f4b3 --- /dev/null +++ b/data/fighter/imp3 @@ -0,0 +1,20 @@ +Kabugbu +Monster +4 +60 +0 +0 +25 +25 +9 +6 +6 +6 +3 +3 +0 +Helm +Chain Mail +Sword +Shield +2 diff --git a/data/fighter/imp4 b/data/fighter/imp4 new file mode 100644 index 0000000..f66d2bf --- /dev/null +++ b/data/fighter/imp4 @@ -0,0 +1,20 @@ +Kagan +Monster +4 +50 +0 +0 +30 +30 +4 +5 +5 +5 +3 +3 +0 +Helm +Chain Mail +Sword +Shield +2 diff --git a/data/fighter/imp5 b/data/fighter/imp5 new file mode 100644 index 0000000..09cd5bf --- /dev/null +++ b/data/fighter/imp5 @@ -0,0 +1,20 @@ +Shomdud +Monster +4 +100 +0 +0 +60 +60 +10 +5 +5 +5 +3 +3 +0 +Helm +Chain Mail +Sword +Shield +2 diff --git a/data/fighter/imp6 b/data/fighter/imp6 new file mode 100644 index 0000000..1d4ae37 --- /dev/null +++ b/data/fighter/imp6 @@ -0,0 +1,20 @@ +Crunxor +Monster +3 +40 +0 +0 +30 +30 +7 +5 +5 +5 +3 +3 +0 +Helm +Chain Mail +Sword +Shield +2 diff --git a/data/job/archer b/data/job/archer new file mode 100644 index 0000000..c65aed2 --- /dev/null +++ b/data/job/archer @@ -0,0 +1,16 @@ +Archer +.35 +15 +1 +3 +1 +2 +0 +0 +.6 +.5 +.2 +.3 +.3 +.0 +.0 diff --git a/data/job/npc b/data/job/npc new file mode 100644 index 0000000..c2a1373 --- /dev/null +++ b/data/job/npc @@ -0,0 +1,16 @@ +Monster +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 diff --git a/data/job/swordsman b/data/job/swordsman new file mode 100644 index 0000000..3efc8c2 --- /dev/null +++ b/data/job/swordsman @@ -0,0 +1,16 @@ +Swordsman +.75 +50 +3 +2 +2 +2 +0 +0 +.7 +.6 +.3 +.2 +.3 +.0 +.0 diff --git a/data/job/thief b/data/job/thief new file mode 100644 index 0000000..444faa5 --- /dev/null +++ b/data/job/thief @@ -0,0 +1,16 @@ +Thief +.40 +20 +1 +4 +3 +6 +0 +0 +.7 +.4 +.3 +.35 +.25 +.0 +.0 diff --git a/data/party/party1 b/data/party/party1 new file mode 100644 index 0000000..421877f --- /dev/null +++ b/data/party/party1 @@ -0,0 +1,2 @@ +1 +The Heros diff --git a/data/party/party2 b/data/party/party2 new file mode 100644 index 0000000..1d041f3 --- /dev/null +++ b/data/party/party2 @@ -0,0 +1,2 @@ +2 +The Villains diff --git a/equiption.py b/equiption.py new file mode 100644 index 0000000..c3425b3 --- /dev/null +++ b/equiption.py @@ -0,0 +1,110 @@ +######################################################## +#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 Equiption: + + def __init__(self,head,armor,l,r): + self.__head = head + self.__armor = armor + self.__left = l + self.__right = r + + def getHead(self): + """Get head armor.""" + return self.__head + + def setHead(self,h): + """Change head armor.""" + self.__head = h + + def getArmor(self): + """Get body armor.""" + return self.__armor + + def setArmor(self,a): + """Change body armor.""" + self.__armor = a + + def getLeft(self): + """Get left arm weapon/armor.""" + return self.__left + + def setLeft(self,l): + """Change left arm weapon/armor.""" + self.__left = l + + def getRight(self): + """Get right arm weapon/armor.""" + return self.__right + + def setRight(self,r): + """Change right arm weapon/armor.""" + self.__right = r + + def computeAtkMod(self): + """Compute attack modifier.""" + # Left/Right Attack Mods + if self.__left == 'Sword' or self.__right == 'Sword': + return 10 + elif self.__left == 'Katana' or self.__right == 'Katana': + return 12 + elif self.__left == 'Bow' or self.__right == 'Bow': + return 5 + elif self.__left == 'Staff' or self.__right == 'Staff': + return 7 + + + def computeDefMod(self): + """Compute defense modifier.""" + dMod = 0 + + # Head Defense Mods + if self.__head == 'Helm': + dMod += 2 + # Left/Right Defense Mods + if self.__left == 'Shield' or self.__right == 'Shield': + dMod += 3 + # Armor Defense Mods + if self.__armor == 'Chain Mail': + dMod += 8 + elif self.__armor == 'Cloak': + dMod += 3 + + return dMod + + def computeEvaMod(self): + """Compute evasion modifier.""" + eMod = 0 + + # Left/Right Evasion Mods + if self.__left == 'Shield' or self.__right == 'Shield': + eMod += 1 + if self.__left == 'Sword' or self.__right == 'Sword': + eMod += 3 + if self.__left == 'Katana' or self.__right == 'Katana': + eMod += 1 + if self.__left == 'Staff' or self.__right == 'Staff': + eMod += 5 + # Armor Evasion Mods + if self.__armor == 'Chain Mail': + eMod += 4 + elif self.__armor == 'Cloak': + eMod += 6 + + return eMod + diff --git a/event.py b/event.py new file mode 100644 index 0000000..a819337 --- /dev/null +++ b/event.py @@ -0,0 +1,74 @@ +######################################################## +#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 +######################################################## +from random import * +import sys + +class Event: + def __init__(self,ex,targ,t): + """Constructor.""" + self.__executor = ex + self.__target = targ + self.__type = t + self.__computeHpChange() + + def getExecutor(self): + """Get executor of event.""" + return self.__executor + + def setExecutor(self, ex): + """Change executor of event.""" + self.__executor = ex + + def getTarget(self): + """Get target of event.""" + return self.__target + + def setTarget(self, targ): + """Change target of event.""" + self.__target = targ + + def getType(self): + """Get Event Type""" + return self.__type + + def setType(self, t): + """Set Event Type.""" + self.__type = t + + def execute(self): + """Execute event.""" + + # Quit + if self.__type == "quit": + sys.exit(0) + # Attack + elif self.__type == "Attack": + ri = randint(0,99) + + if ri <= self.__target.getEvade(): + return + + self.__target.setHpCurrent(self.__target.getHpCurrent() + self.__hpChange) + + def __computeHpChange(self): + """Compute hp change due to this event.""" + if self.__type == "Attack": + self.__hpChange = self.__target.getDefense() - self.__executor.getAttack() + elif self.__type == "quit": + self.__hpChange = 0 diff --git a/fighter.py b/fighter.py new file mode 100644 index 0000000..f607a33 --- /dev/null +++ b/fighter.py @@ -0,0 +1,294 @@ +######################################################## +#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 +######################################################## +from random import * +from equiption import * +from event import * +class Fighter: + def __init__(self,name,level,exp,exptnlm,exptnl,hpmax,hpcurrent,str,speed,dex,agility,wisdom,will,tom,plyble,equip,job): + """Constructor.""" + self.__name = name + self.__level = level + self.__exp = exp + + # this should probably be changed to expNextLevel + self.__expTillNextLevelMax = exptnlm + self.__expTillNextLevel = exptnl + + self.__hpMax = hpmax + self.__hpCurrent = hpcurrent + self.__strength = str + self.__speed = speed + self.__dexterity = dex + self.__agility = agility + self.__wisdom = wisdom + self.__will = will + self.__timeOfMove = tom + self.__playable = plyble + self.__equiption = equip + self.__job = job + + def getName(self): + """Get fighter's name.""" + return self.__name + + def setName(self, n): + """Change fighter's name.""" + self.__name = n + + def getLevel(self): + """Get fighter's level """ + return self.__level + + def setLevel(self, level): + """Set fighter's level """ + self.__level = level + + def getExp(self): + """Get fighter's experience """ + return self.__exp + + def setExp(self, exp): + """Set fighter's experience """ + self.__exp = exp + + def getExpTillNextLevelMax(self): + """Get the amount of experience the fighter + needs to attain to get to the next level when they started + their current level """ + return self.__expTillNextLevelMax + + def setExpTillNextLevelMax(self, exptnlm): + """Get the amount of experience the fighter + needs to attain to get to the next level when they started + their current level """ + self.__expTillNextLevelMax = exptnlm + + def getExpTillNextLevel(self): + """Get the amount of experience the fighter + needs to attain to get to the next level """ + return self.__expTillNextLevel + + def setExpTillNextLevel(self, exptnl): + """Set the amount of experience the fighter + needs to attain to get to the next level """ + self.__expTillNextLevel = exptnl + + def getHpMax(self): + """Get fighter's hp.""" + return self.__hpMax + + def setHpMax(self, hm): + """Change fighter's hp.""" + self.__hpMax = hm + + def getHpCurrent(self): + """Get fighter's hp.""" + return self.__hpCurrent + + def setHpCurrent(self, hc): + """Change fighter's hp.""" + self.__hpCurrent = hc + + def getStrength(self): + """Get fighter's strength.""" + return self.__strength + + def setStrength(self, s): + """Change fighter's strength.""" + self.__strength = s + + def getSpeed(self): + """Get the fighter's speed (frequency of moves) """ + return self.__speed + + def setSpeed(self, speed): + """Set the fighter's speed (frequency of moves) """ + self.__speed = speed + + def getDexterity(self): + """Get fighter's dexterity. (who gets to go first among ready fighters)""" + return self.__dexterity + + def setDexterity(self, d): + """Change figther's dexterity. (who gets to go first among ready fighters)""" + self.__dexterity = d + + def getAgility(self): + """Get the fighter's agility. (how often they are missed when attacked """ + return self.__agility + + def setAgility(self, agility): + """Set the fighter's agility. (how often they are missed when attacked """ + self.__agility = agility + + def getWisdom(self): + """Get white magic effectiveness """ + return self.__wisdom + + def setWisdom(self, wisdom): + """Set white magic effectiveness """ + self.__wisdom = wisdom + + def getWill(self): + """Get black magic effectiveness """ + return self.__will + + def setWill(self, will): + """Set black magic effectiveness """ + self.__will = will + + def getTimeOfMove(self): + """Get fighter's time of move.""" + return self.__timeOfMove + + def setTimeOfMove(self, tMv): + """Change fighter's time of move.""" + self.__timeOfMove = tMv + + def getEquiption(self): + """Get equiption for fighter.""" + + return self.__equiption + + def setEquiption(self, eq): + """Set equiption for fighter.""" + + self.__equiption = eq + + def getPlayable(self): + """Is fighter playable?""" + return self.__playable + + def setPlayable(self, plyble): + """Set fighter's playability.""" + self.__playable = plyble + + def getAttack(self): + """Compute value of attack.""" + return self.__strength + self.__equiption.computeAtkMod() + + def getDefense(self): + """Compute value of defense.""" + return self.__equiption.computeDefMod() + + def getEvade(self): + """Compute value of evade.""" + return self.__agility + self.__equiption.computeEvaMod() + + + def makeEvent(self, eparty, currentTime, cont): + """ Check if ready to make move. + + If so, select random fighter from enemy party and return. + """ + + if not self.isAlive(): + return None + + if self.__timeOfMove != currentTime: + return None + + # Playable fighters have battle menu + if self.getPlayable(): + # Show battle menu and choose event from battle menu + command = cont.getCommand(eparty,self) + d = command[0] + t = command[1] + + # Nonplayable fighters + elif currentTime >= self.__timeOfMove: + x = randint(0,eparty.sizeOfParty()-1) + while not eparty.getFighter(x).isAlive(): + x = randint(0,eparty.sizeOfParty()-1) + + d = eparty.getFighter(x) + t = "Attack" + + self.__timeOfMove += round((1/float(self.__speed))*100) + return Event(self,d,t) + + def isAlive(self): + """If hp is greater than 0... return true""" + return (self.__hpCurrent > 0) + + def getEventTypes(self): + """Return list of events available to fighter.""" + return ["Attack","quit"] + + def getJob(self): + return self.__job + + def setJob(self,job): + self.__job = job + + def receiveExp(self,exp): + """Fighter receives experience for leveling up.""" + # Add on exp + self.__exp += exp + + # Tax off exp from expTillNextLevel + self.__expTillNextLevel -= exp + + # Level up? + while self.__expTillNextLevel <= 0: + # Increase level number + self.__level += 1 + + ## Increase stats... + x = randint(1,100) + # Increase hp? + if x <= self.__job.getHpChance() * 100: + self.__hpMax += self.__job.getHpPlus() + + x = randint(1,100) + # Increase strength? + if x <= self.__job.getStrChance() * 100: + self.__strength += self.__job.getStrPlus() + + x = randint(1,100) + # Increase speed? + if x <= self.__job.getSpeedChance() * 100: + self.__speed += self.__job.getSpeedPlus() + + x = randint(1,100) + # Increase dexterity? + if x <= self.__job.getDexChance() * 100: + self.__dexterity += self.__job.getDexPlus() + + x = randint(1,100) + # Increase agility? + if x <= self.__job.getAgilityChance() * 100: + self.__agility += self.__job.getAgilityPlus() + + x = randint(1,100) + # Increase wisdom? + if x <= self.__job.getWisdomChance() * 100: + self.__wisdom += self.__job.getWisdomPlus() + + x = randint(1,100) + # Increase will? + if x <= self.__job.getWillChance() * 100: + self.__will += self.__job.getWillPlus() + + # Set new exp till next level maximum + self.__expTillNextLevelMax = int(self.__expTillNextLevelMax * float(1 + self.__job.getExpTillLevelGR())) + + # Carry over any experience that didn't go towards getting the last level + self.__expTillNextLevel = int(self.__expTillNextLevelMax + self.__expTillNextLevel) + diff --git a/job.py b/job.py new file mode 100644 index 0000000..c08d3e9 --- /dev/null +++ b/job.py @@ -0,0 +1,197 @@ +######################################################## +#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,strp,spdp,dexp,aglp,wisp,wp,hpch,strch,spdch,dexch,aglch,wisch,wch): + self.__name = n + self.__expTillLevelGR = expTill + self.__hpPlus = hpp + self.__strPlus = strp + self.__speedPlus = spdp + self.__dexPlus = dexp + self.__agilityPlus = aglp + self.__wisdomPlus = wisp + self.__willPlus = wp + self.__hpChance = hpch + 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 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 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/main.py b/main.py new file mode 100755 index 0000000..1e7698d --- /dev/null +++ b/main.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +######################################################## +#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 +######################################################## + +from battle import * +from consoleview import * +from consolecontroller import * + +# Hookup the Model, the View, and the Controller +m = Battle() +v = ConsoleView() +c = ConsoleController(True,m,v) + + diff --git a/party.py b/party.py new file mode 100644 index 0000000..733eb4c --- /dev/null +++ b/party.py @@ -0,0 +1,109 @@ +######################################################## +#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 +######################################################## +from event import * + +class Party: + + def __init__(self,name): + """Constructor.""" + self.__fighters = [] + self.__name = name + + def getName(self): + return self.__name + + def setName(self,name): + self.__name = name + + def isAlive(self): + """Is party alive?""" + for f in self.__fighters: + if f.isAlive(): + return True + + return False + + def getNextEvent(self, enemy, ctime, cont): + """Check moves for enemy.""" + + ffWithHighestDex = None + efWithHighestDex = None + + if not self.isAlive(): + return None + + # find the enemy that's ready that has the highest dex + for f in enemy.getFighters(): + if f.getTimeOfMove() <= ctime and f.isAlive(): + if efWithHighestDex == None: + efWithHighestDex = f + elif efWithHighestDex.getDexterity() < f.getDexterity(): + efWithHighestDex = f + + #find the friendly fighter that's ready that has the highest dex + for f in self.__fighters: + if f.getTimeOfMove() <= ctime and f.isAlive(): + if ffWithHighestDex == None: + ffWithHighestDex = f + elif ffWithHighestDex.getDexterity() < f.getDexterity(): + ffWithHighestDex = f + + # does the friendly or the enemy have the highest dex + # if friendly, make event + if ffWithHighestDex == None: + return None + elif efWithHighestDex == None: + return ffWithHighestDex.makeEvent(enemy,ctime,cont) + elif ffWithHighestDex.getDexterity() < efWithHighestDex.getDexterity(): + return ffWithHighestDex.makeEvent(enemy,ctime,cont) + + #otherwise, return none + return None + + def addFighter(self,fighter): + if self.sizeOfParty() != 6: + self.__fighters.append(fighter) + return True + return False + + def getFighter(self, n): + """Return fighter.""" + return self.__fighters[n] + + def getFighters(self): + return self.__fighters + + def sizeOfParty(self): + """Compute party's size.""" + return len(self.__fighters) + + def giveExp(self, exp): + """Divy up battle experience among living fighters in party.""" + fighters = self.getFighters() + + numLeft = 0 + for f in fighters: + if f.isAlive(): + numLeft += 1 + + exp = exp/numLeft + + for f in fighters: + f.receiveExp(exp) + -- 2.11.4.GIT