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
Post a Comment