Skip to main content

Posts

Showing posts from March, 2023

Item() rundown

 The item() class holds the information of the item and also runs the item effect when it gets used. Constructor def __init__ ( self , command , name , cost , usage): self .effect = command self .name = name self .cost = cost self .usage = usage The effect holds the string name of the effect for the item,  usage holds the value of the Effect . The rest are self-explanatory. EffectHandler() def effectHandler ( self , user: PlayableCharacter , equip= True ): #learned how to specify type of parameter. if equip: if self .effect == "Def" : user.defense = user.defense + self .usage elif self .effect == "AtkPhy" or self .effect == "AtkMag" : user.attack = user.attack + self .usage else : if self .effect == "hp" : user = self .healing(user) return user This handles the effects of the item when it is used. If equip is true then it will check for the equip...

Item() rundown

 The item() class holds the information of the item and also runs the item effect when it gets used. Constructor def __init__ ( self , command , name , cost , usage): self .effect = command self .name = name self .cost = cost self .usage = usage The effect holds the string name of the effect for the item,  usage holds the value of the Effect . The rest are self-explanatory. EffectHandler() def effectHandler ( self , user: PlayableCharacter , equip= True ): #learned how to specify type of parameter. if equip: if self .effect == "Def" : user.defense = user.defense + self .usage elif self .effect == "AtkPhy" or self .effect == "AtkMag" : user.attack = user.attack + self .usage else : if self .effect == "hp" : user = self .healing(user) return user This handles the effects of the item when it is used. If equip is true then it will check for the equip...

Shop() run down

 This class is responsible for running the shop and creating the Item() objects. Constructor: def __init__ ( self ): self .items = [] f = open ( "items.csv" ) fReader = csv.reader(f) for line in fReader: if line == []: continue self .items.append(Item(line[ 2 ] , line[ 0 ] , int (line[ 1 ]) , int (line[ 3 ]))) f.close() When the class is called the class list items are filled with Item() objects created by opening items.csv and taking the data in there to instantiate the items. Then we close the file. WhoIsShopping(): def whoIsShopping ( self , squad : list ): counter = 0 choices = [] print ( "Who is shopping?" ) for member in squad: if member.level > 0 : print ( str (counter) + ": " + member.displayName) choices.append(counter) counter += 1 selection = inputAndCheck( "Selection: " , choices) return squad[selection] T...

Shop() is complete!!!!!!

 Now that the big classes are over, we can create the items, and shop for the game. I had all the item’s stats I made beforehand, and I also made the shop() class UML beforehand, but when I began making the shop() class, I realized it was going to big hassle to keep all the items in an array and creating functions that use them because those functions would need to be available not just in shop(), but in PlayableCharacter() as well. Thus I made the Item() class handle all of its functions and made data access easier. I’ll make two posts: shop() breakdown, and Item() breakdown.

combat.combatEndCheck()

def combatEndCheck ( self ): removalList = [] follow = False playerCounter = 0 for figther in self .listing: removeFlag = self .listing[figther].deathCheck() if removeFlag == True : removalList.append(figther) i = 0 for thing in self .order: if thing[ 0 ] == figther: break i += 1 self .order.pop(i) continue if isinstance ( self .listing[figther] , Monster): follow = True if isinstance ( self .listing[figther] , PlayableCharacter) and self .listing[figther].currentHealth > 0 : playerCounter += 1 for body in removalList: self .exp = self .exp + self .listing[body].experience self .listing.pop(body) if playerCounter <= 0 : follow = False return follow This is the final function we need to discuss for Combat() . It takes no parameters and it returns bool depending o...

Combat.safteyRcovery()

def safteyRecovery ( self , ally): luck = int (random.random() * 20 ) friend = self .listing[ally] if isinstance (friend , PlayableCharacter): friend.currentHealth = friend.currentHealth + luck friend.currentEnergy = friend.currentEnergy + luck if friend.currentEnergy > friend.energyValue: friend.currentEnergy = friend.energyValue if friend.currentHealth > friend.health: friend.currentHealth = friend.health self .listing[ally] = friend This one is a lot like rest() from the main line. It takes ally as the name of the character that is being healed. I first fetch the character from listing and save it to friend . I then use a randomly generated number to determine how much health and energy they regain. Finally, the last few ifs are for to make sure the energy and hp didn’t go over max. The I update the copy of the object in listing .

Combat.Saftey()

def saftey ( self , availability= True, Ally= None, Removal= False ): counter = 0 if Removal: self .protected.remove(Ally) return 0 if availability: if len ( self .protected) > 0 : return False for figther in self .listing: if self .listing[figther].currentHealth > 0 : if isinstance ( self .listing[figther] , PlayableCharacter): counter += 1 if counter > 1 : return True else : return False else : self .protected.append(Ally) This function is what does half of the work with my backline battle gimmick. It is multi-purpose, so the bools which are used as parameters merely change which purpose would like to evoke. Thus I will break this function down by parameter. Removal if Removal: self .protected.remove(Ally) return 0 This simply removes the name in Ally from protected . Returns 0 to end the function.   ...

Combat.baseAttack()

 This is the basic command that is run for all monster attacks. Parameters It simply takes the current monster as a parameter named attacker . The rundown def baseAttack ( self , attacker): targetingNum = int (random.random() * 100 ) while targetingNum < 1 : targetingNum = int (random.random() * 100 ) targets = [] I start by generating a random number into targetingNum and ensuring it’s greater than 1. for fighter in self .listing: if isinstance ( self .listing[fighter] , PlayableCharacter): targets.append(fighter) Then I add all the available playable characters a monster can attack using a loop that iterates over the listing . Those characters’ names are added to targets . if self .taunt == []: dividers = [ 81 , 61 , 41 , 21 ] else : dividers = [] counter = 100 for peep in targets: if peep == self .taunt[ 0 ][ 0 ]: counter -= 34 dividers.append(counter) else : counter...

