Skip to main content

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...

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:
for skill in ally.skills:
if ally.skillCosts[i] <= ally.currentEnergy:
print(str(i) + ": " + skill)
choices.append(i)
i += 1
protect = i
if self.saftey():
print(str(protect)+ ": Fall back")
choices.append(i)
chosen = inputAndCheck("What will " + ally.displayName + " do? ", choices)
if chosen == protect:
self.saftey(availability= False, Ally= ally.displayName)
else:
ally.currentEnergy = ally.currentEnergy - ally.skillCosts[chosen]
self.skillHandler(ally, ally.skills[chosen])

Else, I assume the ally is a PlayableCharacter() and I check if they have more than zero hp. The try block is there just in case a nonplayable character gets through. Then I display important info like who’s turn it is and who’s coming up next using the display functions in the class.

If they aren’t protected, I use a for loop to check the energy cost of the character’s skills with the character’s current energy. If the character has enough energy I display the skill as an option and add the current i value to choices. I also use i in this loop to create an additional option for my fallback gimmick. If there isn’t anyone already in the back line and the ally isn’t the last PlayableCharacter() standing (self.saftey()) then I display falling back as an option.

chosen = inputAndCheck("What will " + ally.displayName + " do? ", choices)
if chosen == protect:
self.saftey(availability= False, Ally= ally.displayName)
else:
ally.currentEnergy = ally.currentEnergy - ally.skillCosts[chosen]
self.skillHandler(ally, ally.skills[chosen])

Now that the options are displayed, I call input and check for the player input via inputAndCheck(). And store it in chosen. If the protected value was chosen then I put the character in the back line by adding them to the protected class variable (via self.saftey()). Otherwise, I use the chosen value to get the cost of the skill and subtract it from the characters total and fetch the name of the skill so I can plug it into the skillHandler() to execute the skill’s effect.

else:
choices = [0,1]
print("0: Stay back")
print("1: go back to front")
chosen = inputAndCheck("What will " + ally.displayName + " do? ", choices)
if chosen == 0:
self.safteyRecovery(ally.displayName)
else:
self.saftey(Ally= ally.displayName, Removal= True)

If they were protected earlier, then they only have two options: Leave the back line or stay back. I display those options on the screen and pass an inputAndCheck(). If they stay in the back (option 0) then I gave them some healing and energy generation (self.safteyRecovery()). If they go back (option 1) they get removed from the protected list.

counter = -1
for defender in self.defRaise:
counter += 1
if defender[0] == ally.displayName:
defender[1] = defender[1] - 1
if defender[1] <= 0:
ally.defense = ally.defense - defender[2]
break
try:
self.defRaise.pop(counter)
except IndexError:
pass
counter = -1
for attacker in self.atkRaise:
counter += 1
if attacker[0] == ally.displayName:
attacker[1] = attacker[1] - 1
if attacker[1] <= 0:
ally.attack = ally.attack - attacker[2]
break
try:
self.atkRaise.pop(counter)
except IndexError:
pass
counter = -1
for annoyance in self.taunt:
counter += 1
if annoyance[0] == ally.displayName:
annoyance[1] = annoyance[1] - 1
if annoyance[1] <= 0:
break
try:
self.taunt.pop(counter)
except IndexError:
pass

These last couple of loops are to tick down any passive effects on the character, so it checks all the listings and if the character name is not found there then it moves on. If it does find a match I tick the count of the effect down by one if it goes down to zero, I remove the effect from the character. Counter here is to help keep track of the index so I can remove them from the list easily after the loop finishes. The reason I wait until after the loop to remove things is that python doesn’t like it when you try to change a list or dictionary while iterating over it at the same time.

 

This is the most central portion of this class. as you can see it calls a lot of other functions to make it do what it does. I’ll be going over all the display functions next, then I will dissect the remaining 6 big ones: targetChooser(),skillHandler(), baseAttack(), safety(), and safetyRecovery(), combatEndCheck().

Comments

Popular posts from this blog

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...

Explorer() progress

I decided to start with the explorer() method because of how central it is to the program. I quickly realized I'd need new functions for accessing specific pieces of data from the CVSs, so I made a few for detecting what region the part is in, another for fetching the region name and fetching the region z coordinate. Here is what explorer looks like now. def explorer (): global x global y global z global chapter global region global regionDisplay global Lori global Lauren global Julius global Marcus menu = GameMenu() characters = [Lori , Lauren , Julius , Marcus] menu.update(characters) selections = [ 4 , 5 ] #Code goes here print (regionDisplay + ":" ) print (regionDiscribe(region)) # need and area scanner for detecting nearby locations if regionCheck(x+ 1 , y , z) >= 0 and \ (fetchRegionZ(regionCheck(x+ 1 , y , z))-fetchRegionZ(region) <= 5 and fetchRegionZ(region)-fetchRegionZ(regionCheck...

Flow Charts are Born

Flow charts weren't that difficult to make. I honestly already had a decent idea of how my program would run, so this was really taking what was on my mind and putting it into a graphic. For those who don't know, I'm using a common key for software design for all of the flow charts: Source:  https://www.zenflowchart.com/flowchart-symbols First I have the simplest of my flow charts: theInstaller.py Flow chart. Then I made the Flow chart for theMain.py: Finally, I decided to include 2 flow charts for the important subprocess in the game: Explore() and runCombat(). For all of these, I used color codes to help subdivide the pieces of the code into their smaller loops or different paths. I'll be using these flow charts a lot to point out where exactly I'm at in the game as I go along with this blog.