package de.heatup.objects;

import java.util.ArrayList;

import de.heatup.cfg.Config;
import de.heatup.ui.Main;
import de.heatup.ui.PanelBuilder;
import de.heatup.ui.StatusPanelAdder;
import de.heatup.ui.statusPanel.Score;

public class PowerUpController {
	private static ArrayList<Player> objects;
	private static int availablePUs = 3;
	
	public static int getAvailablePUs() {
		return availablePUs;
	}
	/*
	 * isPlayer true -> PowerUp wird für spieler verwendet
	 * 
	 */
	public static void activate(int powerup, boolean isPlayer) {
		setInstancedObjects();
		if (isPlayer) {
			
			if ( powerup == 1 ) {
				objects.get(0).setSpeedMultiplicatorAbsolute(4);
			}
			
			if ( powerup == 0 ) {
				for (int i=1; i<objects.size(); i++) {
					objects.get(i).setSpeedMultiplicatorAbsolute(0);
				}
			}
			
			if ( powerup == 2 ) {
				Score.raiseScore(100);
			}
			
		} else {
			
			if ( powerup == 1 ) {
				for (int i=1; i<objects.size(); i++) {
					objects.get(i).setSpeedMultiplicatorAbsolute(4);
				}
			}
			
			if ( powerup == 0 ) {
				objects.get(0).setSpeedMultiplicatorAbsolute(0);
			}
			
			if ( powerup == 2 ) {
				Score.reduceScore(100);
			}
		}
	}
	
	public static void deactivate(int powerup, boolean isPlayer) {
		setInstancedObjects();
		if (isPlayer) {
			
			if ( powerup == 1 ) {
				objects.get(0).setSpeedMultiplicatorAbsolute(Config.initialSpeedMultiplicator);
			}
			
			if (powerup == 0) {
				for (int i=1; i<objects.size(); i++) {
					objects.get(i).setSpeedMultiplicatorAbsolute(Config.initialSpeedMultiplicator);
				}
			}
			
		} else {
			
			if ( powerup == 1 ) {
				for (int i=1; i<objects.size(); i++) {
					objects.get(i).setSpeedMultiplicatorAbsolute(Config.initialSpeedMultiplicator);
				}
			}
			
			if (powerup == 0) {
				objects.get(0).setSpeedMultiplicatorAbsolute(Config.initialSpeedMultiplicator);
			}
			
		}	
	}
	private static void setInstancedObjects() {
		objects = PanelBuilder.getInstancedObjects().getObjects();
	}
	public static int getDuration(int powerup) {
		if ( powerup == 1 ) {
			return 8;
		}
		if (powerup == 0) {
			return 5;
		}
		if (powerup == 2) {
			return 1;
		}
		return 0;
	}
	public static String getName(int powerup) {
		if (powerup == 0) {
			return "Freeze";
		}
		if (powerup == 1) {
			return "Speed";
		}
		if (powerup == 2) {
			return "Score";
		}
		return null;
	}
}
