private void Awake() { unlockedSpells = new spells[3]; if (PlayerPrefs.HasKey("unlockedSpells")) { string spellArray = PlayerPrefs.GetString("unlockedSpells"); if (spellArray[0] == '1') { unlockedSpells[0] = spells.Fire; unlockedSpellCount += 1; equipedSpell = unlockedSpells[0]; } if (spellArray[1] == '1') { unlockedSpells[1] = spells.Ice; unlockedSpellCount += 1; equipedSpell = unlockedSpells[1]; } if (spellArray[2] == '1') { unlockedSpells[2] = spells.Air; unlockedSpellCount += 1; equipedSpell = unlockedSpells[2]; } } else { equipedSpell = spells.None; } }
void cast(spells sp, GameObject target) { Robot_behavior_base commands = target.GetComponent <Robot_behavior_base>(); switch (sp) { case spells.Freeze: break; case spells.MoveLeft: commands.StopAllCoroutines(); commands.StartCoroutine("moveLeft", 5); break; case spells.MoveRight: commands.StopAllCoroutines(); commands.StartCoroutine("moveRight", 5); break; } StartCoroutine(castingFor(castingAnimationTime)); if (debug) { Debug.Log("Cast " + sp + " on " + target); } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("Book")) // Si coge libro, pocion o corazon, desaparece { animator.SetBool("isFrontSide", true); player.GetComponent <PlayerController>().enableMoving = false; other.gameObject.transform.position = new Vector2(player.transform.position.x, player.transform.position.y + 1); int spellId = other.gameObject.GetComponent <BookController>().id; if (PlayerPrefs.HasKey("unlockedSpells")) { string unlockedSpells = PlayerPrefs.GetString("unlockedSpells"); char[] spellArray = unlockedSpells.ToCharArray(); spellArray[spellId] = '1'; unlockedSpells = new string(spellArray); PlayerPrefs.SetString("unlockedSpells", unlockedSpells); } else { char[] spells = { '0', '0', '0' }; spells[spellId] = '1'; string unlockedSpells = new string(spells); PlayerPrefs.SetString("unlockedSpells", unlockedSpells); } if (spellId == 0) { unlockedSpells[0] = spells.Fire; } else if (spellId == 1) { unlockedSpells[1] = spells.Ice; } else if (spellId == 2) { unlockedSpells[2] = spells.Air; } equipedSpell = unlockedSpells[spellId]; unlockedSpellCount += 1; //StartCoroutine(showObject(1, other.gameObject)); } }
void scrollSpell(int amount) { int final = (int)spell + amount; if (final >= (int)spells.max - 1) { final = 0; } else if (final < 0) { final = (int)spells.max - 1; } spell = (spells)final; if (debug) { Debug.Log("Changed to spell " + spell); } }
IEnumerator seterror; //Sets error state to false after t_error time. #endregion void Awake() { spellarray[0] = new spells("FireBall", 1.5f, (int)enum_casting.StraightMagicShot, fireballanim, CastLocationFireBall, 100f, 0.6f, 0f, 0f, true); spellarray[1] = new spells("FrostBolt", 1.0f, (int)enum_casting.CastSpell, frostboltanim, CastLocationFrostBolt, 10f, 0.2f, 0f, 0f, true); spellarray[2] = new spells("PermaFrost", 2.0f, (int)enum_casting.CastSpell, PermaFrostGameObject, CastLocationPermaFrost, 10f, 0f, 8f, 0f, true); aoespellarray[0] = new AoEspell(10f, 30f, 15f); castkeys = new string[3] { "q", "e", "r" }; //Cast Keys spellerrors = new string[4] { "You Must Face The Target!", "No Target!", "Currently Casting", "Spell is On CoolDown!" }; t_error = 0.5f;//Display error for 0.5 sec //Cast bar Initializers castbarp_y = 1.5f;//Distance the cast bar is placed from the middle(pos) castbarp_x = 0.75f; castbarsize = new Vector2(160, 16); castbarpos = new Vector2(Screen.width / 2, Screen.height / 2); //Error Initializer }
IEnumerator targettedspell(int spellname) {//Spell Coroutine which generates a spell provided with a cast time, cast anim, and object which is defined via the caller. //this.GetComponent<GameObject> b_casting = true; this.GetComponent <Animator>().speed = 0.5f;//This speed works well for all spells. spells c_spell = spellarray[spellname]; //Current spell struct which contains the information regarding the spell float casttime = c_spell.casttime * (1f - this.GetComponent <Properties>().haste / GeneralProperties.hastecap); //Cast time * fraction(of haste cap the player has achieved) float dmg = c_spell.b_damage + (GetComponent <Properties>().AP *c_spell.APratio); //Base Damage of spell + Ability Power * AP ratio GameObject castobject = c_spell.spell; //Cast Object of Spell this.GetComponent <Player_controller>().mainsubmachinestate = (int)mainsubmachinstates.Casting; //Change Main SubState to Casting. this.GetComponent <Player_controller>().currentCastinganim = c_spell.castanim; //Set the currentcasting anim to spell casting animation. Transform castlocation = c_spell.s_location; //The Location where the Spell will be instantiated. spell_casting = spellname; //Update current spell being casted. s_starttime = Time.time; //Start timer of current spell yield return(new WaitForSeconds(casttime)); //Wait for cast time to completed StartCoroutine(CoolDown(spell_casting)); //Start cooldown coroutine and pass it the current spell being casted. b_casting = false; this.GetComponent <Animator>().speed = 1f;//Set Speed back to 1 if (Target != null) {//Ensure that spell doesnt get instantiated if target is dead. GameObject spell = Instantiate(castobject, castlocation.position, this.transform.rotation) as GameObject; //Cast a fire ball and keep a variable of its gameobject. spell.GetComponent <Targetedspell>().target = Target; //Set the target of our spell to current target. spell.GetComponent <Targetedspell>().damage = dmg; //Damage of Spell spell.GetComponent <Targetedspell>().castedby = this.gameObject; //The Game Object which casted the spell; spell.GetComponent <Targetedspell>().c_spell = spellname; //Notify Target spell of the current spell being casted } }
public IEnumerator castPermaFrost() { spells c_spells = spellarray[(int)enum_spell.PermaFrost];//General Spell Values of permafrost. b_casting = true; this.GetComponent <Animator>().speed = 0.5f; //This speed works well for all spells. spell_casting = (int)enum_spell.PermaFrost; //Update current spell being cast. this.GetComponent <Player_controller>().mainsubmachinestate = (int)mainsubmachinstates.Casting; this.GetComponent <Player_controller>().currentCastinganim = (int)enum_casting.PermaFrost; AoEspell c_spell = aoespellarray[(int)enum_AoESpells.PermaFrost]; //AoE specific values GameObject castobject = c_spells.spell; //Game Object to cast. float dmg = c_spells.b_damage; float radius = c_spell.radius; float speed = c_spell.speed; Transform origin = c_spells.s_location; float casttime = c_spells.casttime; s_starttime = Time.time;//Log the spell start time yield return(new WaitForSeconds(casttime * (1f - this.GetComponent <Properties>().haste / GeneralProperties.hastecap))); this.GetComponent <Animator>().speed = 1f; //Set Speed Back to one StartCoroutine(CoolDown(spell_casting)); //Start cooldown coroutine and pass it the current spell being casted. GameObject spell = Instantiate(castobject, origin.position, this.transform.rotation) as GameObject; spell.GetComponent <PermaFrost>().castedby = this.gameObject; spell.GetComponent <PermaFrost>().radius = radius; //Max Radius of spell spell.GetComponent <PermaFrost>().damage = dmg; //Base Damage of Spell spell.GetComponent <PermaFrost>().speed = speed; //Speed of Expantion. b_casting = false; //Done Casting }
// Update is called once per frame void Update() { if (!PauseMenu.IsPaused) { if (Input.GetButton("Fire1") && Time.time >= nextBasicAttackTime && player.GetComponent <PlayerController>().enableMoving) { nextBasicAttackTime = Time.time + basicAttackCoolDown; animator.SetTrigger(Attack); sfx.PlayChawaAttack(transform.position); } if (Input.GetButton("Fire2") && player.GetComponent <PlayerController>().enableMoving) { if (equipedSpell == spells.Fire && Time.time >= nextFireballTime) { //Starts cooldown animation in HUD _spellCooldownController.triggerSpell("fire"); nextFireballTime = Time.time + fireballCoolDown; var position = attackPos.position; GameObject spell = Instantiate(fireball, new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x), position.y), Quaternion.identity); sfx.PlayFireBallSFX(position); PlayerFireBall spellController = spell.GetComponent <PlayerFireBall>(); spellController.enemy = "Enemy"; Vector3 spellScale = spell.transform.localScale; spell.transform.localScale = new Vector3(spellScale.x * Mathf.Sign(gameObject.transform.localScale.x), spellScale.y, spellScale.z); //Instantiate(fireball, attackPos.transform); } if (equipedSpell == spells.Ice && Time.time >= nextIceTime) { //Starts cooldown animation in HUD _spellCooldownController.triggerSpell("ice"); nextIceTime = Time.time + iceCoolDown; var position = transform.position; GameObject spell = Instantiate(ice, new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x), position.y), Quaternion.identity); PlayerIce spell1Controller = spell.GetComponent <PlayerIce>(); spell1Controller.enemy = "Enemy"; GameObject spell2 = Instantiate(ice, new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x), position.y), Quaternion.identity); PlayerIce spell2Controller = spell2.GetComponent <PlayerIce>(); spell2Controller.enemy = "Enemy"; GameObject spell3 = Instantiate(ice, new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x), position.y), Quaternion.identity); PlayerIce spell3Controller = spell3.GetComponent <PlayerIce>(); spell3Controller.enemy = "Enemy"; sfx.PlayIceSFX(position); if (Mathf.Sign(transform.localScale.x) > 0) { spell2.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, iceAngle); spell3.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, 360 - iceAngle); } else { spell.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, 180); spell2.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, 180 + iceAngle); spell3.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, 180 - iceAngle); } Vector3 spellScale = spell.transform.localScale; spell.transform.localScale = new Vector3(spellScale.x * Mathf.Sign(gameObject.transform.localScale.x), spellScale.y, spellScale.z); } if (equipedSpell == spells.Air && Time.time >= nextDashTime) { //Starts cooldown animation in HUD _spellCooldownController.triggerSpell("air"); nextDashTime = Time.time + dashCoolDown; animator.SetBool("isDashing", true); sfx.PlayAirDashSFX(transform.position); } } if (Input.GetButton("ChangeRight") && Time.time > nextSpellChange) { if (unlockedSpellCount > 1) { nextSpellChange = Time.time + spellChangeCoolDown; int index = Array.IndexOf(unlockedSpells, equipedSpell); index = (index + 1) % unlockedSpellCount; equipedSpell = unlockedSpells[index]; } } if (Input.GetButton("ChangeLeft") && Time.time > nextSpellChange) { if (unlockedSpellCount > 1) { nextSpellChange = Time.time + spellChangeCoolDown; int index = Array.IndexOf(unlockedSpells, equipedSpell); index = (index - 1) % unlockedSpellCount; if (index == -1) { index = unlockedSpellCount - 1; } equipedSpell = unlockedSpells[index]; } } if (animator.GetCurrentAnimatorStateInfo(0).IsName("Attack")) { Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemy); for (int i = 0; i < enemiesToDamage.Length; ++i) { //enemiesToDamage[i].GetComponent<EnemyController>().takeDamage(damage); if (enemiesToDamage[i].GetComponent <EnemyController>().enemyName.CompareTo("Aabbeell") == 0) { enemiesToDamage[i].GetComponent <EnemyController>().takeDamage(damage, damage /*Basic*/); } else { enemiesToDamage[i].GetComponent <EnemyController>().takeDamage(damage); } } } } }