import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;

/**
 * Write a description of class Bottle here.
 * 
 * @author Jonathan Lutz
 * @version (a version number or a date)
 */
public class Bomb extends Weapon
{
    private static int sizex = 50;
    private static int sizey = 50;
    
    private boolean alreadypicked = false;
    private long alreadypickedmillis = 0;
    private int count = 0;
    public static boolean available;
    private long bPressed;
    public static int amount = 0;

    private boolean set = false;
    private long timer = 0;
    private long exploded = 0;
    private boolean alreadyexploded = false;

    private List<Monster> damagedobjects;

    protected String[] explosionspics = {"Skins/Explosion/explosion 1.png", "Skins/Explosion/explosion 2.png", "Skins/Explosion/explosion 3.png", "Skins/Explosion/explosion 4.png", "Skins/Explosion/explosion 5.png", "Skins/Explosion/explosion 6.png"};

    Linch linch;

    public Bomb()
    {
        GreenfootImage img = new GreenfootImage("Skins/Waffe/bomb.png");
        img.scale(sizex, sizey);
        setImage(img);
        amount = 0;
    }

    /**
     * Act - do whatever the Bottle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        //System.out.println("sersssssss");
       // System.out.println(amount);
        if (Welt.pause != true)
        {
            if (available && amount > 0)
            {
                if (Greenfoot.isKeyDown("b") && set != true)
                {
                    setLocation(linch.Xcoord,linch.Ycoord);
                    set = true;
                    timer = System.currentTimeMillis();
                    amount--;
                }
                if (!Greenfoot.isKeyDown("b") && set == true && System.currentTimeMillis()-timer > 2000)
                {
                    damagedobjects = getObjectsInRange(100,Monster.class);
                    
                    //setLocation(-100,-100);

                    for(Monster monster: damagedobjects){
                        monster.livedown();
                    }
                    if (alreadyexploded != true)
                    {
                        exploded = System.currentTimeMillis();
                    }
                    move(explosionspics,true, 30,30);
                    alreadyexploded = true;
                }
                if (System.currentTimeMillis()-exploded>1000 && set == true && alreadyexploded == true)
                {
                    
                    setImage("Skins/Waffe/bomb.png");
                    setLocation(-100,-100);
                    
                    set = false;
                    alreadyexploded = false;
                }
            }
            else
            {
            
            }
        }
    }    

    public void giveLinch(Linch linchget)
    {
        linch = linchget;
    }

    public void bottlecheck(Bottlecheck bottlecheck)
    {

    }

}
