2023-11-15 01:38:52 +00:00
|
|
|
#include "ConsumeItemBehavior.h"
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "InventoryComponent.h"
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void ConsumeItemBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2023-11-15 01:38:52 +00:00
|
|
|
auto action_to_cast = m_ActionNotConsumed;
|
|
|
|
if (this->m_ConsumeLOT != -1) {
|
|
|
|
auto caster = Game::entityManager->GetEntity(context->caster);
|
|
|
|
if (!caster) return;
|
|
|
|
|
|
|
|
auto inventoryComponent = caster->GetComponent<InventoryComponent>();
|
|
|
|
if (!inventoryComponent) return;
|
|
|
|
|
|
|
|
if (inventoryComponent->RemoveItem(this->m_ConsumeLOT, this->m_NumToConsume, eInventoryType::INVALID, false, true)){
|
|
|
|
action_to_cast = m_ActionConsumed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(action_to_cast) action_to_cast->Handle(context, bitStream, branch);
|
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void ConsumeItemBehavior::Sync(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2023-11-15 01:38:52 +00:00
|
|
|
Handle(context, bitStream, branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConsumeItemBehavior::Load() {
|
|
|
|
this->m_ConsumeLOT = GetInt("consume_lot", -1);
|
|
|
|
this->m_NumToConsume = GetInt("num_to_consume", 1);
|
|
|
|
this->m_ActionNotConsumed = GetAction("action_not_consumed");
|
|
|
|
this->m_ActionConsumed = GetAction("action_consumed");
|
|
|
|
}
|