#include "stdafx.h"
#include "Damageable.h"

#include "Infrastructure\Vector2.h"
//#include "Actors\TextActor.h"
#include "CellWarsGameManager.h"
//#include "Util\MathUtil.h"

//#include <sstream>

Damageable::Damageable(float newMaxHP = 100)
{
	healthPoints = newMaxHP;
	maxHP = newMaxHP;

	/*
	printHP = new TextActor("Console", getHPString());
	printHP->SetPosition(0, 0);
	theWorld.Add(printHP, LayerEnum::HPString);
	*/
}

Damageable::~Damageable()
{
	//printHP->Destroy();
}

void Damageable::addLifePoints(float healAmount)
{
	healthPoints += healAmount;
	if (healthPoints > maxHP)
		healthPoints = maxHP;
	else if (healthPoints < 0)
		healthPoints = 0;
	
	deleteThisIfDead();
}

void Damageable::setLifePoints(float lifePoints)
{
	if (lifePoints >= 0 && lifePoints <= maxHP)
	{
		healthPoints = lifePoints;
		deleteThisIfDead();
	}
}

void Damageable::setLifePercentage(float lifePercentage)
{
	healthPoints = lifePercentage * maxHP;
	if (healthPoints > maxHP)
		healthPoints = maxHP;
	deleteThisIfDead();
}

void Damageable::setMaxLifePoints(float newMaxHP)
{
	maxHP = newMaxHP; 
}

float Damageable::getLifePoints()
{
	return healthPoints;
}

float Damageable::getLifePercentage()
{
	return healthPoints / maxHP;
}

float Damageable::getMaxLifePoints()
{
	return maxHP;
}

void Damageable::deleteThisIfDead()
{
	if (healthPoints <= 0)
		die();
}
/*
String Damageable::getHPString()
{
	std::ostringstream buff;
	buff << healthPoints << " / " << maxHP;
	return buff.str();
}*/
/*
void Damageable::updateHPString(Vector2 pos, Vector2 size)
{
	printHP->SetDisplayString(getHPString());

	Vector2 newPos(pos);
	
	newPos.X -= 0.5f * size.X;
	newPos.Y -= 0.5f * size.Y;
	printHP->SetPosition(newPos);
}
*/