#include "Player.h"

Player::Player(void)
{
}

Player::Player(UnitTemplate* u, cocos2d::Vec2 position, unsigned team, cocos2d::Node* parent):
	Unit(u,position,team,parent)
{
	_throw = false;
}

Player::~Player(void)
{
}

float Player::getRatio()
{
	return (float)_health/_template->_health;
}

int Player::getAP()
{
	return _specialCount;
}

bool Player::UpdateThrow(std::vector<Item*>* items)
{
	for(unsigned i=0;i< items->size();i++)
	{
		Item* item = (*items)[i];
		if (rectConflict(item->getRect(),&_rect))
		{
			_throw = item;
			return true;
		}
	}

	return false;
}

void Player::Attack(unsigned type)
{
	if (type == ATTACK_THROW && _throw)
	{
		if (_throw->isUsed())
		{
			return;
		}
		else
		{
			_throw->setUsed();
		}
	}
	else if (type == ATTACK_THROW)
	{
		return;
	}
	
	Unit::Attack(type);
}