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.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 user’s attack minus the defender’s defense, but if that is less than or equal to zero then I’ll have it do one damage.

Sweeping Slash

elif skill == "Sweeping Slash":
for figther in self.listing:
if isinstance(self.listing[figther], Monster):
if ally.attack - self.listing[figther].defense > 0:
self.listing[figther].currentHealth = self.listing[figther].currentHealth - (
ally.attack - self.listing[figther].defense)
else:
self.listing[figther].currentHealth = self.listing[figther].currentHealth - 1

Lori’s sweeping slash hits all monsters, so same thing as the last one for damage. The difference is I skip the target choosing and just iterate over listing to find the monsters and deal damage to them.

Second Wind

elif skill == "Second Wind":
luck = int(random.random() * 10)
ally.currentHealth = ally.currentHealth + luck
if ally.currentHealth > ally.health:
ally.currentHealth = ally.health

Lori’s Second wind restores some of her hp. I make sure she doesn’t go over her max with an if statement.

Guard Up

elif skill == "Guard up":
luck = int(random.random() * 10) + 1
change = ally.defense/2
self.defRaise.append([ally.displayName, luck, change])
ally.defense = ally.defense + change

Lori’s Guard Up raises her defenses. I store a record of her defense increase in defRaise so that I can undo it when it expires later. The duration is randomly determined by random.random().

Restoring Arrow

elif skill == "Restoring Arrow":
target = self.targetChooser(Ally=True, User=ally.displayName)
self.listing[target].currentHealth = self.listing[target].currentHealth + ally.attack
if self.listing[target].currentHealth > self.listing[target].health:
self.listing[target].currentHealth = self.listing[target].health

Lauren’s restoring arrow heals one ally. I have the player choose a target then I heal that target. An if is used to make sure they don’t overheal.

 

Focus Light, Focus Light0

elif skill == "Focus Light" or skill == "Focus Light0":
luck = int(random.random()*10) + 1
change = ally.attack
self.atkRaise.append([ally.displayName, luck, change])
ally.attack = ally.attack + change

Lauren’s Focus Light raises her attack. Marcus also has a rally that does something similar and it does it through Focus Light0.

 

Lightning Bolt

elif skill == "Lightning Bolt":
target = self.targetChooser()
potential = ally.attack + ally.currentEnergy
if potential - self.listing[target].defense > 0:
self.listing[target].currentHealth = self.listing[target].currentHealth - (potential - self.listing[target].defense)
else:
self.listing[target].currentHealth = self.listing[target].currentHealth - 1

Julius’ Lightning Bolt is a lot like the normal attack, but it has extra attack power based on his current energy.

Close Wounds

elif skill == "Close Wound":
target = self.targetChooser(Ally=True , User= ally.displayName)
self.listing[target].currentHealth = self.listing[target].currentHealth + ally.currentEnergy
if self.listing[target].currentHealth > self.listing[target].health:
self.listing[target].currentHealth = self.listing[target].health

Julius’ Close Wounds heals an ally equal to the amount of Mana he has. I used an if to prevent healing over their max health.

Fire Ball

elif skill == "Fire Ball":
potential = ally.attack + ally.currentEnergy
for figther in self.listing:
if isinstance(self.listing[figther], Monster):
if potential - self.listing[figther].defense > 0:
self.listing[figther].currentHealth = self.listing[figther].currentHealth - (
potential - self.listing[figther].defense)
else:
self.listing[figther].currentHealth = self.listing[figther].currentHealth - 1

Julius’ fireball Is a lot like sweeping slash (yes I’m paying homage to the classic wizard fireball spell from dnd),  but it has extra damage equal to his remaining mana.

 

Full Guard

elif skill == "Full Guard":
luck = int(random.random() * 10) + 2
change = ally.defense
self.defRaise.append([ally.displayName, luck, change])
ally.defense = ally.defense + change

Raises Marcus’ defense and adds a record of the changes to defRaise to keep track of timing.

Taunting Cry

elif skill == "Taunting Cry":
luck = int(random.random() * 10) + 1
self.taunt.append([ally.displayName, luck])

Marcus’ is added to the taunt list which will increase the chance of him getting hit and decrease the chance of allies getting hit. I will see how in baseAttack(). For now, just know that the information of who and how long is saved in taunt.

Rally

elif skill == "Rally":
for fighter in self.listing:
if isinstance(self.listing[fighter], PlayableCharacter):
self.skillHandler(self.listing[fighter], "Focus Light0")

Rally is Marcus’ last ability and it raises all ally’s attacks. Data of the change is made in atkRaise for each ally boosted by this ability. This is all done by calling Focus Light0.

Quick Hands

elif skill == "Quick Hands":
menuMoment = GameMenu()
menuMoment.update([ally])
itemChoices = menuMoment.displayPC(ally, pcSkip= True)
itemSlected = inputAndCheck("Lauren's call: ", itemChoices)
target = self.targetChooser(Ally= True, User= PlayableCharacter("No One"))
item = ally.inventory[itemSlected]
updatedTarget = item.effectHandler(self.listing[target], equip= False)
self.listing[target] = updatedTarget
ally.inventory.remove(item)
self.listing[ally.displayName] = ally

Quick hands are Lori’s last ability and it lets her use items in her inventory on any ally (including herself), It uses some features from the Shop() and Item() class which hasn’t been discussed here yet, and at the time of starting this post series about combat()  hadn’t even been written. So I will come back to this some other time when I discuss the implementation of Shop() and Item().

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.