package ru.alphatech.icfpc.cards;

import ru.alphatech.icfpc.game.ICFPCException;
import ru.alphatech.icfpc.game.IValue;
import ru.alphatech.icfpc.game.Player;
import ru.alphatech.icfpc.game.Value;

public class Dec implements ICard
{
	@Override
	public IValue returnValue(IValue value, Player proponent, Player opponent)
	{
		if(value.getClass().equals(Value.class))
		{
			int i = ((Value)value).getValue();

			if (i > 0 && i < 256)
			{
				int v = proponent.getSlot(255 - i).getVitality();
				if (v < 65535 && v > 0)
				{
					proponent.getSlot(255 - i).setVitality(proponent.getSlot(255 - i).getVitality() - 1);
				}
			}
			else
			{
				throw new ICFPCException();
			}
		}
		else
		{
			throw new ICFPCException();
		}

		return new Value(-100);
	}
}
