package net.wayward_realms.waywardskills.spell;

import net.wayward_realms.waywardlib.character.Character;
import net.wayward_realms.waywardlib.classes.Stat;
import net.wayward_realms.waywardlib.combat.Fight;
import net.wayward_realms.waywardlib.skills.AttackSpellBase;
import net.wayward_realms.waywardlib.skills.SkillType;
import net.wayward_realms.waywardlib.util.lineofsight.LineOfSightUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class ExplosiveSpellSpell extends AttackSpellBase {

    public ExplosiveSpellSpell() {
        setName("ExplosiveSpell");
        setType(SkillType.MAGIC_OFFENCE);
        setAttackStat(Stat.MAGIC_ATTACK);
        setDefenceStat(Stat.MAGIC_DEFENCE);
        setHitChance(100);
        setCriticalChance(20);
        setCriticalMultiplier(2D);
        setPower(120D);
        setManaCost(50);
        setCoolDown(300);
    }

    @Override
    public void animate(Fight fight, Character attacking, Character defending, ItemStack weapon) {
        Player defendingPlayer = defending.getPlayer().getPlayer();
        defendingPlayer.getWorld().createExplosion(defendingPlayer.getLocation(), 0F, false);
    }

    @Override
    public double getWeaponModifier(ItemStack weapon) {
        return getMagicWeaponModifier(weapon);
    }

    @Override
    public String getFightUseMessage(Character attacking, Character defending, double damage) {
        return (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " blew " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + " up with explosive magic, dealing " + damage + " damage.";
    }

    @Override
    public String getFightFailManaMessage(Character attacking, Character defending) {
        return (attacking.isNameHidden() ? ChatColor.MAGIC + attacking.getName() + ChatColor.RESET : attacking.getName()) + ChatColor.YELLOW + " attempted to blow " + (defending.isNameHidden() ? ChatColor.MAGIC + defending.getName() + ChatColor.RESET : defending.getName()) + ChatColor.YELLOW + " up, but did not have enough mana.";
    }

    @Override
    public boolean use(Player player) {
        Block targetBlock = LineOfSightUtils.getTargetBlock(player, null, 64);
        targetBlock.getWorld().createExplosion(targetBlock.getLocation(), 8F, true);
        return true;
    }

    @Override
    public ItemStack getIcon() {
        ItemStack icon = new ItemStack(Material.TNT);
        ItemMeta meta = icon.getItemMeta();
        meta.setDisplayName("Explosive Spell");
        icon.setItemMeta(meta);
        return icon;
    }

    @Override
    public boolean canUse(Character character) {
        return character.getSkillPoints(SkillType.MAGIC_OFFENCE) >= 24;
    }
}

@@ -437,24 +437,24 @@
 .bukkit.
-Material
+Location
 ;%0Aimport
@@ -469,19 +469,16 @@
 kit.
-block.Block
+Material
 ;%0Aim
@@ -2395,25 +2395,23 @@
     
-Block
+Location
  target
-Block
  = L
@@ -2462,82 +2462,175 @@
  64)
-;%0A        targetBlock.getWorld().createExplosion(targetBlock.getLocation()
+.getLocation();%0A        double x = target.getX();%0A        double y = target.getY();%0A        double z = target.getZ();%0A        target.getWorld().createExplosion(x, y, z
 , 8F
@@ -2635,16 +2635,23 @@
 8F, true
+, false
 );%0A     

Remove block damage for explosive spell, closes #242