-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement consume item behavior (#1098)
* feature: implement consume item behavior * Cleanup * tested with skill 456 and fixed some things * remove logs
- Loading branch information
1 parent
8a9883c
commit 8cd5bf7
Showing
6 changed files
with
63 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "ConsumeItemBehavior.h" | ||
#include "BehaviorContext.h" | ||
#include "BehaviorBranchContext.h" | ||
#include "InventoryComponent.h" | ||
|
||
void ConsumeItemBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { | ||
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); | ||
} | ||
|
||
void ConsumeItemBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { | ||
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
#include "Behavior.h" | ||
|
||
class ConsumeItemBehavior final : public Behavior | ||
{ | ||
public: | ||
explicit ConsumeItemBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {} | ||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; | ||
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; | ||
void Load() override; | ||
|
||
private: | ||
LOT m_ConsumeLOT; | ||
uint32_t m_NumToConsume; | ||
Behavior* m_ActionNotConsumed; | ||
Behavior* m_ActionConsumed; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters