My question is how could I improve it (make it smaller and more efficient).
Here I have a code that when item is selected this function will become active I explained every step in the code. Basically what I'm aiming for is to have better cooldown system that I have right now.
What if i had like 30+ items do I really need to make "self.COOLDOWN_ITEM_1, 2, 3 ,4, 5...etc." for every new item I make?
Code: Select all
def USE_POTION(self, item):
item_name = item.NAME # Used to display the name that was consumed
player_name = self.NAME # Displays the name of player that used pot
if self.CURRENT_MANA >= 30: # If we don't have enough mana we can't use this potion
self.CURRENT_MANA -= 30
if item.NAME == "Potion Of Fire Resistance":
self.COOLDOWN_ITEM_1 = 4 # As long as this is > 0 the potion will be active on character
elif item.NAME == "Apple":
self.COOLDOWN_ITEM_2 = 3
item.AMOUNT -= 1 # Decrease the amount that is in inventory
self.FIRE_RESISTANCE += item.FIRE_RESISTANCE # Player will get additional fire resistance based on item resistance
self.HP_REGENERATION += item.HP_REGENERATION
renpy.say(battle_speaker,"{} consumed {}!".format(current_player.NAME, item_name)) # Displays a message of current action
renpy.jump("END_TURN_{}".format(player_name)) # Jump to specific label that will end players turn and go into the loop of POTION_COOLDOWNS
else:
renpy.say(battle_speaker,"{} don't have enough energy!".format(current_player.NAME))
Here is my cooldown system inside the battle engine loop:
Same question is for this also as these two are connected witch each other.
So for every item I have to make new cooldown number which is not very efficient and I would like to get better at making my code so if anyone have any suggestions on how to do it please tell me
Code: Select all
def POTION_COOLDOWNS(self):
if self.COOLDOWN_ITEM_1 > 0: ### Potion Of Fire Resistance
self.COOLDOWN_ITEM_1 -= 1 # Each turn item cooldown gets dropped by 1
if self.COOLDOWN_ITEM_1 == 0: # After the potion time hits 0 the item value will be removed from a player
self.FIRE_RESISTANCE -= P1.FIRE_RESISTANCE
if self.COOLDOWN_ITEM_2 > 0: ### Apple Hp Regeneration +10%
self.COOLDOWN_ITEM_2 -= 1
if self.COOLDOWN_ITEM_2 == 0:
self.HP_REGENERATION -= P2.HP_REGENERATION