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(); activeLight.intensity = 8; activeLight.range = 10; Destroy(lightGO, spell.duration); break; case UtilityEffect.Charm: if (target != null && target.GetComponent() != 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(); if (enemyStats != null) { //int damage = Dice.Roll(spell.damageDice) + spell.baseDamage + playerStats.intelligence; //enemyStats.TakeDamage(damage, spell.damageType); } } } }