Encounter / Assets / Scripts / EntityHandler / PlayerHandler.cs
PlayerHandler.cs
Raw
using System;
using System.Collections.Generic;
using UnityEngine;

public class PlayerHandler
{
    public int Strength;                           // Strength stat | Used for determining weapon usage, situation requirements, etc.
    public int Intelligence;                       // Intelligence stat | Used for wizardly characteristics, such as mana determination
    public int Constitution;                       // Constitution stat | Used for health determination, resistances
    public int Dexterity;                          // Dexterity stat | Used for armor determination, ability to hit
    public int Charisma;                           // Charisma stat | Situation requirements, bartering and pricing
    public int Wisdom;                             // Wisdom stat | Situation requirements, event encounter handling
    public int Luck;                               // Luck stat | Critical strike chance, overall item chances and encounter rolls
    public int Armor;                              // Armor stat | The lower the value the higher amount the damage will be
    public int MaxHealth;                          // The Max Health parameter that sets the ceiling for the health property
    public int Health;                             // Health stat | General determining factor for if the player is alive or dead
    public int MaxMana;                            // The Max Mana parameter that the sets the ceiling for the mana property
    public int Mana;                               // Mana stat | Economy pool for Spells
    public string PlayerName;                      // Name of the player
    public Inventory PlayerInven;                  // Inventory container for this player object that holds the weapons, apparel, abilities, spells, and items
    public Player.PlayerType PlayersType;          // Indicator what class the player is 
    public GameObject PlayerSkillTree;

    public GameObject CreatePlayerObject()
    {
        GameObject playerObject = PositionHandler.Instance.PositionPlayer(Resources.Load<GameObject>("Entities/Player"));
        Player playerComponent = playerObject.GetComponent<Player>();
        playerComponent.DeactivateVisually();
        playerComponent.AddSkillTree(PlayerSkillTree);
        playerComponent.IndicateStats(this);
        playerComponent.GetInventory().InjectAttachedPlayer(playerComponent);
        return playerObject;
    }

    /// <summary>
    /// Constructor for the Player when starting the game from the character creation screen
    /// </summary>
    /// <param name="stats">Array of stats passed from the character creation screen</param>
    /// <param name="armor">Int parameter retrieved from string ref</param>
    /// <param name="health">Int parameter retrieved from string ref</param>
    /// <param name="mana">Int parameter retrieved from string ref</param>
    /// <param name="name">String parameter retrievd from string ref</param>
    /// <param name="weapons">Contains all of the weapons to initialize with the player</param>
    /// <param name="apparel">Contains all of the apparel to initialize with the player</param>
    /// <param name="abilities">Contains all of the abilities to initialize with the player</param>
    /// <param name="spells">Contains all of the spells to initialize with the player</param>
    public PlayerHandler(int[] stats, int armor, int health, int mana, string name, Player.PlayerType playerType, List<Weapon> weapons, List<Apparel> apparel, List<Ability> abilities, List<Spell> spells, GameObject skillTree)
    {
        for (int i = 0; i < stats.Length; i++)
        {
            switch (i)
            {
                case 0:
                    this.Strength               = stats[i]; 
                    break;
                case 1: 
                    this.Intelligence           = stats[i]; 
                    break;
                case 2:
                    this.Constitution           = stats[i]; 
                    break;
                case 3:
                    this.Dexterity              = stats[i]; 
                    break;
                case 4:
                    this.Charisma               = stats[i]; 
                    break;
                case 5:
                    this.Wisdom                 = stats[i]; 
                    break;
                case 6:
                    this.Luck                   = stats[i]; 
                    break;
            }
        }

        this.Armor                              = armor;
        this.MaxHealth                          = health;
        this.Health                             = health;
        this.MaxMana                            = mana;
        this.Mana                               = mana;
        this.PlayerName                         = name;

        this.PlayerInven                        = new Inventory(weapons, apparel, abilities, spells);
        this.PlayersType                        = playerType;
        this.PlayerSkillTree                    = skillTree;   
    }
    /// <summary>
    /// Constructor used for requirement handling
    /// </summary>
    /// <param name="stats">Array of stats passed from the character creation screen</param>
    /// <param name="armor">Int parameter retrieved from string ref</param>
    /// <param name="health">Int parameter retrieved from string ref</param>
    /// <param name="mana">Int parameter retrieved from string ref</param>
    /// <param name="name">String parameter retrievd from string ref</param>
    public PlayerHandler(int[] stats, int armor, int health, int mana, string name, Player.PlayerType playerType)
    {
        for (int i = 0; i < stats.Length; i++)
        {
            switch (i)
            {
                case 0:
                    this.Strength               = stats[i];
                    break;
                case 1:
                    this.Intelligence           = stats[i];
                    break;
                case 2:
                    this.Constitution           = stats[i];
                    break;
                case 3:
                    this.Dexterity              = stats[i];
                    break;
                case 4:
                    this.Charisma               = stats[i];
                    break;
                case 5:
                    this.Wisdom                 = stats[i];
                    break;
                case 6:
                    this.Luck                   = stats[i];
                    break;
            }
        }

        this.Armor                              = armor;
        this.MaxHealth                          = health;
        this.Health                             = health;
        this.MaxMana                            = mana;
        this.Mana                               = mana;
        this.PlayerName                         = name;

        this.PlayerInven                        = new Inventory();
        this.PlayersType                        = playerType;
    }
    /// <summary>
    /// Modifies the stat based off of the stat_Value passed and changes it to the new_Value
    /// </summary>
    /// <param name="statValue">0-STR|1-INT|2-CON|3-DEX|4-CHA|5-WIS|6-LCK</param>
    /// <param name="newValue">The new value that the stat will be set to</param>
    /// <exception cref="InvalidOperationException">If the new_Value is less than or equal to 0 or if the stat_Value is not within the range of 0-6 -inclusive-</exception>
    public void ModifyStat(int statValue, int newValue)
    {
        if (newValue <= 0)
            throw new InvalidOperationException("new_Value cannot be below or equal to 0, please check passed parameters ---> new_Value | " + newValue);

        switch (statValue)
        {
            case 0:
                this.Strength           = newValue; 
                break;
            case 1:
                this.Intelligence       = newValue; 
                break;
            case 2:
                this.Constitution       = newValue; 
                break;
            case 3:
                this.Dexterity          = newValue; 
                break;
            case 4:
                this.Charisma           = newValue; 
                break;
            case 5:
                this.Wisdom             = newValue; 
                break;
            case 6:
                this.Luck               = newValue; 
                break;
            default:
                throw new InvalidOperationException("Invalid stat_Value was passed into ModifyStat(), please check passed parameters ---> stat_Value | " + statValue);
        }
    }
}