public void CastSpell() { if (cardId.ToString() == "rockthrow") { if (playField.player1Turn) { foreach (Transform hero in playField.player2.transform) { //If there is an enemy in the square I clicked on then do spell damage to them (spell damage is applied through 'EndOfSpellEffects' method which is part of Spell.cs and is attached to //the 'Rock' object nested under the 'RockThrowParticle' object) if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { spellParticle.GetComponentInChildren <Spell>().hero = hero; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, player1.transform); SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { foreach (Transform hero in playField.player1.transform) { //If there is an enemy in the square I clicked on then do spell damage to them (spell damage is applied through 'EndOfSpellEffects' method which is part of Spell.cs and is attached to //the 'Rock' object nested under the 'RockThrowParticle' object) if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { spellParticle.GetComponentInChildren <Spell>().hero = hero; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, player2.transform); SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { Transform hero; hero = playField.TargetSpellCheckEntireBoardOneRandomHero("enemy")[0]; spellParticle.GetComponentInChildren <Spell>().hero = hero; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity); SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "fireball") { Debug.Log("FIREBALL MARKER # 1"); if (playField.player1Turn) { Debug.Log("FIREBALL MARKER # 2"); foreach (Transform hero in playField.player2.transform) { //If there is an enemy in the square I clicked on then do spell damage to them (spell damage is applied through 'EndOfSpellEffects' method which is part of Spell.cs and is attached to //the 'Fireball' object nested under the 'FireballParticle' object) if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { spellParticle.GetComponentInChildren <Spell>().hero = hero; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, player1.transform); SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { Debug.Log("FIREBALL MARKER # 3"); foreach (Transform hero in playField.player1.transform) { //If there is an enemy in the square I clicked on then do spell damage to them (spell damage is applied through 'EndOfSpellEffects' method which is part of Spell.cs and is attached to //the 'Fireball' object nested under the 'FireballParticle' object) if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { spellParticle.GetComponentInChildren <Spell>().hero = hero; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, player2.transform); SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { Debug.Log("FIREBALL MARKER # 4"); Transform hero; hero = playField.TargetSpellCheckEntireBoardOneRandomHero("enemy")[0]; //Debug.Log("The hero I've found is: " + hero.GetComponent<Hero>().name); spellParticle.GetComponentInChildren <Spell>().hero = hero; //Debug.Log("spellParticle is: " + spellParticle.name); Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity); SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "flamestrike") { if (playField.player1Turn) { foreach (Transform hero in playField.player2.transform) { //If there are any enemies in the COLUMN that I clicked on then do spell damage to all of them (spell damage is applied through 'EndOfSpellEffects' method) if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x) { Debug.Log("FOUND A HERO"); spellParticle.GetComponentInChildren <Spell>().hero = hero; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, player1.transform); } } SpellCleanup(); } else if (!playField.player1Turn) { foreach (Transform hero in playField.player1.transform) { //If there are any enemies in the COLUMN that I clicked on then do spell damage to all of them (spell damage is applied through 'EndOfSpellEffects' method) if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x) { Debug.Log("FOUND A HERO"); spellParticle.GetComponentInChildren <Spell>().hero = hero; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, player2.transform); } } SpellCleanup(); } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "heal") { if (playField.player1Turn) { foreach (Transform hero in playField.player1.transform) { //If one of my heroes is in the square I clicked on AND they are below max health AND they are not a 'Ghost' then heal them for the proper amount if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y && hero.GetComponent <Hero>().currentHealth < hero.GetComponent <Hero>().maxHealth && hero.GetComponent <Hero>().id != "ghost") { //Instantiate(spellParticle,hero.transform.localPosition, Quaternion.identity); hero.GetComponent <Hero>().HealPartial(2); SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { foreach (Transform hero in playField.player2.transform) { //If one of my heroes is in the square I clicked on AND they are below max health AND they are not a 'Ghost' then heal them for the proper amount if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y && hero.GetComponent <Hero>().currentHealth < hero.GetComponent <Hero>().maxHealth && hero.GetComponent <Hero>().id != "ghost") { //Instantiate(spellParticle,hero.transform.localPosition, Quaternion.identity); hero.GetComponent <Hero>().HealPartial(2); SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { //Heal a random ally List <Transform> allies = playField.TargetSpellCheckEntireBoardOneRandomHero("ally", "heal"); if (allies.Count() > 0) { Transform allyToHeal = allies[0]; allyToHeal.GetComponent <Hero>().HealPartial(2); } SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "haste") { if (playField.player1Turn) { foreach (Transform hero in playField.player1.transform) { //If one of my heroes is in the square I clicked on set 'movingRight' variable in Hero.cs to true if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().usingHaste = true; playField.Player1MoveHasteCheck(hero); SpellCleanup(); return; } } } else if (!playField.player1Turn) { foreach (Transform hero in playField.player2.transform) { //If one of my heroes is in the square I clicked on set 'movingLeft' variable in Hero.cs to true if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().usingHaste = true; playField.Player2MoveHasteCheck(hero); SpellCleanup(); return; } } } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "might") { if (playField.player1Turn) { foreach (Transform hero in playField.player1.transform) { //If one of my heroes is in the square I clicked on then give them the 'Might' buff for the appropriate duration if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("might", hero); SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { foreach (Transform hero in playField.player2.transform) { //If one of my heroes is in the square I clicked on then give them the 'Might' buff for the appropriate duration if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("might", hero); SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { Transform hero; hero = playField.TargetSpellCheckEntireBoardOneRandomHero("ally", "might")[0]; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("might", hero); SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "shroud") { if (playField.player1Turn) { foreach (Transform hero in playField.player1.transform) { //If one of my heroes is in the square I clicked on then give them the 'Shroud' buff for the appropriate duration if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("shroud", hero); SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { foreach (Transform hero in playField.player2.transform) { //If one of my heroes is in the square I clicked on then give them the 'Shroud' buff for the appropriate duration if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("shroud", hero); SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { Transform hero; hero = playField.TargetSpellCheckEntireBoardOneRandomHero("ally", "shroud")[0]; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("shroud", hero); SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "armor") { if (playField.player1Turn) { foreach (Transform hero in playField.player1.transform) { //If one of my heroes is in the square I clicked on AND they are not a 'Ghost' then add to their armor value by the appropriate amount if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y && hero.GetComponent <Hero>().id != "ghost") { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().AddArmor(1); SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { foreach (Transform hero in playField.player2.transform) { //If one of my heroes is in the square I clicked on AND they are not a 'Ghost' then add to their armor value by the appropriate amount if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y && hero.GetComponent <Hero>().id != "ghost") { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().AddArmor(1); SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { Transform hero; hero = playField.TargetSpellCheckEntireBoardOneRandomHero("ally", "armor")[0]; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().AddArmor(1); SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "blessing") { if (playField.player1Turn) { foreach (Transform hero in playField.player1.transform) { //If one of my heroes is in the square I clicked on AND they are not a 'Ghost' then add to their armor value by the appropriate amount if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y && hero.GetComponent <Hero>().id != "ghost") { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().HealFull(); hero.GetComponent <Hero>().AddArmor(3); SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { foreach (Transform hero in playField.player2.transform) { //If one of my heroes is in the square I clicked on AND they are not a 'Ghost' then add to their armor value by the appropriate amount if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y && hero.GetComponent <Hero>().id != "ghost") { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().HealFull(); hero.GetComponent <Hero>().AddArmor(3); SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { Transform hero; hero = playField.TargetSpellCheckEntireBoardOneRandomHero("ally", "blessing")[0]; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().HealFull(); hero.GetComponent <Hero>().AddArmor(3); SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "root") { if (playField.player1Turn) { foreach (Transform hero in playField.player2.transform) { //If there is an enemy in the square I clicked on then cast the 'Root' debuff on them if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("root", hero); //DoSpellDamage(hero,spellDamage); SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { foreach (Transform hero in playField.player1.transform) { //If there is an enemy in the square I clicked on then cast the 'Root' debuff on them if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("root", hero); //DoSpellDamage(hero,spellDamage); SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { Transform hero; hero = playField.TargetSpellCheckEntireBoardOneRandomHero("enemy", "root")[0]; Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); buffManager.ApplyBuff("root", hero); //DoSpellDamage(hero,spellDamage); SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "windgust") { float maxDistToMove = 3f; float currentDistToMove; if (playField.player1Turn) { foreach (Transform hero in playField.player2.transform) { //If there is an enemy in the square I clicked on then do attempt to cast this spell on them if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { if (playField.FindClosestHeroToTheRight(hero) == 1 || hero.transform.position.x == playField.player2HomeColumn) { Debug.LogWarning("Cannot move hero b/c there is no space behind them"); return; } //If there are NOT any heroes in the way of my maxDistToMove then move that max distance, else move as far as I can if (playField.FindClosestHeroToTheRight(hero) > maxDistToMove) { currentDistToMove = maxDistToMove + 1; //If the currentDistToMove would place me beyond the player2HomeColumn then adjust the value so it only takes me as far as the player2HomeColumn if (currentDistToMove + hero.transform.position.x > playField.player2HomeColumn) { currentDistToMove = playField.player2HomeColumn - hero.transform.position.x + 1; } } else { currentDistToMove = playField.FindClosestHeroToTheRight(hero); } Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().MoveSingleHeroRight(currentDistToMove - 1); SpellCleanup(); return; } } } else if (!playField.player1Turn) { foreach (Transform hero in playField.player1.transform) { //If there is an enemy in the square I clicked on then do attempt to cast this spell on them if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { if (playField.FindClosestHeroToTheLeft(hero) == 1 || hero.transform.position.x == playField.player1HomeColumn) { Debug.LogWarning("Cannot move hero b/c there is no space behind them"); return; } //If there are NOT any heroes in the way of my maxDistToMove then move that max distance, else move as far as I can if (playField.FindClosestHeroToTheLeft(hero) > maxDistToMove) { currentDistToMove = maxDistToMove + 1; //If the currentDistToMove would place me beyond the player2HomeColumn then adjust the value so it only takes me as far as the player2HomeColumn if (hero.transform.position.x - currentDistToMove < playField.player1HomeColumn) { currentDistToMove = hero.transform.position.x - playField.player1HomeColumn + 1; } } else { currentDistToMove = playField.FindClosestHeroToTheLeft(hero); } Instantiate(spellParticle, hero.transform.localPosition, Quaternion.identity, hero.transform); hero.GetComponent <Hero>().MoveSingleHeroLeft(currentDistToMove - 1); SpellCleanup(); return; } } } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } else if (cardId.ToString() == "drainlife") { if (playField.player1Turn) { foreach (Transform hero in playField.player2.transform) { //Logic for player 1 selecting an enemy hero if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { //TODO Replace with a new unique particle when we have one for this Spell ParticleSystem hitParticle = hero.GetComponent <Hero>().hitParticle; Instantiate(hitParticle, hero.transform.position, Quaternion.identity); //Do the damage to the enemy PlayField.instance.DamageHero(hero.GetComponent <Hero>(), 1); //Heal a random ally List <Transform> allies = playField.TargetSpellCheckEntireBoardOneRandomHero("ally", "heal"); if (allies.Count() > 0) { Transform allyToHeal = allies[0]; allyToHeal.GetComponent <Hero>().HealPartial(1); } SpellCleanup(); return; } } } else if (!playField.player1Turn && !GlobalObject.aiEnabled) { foreach (Transform hero in playField.player1.transform) { //Logic for player 2 selecting an enemy hero if (Mathf.RoundToInt(hero.transform.position.x) == playField.roundedPos.x && Mathf.RoundToInt(hero.transform.position.y) == playField.roundedPos.y) { //TODO Replace with a new unique particle when we have one for this Spell ParticleSystem hitParticle = hero.GetComponent <Hero>().hitParticle; Instantiate(hitParticle, hero.transform.position, Quaternion.identity); //Do the damage to the enemy PlayField.instance.DamageHero(hero.GetComponent <Hero>(), 1); //Heal a random ally List <Transform> allies = playField.TargetSpellCheckEntireBoardOneRandomHero("ally", "heal"); if (allies.Count() > 0) { Transform allyToHeal = allies[0]; allyToHeal.GetComponent <Hero>().HealPartial(1); } SpellCleanup(); return; } } } else if (!playField.player1Turn && GlobalObject.aiEnabled) { //Logic for the AI selecting an enemy hero //Find a player soldier to attack Transform heroToAttack; heroToAttack = playField.TargetSpellCheckEntireBoardOneRandomHero("enemy")[0]; //TODO Replace with a new unique particle when we have one for this Spell ParticleSystem hitParticle = heroToAttack.GetComponent <Hero>().hitParticle; Instantiate(hitParticle, heroToAttack.transform.position, Quaternion.identity); //Do the damage to the enemy PlayField.instance.DamageHero(heroToAttack.GetComponent <Hero>(), 1); //Heal a random ally List <Transform> allies = playField.TargetSpellCheckEntireBoardOneRandomHero("ally", "heal"); if (allies.Count() > 0) { Transform allyToHeal = allies[0]; allyToHeal.GetComponent <Hero>().HealPartial(1); } SpellCleanup(); return; } Debug.LogWarning("NOT A VALID TARGET FOR SPELL"); } }