232 lines
6.7 KiB
C#
232 lines
6.7 KiB
C#
using UnityEngine;
|
|
using System.Reflection;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
|
|
[System.Serializable]
|
|
public class PlayerStats : MonoBehaviour
|
|
{
|
|
[Header("Player Stats")]
|
|
public string playerName { get; private set; } = "Hero";
|
|
public Sprite avatarImage { get; private set; } = null;
|
|
public int level { get; private set; } = 1;
|
|
public int score { get; private set; } = 0;
|
|
public int gold { get; set; } = 0;
|
|
|
|
[Header("Experience")]
|
|
public int experience { get; private set; } = 37;
|
|
public int experienceToNextLevel { get; private set; } = 100;
|
|
|
|
[Header("Health and Resources")]
|
|
public int health { get; private set; } = 20;
|
|
public int maxHealth { get; private set; } = 100;
|
|
public int mana { get; private set; } = 10;
|
|
public int maxMana { get; private set; } = 50;
|
|
public int stamina { get; private set; } = 50;
|
|
public int maxStamina { get; private set; } = 100;
|
|
|
|
[Header("Attributes")]
|
|
public int strength { get; private set; } = 5;
|
|
public int agility { get; private set; } = 5;
|
|
public int dexterity { get; private set; } = 5;
|
|
public int intelligence { get; private set; } = 5;
|
|
public int charisma { get; private set; } = 5;
|
|
public int wisdom { get; private set; } = 5;
|
|
public int luck { get; private set; } = 5;
|
|
public int perception { get; private set; } = 5;
|
|
public int sneak { get; private set; } = 5;
|
|
public int lockpick { get; private set; } = 5;
|
|
public int bribe { get; private set; } = 5;
|
|
public int persuasion { get; private set; } = 5;
|
|
public int manipulation { get; private set; } = 5;
|
|
public int shield { get; private set; } = 5;
|
|
public int kick { get; private set; } = 5;
|
|
public int crafting { get; private set; } = 5;
|
|
public int dodge { get; private set; } = 5;
|
|
public int archery { get; private set; } = 5;
|
|
public int magic { get; private set; } = 5;
|
|
public int slash { get; private set; } = 5;
|
|
public int blunt { get; private set; } = 5;
|
|
public int healing { get; private set; } = 5;
|
|
|
|
[Header("Combat Stats")]
|
|
public int attackPower { get; private set; } = 10;
|
|
public int armour { get; private set; } = 5;
|
|
public int speed { get; private set; } = 5;
|
|
public int criticalHitChance { get; private set; } = 5;
|
|
public int criticalHitDamageMultiplier { get; private set; } = 2;
|
|
|
|
[Header("Magic Stats")]
|
|
public int magicPower { get; private set; } = 5;
|
|
public int magicDefense { get; private set; } = 5;
|
|
public int healingPower { get; private set; } = 5;
|
|
public int spellSlots { get; private set; } = 3;
|
|
|
|
[Header("Resistances")]
|
|
public int poisonResistance { get; private set; } = 5;
|
|
public int fireResistance { get; private set; } = 5;
|
|
public int iceResistance { get; private set; } = 5;
|
|
public int lightningResistance { get; private set; } = 5;
|
|
public int earthResistance { get; private set; } = 5;
|
|
public int waterResistance { get; private set; } = 5;
|
|
public int windResistance { get; private set; } = 5;
|
|
public int lightResistance { get; private set; } = 5;
|
|
public int darkResistance { get; private set; } = 5;
|
|
public int holyResistance { get; private set; } = 5;
|
|
public int natureResistance { get; private set; } = 5;
|
|
public int meleeResistance { get; private set; } = 5;
|
|
public int rangedResistance { get; private set; } = 5;
|
|
public int magicResistance { get; private set; } = 5;
|
|
|
|
[Header("Elemental Damage")]
|
|
public int poisonDamage { get; private set; } = 5;
|
|
public int fireDamage { get; private set; } = 5;
|
|
public int iceDamage { get; private set; } = 5;
|
|
public int lightningDamage { get; private set; } = 5;
|
|
public int earthDamage { get; private set; } = 5;
|
|
public int waterDamage { get; private set; } = 5;
|
|
public int windDamage { get; private set; } = 5;
|
|
public int lightDamage { get; private set; } = 5;
|
|
public int darkDamage { get; private set; } = 5;
|
|
public enum Skills
|
|
{
|
|
HiltStrike,
|
|
Pin,
|
|
Tackle,
|
|
TrueShot,
|
|
Slow,
|
|
RainArrows,
|
|
Bleed,
|
|
Rage,
|
|
Stun,
|
|
FastStrike,
|
|
PowerStrike,
|
|
HolyArrow,
|
|
MagicShot,
|
|
MultiShot,
|
|
Hack,
|
|
ShieldBash,
|
|
DoubleSlash,
|
|
IncreaseStrength,
|
|
Push,
|
|
Evade,
|
|
Kick
|
|
}
|
|
[Header("Skills")]
|
|
public List<Skills> skills = new List<Skills>();
|
|
public enum Spells
|
|
{
|
|
Fireball,
|
|
IceArrow,
|
|
HolyArrow,
|
|
LightningStrike,
|
|
Blizzard,
|
|
LifeTap,
|
|
Fear,
|
|
FireStorm,
|
|
HolyRain,
|
|
HolyBolt,
|
|
LightningBolt,
|
|
DarkBolt,
|
|
DarkStorm,
|
|
LightningStorm,
|
|
Confusion,
|
|
LearnSkill,
|
|
HardenArmour,
|
|
Invisibility,
|
|
Lullaby,
|
|
Protection,
|
|
Heal
|
|
}
|
|
[Header("Spells")]
|
|
public List<Spells> spells = new List<Spells>();
|
|
|
|
public void SetPlayerName(string newName)
|
|
{
|
|
playerName = newName;
|
|
}
|
|
|
|
public void AddScore(int points)
|
|
{
|
|
score += points;
|
|
}
|
|
|
|
public void AddGold(int amount)
|
|
{
|
|
gold += amount;
|
|
}
|
|
|
|
public void GainExperience(int amount)
|
|
{
|
|
experience += amount;
|
|
if (experience >= experienceToNextLevel)
|
|
{
|
|
LevelUp();
|
|
}
|
|
}
|
|
|
|
private void LevelUp()
|
|
{
|
|
level++;
|
|
experience -= experienceToNextLevel;
|
|
experienceToNextLevel += 50;
|
|
maxHealth += 10;
|
|
health = maxHealth;
|
|
maxMana += 5;
|
|
mana = maxMana;
|
|
}
|
|
|
|
public void RestoreHealth(int amount)
|
|
{
|
|
health = Mathf.Min(health + amount, maxHealth);
|
|
}
|
|
|
|
public void RestoreMana(int amount)
|
|
{
|
|
mana = Mathf.Min(mana + amount, maxMana);
|
|
}
|
|
|
|
public void RestoreStamina(int amount)
|
|
{
|
|
stamina = Mathf.Min(stamina + amount, maxStamina);
|
|
}
|
|
public void TakeDamage(int damage)
|
|
{
|
|
health -= damage;
|
|
if (health < 0)
|
|
{
|
|
health = 0;
|
|
}
|
|
}
|
|
|
|
public void SpendMana(int amount)
|
|
{
|
|
mana -= amount;
|
|
if (mana < 0)
|
|
{
|
|
mana = 0;
|
|
}
|
|
}
|
|
public void SpendStamina(int amount)
|
|
{
|
|
stamina -= amount;
|
|
if (stamina < 0)
|
|
{
|
|
stamina = 0;
|
|
}
|
|
}
|
|
|
|
public int GetStatValue(string statName)
|
|
{
|
|
// The fix is to use GetProperty instead of GetField
|
|
PropertyInfo property = GetType().GetProperty(statName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
if (property != null && property.PropertyType == typeof(int))
|
|
{
|
|
return (int)property.GetValue(this);
|
|
}
|
|
|
|
Debug.LogWarning($"Stat '{statName}' not found or is not an integer.");
|
|
return 0;
|
|
}
|
|
} |