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.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(attack=int(enemy[2]), health=int(enemy[1]), defense=int(enemy[3]), displayName=autoSlected, experince=int(enemy[7]), petRate=int(enemy[4]), buddyRate=int(enemy[5]), weapon=enemy[6])
self.intiativeRoll(starter)
break
f.close()

First, I start by generating a random number and making it an integer so I can use it later.  Then if there was no autoSelected, I will find the first monster in the listing and use that monster as our starter. Otherwise, I will find the autoSlected monster in the monsterStats.csv and use the stats found there to instantiate a new monster as the starter and roll initiative for the new monster.

dividers = []
if starter.buddyRate > 0:
dividers.append(starter.buddyRate)
dividers.append(starter.buddyRate + starter.petRate)
else:
dividers.append(0)
dividers.append(starter.petRate)

Second, I set up dividers to make the selection process of a buddy or pet easier.  The dividers a set up based on the stats of the monster (monster.buddyRate and monster.petRate). Some monsters don’t have a buddy rate, so for those only one divider is needed.

if luck < dividers[0]:
buddy = Monster(attack= starter.attack, health= starter.health, defense= starter.defense, displayName= starter.displayName + "(0)", experince= starter.experience, petRate=starter.petRate, buddyRate= starter.buddyRate, weapon=starter.weapon )
self.intiativeRoll(buddy)
flag = True
counter = 1
while flag:
luck = int(random.random() * 100)
if luck < dividers[0]:
buddy = Monster(attack=starter.attack, health=starter.health, defense=starter.defense,
displayName=starter.displayName + "(" + str(counter) + ")", experince=starter.experience,
petRate=starter.petRate, buddyRate=starter.buddyRate, weapon=starter.weapon)
self.intiativeRoll(buddy)
else:
flag = False
counter += 1
if counter == 6:
flag = False

If the random number from earlier (luck) is less than the first divider then I go into buddy generation. Where I continue to make copies of the monster and add them to the fight until either a number higher than the divider is rolled or 6 buddies are generated.

if luck < dividers[1]:
f = open("encounters.csv")
reader = csv.reader(f)
regionCounter = 0
endFlag = False
for line in reader:
if line == []:
continue
for item in line:
if starter.displayName == item:
endFlag = True
break
if endFlag:
break
regionCounter += 1
f.close()
f = open("pets.csv")
reader = csv.reader(f)
pets = []
for line in reader:
if line == []:
continue
if int(line[0]) == regionCounter:
for pet in line:
try:
int(pet)
continue
except ValueError:
pets.append(pet)
division = int(100/len(pets))
dividers = []
while division < 100:
dividers.append(division)
division += division
dividers.append(100)
luck = int(random.random() * 100)
while luck < 1:
luck = int(random.random() * 100)
counter = 0
for divider in dividers:
if luck < divider:
break
counter += 1
self.foePrep(autoSlected= pets[counter])
else:
pass

If luck is less than the second divider. then there are pets, I check what types of pets are available by first getting a region id by checking the starter name against its location in the csv. Each line in the file is a region in the game starting with the first line being zero and the last line being 9. Then it goes to pets.csv and goes to the line with the region’s id as the first entry. It then takes the pets in that line to fill in the options and set up evenly distributed dividers. It then generates another random number and then uses the random number to find to select a pet. The pet chosen is the one in-between the range that the random number falls in. It then calls foePrep() with the pet name as the autoSelected to instantiate the pet and see if it has buddies.

Once this function has been run, combat is almost ready to begin. Next up is combatantOrganizer().

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.