package ncrashed.warp.cores.actions;

import java.util.List;
import java.util.ListIterator;

import ncrashed.warp.api.ICoreAction;
import ncrashed.warp.api.IWarpCore;
import net.minecraft.entity.player.EntityPlayerMP;

public class CrewSummon implements ICoreAction 
{

	@Override
	public int getRequiredEnergy(IWarpCore core, int multCounter, int north,
			int south, int west, int east, int up, int down) 
	{
		return core.getCrewNotOnBoard().size()*90000;
	}

	@Override
	public boolean performAction(IWarpCore core, int multCounter, int north,
			int south, int west, int east, int up, int down) 
	{
		int dx = 6*(east-west);
		int dy = 6*(up-down);
		int dz = 6*(south-north);
		
		if(dx == 0 && dy == 0 && dz == 0)
		{
			dy = 2;
		}
		
		List<EntityPlayerMP> summonCrew = core.getCrewNotOnBoard(); 
		ListIterator<EntityPlayerMP> iter = summonCrew.listIterator();
		while(iter.hasNext())
		{
			EntityPlayerMP player = iter.next();
			player.playerNetServerHandler.setPlayerLocation(core.getCoreX()+dx, core.getCoreY()+dy, core.getCoreZ()+dz, player.rotationYaw, player.rotationPitch);
		}
		
		return true;
	}

	@Override
	public int getLowMultCounter() 
	{
		return 0;
	}

	@Override
	public int getHighMultCounter() 
	{
		return 0;
	}

	@Override
	public int getSuccessCooldown(IWarpCore core, int multCounter, int north,
			int south, int west, int east, int up, int down) 
	{
		return 1;
	}

	@Override
	public int getFailCooldown(IWarpCore core, int multCounter, int north,
			int south, int west, int east, int up, int down) 
	{
		return 1;
	}

	@Override
	public int getMinimumCooldown(IWarpCore core, int multCounter, int north,
			int south, int west, int east, int up, int down) 
	{
		return 0;
	}

	@Override
	public boolean printActionResult() 
	{
		return true;
	}

	@Override
	public int getErrorBit() 
	{
		return -1;
	}

}
