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.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 -= 14
dividers.append(counter)

If there is nothing in taunt, then I simply set up some evenly separated numbers for our characters in dividers. Otherwise, I go through the targets and compare those names to the name found in the taunt. If there is a match the match will receive a bigger number in divider than the other characters making it more likely for them to be hit.

flag = False
for divider in dividers:
if flag:
break
if targetingNum > divider:
target = targets[dividers.index(divider)]
flag = True

Now I set up an indicator bool called flag for another loop. This loop checks each number of the divider to see if it was less than the targetingNum. How this works is that each character in targets has a corresponding number (at the same index) in dividers and the numbers are decreasing as you iterate through dividers. This makes it so that I only need to check greater than (because all the unwanted numbers higher than previous ones have already been checked), and, using the index of the number, I can quickly set target to the corresponding name of the target. Once this target is found the flag is set to true so it can break us out of the loop.

try:
if target not in self.protected:
if self.listing[target].level > 0 and self.listing[target].currentHealth > 0:
self.attackDispaly(attacker, target)
if (attacker.attack - self.listing[target].defense >= 0):
self.listing[target].currentHealth = self.listing[target].currentHealth - attacker.attack + self.listing[target].defense
else:
self.listing[target].currentHealth = self.listing[target].currentHealth - 1
except UnboundLocalError:
pass

Should a target fail to be selected, the first lines of the code that are in the try statement will return a UnboundLocalError., so I added an exception that will do nothing. I did this knowing that if a specific target wasn’t selected, then the monster wasn’t lucky and their attack missed all the characters. If there is a specifically selected target name in target, we first check to make sure they aren’t protected then we apply the damage by taking attack of the attacker and subtracting it from the defender’s defense. If the result for that subtraction is grater than zero than subtract it from the target’s currentHealth. If the result is less than zero, then we subtract 1 form the defender’s currentHealth.

Comments

Popular posts from this blog

Combat() completion! Fights exist now!

Combat() has been completed and the game now is starting to feel like a game. It was a lot of work, but I will be honest I was distracted by holiday events and starting University and that's why it took so long to complete. There is so much to go over with Combat() that I'll be making separate posts for each piece of the Combat class with breakdowns on what they do and how. Here I'll post the results and an implementation overview. Comba() as of now: class Combat( object ): def __init__ ( self , continueStatus = True ): self .order = [] self .listing = {} self .continueStatus = continueStatus self .taunt = [] self .defRaise = [] self .atkRaise = [] self .protected = [] self .exp = 0 def combatantOrganizer ( self ): organizedOrder = [] theStringOrder = [] NumOrder = [] for listing in self .order: NumOrder.append(listing[ 1 ]) NumOrder.sort() for...

UML Diagram and Object Oriented Programing.

Currently, the game uses only global variables and the methods in theMain.py to open and load data. It's become cumbersome to constantly call on the global variables for all my methods and I've realized that I'll be limited in the number of monsters I have if I only use global variables for everything. So this has led me to decide to shift to using Object-oriented programing to run my game. Thus I've prepared a UML diagram to show you all my classes, and subclasses, as well as their interactions, methods, and variables.      theMain.py will function as my main line where all classes and methods will be called as well as have some very important functions built into it. That's they it is connected to almost all the other classes. It'll take care of exploration, descriptions, story tracking, starting the game, ending the game, encounter rates, and gold.      GameMenu will be treated as a static class that has information displayed for the game menu as well as...

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