Question about stats reset after the battle

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Question about stats reset after the battle

#1 Post by Nero »

Hi there.

So I'm making battle engine that will change default values of current player. For example here are defined values of current player

Code: Select all

label define_player_stats:
        default dude = Player(
        "Dude",### Name
        2000,   ### Max HP
        2000,   ### Current Hp
        "images/DUDE.png", ### Player Image
        MAX_MANA = 10, ### Max Mana
        CURRENT_MANA = 10, ### Current Mana
        PLAYER_IMMUNITY_LEVEL=0, ### What tier of spells can player resist?
        MAX_SHOCK_DEFENSE=0, ### Ele. Max shock defense
        MIN_SHOCK_DEFENSE=0, ### Ele. Min shock defense
        MAX_ARMOR_PROTECTION=0, ### Max basic attack resistance
        MIN_ARMOR_PROTECTION=0, ### Min basic attack resistance
        MAX_PLAYER_SHOCK_DAMAGE=10, ### Ele.shock max damage
        MAX_PLAYER_SHOCK_DAMAGE=20,### Ele.shock min damage
        PLAYER_MAX_DAMAGE=800, ### Max player basic damage
        PLAYER_MIN_DAMAGE=700) ###Min player basic damage
Now, when battle starts I made few skills that will change those values like this one...

Code: Select all

label battle_code:
    ### Here is the example of 1 spell that will mess up default values that will need to be reseted after battle.
    #
    menu:
        "Debuff enemy damage!":
            $ enemy_members_list[res].PLAYER_MAX_DAMAGE -= 20 * enemy_members_list[res].PLAYER_MAX_DAMAGE / 100     ### 20% weaken enemy MAX attack damage
            $ enemy_members_list[res].PLAYER_MIN_DAMAGE -= 20 * enemy_members_list[res].PLAYER_MIN_DAMAGE / 100       ### 20% weaken enemy MIN attack damage
            "Enemy damage weakened by 20 percent!"
            jump PLAYER_TURN_RESET 
    

    "Blah,blah battle code goes here..."
    
So after battle is finished PLAYER_MAX_DAMAGE and PLAYER_MIN_DAMAGE will no more be 800 and 700 now it will be..lets say 460 and 320. My question is: after the battle is finished how do I reset those stats to original state of MAX800- MIN700 damage without needing to re-type those values over and over after each battle?

User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Re: Question about stats reset after the battle

#2 Post by Evildumdum »

It looks like you are using a class. Classes support functions inside themselves. All you need to do is define a stat reset function inside the Player() class and then call it. I've no idea what you've structured you class like but imagine you'll need something like this.

Code: Select all

 class Player(object):
    def __init__(self, bla, bla, bla):
        # insert all random stat junk here

    def reset_stats(self):
        self.whatever_stat = 700
        self.next_stat = 800
        self.you_get_the_idea = 1000

Evil_dave = Player(bla, bla, bla)

label battle_finish:
    $ Evil_dave.reset_stats()

I will say that you seem to be going about it in a way that seems logical, but is actually extremely inefficient. I can say that because you are doing exactly what i was doing two years ago. By the looks of it you have a basic grasp of classes. If i were you i would pour some serious time into learning how to use functions instead of labels to do your shizzle.
"If at first you don't succeed, try hitting it with a shoe."

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Question about stats reset after the battle

#3 Post by Nero »

Yeah I'm using few functions and a lot labels right now and I'm starting to feel it how inefficient it looks. So basically I have to do new function for every player-item reset_stats then ugh code will be so large. Thanks for the tips.

User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Re: Question about stats reset after the battle

#4 Post by Evildumdum »

No, no that is not the case. You build the reset function into the class. The whole point is that it reduces code significantly.
"If at first you don't succeed, try hitting it with a shoe."

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Question about stats reset after the battle

#5 Post by Nero »

So I'm stuck little bit again I made stats for all those players but problem is I have a equip item system in the game so it means that player values will no more be static they will be changed dependent on the current item player is wearing. Now how do I tell the game to recognize which item is "bob" wearing and based on that to calculate his attack values that will need to be reseted? I hope it makes sense here I did simplified version of what I have see inside the code QUESTION LINE

Code: Select all

init -1 python:  
    class Item(store.object):
        def __init__(self, MAX_DAMAGE, MIN_DAMAGE):
            self.MAX_DAMAGE = MAX_DAMAGE # Item max dmg
            self.MIN_DAMAGE = MIN_DAMAGE # Item min dmg


init -1 python:
    class Player(renpy.store.object):
        def __init__(self,PLAYER_MAX_DAMAGE, PLAYER_MIN_DAMAGE):
            self.PLAYER_MAX_DAMAGE = PLAYER_MAX_DAMAGE # Player max dmg 
            self.PLAYER_MIN_DAMAGE = PLAYER_MIN_DAMAGE #Player min dmg
            
            
        def enemy_stats_only_reset(self): # Values used for resetting enemy stats after the battle (ONLY USED FOR ENEMIES!)
            self.PLAYER_MAX_DAMAGE=800 
            self.PLAYER_MIN_DAMAGE=700
                  
######################################################### QUESTION LINE            
        def bob_with_item_reset(self):
            self.PLAYER_MAX_DAMAGE= "What do I type here?"
            self.PLAYER_MIN_DAMAGE=  "And here?"
######################################################### QUESTION LINE            
            
        def equip(self, item): #Function used for adding stats to player after item is equipped            
            if item.PLAYER_EQ == "ALL" and item.EQUIPMENT_TYPE == "WEAPON": #Define who can use weapon and what type of equipment it is?
                self.PLAYER_MAX_DAMAGE += item.MAX_DAMAGE # Calculate MAX item dmg to player damage
                self.PLAYER_MIN_DAMAGE += item.MIN_DAMAGE # Calculate MIN item dmg to player damage
                renpy.show_screen("inventory_popup", message="Bob equiped [bob.WEAPON]") 

