2021-05-08 03:36:26 +02:00
|
|
|
#include "itemcontroller.h"
|
|
|
|
#include "item.h"
|
|
|
|
#include "actor.h"
|
2021-05-16 01:44:19 +02:00
|
|
|
#include "validator.h"
|
2021-05-08 03:36:26 +02:00
|
|
|
|
|
|
|
ItemController::ItemController(Initializer &&initializer) :
|
|
|
|
Controller(std::move(initializer))
|
|
|
|
{}
|
|
|
|
|
|
|
|
ItemController::~ItemController()
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string ItemController::interact(std::shared_ptr<Actor> actor)
|
|
|
|
{
|
|
|
|
std::string interaction_output;
|
|
|
|
|
2021-05-16 01:44:19 +02:00
|
|
|
const auto validation_result = _validator
|
|
|
|
? _validator->validate(actor)
|
|
|
|
: Validator::ValidateResult{true, ""};
|
|
|
|
|
|
|
|
interaction_output += validation_result.validate_output;
|
2021-05-08 03:36:26 +02:00
|
|
|
|
|
|
|
if (validation_result.success)
|
|
|
|
{
|
|
|
|
actor->giveItem(_item);
|
|
|
|
interaction_output += _interaction_message;
|
2021-05-16 01:44:19 +02:00
|
|
|
runModificators();
|
2021-05-08 03:36:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return interaction_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemController::setDependentItem(const std::shared_ptr<Item> &item)
|
|
|
|
{
|
|
|
|
_item = item;
|
|
|
|
}
|
|
|
|
|