Files
RPGBook/Assets/Scripts/CharacterStats.cs
SHOUTING_PIRATE f5928e04c4 intial commit
2025-07-21 17:10:16 +01:00

49 lines
1.5 KiB
C#

using UnityEngine;
public class CharacterStats : MonoBehaviour
{
[Tooltip("The profile defining the base stats and info for this character.")]
public NPCProfile profile;
// Runtime stats
public int currentHealth { get; private set; }
public int currentMana { get; private set; }
void Awake()
{
// Initialize runtime stats from the profile template
currentHealth = profile.maxHealth;
currentMana = profile.maxMana;
}
/// <summary>
/// Reduces the character's health by a given amount, applying resistances/vulnerabilities.
/// </summary>
/// <param name="damageAmount">The base amount of damage.</param>
/// <param name="damageType">The type of damage being dealt.</param>
/// <returns>True if the character's health dropped to 0 or below.</returns>
public bool TakeDamage(int damageAmount, DamageType damageType)
{
float multiplier = profile.GetDamageMultiplier(damageType);
int finalDamage = Mathf.RoundToInt(damageAmount * multiplier);
currentHealth -= finalDamage;
if (currentHealth < 0)
{
currentHealth = 0;
}
Debug.Log($"{profile.npcName} took {finalDamage} {damageType} damage.");
return currentHealth <= 0;
}
public void Heal(int amount)
{
currentHealth += amount;
if (currentHealth > profile.maxHealth)
{
currentHealth = profile.maxHealth;
}
}
}