Unity3D/C#–Attacks with Additional Effects

To follow on from the conditions tutorial it only seems appropriate to talk about a simple way of getting an attack with ‘additional’ effects. Of course, the straight forward way would be to say, for example:

This attack is called “Burn”, so I will create a condition when using burn it’ll take off damage and add an effect. But when you look at your ‘actions’ list, you might find that doing it that way could make the code rather large. Particularly if you have extra tiers or other attacks with similar effects, for example, “You might have Burn 1, Burn 2 and Burn 3” or “Scold”, which’ll apply the burn condition but without the extra effect. My system has an approach, it’ll create condition based on attack type and then use any stats associated with the skill in its calculations. To see how I set out my abilities check out my Inventory tutorial, it’s the same system, but with extra variables. I’ve called the list ‘NeuroInv’.

The additional variables are all called:

public string school;
    public string modEff1;
    public string modEff2;
    public float mod1;
    public float mod2;
    public float mpCost;
    public bool got;

School –> Type of skill, it might be Magic, Technique, Nijutsu or whatever. If you create a list specific to the school, like I just have, this will be redundant, but I’ve left it in this tutorial in case you choose a different method.

ModEff 1 & 2 –> The ‘name’ of the type of attack. I’ve split it into 2 types. I’ll explain below

Mod 1 & 2 –> The number used in the maths for the modifier

MPCost –> How much MP the skill uses

Got –> To check if the player has it or not.

So when it comes to actually creating these conditions, you’ll need to parse through your list and check the current selection. (So you need a ‘for’ statement and check if it matches the selection variable, like in my inventory system).

Then within that, you’ll need to check the damage ‘types’ of the current selected skill.

I’ve split the ModEffect into 2 groups, so basically you can match and combine status effects. You don’t always have to use 2 at once. The way I’ve split it is:

Group 1: Damage, Drains and Healing

Group 2: Status/Additional Effects

For example, this attack has a group 1 effect:

if (Stats.Psycho[i] == “Brawl”)
            {
                Stats.PsychoInv[i].school = “Psycho”;
                Stats.PsychoInv[i].Frantic = true;
                Stats.PsychoInv[i].description = “Frantic Attack”;
                Stats.PsychoInv[i].modEff1 = “damage”;
                Stats.PsychoInv[i].mod1 = 45;
                Stats.PsychoInv[i].mpCost = 17;
            }

Which is just damage.

This one on the other hand only has a group 2 effect:

if (Stats.Neuro[i] == “Shadow Blend”)
            {
                Stats.NeuroInv[i].school = “Neuro”;
                Stats.NeuroInv[i].Curse = true;
                Stats.NeuroInv[i].description = “Increases Agility”;
                Stats.NeuroInv[i].modEff2 = “agiboost”;
                Stats.NeuroInv[i].mod2 = 25;
                Stats.NeuroInv[i].mpCost = 7;
            }

And this one, has a group 1 and group 2 effect

if (Stats.Psycho[i] == “Hand of Loki”)
            {
                Stats.PsychoInv[i].school = “Psycho”;
                Stats.PsychoInv[i].Frantic = true;
                Stats.PsychoInv[i].description = “Frantic attack that boosts Strength”;
                Stats.PsychoInv[i].modEff1 = “damage”;
                Stats.PsychoInv[i].mod1 = 45;
                Stats.PsychoInv[i].mpCost = 55;
                Stats.PsychoInv[i].modEff2 = “strboost”;
                Stats.PsychoInv[i].mod2 = 35;
            }

So, inside of the parser used for selecting an attack? This is what it may read. So we’ve got 2 attacks that do damage, which is ‘group 1’.

if (Stats.NeuroInv[x].modEff1 == “damage”)
                                {
                                    Enem.HP -= Stats.NeuroInv[x].mod1;
                                    Stats.MP -= Stats.NeuroInv[x].mpCost;
                                    selectionM = 0;
                                    selection = 0;
                                    scroll = 0;
                                    Anim.CrossFade(“Cast”);
                                   
                                    Stats.ATB = 0f;

                                }

 

This is Neuro specific of course. The reason the two are separate is because they use different ‘use’ animations.

Then a group 2 example:

if (Stats.NeuroInv[x].modEff2 == “agiboost”)
                               {

                                   if (agiboost == false)
                                   {

                                       selectionM = 0;
                                       selection = 0;
                                       scroll = 0;
                                       Anim.CrossFade(“Cast”);
                                       Stats.ATB = 0f;
                                       Stats.AGI += Stats.NeuroInv[x].mod2;
                                       agiboost = true;
                                   }

                               }

 

And the different types of attacks you might use could be endless. You might have:

Group 1: (Damage/Drain/Heal)

Damage, DamageWithAGI, DamageWithHP, RestoreHP, RestoreMP, DrainHP, DrainHPWithAGI (like my Draw Blood), DrainMP

Group 2:  (additional effects)

AGIBoost, STRBoost, Burn, Poison, DecAGI (decrease), DecSTR, Poison-self, DecAGI-self, DrainHP (you may wish to reuse some from group one if you need to)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s