Text Based RPG: Status Effects?

Hello fellow programmers!

I'm a newbie here. I've been learning to code for the past year. I've really learned a lot from reading forums like these to answer my questions.

I made an account here so if I had a question I couldn't find, I could ask it.

oh yeah, so I'm making a Text-based RPG, (it's all the rage these days)

So here goes...

I have a class called Magic, and I have a class called Entity. The Entity class has members of a vector inventory, has a Job class (for titles that boost enemies and player stats) and now I'm working on Magic.

Before I had magic as a variable that only Main Character (Player Class derived from Entity) knows, but I didn't think that was fair for the Enemies, anyway now i'm trying to work on adding special effects to magic.

For example:

Fire - burn damage for a certain duration for x damage
Lightning - shock damage that has a chance to halve the enemies attack
Wind - does wind damage and has a chance to increase you (the player's speed) and decrease enemies.
Earth - does earth damage and has a chance to make the enemy stunned (skipping their turn)

My main question is: what is a best way of going about this. I want to probably have a duration member and a status effect member. But my research online has confused me on the matter. Hence why I come to humbly ask for your assistance,

I don't have the code written for Magic yet, but if you guys want to see the other pieces let me know.

Thanks so much!
Welcome to the forums KTP ;) could you please post your code it makes it easier for everybody to understand what you really need.
A few suggestions so that we can help you:
1. Post your code. Put all of it in a zip file and upload it somewhere.
2. Clarify your post a bit
what is a best way of going about this. I want to probably have a duration member and a status effect member. But my research online has confused me on the matter. Hence why I come to humbly ask for your assistance,

Well.. You're confusing me. Your question is such that you HAVE to post your code. You also have to tell us exactly what you were expecting but what you got.
3. Good Night. See you tomorrow

EDIT: Do you want your fire to deal x damage for y seconds? or do you want your fire to do x damage y times?
Last edited on
Thanks for the quick responses! Sorry I was in class.

Here is a zip to my files. (I prewarn you it's a lot to look at, because I'm just testing stuff out)

https://mega.co.nz/#!3NkikIpK!Rd4oCW6hkAK_Bie4eu1ilSmpR5MT81EExwAWiibeUn8

EDIT: Just to clarify too, sorry about the vagueness. I want Fire to do a status effect, "Burn" which will do x amount of damage to opponent (this would include the player if casted from Enemy) for y amount of turns.

y being a random number and x being a calculated number based off magical stats.

Basically, I'm kinda confused how to go about it. In the sense of how to implement it. All my files are attached to the link

EDIT #2: And also, I haven't made the code for the separate magics yet (i'm using a combination of composition and inheritance) thanks so much!
Last edited on
I have some pseudocode for you
1
2
3
4
5
if (enemy.underFire() == true){
 //do fire damage
 enemy.DamagedFireDamage() // This reduces the number of turns the enemy is still to be damaged
 //  ^ This function also sets underFire to false if the count reaches 0 or less
}

NOTE: I have not yet read your code.
Edit: No Comments??
Last edited on
I'm getting this error: http://snipt.org/Aifga4
Reason: I'm on Linux.
I had cscope around your code to understand it. Next time provide a makefile or at least a code-blocks project.
(Which is what i assume you are using)
[Sorry if I sound harsh]
Can you provide a .exe I can run under Wine?
Yeah I have failed to comments. It's a lot of files. But let me know any other questions.

here's an example for easier use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <string>

enum MagicType
{
    mnone = 0x99,
    mburn = 0x88,
    mstun = 0x89,
    mspdb = 0x90,
    mgrnd = 0x91,
};

enum UMagicType
{
    uatk = 0x92,
    udef = 0x93,
    uspd = 0x94,
    uplt = 0x95,
    uhel = 0x96,
    udet = 0x97,
    udrg = 0x98
};

class Entity;

class Magic
{
    public:
        /** Default constructor */
        Magic();
        /** Default destructor */
        virtual ~Magic();

        int magic_damage(int mstat)
        {
            int dmg;
            int mod = (mstat - 10)/2;
            if (mod <= 0)
                mod = 0;;
            dmg = mod + (10+(10*m_rank));

            return dmg;
        }
        float magic_mod(char choice, int stat)
        {
            double mod;
            if (choice != '6')
            {
                mod = (stat/5.0);
                if (mod <= 0)
                    mod = 0;
            }
            else
            {
                mod = (stat/5.0);
                if (mod <= 0)
                    mod = 0;
            }
            return mod;
        }
        //virtual void applySkill(Entity& entity) = 0;
        //virtual std::string getDescription() = 0;
        int m_rank;
    protected:
    private:
        int stat_eff;
        int duration;
};

class Fireball : public Magic
{

};
/*class ISkill {
public:
    virtual void applySkill(Actor& actor) = 0;
    virtual std::string getDescription() = 0;
};

class Fireball : public ISkill {
public:
    virtual void applySkill(Actor& actor) {
	    // do fireball damage here to actor
    }
};*/


I thought of having in MainCharacter this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>

#include "Item.h"
#include "Title.h"
#include "Equipment.h"
#include "Magic.h"
#include "hub.h"

using namespace std;

class Entity
{
    public://protected:
        std::string m_name;
        //std::string m_cname;
        int m_health;
        int m_health_max;
        int m_level;
        int m_urank;
        int m_rage;
        int m_rage_max;

    //public:
        PlayerInventory inventory;
        Equipment* equipment;
        Title mname;
        Magic magic;

        Entity(){}
        Entity(const char * name, int health, int level)
        {
            m_name = name;

            m_health = health;
            m_health_max = health;
            m_level = level;

            equipment = new Equipment();
        }