Combat.skillHandler()

 This function handles all the effects skills have on battles. It’s a lot of if-else, so I’ll just go over each block individually and explain what happens. Parameters def skillHandler ( self , ally :PlayableCharacter , skill): This function takes ally and skill as parameters. Ally must be a playableCharacter object, and skill is a string that is the name of the skill. Axe, Smiting Arrow, Dagger Poke, Slash if skill == "Axe" or skill == "Smiting Arrow" or skill == "Dagger Poke" or skill == "Slash" : target = self .targetChooser() if ally.attack - self .listing[target].defense > 0 : self .listing[target].currentHealth = self .listing[target].currentHealth - (ally.attack - self .listing[target].defense) else : self .listing[target].currentHealth = self .listing[target].currentHealth - 1 This is the most basic attack in the game. I simply call for a target and then attack. The damage dealt is equal to the u...

Combat.targetChooser()

this function enables the selection of targets for the abilities that need it in my game. Parameters and variables def targetChooser ( self , Ally= False, User= None ): choices = [] i = 0 forum = [] I made 3 parameters to make this function more adaptable. Ally is a bool that when true will go into the if stamen that displays allies, when false it’ll go into displaying the monsters. User is for when an ability targets allies, you put in the name of the user if you don’t want them to be able to target themselves. Choices is where I will store the numbers that correspond to the enemies or allies that can be selected. Then forum is where the names of the targets will be stored in the index that corresponds with their number in choices . i will be used as a counter for setting up choices and then later a container to receive the player input. The rundown if Ally: for target in self .listing: if isinstance ( self .listing[target] , PlayableCharacter): ...

Combat() display functions!

 Here I’ll go over all the display functions starting from smallest to largest. attackDisplay() def attackDispaly ( self , attacker , target): #might remove if it slows down game to much. Might rewrite for more flavor. if isinstance (attacker , Monster): input (attacker.displayName + " used their " + attacker.weapon + " on " + target + "(Enter to continue)" ) This takes a monster object and the target name as attacker and target respectively. Then it makes sure that the object is a monster using isInstance() then proceeds to display the attack information: Turn: Wolf Wolf used their Fangs on Lauren(Enter to continue)  QuickDisplay() def quickdisplay ( self , ally , newLineOverride= False ): if newLineOverride: return ally.displayName + "(hp: " + str (ally.currentHealth) + "/" + str ( ally.health) + " " + ally.energyName + ": " + str (ally.currentEnergy) + "/...

Combat.turn()

 Now finally I can do the beloved turn() , this function executes a turn for the specified character. Local Variables and Parameters def turn ( self , ally): choices = [] chosen = 0 i = 0 Ally , must be a character() object. Choices are a list where the options will be stored for when I call inputandCheck() . Chosen is where the returned value of input and check will be stored. i is used as a variable for counting through my loops. The rundown if isinstance (ally , Monster): print ( "Turn: " + ally.displayName) self .baseAttack(ally) First, I right away check if the ally is a monster and if it is, I display that it’s the monster’s turn and then have it call for a baseAttack() . else : if ally.currentHealth > 0 : try : print ( "up next:" + self .intiativeDisplay(ally.displayName)) print ( "Current turn: " + self .quickdisplay(ally)) if ally.displayName not in self .protected: ...

Combat.combatOrganizer()

 This function is meant to organize all the combatants based on the initiative number they rolled in rollIntiative() . Local variables def combatantOrganizer ( self ): organizedOrder = [] theStringOrder = [] NumOrder = [] organizedOrder is where the updated list will be stored and this will late be used to update the old order.   theStringOrder is where the names will be stored once the numbers have been organized. NumOrder is where the numbers will be stored and sorted from least to greatest. The rundown for fighter in self .order: NumOrder.append(fighter[ 1 ]) NumOrder.sort() First, I take all the numbers from the order and put them in NumOrder . Then I used .sort to organize all the numbers. for Num in NumOrder: for item in self .order: if Num == item[ 1 ]: theStringOrder.append(item[ 0 ]) Then I take the order and the NumOrder and match up the numbers with their owner’s names and store the owner’s names in theStringOrde...

Combat.foePrep()

  foePrep() is one of the more complicated functions in this class. I’ll start by discussing the parameters and then go through everything the function does to accomplish its goal: adding extra buddies and pets to the fight. Parameters def foePrep ( self , autoSlected= "" ): The only optional parameter is autoSelected which allows you to start the fight with a specific monster already in mind. The rundown luck = int (random.random() * 100 ) while luck < 1 : luck = int (random.random() * 100 ) if autoSlected == "" : for figther in self .listing: if isinstance ( self .listing[figther] , Monster): starter = self .listing[figther] else : enemyCatalog = [] f = open ( "monsterStats.csv" ) fReader = csv.reader(f) for line in fReader: if line == []: continue enemyCatalog.append(line) for enemy in enemyCatalog: if autoSlected == enemy[ 0 ]: starter = Monster...

Combat.intiativeRoll()

 This is probably the simplest of all the functions, but still one of the most important. def intiativeRoll ( self , Combatant): # defualt for now self .listing.update({Combatant.displayName : Combatant}) self .order.append([Combatant.displayName , random.random()])      Essentially all it does is add combatants to the order and listing. As I said in the main post it was the order that holds the initiative and the listing has combatant names as keys and character object as the content. I used random.random() to assign a number to the name as the initiative value. This will be used a lot by foePrep() . So now that it’s out of the way, I’ll hope into foePrep() next!