/** * Tries to cast the spell with the given index. Checks cooldown and manacosts. * * @param index */ public void spellAttack(int index) { if (state == DynamicObjectState.Attacking) return; curAnim = idleAnim.get(heading); Vector2 spVelo = new Vector2(); Vector2 startPos = new Vector2(); if (heading == Heading.Right) { spVelo.x = spSpeed; startPos = new Vector2(collisionRect.x + collisionRect.width, collisionRect.y); } else if (heading == Heading.Left) { spVelo.x = -spSpeed; startPos = new Vector2(collisionRect.x - 32, collisionRect.y); } else if (heading == Heading.Up) { spVelo.y = -spSpeed; startPos = new Vector2(collisionRect.x, collisionRect.y - 32); } else { spVelo.y = spSpeed; startPos = new Vector2(collisionRect.x, collisionRect.y + (float) collisionRect.getHeight()); } Spell curSpell = spellManager.getSpell(index); if (!curSpell.isOnCooldown() && mana.getCurrentMana() >= curSpell.getManaCost()) { mana.reduceMana(curSpell.getManaCost()); manager.spawnSpell(curSpell.getProjectile(startPos, heading)); spellManager.activate(index); if (isInNetwork && controllerActive) { NetworkManager.sendSpellMessage(this, index); } } }