all repos — RPG @ 502924ae35666f2d5ac541310b3e57f2e4fe70b4

Fully functional 3D turn based role playing game coded in C# and base Unity.

Assets/Scripts/Utility/Stats.cs (view raw)

  1using System.Collections;
  2using System.Collections.Generic;
  3using UnityEngine;
  4
  5[System.Serializable]
  6public class Stats
  7{
  8    #region Private
  9    private string name;
 10
 11    private double hp;
 12    private double mp;
 13    private double atk;
 14    private double def;
 15    private double agl;
 16    private double lck;
 17
 18    private double maxHP;
 19    private double maxMP;
 20    private double maxATK;
 21    private double maxDEF;
 22    private double maxAGL;
 23    private double maxLCK;
 24
 25    private List<Ability> abilities;
 26    #endregion
 27
 28    #region Constructors
 29    public Stats(string name, double HP, double MP, double ATK, double DEF, double AGL, double LCK, List<Ability> abilities)
 30    {
 31        this.name = name;
 32        hp = maxHP = HP;
 33        mp = maxMP = MP;
 34        atk = maxATK = ATK;
 35        def = maxDEF = DEF;
 36        agl = maxAGL = AGL;
 37        lck = maxLCK = LCK;
 38        
 39        this.abilities = new List<Ability>(abilities);
 40    }
 41
 42    public Stats(Stats s) //copy stats
 43    {
 44        name = s.name;
 45
 46        maxHP = s.MaxHP;
 47        maxMP = s.MaxMP;
 48        maxATK = s.MaxATK;
 49        maxDEF = s.MaxDEF;
 50        maxAGL = s.MaxAGL;
 51        maxLCK = s.MaxLCK;
 52
 53        hp = s.HP;
 54        mp = s.MP;
 55        atk = s.ATK;
 56        def = s.DEF;
 57        agl = s.AGL;
 58        lck = s.LCK;
 59
 60        abilities = new List<Ability>(s.abilities);
 61    }
 62    #endregion
 63
 64    #region Stats DB
 65    public Stats(string key)
 66    {
 67        name = key;
 68        abilities = new List<Ability>();
 69        abilities.Add(new Attack());
 70        abilities.Add(new Defend());
 71        switch (key)
 72        {
 73            case "Paladin":
 74                hp = maxHP = 500;
 75                mp = maxMP = 0;
 76                atk = maxATK = 50;
 77                def = maxDEF = 63;
 78                agl = maxAGL = 30;
 79                lck = maxLCK = 15;
 80                break;
 81            case "Archer":
 82                hp = maxHP = 400;
 83                mp = maxMP = 400;
 84                atk = maxATK = 40;
 85                def = maxDEF = 50;
 86                agl = maxAGL = 35;
 87                lck = maxLCK = 40;
 88                abilities.Add(new Heal());
 89                abilities.Add(new HealBig());
 90                abilities.Add(new ReviveHalf());
 91                break;
 92            case "Boxer":
 93                hp = maxHP = 600;
 94                mp = maxMP = 0;
 95                atk = maxATK = 30;
 96                def = maxDEF = 80;
 97                agl = maxAGL = 28;
 98                lck = maxLCK = 25;
 99                break;
100            case "Mage":
101                hp = maxHP = 375;
102                mp = maxMP = 600;
103                atk = maxATK = 30;
104                def = maxDEF = 50;
105                agl = maxAGL = 32;
106                lck = maxLCK = 5;
107                abilities.Add(new HealBig());
108                abilities.Add(new HealGreat());
109                abilities.Add(new ReviveFull());
110                break;
111            case "Orc":
112                hp = maxHP = 300;
113                mp = maxMP = 0;
114                atk = maxATK = 40;
115                def = maxDEF = 55;
116                agl = maxAGL = 25;
117                lck = maxLCK = 15;
118                break;
119            case "Mutant":
120                hp = maxHP = 500;
121                mp = maxMP = 0;
122                atk = maxATK = 43;
123                def = maxDEF = 60;
124                agl = maxAGL = 27;
125                lck = maxLCK = 20;
126                break;
127            case "Brady":
128                hp = maxHP = 1000;
129                mp = maxMP = 500;
130                atk = maxATK = 50;
131                def = maxDEF = 60;
132                agl = maxAGL = 30;
133                lck = maxLCK = 35;
134                break;
135            case "Ganfaul":
136                hp = maxHP = 2000;
137                mp = maxMP = 500;
138                atk = maxATK = 55;
139                def = maxDEF = 60;
140                agl = maxAGL = 32;
141                lck = maxLCK = 30;
142                break;
143            default:
144
145                break;
146        }
147    }
148    #endregion
149
150    #region Getters and Setters
151    public string Name { get => name; protected set => name = value; }
152
153    public double HP
154    {
155        get
156        {
157            return hp;
158        }
159        set
160        {
161            if (value > MaxHP)
162            {
163                hp = MaxHP;
164            }
165            else
166            if(value < 0)
167            {
168                hp = 0;
169            }
170            else
171            {
172                hp = value;
173            }
174        }
175    }
176    public double MP
177    {
178        get
179
180        {
181            return mp;
182        }
183        set
184        {
185            if (value > MaxMP)
186            {
187                mp = MaxMP;
188            }
189            else
190            if (value < 0)
191            {
192                mp = 0;
193            }
194            else
195            {
196                mp = value;
197            }
198        }
199    }
200    public double ATK
201    {
202        get
203        {
204            return atk;
205        }
206        set
207        {
208            if (value < 1)
209            {
210                atk = 1;
211            } else
212            {
213                atk = value;
214            }
215        }
216    }
217    public double DEF
218    {
219        get
220        {
221            return def;
222        }
223        set
224        {
225            if (value < 1)
226            {
227                def = 1;
228            }
229            else
230            {
231                def = value;
232            }
233        }
234    }
235    public double AGL
236    {
237        get
238        {
239            return agl;
240        }
241        set
242        {
243            if (value < 1)
244            {
245                agl = 1;
246            }
247            else
248            {
249                agl = value;
250            }
251        }
252    }
253    public double LCK
254    {
255        get
256        {
257            return lck;
258        }
259        set
260        {
261            if (value < 1)
262            {
263                lck = 1;
264            }
265            else
266            {
267                lck = value;
268            }
269        }
270    }
271
272    public double MaxHP { get => maxHP; protected set => maxHP = value; }
273    public double MaxMP { get => maxMP; protected set => maxMP = value; }
274    public double MaxATK { get => maxATK; protected set => maxATK = value; }
275    public double MaxDEF { get => maxDEF; protected set => maxDEF = value; }
276    public double MaxAGL { get => maxAGL; protected set => maxAGL = value; }
277    public double MaxLCK { get => maxLCK; protected set => maxLCK = value; }
278
279    public List<Ability> GetAbilities()
280    {
281        return new List<Ability>(abilities);
282    }
283    #endregion
284    
285
286    public override string ToString()
287    {
288        return "HP: " + (int)hp + "/" + (int)maxHP + "\n" +
289               "MP: " + (int)mp + "/" + (int)maxMP + "\n" +
290               "ATK: " + (int)atk + "\n" +
291               "DEF: " + (int)def + "\n" +
292               "AGL: " + (int)agl + "\n" +
293               "LCK: " + (int)lck;
294    }
295}