How do I create dynamic formula for calculate damage step?

Hi
I try to create a skill system.
I used scriptablegameobject for this.
My problem is I can’t change damage formula for each skills.

I have a main class is called SkillsClass which contain {Name , Cost class,Damage Class,…}
The damage formula contained in Damage Class.
I don’t know how to code Damage Class for dynamic formula( like I can chose Plus,Minus,… and status value from user and target)

Can anyone guide me or I should use normal class for this?

I do not fully comprehend what you’re asking. Could you give a small example of how you’d like this dynamic damage to be calculated?

Ex.
first skill the damage calculated by UserAttack-TargetDef
second skill the damage calculated by (UserHp-TargetHp)*2
third skill the damage calculated by (UserCurrentMp)

I would like to change formula for each skills or I need to code new .cs for every skills ?

Well, I dunno… just reading your example, it sounds like you’re making criteria for each skill.
Now, if you have a group of skills that is calculated in the same fashion, but with different values, you could put those together. but if the calculation is totally different, I don’t see how you could make it general ? how would it know what you want to do?! :slight_smile:

1 Like

Ideally you would standardise the system. All of those formulas take the form of (a-b)*c. You can easily develop a method where you pass in the appropriate values and get an answer. Without needing a seperate formula for each.

If you are doing it a lot, you can get tricky with reflection and set this all up in the inspector.

If all of those use same formula how I pick a,b,c value? (Like atk value ,def value) can u guide me ?

Maybe you should calculate the damage of the skills and the damage taken by the enemies separately. I mean the skill damages may depend on the weapons and stats the character has.But damage taken is also effected by the enemies armor etc. So your damage output in the player’s skill script should give a variable to put into the damage taken script to calculate the health loss. I’m not an expert on scripting so i could not write this right now. But you may try this.

In the first

  • a = userAttack
  • b = targetDefense
  • c = 1

In the second

  • a = userHP
  • b = targetHP
  • c = 2

In the third

  • a = userCurrentMP
  • b = 0
  • c = 1

Normally you would set up a system in the inspector that lets you pick which parameters will be passed in. That way you have one Attack Component, but you can configure it to behave differently for each attack.

I think I’ll use enum for this.

enum Attributes{ UserHp,TargetHp,UserAtk,TargetAtk};
Attributes a;
Attributes b;
Attributes c;

int aValue;
int bValue;
int cValue;
if(a==Attributes.UserHp)
{
a=(getCompoent().UserHp)
}
else if ( a==Attributes.UserAtk)
{
a=(getCompoent().UserAtk)
}
....

but If I would like to use constant value how I set this?