// TODO : Add checks for reload // function casting a spell public void CastSpell(string spellName) { if (_activeCheckDatabase[spellName] && _mana.CurrentValue >= _abilitiesDatabase[spellName]._cost && !_reloadingCheckDatabase[spellName]) { GameObject ability = null; switch (spellName) { case "Firebolt": float dist = Vector3.Distance(_currentTarget.position, transform.position); if (dist < _attackDistance) { // TODO: Implement root check if (_isRooted && _currentTarget.GetComponentInParent <Tangler>() == null) // dont fire scenario { } else if ((_isRooted && _currentTarget.GetComponentInParent <Tangler>() && !_currentTarget.GetComponentInParent <Tangler>().IsBunny) || !_isRooted) // fire scenario { ability = (GameObject)Instantiate(_abilitiesDatabase[spellName]._prefab, transform.position, Quaternion.identity); if (ability != null) { UseMana(_abilitiesDatabase[spellName]._cost); FireboltController fireboltController = ability.GetComponent <FireboltController>(); fireboltController._target = _currentTarget; fireboltController.Damage = _abilitiesDatabase[spellName]._damage; ActionBarUIController.Instance.ReloadAbility(0, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(SpellWaitCoroutine(_abilitiesDatabase[spellName]._reloadTime, spellName)); _fireboltSFX.PlaySfx(); } } } break; case "Invisibility": GameObject[] targetField = GameObject.FindGameObjectsWithTag("EnemyTargetField"); List <EnemyController> targetControllersList = new List <EnemyController>(); if (targetField.Length != 0) { foreach (GameObject target in targetField) { targetControllersList.Add(target.GetComponent <EnemyController>()); } if (targetControllersList.Count != 0) { GetComponent <SpriteRenderer>().color = Color.blue; foreach (EnemyController controller in targetControllersList) { controller.TogglePlayerInvisibility(); } UseMana(_abilitiesDatabase[spellName]._cost); ActionBarUIController.Instance.ReloadAbility(2, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(InvisibleCoroutine(_abilitiesDatabase[spellName]._damage, _abilitiesDatabase[spellName]._reloadTime, spellName, targetControllersList)); _invisibilitySFX.PlaySfx(); } } else { GetComponent <SpriteRenderer>().color = Color.blue; UseMana(_abilitiesDatabase[spellName]._cost); ActionBarUIController.Instance.ReloadAbility(2, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(InvisibleCoroutine(_abilitiesDatabase[spellName]._damage, _abilitiesDatabase[spellName]._reloadTime, spellName, null)); _invisibilitySFX.PlaySfx(); } break; case "Haste": UseMana(_abilitiesDatabase[spellName]._cost); _speed *= 2; ActionBarUIController.Instance.ReloadAbility(1, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(HasteCoroutine(_abilitiesDatabase[spellName]._damage, _abilitiesDatabase[spellName]._reloadTime, spellName)); _hasteSFX.PlaySfx(); break; case "ProtectiveBubble": UseMana(_abilitiesDatabase[spellName]._cost); GetComponent <SpriteRenderer>().color = Color.yellow; _health.ActivateShield(); ActionBarUIController.Instance.ReloadAbility(3, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(ShieldRoutine(_abilitiesDatabase[spellName]._damage, _abilitiesDatabase[spellName]._reloadTime, spellName)); _bubbleSFX.PlaySfx(); break; case "RemoveRoots": if (_currentTarget != null && _currentTarget.tag == "Roots") { float distance = Vector3.Distance(_currentTarget.position, transform.position); if (distance <= _attackDistance) { Tangler targetTangler = _currentTarget.gameObject.GetComponentInParent <Tangler>(); if (targetTangler.IsBunny && _isRooted) { } else { UseMana(_abilitiesDatabase[spellName]._cost); targetTangler.DestroyRoot(); RemoveTarget(); ActionBarUIController.Instance.ReloadAbility(4, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(SpellWaitCoroutine(_abilitiesDatabase[spellName]._reloadTime, spellName)); _rootsSFX.PlaySfx(); } } } break; case "WaterFreeze": UseMana(_abilitiesDatabase[spellName]._cost); TransformReference reference = _currentTarget.GetComponentInChildren <TransformReference>(); reference.TransformedObject.SetActive(true); _currentTarget.gameObject.SetActive(false); ActionBarUIController.Instance.ReloadAbility(5, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(SpellWaitCoroutine(_abilitiesDatabase[spellName]._reloadTime, spellName)); _freezeSFX.PlaySfx(); ActionBarUIController.Instance.HideFreezeFlash(); GoodItem tempItem = FindObjectOfType <GoodItem>(); if (tempItem != null) { ActionBarUIController.Instance.ActivateFireboltFlash(); ActionBarUIController.Instance.ActivateCharmFlash(); } break; case "Charm": if (_currentTarget != null && _currentTarget.tag == "CharmableEnemy" && _currentTarget.GetComponent <Stats>().CurrentValue > 0) { float distance = Vector3.Distance(_currentTarget.position, transform.position); if (distance < _attackDistance) { UseMana(_abilitiesDatabase[spellName]._cost); _currentTarget.gameObject.GetComponent <SpriteRenderer>().color = Color.red; //_currentTarget.tag = "Untagged"; _currentTarget.gameObject.layer = 1; ActionBarUIController.Instance.ReloadAbility(6, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(CharmRoutine(_abilitiesDatabase[spellName]._damage, _abilitiesDatabase[spellName]._reloadTime, spellName, _currentTarget.gameObject)); _charmSFX.PlaySfx(); RemoveTarget(); // perform logic for charm scene GoodItem item = FindObjectOfType <GoodItem>(); Debug.Log(item); if (item != null) { item.ActivateObject(); ActionBarUIController.Instance.HideCharmFlash(); ActionBarUIController.Instance.HideFireboltFlash(); } } } break; case "Heal": if (_currentTarget != null && _currentTarget.tag == "HealableEnemy" && (_currentTarget.gameObject.GetComponent <Stats>().CurrentValue != _currentTarget.gameObject.GetComponent <Stats>().MaxValue) && (_currentTarget.gameObject.GetComponent <Stats>().CurrentValue != 0) && (!_currentTarget.gameObject.GetComponent <Stats>().OneHealthTrigger)) { float distanceHeal = Vector3.Distance(_currentTarget.position, transform.position); if (distanceHeal <= _attackDistance) { UseMana(_abilitiesDatabase[spellName]._cost); _currentTarget.gameObject.GetComponent <Stats>().AddValue(_abilitiesDatabase[spellName]._damage); ActionBarUIController.Instance.ReloadAbility(7, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(SpellWaitCoroutine(_abilitiesDatabase[spellName]._reloadTime, spellName)); _healSFX.PlaySfx(); } } else if (_currentTarget == null && (_health.CurrentValue != _health.MaxValue) && _health.CurrentValue != 0) { UseMana(_abilitiesDatabase[spellName]._cost); _health.AddValue(_abilitiesDatabase[spellName]._damage); ActionBarUIController.Instance.ReloadAbility(7, _abilitiesDatabase[spellName]._reloadTime); StartCoroutine(SpellWaitCoroutine(_abilitiesDatabase[spellName]._reloadTime, spellName)); _healSFX.PlaySfx(); } break; default: break; } } else { if (!_activeCheckDatabase[spellName]) { } } }