        virtual ~Entity(){}
        std::string get_name(){ return m_name; }
        int get_health() { return m_health; }
        int get_mhealth(){ return m_health_max; }
        int get_rage() { return m_rage; }
        int get_mrage(){ return m_rage_max; }

        virtual int dmg_modifier(int stat)
        {
            int dmg = (stat - 10)/2;
            if (dmg <= 0)
                dmg = 0;
            return dmg;
        }

};

class MainCharacter;

class Enemy: public Entity
{
    public:
        Enemy(const char * name, int health, int level,int str, int def, int dex, int skl, int sol, int intel, int spd, int block, int crit, int mrank): Entity(name,health,level)
        {
            m_mana_max = 2*sol;
            m_mana = 2*sol;

            m_str=str;
            m_def=def;
            m_dex=dex;
            m_skl=skl;
            m_sol=sol;
            m_int=intel;
            m_spd=spd;

            m_block=block;
            m_crit=crit;

            magic.m_rank=mrank;
            m_xp = m_health_max+((m_health_max*(m_level))/20);
            m_gold = m_xp - (m_health_max/2.0);

            m_rage = 0;
            m_rage_max = (m_health_max/2.0);
            m_urank = (m_level/5);
            if (m_level == 0)
                m_urank = 0;
        }
        virtual ~Enemy(){}

        void Attack(MainCharacter & target);

        void take_damage(int damage)
        {
            m_health -= damage;
            if (m_urank > 0)
            {
                m_rage+=damage;
                if (m_rage > m_rage_max)
                    m_rage=m_rage_max;
            }
        }
        int get_health() { return m_health; }

    //protected:
        int m_xp;
        int m_gold;
        int m_mana;
        int m_mana_max;
        int m_str;
        int m_def;
        int m_dex;
        int m_skl;
        int m_sol;
        int m_int;
        int m_spd;
        int m_block;
        int m_crit;
};
class Mob: public Enemy
{
    //Normal Enemies
    public:
        Mob(const char * name, int health, int level,int str, int def, int dex, int skl,
          int sol, int intel, int spd, int block, int crit, int mrank) : Enemy(name,health,level,str,def,dex,skl,sol,intel,spd,block,crit,mrank)
        {

        }
};
class Boss: public Enemy
{
    //Generic Boss Class
};
class SubBoss: public Boss
{
    //a quarter of the way to Story Boss
};
class MidBoss: public Boss
{
    //a halfway point to the Story Boss
};
class StoryBoss: public Boss
{
    //Story Boss
};

class NPC: public Entity
{
    //Parent Class of Non-Playable Characters:
    //Possible Recruitment on MC(Main Character)'s team?
};
class ShopKeeper: public NPC
{
    // Faun
};
class SpecCharacter: public NPC
{
    // Corrupted Enemies...
};
I have no more questions.
Try implementing that pseudocode.


The basic idea:
When our character perform the fire spell on an enemy, a function in the enemy's class should be called. This function will set the amount of turns the enemy will be damaged.
Every time a turn cycles by, your code should call a function in both your and your enemy's classes called turnOver() or something like that. When this function is executed, it will check if your enemy has any fire damage pending amongst other things. If yes, cause fire damage and decrement number of turns remaining. I turns reaches 0 or less, well, turn becomes 0 and your work is done..
[Sorry if I sound vague, English is not my first language]

Edit: http://s21.postimg.org/ribfrjg07/33_Selectiongvjn.png
Last edited on
Oh yeah sorry about that. MY files weren't working right so I made a title.h after title.h.h lolz

But i'll try to implement. If I have more questions I will

thanks!
I read your last post about decrementing as a status effect is true, I think my project is somewhat similar, albeit unreadable. I started it a few weeks ago and I've learned a LOT since then so I'm thinking of just scrapping this one and starting over to make it more organized, here it is though, fair warning though: spaghetti.
https://github.com/xeon826/blaaahh/tree/master/ffdevolved
Hmm... For this status effect issue, it could be recommended that you follow a factory-style (http://en.wikibooks.org/wiki/C%2B%2B_Programming/Code/Design_Patterns#Abstract_Factory) creational pattern so that you could create some sort of base class for all status effects to include the basis for initializing effects for durations of time... Actually, even better. You could create a function that takes the name of an effect, its strength (in whatever relative terms that you could give each effect) and the duration. From there, it creates a variable of whatever effect class (factory) that would induce that effect by applying it to whatever creature is a part of it. The lifetime of this object would be that of the time passed, and the strength of it (chance of not being able to hit, damage taken per second, et cetera) would be simple variables passed to this function. As for applying, you could always use the decorator (http://en.wikibooks.org/wiki/C%2B%2B_Programming/Code/Design_Patterns#Decorator) structural pattern so that the effect would be "applied" to it... Actually, a decorator factory would work perfectly here. The decorator would add an object of that class to the entity, which would call some sort of initiating-status-effect function (easily done if you can keep track of what affects are applied, et cetera). The factory would be a result of simply being able to pass a string for the name of the effect, and create the appropriate object. Modular code that would work wonders if you ever wanted to add new effects...

If the name-dropping was a bit much, just think of it this way: Each entity has a function that creates a status effect. The status effects can be created through a string-based name, strength value, and duration. A function is called at every turn that calls a function that is associated with every status effect (some sort of induce_effect() thing) to have the effect occur. Once the duration is up, the effect is deleted. I just used the terms so that I have a better understanding of them, and so that you can get a better understanding when it comes to larger projects. Design patterns are awesome once you know what they are.
Topic archived. No new replies allowed.