Search Unity

Basic Stats and effects (hit, damage, dodge, critical, regen and dps)

Discussion in 'Scripting' started by EmilioLuizz, Jul 30, 2014.

  1. EmilioLuizz

    EmilioLuizz

    Joined:
    Jul 30, 2014
    Posts:
    2
    Hello community,

    I'm new here, and am generally not user forums to avoid questions useless posts.

    few hours I am trying to improve this code for a mini personal project, and I am without complete success.

    if not begging, some tips would be good. (since I'm starting).

    Thank you alot.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Attributes : MonoBehaviour
    5. {
    6.     public CharacterController controller;
    7.  
    8.     //Class of player
    9.     public bool Meele;
    10.     public bool Range;
    11.     public bool Mage;
    12.  
    13.     //Base Stats
    14.     public int BaseSTR;
    15.     public int BaseDEX;
    16.     public int BaseINT;
    17.  
    18.     //equipament add
    19.     private int equipSTR;
    20.     private int equipDEX;
    21.     private int equipINT;
    22.    
    23.     private int EquipHit;
    24.     private int EquipCrit;
    25.     private int EquipDodge;
    26.     private int EquipHpS;
    27.     private int EquipMpS;
    28.  
    29.     private int EquipDamage;
    30.     private int EquipDPS;
    31.     private int WeaponSpeed;
    32.  
    33.     //Sigma
    34.     public int STR;
    35.     public int DEX;
    36.     public int INT;
    37.  
    38.     //Final Result (public only to see)
    39.     public double hitPorcent;
    40.     public double critPorcent;
    41.     public double DodgePorcent;
    42.     public double HPforSec;
    43.     public double MPforSec;
    44.     public double Damage;
    45.     //public int DamageMin;
    46.     //public int DamageMax;
    47.     public double DamageSpeed;
    48.    
    49.     void Start ()
    50.     {
    51.  
    52.     }
    53.  
    54.     void Update ()
    55.     {
    56.         STR = SomaStr(BaseSTR,equipSTR);
    57.         DEX = SomaStr(BaseDEX,equipDEX);
    58.         INT = SomaStr(BaseINT,equipINT);
    59.         Player();
    60.     }
    61.  
    62.     int SomaStr(int Str, int Strr)
    63.     {
    64.         int STR = Str+Strr;
    65.         return STR;
    66.     }
    67.     int SomaDex(int Dex, int Dexx)
    68.     {
    69.         int DEX = Dex+Dexx;
    70.         return DEX;
    71.     }
    72.  
    73.     int SomaInt( int Int, int Intt)
    74.     {
    75.         int INT = Int+Intt;
    76.         return INT;
    77.     }
    78.     /*
    79.     void Player()
    80.     {
    81.         if(Meele == true)
    82.         {
    83.             hitPorcent = 65.303+ (DEX * 0.167) + (INT * 0.1); // +hit from equips;
    84.             critPorcent = 1.508 + (STR * 0.03) + (DEX * 0.032) + (INT * 0.02);// + Crit from equips
    85.             DodgePorcent = 1.5025 + (STR * 0.025) + (DEX * 0.0125) + (INT * 0.005);// + Dodge from equips
    86.             HPforSec = 0.8 + (STR * 0.02) + (DEX * 0.01) + (INT * 0.005);// + H/s from equips
    87.             MPforSec = 0.68 + (INT * 0.02);// + M/s from equips
    88.             Damage = (Random.Range (7.35F,13.35F)) + (STR * 0.02) + (DEX * 0.15) + (INT * 0.08);// + Damage from equips //10.35(max+3,min-3)
    89.             DamageSpeed = 7.8741 + (STR * 0.0167) + (DEX * 0.125) + (INT * 0.067);// + (Damage from equips / weapon speed)
    90.         }
    91.     }
    92.  
    93.     void Player()
    94.     {
    95.         if(Range == true)
    96.         {
    97.             hitPorcent = 65.391 + (DEX * 0.167) + (INT * 0.1);// + Hit% from equips
    98.             critPorcent = 1.472 + (STR * 0.03) + (DEX * 0.032) + (INT * 0.02);// + Crit from equips
    99.             DodgePorcent = 1.4825 + (STR * 0.025) + (DEX * 0.0125) + (INT * 0.005);// + Dodge from equips
    100.             HPforSec = 0.785 + (STR * 0.02) + (DEX * 0.01) + (INT * 0.005);// + H/s from equips
    101.             MPforSec = 0.78 + (INT * 0.02);// + M/s from equips
    102.             Damage = (Random.Range (8.38F,14.38F)) + (STR * 0.02) + (DEX * 0.15) + (INT * 0.08);// + Damage from equips //11.38(max+3,min-3)
    103.             DamageSpeed = 9.5246 + (STR * 0.0167) + (DEX * 0.125) + (INT * 0.067);// + (Damage from equips / weapon speed)
    104.         }
    105.     }
    106.         */
    107.     void Player()
    108.     {  
    109.         double[] varChanger;
    110.  
    111.         if(Mage == true && Range == false && Meele == false)
    112.         {  
    113.             varChanger = new double[] {65.456};
    114.             varChanger = new double[] {1.496};
    115.             varChanger = new double[] {1.49};
    116.             varChanger = new double[] {0.685};
    117.             varChanger = new double[] {0.78};
    118.             varChanger = new double[] {7.47F};
    119.             varChanger = new double[] {13.47F};
    120.             varChanger = new double[] {8.8143};
    121.         }
    122.         if(Mage == false && Range == true && Meele == false)
    123.         {
    124.            
    125.         }
    126.         if(Mage == false && Range == false && Meele == true)
    127.         {
    128.            
    129.         }
    130.  
    131.         hitPorcent = varChanger[0] + (DEX * 0.167) + (INT * 0.1);// + Hit% from equips
    132.         critPorcent = varChanger[0] + (STR * 0.03) + (DEX * 0.032) + (INT * 0.02);// + Crit from equips
    133.         DodgePorcent = varChanger[2] + (STR * 0.025) + (DEX * 0.0125) + (INT * 0.005);// + Dodge from equips
    134.         HPforSec = varChanger[3] + (STR * 0.02) + (DEX * 0.01) + (INT * 0.005);// + H/s from equips
    135.         MPforSec = varChanger[4] + (INT * 0.02);// + M/s from equips          
    136.         Damage = (Random.Range (varChanger[5],varChanger[6])) + (STR * 0.02) + (DEX * 0.15) + (INT * 0.08);// + Damage from equips //10.47(max+3,min-3)
    137.         DamageSpeed = varChanger[7] + (STR * 0.0167) + (DEX * 0.125) + (INT * 0.067);// + (Damage from equips / weapon speed)
    138.  
    139.         varChanger.Clear();
    140.     }
    141.  
    142. }
    143.  
     
  2. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    What exactly are you trying to do?
     
  3. talecrafter

    talecrafter

    Joined:
    Mar 26, 2013
    Posts:
    34
    That looks very confusing.
    You should use more explicit names.
    For example, this looks like random text with int, Int, Intt.

    Code (CSharp):
    1.  int SomaInt( int Int, int Intt)
    2.     {
    3.         int INT = Int+Intt;
    4.         return INT;
    5.     }
    Apart from the fact that a method that adds two values is totally unnecessary.

    Further down there is an obvious error, where you create the varChanger multiple times instead of adding values to the same object. It should be:

    Code (CSharp):
    1. varChanger = new double[] {
    2.     65.456,
    3.     1.496,
    4.     1.49,
    5.     0.685,
    6.     0.78,
    7.     7.47,
    8.     13.47,
    9.     8.8143
    10. };
    And there is no Clear() for an array. The compiler/Editor should have marked that line as an error.
     
  4. EmilioLuizz

    EmilioLuizz

    Joined:
    Jul 30, 2014
    Posts:
    2
    Thanks crafting legends, this resolves the error that was giving. Creativity zero for variable names, but thanks for the tip, I'll mplement.


    Polymorphik, I was thinking in the calculations of stat character, capturing values. lines 62,67,73 adding the stat equipment with basic stat (which will be almentados level by 5 per player).

    in summary: entering stat: intelligence, strength and dexterity and output returns: hit, damage, dodge, critical, regen and dps