2021-05-07 21:36:26 -04:00
|
|
|
#include "locationcontroller.h"
|
|
|
|
#include "location.h"
|
2021-05-15 19:44:19 -04:00
|
|
|
#include "validator.h"
|
2021-05-07 21:36:26 -04:00
|
|
|
#include "actor.h"
|
|
|
|
|
|
|
|
LocationController::LocationController(Initializer &&initializer) :
|
|
|
|
Controller(std::move(initializer))
|
|
|
|
{}
|
|
|
|
|
|
|
|
LocationController::~LocationController()
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string LocationController::interact(std::shared_ptr<Actor> actor)
|
|
|
|
{
|
|
|
|
std::string interaction_output;
|
|
|
|
|
2021-05-15 19:44:19 -04:00
|
|
|
const auto validation_result = _validator
|
|
|
|
? _validator->validate(actor)
|
|
|
|
: Validator::ValidateResult{true, ""};
|
|
|
|
|
|
|
|
interaction_output += validation_result.validate_output;
|
2021-05-07 21:36:26 -04:00
|
|
|
|
|
|
|
if (validation_result.success)
|
|
|
|
{
|
|
|
|
actor->moveToLocation(_location);
|
|
|
|
|
|
|
|
const std::string& node_interact_message = _location->interact();
|
|
|
|
interaction_output += (_interaction_message + "\n\n" + node_interact_message);
|
|
|
|
}
|
|
|
|
|
2021-05-15 19:44:19 -04:00
|
|
|
runModificators();
|
|
|
|
|
2021-05-07 21:36:26 -04:00
|
|
|
return interaction_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationController::setDependentLocation(const std::shared_ptr<Location> &location)
|
|
|
|
{
|
|
|
|
_location = location;
|
|
|
|
}
|