#include <Utils/UtilsBase.h>

#include "FloatingLogger.h"
#include "Human.h"
#include "PlayerGame.h"

namespace mechanics {

	void FloatingLogger::log(std::string value) {
		mSetAt=gge::Main.CurrentTime;
		mLog=value;

		if(dynamic_cast<Human *>(this)) {
			Human *human = dynamic_cast<Human *>(this);
			PlayerGame::current().AddToGameLog(human->title() + "> " + value);
		}
	}

	std::string FloatingLogger::log() const {
		return mLog;
	}

	bool FloatingLogger::isExpired() const {
		return gge::Main.CurrentTime>mSetAt+5000; //constant
	}

	gge::Byte FloatingLogger::alpha() const {
		if((int)(gge::Main.CurrentTime-mSetAt)-4*5000/5>0) {
			return (gge::Byte)gge::utils::Limit(255*float((5000/5-((int)(gge::Main.CurrentTime-mSetAt)-4*5000/5))/(5000/5)),0.f,255.f);
		}

		return 255;
	}

}