all repos — RPG @ 502924ae35666f2d5ac541310b3e57f2e4fe70b4

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

Assets/Scripts/Battle/AbilityDB.cs (view raw)

  1using System.Collections;
  2using System.Collections.Generic;
  3using UnityEngine;
  4using System;
  5
  6public static class AbilityDB
  7{
  8    
  9    private static string processAbility(Fighter f1, Ability ability, Fighter f2, bool checkMP, out bool output)
 10    {
 11        string tmp;
 12        if (checkMP)
 13        {
 14            tmp = ability.ExecuteSafe(f1, f2, out output);
 15        }
 16        else
 17        {
 18            tmp = ability.Execute(f1, f2, out output);
 19        }
 20        
 21        //Update Fighter status
 22        updateGui(f1);
 23        updateGui(f2);
 24
 25        return tmp;
 26    }
 27
 28    private static string processString(Fighter f1, string ability, Fighter f2, bool checkMP, out bool output)
 29    {
 30        return processAbility(f1, getAbility(ability), f2, checkMP, out output);
 31    }
 32    private static string processItem(Fighter f1, ItemInfo item, Fighter f2, out bool output)
 33    {
 34        return item.ExecuteSafe(f1, f2, out output);
 35    }
 36
 37    public static string Process(Fighter f1, Action action, Fighter f2, bool checkMP, out bool output)
 38    {
 39        if(action is Ability)
 40        {
 41            return processAbility(f1, (Ability)action, f2, checkMP, out output);
 42        } else if (action is ItemInfo)
 43        {
 44            return processItem(f1, (ItemInfo)action, f2, out output);
 45        } else
 46        {
 47            output = false;
 48            return "Error in AbilityDB!";
 49        }
 50    }
 51
 52    public static Ability getAbility(string key)
 53    {
 54        switch (key)
 55        {
 56            case "Attack":
 57                return new Attack();
 58            case "Defend":
 59                return new Defend();
 60            case "Heal":
 61                return new Heal();
 62            case "HealBig":
 63                return new HealBig();
 64            case "HealGreat":
 65                return new HealGreat();
 66            case "ReviveHalf":
 67                return new ReviveHalf();
 68            case "ReviveFull":
 69                return new ReviveFull();
 70            default:
 71                return null;
 72        }
 73    }
 74    
 75    private static void updateGui(Fighter f)
 76    {
 77        if(f is GoodGuy)
 78        {
 79
 80            GoodGuy gg = (GoodGuy)f;
 81
 82            if(gg.inBattle)
 83                gg.updateStatus();
 84        }
 85    }
 86    
 87    public static GoodGuy GetGoodGuy(GameObject partyObject, Stats s)
 88    {
 89        GoodGuy gg = null;
 90
 91        switch (s.Name)
 92        {
 93            case "Paladin":
 94                gg = partyObject.AddComponent<Paladin>();
 95                break;
 96            case "Archer":
 97                gg = partyObject.AddComponent<Archer>();
 98                break;
 99            case "Boxer":
100                gg = partyObject.AddComponent<Boxer>();
101                break;
102            case "Mage":
103                gg = partyObject.AddComponent<Mage>();
104                break;
105            default:
106                break;
107        }
108        gg.inBattle = false;
109
110        return gg;
111    }
112
113
114}