38 lines
869 B
C++
38 lines
869 B
C++
#include "itemcontroller.h"
|
|
#include "item.h"
|
|
#include "actor.h"
|
|
#include "validator.h"
|
|
|
|
ItemController::ItemController(Initializer &&initializer) :
|
|
Controller(std::move(initializer))
|
|
{}
|
|
|
|
ItemController::~ItemController()
|
|
{}
|
|
|
|
std::string ItemController::interact(std::shared_ptr<Actor> actor)
|
|
{
|
|
std::string interaction_output;
|
|
|
|
const auto validation_result = _validator
|
|
? _validator->validate(actor)
|
|
: Validator::ValidateResult{true, ""};
|
|
|
|
interaction_output += validation_result.validate_output;
|
|
|
|
if (validation_result.success)
|
|
{
|
|
actor->giveItem(_item);
|
|
interaction_output += _interaction_message;
|
|
runModificators();
|
|
}
|
|
|
|
return interaction_output;
|
|
}
|
|
|
|
void ItemController::setDependentItem(const std::shared_ptr<Item> &item)
|
|
{
|
|
_item = item;
|
|
}
|
|
|