From: <tul...@us...> - 2003-06-26 11:25:18
|
Update of /cvsroot/once/utils In directory sc8-pr-cvs1:/tmp/cvs-serv25809 Modified Files: start.py Added Files: character.py weapon.py Removed Files: createchar.py Log Message: renamed "createchar.py" to "character.py", after i realised that object creation was going to be controlled by the central "start.py" script. added a VERY small class for weapons - the design documents need more info in this area. Also added an objects directory, were objects are saved. I'm going to save (at least) one object of every type, so the scripts can be used by others without having to reate objects from scratch. Note that the scripts really don't do much at the moment. --- NEW FILE: character.py --- #!/usr/bin/python import sys import pickle import math # program to create a charecter. stores the charecter class using pickle module '''Players are a special class of object, as they are the only required object in any one interaction. . . ''' class character: def __init__(self,name): #the init function. set the stats to reasonable defaults. #the name is the only thing passed to us, because it can't be generated ;) #set all skils to 1 experience point initially. #NOTE that levels are calculated from this value. self.fish = self.dipl = self.mini = self.smit = self.magi = self.herb = self.arch = self.jewe = self.craf = self.cook = 1 self.attack=1 self.defence=1 self.name = name self.weapon = "fists" #remember to add that as a weapon! def addexp(self,exp,skill): '''addexp(self,exp,skill). This function adds some experience to a given level. Notre that the contents of the variables in this class is experience points, not levels. Levels are worked out using a formula which we have not yet designed ;)''' skill+=exp def statlvl(self,skill,tpe="lvl"): '''This function returns an integer level number, depending on how much skill a character has in that skill''' #not yet working if (tpe=="lvl"): return 1 elif (tpe == "exp"): return 1 else: return 0 def use(self,target): '''def use(self,target) This is probably THE most important function on the block ;) This is where PC's can interact with other objects. ALL objects should have this function, although it will change depending on what you are trying to do with it: Attacking != Cooking target is the person who is using us. THis may seem to be reverse logic, but i assure you it works ;) All we do is attack target. We are attacked, but we don't see any of that. We als check to see if target is dead, and again, we don't care if we die, someone else will tell us :P. Once ther target dies, we return 1, to indicate success''' pass #we need somehow to impliment weapons... def update(self): #this function updates skills which are based on other skills, like HP/SP... self.HP = math.floor(((self.statlvl(self.fish) + self.statlvl(self.dipl) + self.statlvl(self.mini) + self.statlvl(self.smit) + self.statlvl(self.magi) + self.statlvl(self.herb) + self.statlvl(self.arch) + self.statlvl(self.jewe) + self.statlvl(self.craf) + self.statlvl(self.cook)) / 10) + ((self.statlvl(self.attack) + self.statlvl(self.defence)) / 2)) #note that because the skill/exp. curve is NOT a linear one, we can't just call statlvl once with the sum of the 10 skills, the answer will be wrong! --- NEW FILE: weapon.py --- #!/usr/bin/python '''This file handles all the weapon specific stuff. Weapons are objects like any other thing. They are slightly different however, inthat htey are not "used" as such. rather, they are simply referenced for their attributes, which are: Weapon Attack Skill Special damage skills -> these have yet to be defined properly, so at the moment this is a pretty empty class. right, so...''' class weapon: def __init__(self,name,WAS=1): self.WAS = WAS #a nice default self.name = name '''yeah, this is a pretty empty filealright ;)''' Index: start.py =================================================================== RCS file: /cvsroot/once/utils/start.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** start.py 26 Jun 2003 06:06:53 -0000 1.4 --- start.py 26 Jun 2003 11:25:15 -0000 1.5 *************** *** 1,4 **** #!/usr/bin/python ! import os ! import createchar --- 1,100 ---- #!/usr/bin/python ! ! '''This file is the starting file. All the modules are loaded from here, and this is also the file which contains the (very basic) UI for these scripts. ! ! Note also that the save and load functions are handled outside of the objecst themselfs. I'm not sure what would happen to a script when you asked it to pickle itself ;) ! ! We also create and save new objects. ! ! ! ''' ! ! ! ! import os,string,pickle ! ! ! #our modules: ! import character ! import weapon ! ! ! #functions: ! ! def createchar(): ! name = string.strip(raw_input("Enter Characters Name (must be unique) :> ")) ! temp = character.character(name) ! #now we pickle it ;) ! saveobj('PC_',name,temp) ! ! def createweapon(): ! pass ! def loadchar(): ! name = string.strip(raw_input("Enter Characters Name:> ")) ! return loadobj('PC_',name) ! ! def saveobj(Type,name,object): ! #'Type' is with a capital T so it doesn't conflict with builtin function "type" ! if (os.access('objects/%s.%s.object' % (Type,name),os.F_OK)): ! raise IOError ! pickle.dump(object,open('objects/%s.%s.object' % (Type,name),'w')) ! #NOTE: add error checking! ! def loadobj(Type,name): ! #'Type' is with a capital T so it doesn't conflict with builtin function "type" ! try: ! return pickle.load(open('objects/%s.%s.object' % (Type,name))) ! except IOError: ! return -1 ! #NOTE: add eror checking! ! ! #main program: ! ! ! #a few variables we need init'd: ! char = '' ! ! ! #make sure we have our objects directory... ! if not os.access('%s/objects/' % os.getcwd(),os.F_OK): ! os.mkdir('%s/objects/' % os.getcwd(),os.F_OK) ! ! # make a little UI, adding op[tions as they become available.. Curses, or even better, Tcl/TK would be a good thing ! # here, but at the moment we'r stuck with shitty old text based stuff.. ! while 1: ! print '''Once Script System: ! ! Would you like to: ! 0.- Create a new Character. ! 1.- Create a new Weapon.''' ! #the above items are printer no matter what. ! ! if not char: ! #we don't have a character loaded. print options to load one. ! '''Note about object nam,ing scheme. Objects are simple pickled python classes. ! We know how to load them, because they all ar named in a certain way: ! XXX.name.object ! - where - ! XXX is a 3 letter code to specify what TYPE of object it is. i.e.- 'NPC', 'WEA', 'PC_', 'MON', and many others. ! name is the name of the object. In the caseof a PC_ (player character), the name is the characters name. With monsters (MON), it is the name of the species (like "archangel). ! the .object on the end is to remind me (and others) what all these files are with the peculiar names... ! ''' ! print ''' ! 50.- Load a Character. ! ! Note: You must have a character loaded before you can do anything!''' ! else: ! #we do have a character loaded. we can now do a whole lot of things! ! pass #must sleep.. continue from here tomorrow.. ! ! print ! choice = int(string.strip(raw_input('Enter your Choice:> '))) ! ! #work out what to do based on what is in choice. ! if (choice == 0): ! createchar() ! elif (choice == 1): ! createweapon() ! ! elif (choice == 50): ! char = loadchar() --- createchar.py DELETED --- |