#include "Command.h"
#include "Person.h"
#include "List.h"
#include "Level.h"

#include <iostream>

using namespace std;

const string InvincibleCommand::_id = "invincible";

InvincibleCommand::InvincibleCommand(Person *person, bool inv)
:_person(person->id()),_inv(inv)
{
}

InvincibleCommand::InvincibleCommand(List *command)
{
	command = command->rest();
	_person = command->firstString();
	string inv = command->rest()->firstString();
	if(inv == "true")
		_inv = true;
	else
		_inv = false;
}

void InvincibleCommand::execute()
{
	((Person *)Level::instance()->getObject(_person))->setInvincible(_inv);
}

std::string InvincibleCommand::getString()
{
	List *command = new List();
	command->snoc(new Atom(_id));
	command->snoc(new Atom(_person));
	string inv;
	if(_inv)
		inv = "true";
	else
		inv = "false";
	command->snoc(new Atom(inv));
	string commandString = command->getString();
	delete command;

	return commandString;
}