private void Fire(int index) { SpellScript.Spell spell = spells[index]; if (spell != null) { float manaCost = -spell.ManaCost(); if (stats.ModifyMana(-10)) { lock (_lock) canFire = false; companion.didFire = true; StartCoroutine(FireCooldown()); // create spell instance Vector3 startPos = transform.position; startPos.y += 0.5f; // Put the spell a bit in front of us startPos += transform.forward * 0.75f; Vector3 rotEuler = transform.rotation.eulerAngles; rotEuler.x = 90f; GameObject spellObject = Instantiate(emptySpellPrefab, startPos, Quaternion.Euler(rotEuler)) as GameObject; // Add the spell effects SpellScript spellScript = spellObject.GetComponent <SpellScript>(); spellScript.spell = spell; spellScript.parent = gameObject; castSpells.Add(spellObject); } } }
// Start is called before the first frame update void Start() { // Init spells spellModifierAIScoreTracker = new SpellModifierAIScoreTracker(); spellModifierAIScoreTracker.agent = this; AIFirebolt = new SpellScript.Spell() { name = "Firebolt", shape = AllSpellsAndGlyphs.spellShapeBolt, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectFire, spellModifierAIScoreTracker } }; AIHealSelf = new SpellScript.Spell() { name = "Heal self", shape = AllSpellsAndGlyphs.spellShapeSelf, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectHeal, spellModifierAIScoreTracker } }; AIHealOther = new SpellScript.Spell() { name = "Heal other", shape = AllSpellsAndGlyphs.spellShapeBolt, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectHeal, spellModifierAIScoreTracker } }; AIFreeze = new SpellScript.Spell() { name = "Freeze", shape = AllSpellsAndGlyphs.spellShapeBolt, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectFreeze, spellModifierAIScoreTracker } }; AIStun = new SpellScript.Spell() { name = "Stun", shape = AllSpellsAndGlyphs.spellShapeBolt, components = new List <SpellComponent>() { AllSpellsAndGlyphs.spellEffectStun, spellModifierAIScoreTracker } }; spells = new SpellScript.Spell[2] { AIFirebolt, AIFreeze }; startPos = transform.localPosition; stats = GetComponent <StatScript>(); rb = GetComponent <Rigidbody>(); //AgentReset(); startFrame = Time.frameCount; stats.SubscribeToOnDeath(OnDeath); stats.SubscribeToOnHealthChange(OnHealthChange); for (int i = 0; i < enemies.Length; ++i) { GameObject enemy = enemies[i]; StatScript enemyStat = enemy.GetComponent <StatScript>(); EnemyAI enemyAI = enemy.GetComponent <EnemyAI>(); enemyStats[i] = enemyStat; enemyAIs[i] = enemyAI; enemyStat.SubscribeToOnDeath(OnEnemyDeath); enemyStat.SubscribeToOnHealthChange(OnEnemyHealthChange); } enemyFields[0] = Enemy1Fields; enemyFields[1] = Enemy2Fields; enemyFields[2] = Enemy3Fields; enemyFields[3] = Enemy4Fields; }
public void AddChildSpell(SpellScript.Spell spell) => childSpells.Add(spell);