public void SetSpell(int spellID) { if (!usedSpells.ContainsKey(spellID)) { GameObject spellPrefab = SpellManager.instance.createSpell(transform, spellID); SpellBehavior spell = spellPrefab.GetComponent <SpellBehavior>(); spellRack.Add(spell); usedSpells[spellID] = spell; spellStatus[spellID] = true; } else { if (!spellStatus[spellID]) { spellRack.Add(usedSpells[spellID]); spellStatus[spellID] = true; } } if (!hasSpell) { hasSpell = true; selected = spellRack[0]; OnSelection?.Invoke(selected); } }
public void SelectSpell(int index) { if (spellRack.Count > 0) { Debug.Log("scrolled"); int realIndex = (index + spellRack.Count) % spellRack.Count; selected = spellRack[realIndex]; OnSelection?.Invoke(selected); } }
void updateSpellIcon(SpellBehavior sb) { if (sb != null) { Debug.Log("Change Icon"); spellIcon.sprite = sb.spellStats.icon; } else { spellIcon.sprite = defaultIcon; } }
private void Initialize() { if (spellPrefabs.Length > 0) { foreach (GameObject go in spellPrefabs) { GameObject prefab = Instantiate(go, transform); SpellBehavior spell = prefab.GetComponent <SpellBehavior>(); spellRack.Add(spell); usedSpells[spell.spellStats.spellID] = spell; spellStatus[spell.spellStats.spellID] = true; } hasSpell = true; selected = spellRack[0]; OnSelection?.Invoke(selected); } }
public void bindSpellSlot(SpellController playerSpellController) { if (playerSC != null) { playerSC.OnSelection -= updateSpellIcon; } playerSC = playerSpellController; if (playerSC != null) { Debug.Log("Spell UI bind"); playerSC.OnSelection += updateSpellIcon; SpellBehavior selected = playerSC.GetCurrentSpell(); updateSpellIcon(selected); // get cooldown progress here } else { spellIcon.sprite = defaultIcon; } }
public void RemoveSpell(int id) { if (hasSpell) { if (spellStatus.ContainsKey(id) && spellStatus[id]) { spellRack.Remove(usedSpells[id]); spellStatus[id] = false; if (selected.spellStats.spellID == id) { selected = null; } } if (spellRack.Count < 1) { hasSpell = false; selected = null; } OnSelection?.Invoke(selected); } }
void CastSpell(GameObject spell) { SpellBehavior spellBehavior = spell.GetComponent <SpellBehavior>(); if (!spellBehavior.canBeCast) { return; } if (!RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition)) { RaycastHit hit = new RaycastHit(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 1000)) { spellBehavior.Cast(); GameObject prefab = spell.GetComponent <SpellBehavior>().prefab; Instantiate(prefab, hit.point, Quaternion.identity); } } }
public virtual void PerformSpell(ICharacter target) { SpellBehavior.Cast(this, target); }