User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Re: Question about stats reset after the battle

#6 Post by Evildumdum »

Again, class instances hold functions. Simply put two functions in the Item class. Equip(self, wearer) and Unequip(self, wearer).
All you gotta do is have a list of in the player class that stores the class instances of the items he has equipped. Here's some code from a stat adjusting effect class i have. It's much bigger and more complicated than what you will need but you should see the general idea.

Code: Select all

    class Status_Effect(object):
        def __init__(self, name, stat, type, duration, static_effect=0, percentage_effect=0, description="No description"):
            # string, used to identify in info screens
            self.name = name
            # string for use in info screens
            self.description = description
            # list of strings, used to identify which stat to adjust
            self.stat = stat
            # list of strings, used to identify buffs, debuffs etc
            self.type = type
            # integer, number of turns this will be applied for 
            self.duration = duration
            # integer, number of turns until effect is removed
            self.countdown = int(duration)
            # list of integers, if the effect has a standardised effect
            self.static_effect = static_effect
            # list of floats, between 0.0 for 0%, 1.0 for 100%. If the effect has a drain/buff based on a percentage of tagets stats
            self.percentage_effect = percentage_effect
            # list of integers, what values to restore to affected stats
            self.restore_value = []
            
        def turn_start(self):
            self.countdown -= 1
            return self.countdown
        
        def apply(self, target):
            temp = -1
            for x in self.percentage_effect:
                temp += 1
                if (self.stat[temp] == "move"):
                    # cannot be affected by percentage based adjustments
                    self.restore_value.append(int(self.static_effect[temp]))
                    target.max_move += self.restore_value[temp]
                    if (target.current_move >= target.max_move):
                        target.current_move = int(target.max_move)
                    if not (target.max_move):
                        target.max_move = 1
                        target.current_move = 1
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "pab"):
                    # cannot be affected by percentage based adjustments
                    self.restore_value.append(int(self.static_effect[temp]))
                    target.pab += self.restore_value[temp]
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "cab"):
                    # cannot be affected by percentage based adjustments
                    self.restore_value.append(int(self.static_effect[temp]))
                    target.cab += self.restore_value[temp]
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "prb"):
                    # cannot be affected by percentage based adjustments
                    self.restore_value.append(int(self.static_effect[temp]))
                    target.prb += self.restore_value[temp]
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "crb"):
                    # cannot be affected by percentage based adjustments
                    self.restore_value.append(int(self.static_effect[temp]))
                    target.crb += self.restore_value[temp]
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "agression"):
                    # can be affected by both static and percentage based 
                    temp2 = target.aggression*self.percentage_effect[temp]
                    self.restore_value.append(int(self.static_effect[temp]+temp2))
                    target.aggression += self.restore_value[temp]
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "seduction"):
                    # can be affected by both static and percentage based 
                    temp2 = target.seduction*self.percentage_effect[temp]
                    self.restore_value.append(int(self.static_effect[temp]+temp2))
                    target.seduction += self.restore_value[temp]
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "physical_resist"):
                    # can be affected by both static and percentage based 
                    temp2 = target.physical_resist*self.percentage_effect[temp]
                    self.restore_value.append(int(self.static_effect[temp]+temp2))
                    target.physical_resist += self.restore_value[temp]
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "charm_resist"):
                    # can be affected by both static and percentage based 
                    temp2 = target.charm_resist*self.percentage_effect[temp]
                    self.restore_value.append(int(self.static_effect[temp]+temp2))
                    target.charm_resist += self.restore_value[temp]
                    self.restore_value[temp] = self.restore_value[temp]*-1
                if (self.stat[temp] == "action"):
                    # cannot be affected by percentage based adjustments
                    self.restore_value.append(int(self.static_effect[temp]))
                    target._action_max += self.restore_value[temp]
                    if (target._action >= target._action_max):
                        target._action = int(target._action_max)
                    if not (target._action_max):
                        target._action_max = 1
                        target._action = 1
                    self.restore_value[temp] = self.restore_value[temp]*-1
            target.status_effects.append(self)
            
        def remove(self, target):
            temp = -1
            for x in self.restore_value:
                temp += 1
                if (self.stat[temp] == "move"):
                    target.max_move += self.restore_value[temp]
                    target.current_move += self.restore_value[temp]
                if (self.stat[temp] == "pab"):
                    target.pab += self.restore_value[temp]
                if (self.stat[temp] == "cab"):
                    target.cab += self.restore_value[temp]
                if (self.stat[temp] == "prb"):
                    target.prb += self.restore_value[temp]
                if (self.stat[temp] == "crb"):
                    target.crb += self.restore_value[temp]
                if (self.stat[temp] == "agression"):
                    target.aggression += self.restore_value[temp]
                if (self.stat[temp] == "seduction"):
                    target.seduction += self.restore_value[temp]
                if (self.stat[temp] == "physical_resist"):
                    target.physical_resist += self.restore_value[temp]
                if (self.stat[temp] == "charm_resist"):
                    target.charm_resist += self.restore_value[temp]
                if (self.stat[temp] == "action"):
                    target._action_max += self.restore_value[temp]
                    target._action += self.restore_value[temp]
            target.status_effects.pop(self)
"If at first you don't succeed, try hitting it with a shoe."

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Question about stats reset after the battle

#7 Post by Nero »

Ok I figured out how to do it. Im really having hard time understanding this code... but I think its because I don't see the whole code of your battle engine then I might understand meaning behind it. However I must learn a lot about functions to make any serious progress :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]