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

72 lines
2.3 KiB
C#

using UnityEngine;
public class MagicCaster : MonoBehaviour
{
private PlayerStats playerStats;
private Spellbook spellbook;
private Light activeLight;
void Start()
{
playerStats = PlayerController.Instance.playerStats;
spellbook = PlayerController.Instance.spellbook;
}
public void CastSpell(Spell spell, GameObject target = null)
{
if (!spellbook.HasSpell(spell) || playerStats.mana < spell.manaCost) return;
playerStats.SpendMana(spell.manaCost);
Debug.Log($"Casting {spell.spellName}...");
switch (spell.type)
{
case SpellType.Utility:
CastUtilitySpell(spell, target);
break;
case SpellType.Combat:
CastCombatSpell(spell, target);
break;
}
}
private void CastUtilitySpell(Spell spell, GameObject target)
{
switch (spell.utilityEffect)
{
case UtilityEffect.Light:
if (activeLight != null) Destroy(activeLight.gameObject);
GameObject lightGO = new GameObject($"{spell.spellName} Light");
lightGO.transform.SetParent(transform);
lightGO.transform.localPosition = Vector3.up * 1.5f;
activeLight = lightGO.AddComponent<Light>();
activeLight.intensity = 8;
activeLight.range = 10;
Destroy(lightGO, spell.duration);
break;
case UtilityEffect.Charm:
if (target != null && target.GetComponent<NPCInteraction>() != null)
{
Debug.Log($"You cast {spell.spellName} on {target.name}. They seem more agreeable.");
}
break;
}
}
private void CastCombatSpell(Spell spell, GameObject target)
{
if (BattleSystem.Instance.state != BattleSystem.BattleState.PLAYERTURN) return;
if (target != null)
{
var enemyStats = target.GetComponent<CharacterStats>();
if (enemyStats != null)
{
//int damage = Dice.Roll(spell.damageDice) + spell.baseDamage + playerStats.intelligence;
//enemyStats.TakeDamage(damage, spell.damageType);
}
}
}
}