mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-28 16:37:23 +00:00
feat: implement consume item behavior (#1098)
* feature: implement consume item behavior * Cleanup * tested with skill 456 and fixed some things * remove logs
This commit is contained in:
parent
8a9883c224
commit
8cd5bf7b8d
@ -64,6 +64,7 @@
|
|||||||
#include "FallSpeedBehavior.h"
|
#include "FallSpeedBehavior.h"
|
||||||
#include "ChangeIdleFlagsBehavior.h"
|
#include "ChangeIdleFlagsBehavior.h"
|
||||||
#include "DarkInspirationBehavior.h"
|
#include "DarkInspirationBehavior.h"
|
||||||
|
#include "ConsumeItemBehavior.h"
|
||||||
|
|
||||||
//CDClient includes
|
//CDClient includes
|
||||||
#include "CDBehaviorParameterTable.h"
|
#include "CDBehaviorParameterTable.h"
|
||||||
@ -200,7 +201,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) {
|
|||||||
case BehaviorTemplates::BEHAVIOR_SKILL_EVENT:
|
case BehaviorTemplates::BEHAVIOR_SKILL_EVENT:
|
||||||
behavior = new SkillEventBehavior(behaviorId);
|
behavior = new SkillEventBehavior(behaviorId);
|
||||||
break;
|
break;
|
||||||
case BehaviorTemplates::BEHAVIOR_CONSUME_ITEM: break;
|
case BehaviorTemplates::BEHAVIOR_CONSUME_ITEM:
|
||||||
|
behavior = new ConsumeItemBehavior(behaviorId);
|
||||||
|
break;
|
||||||
case BehaviorTemplates::BEHAVIOR_SKILL_CAST_FAILED:
|
case BehaviorTemplates::BEHAVIOR_SKILL_CAST_FAILED:
|
||||||
behavior = new SkillCastFailedBehavior(behaviorId);
|
behavior = new SkillCastFailedBehavior(behaviorId);
|
||||||
break;
|
break;
|
||||||
|
@ -16,6 +16,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
|
|||||||
"ChangeOrientationBehavior.cpp"
|
"ChangeOrientationBehavior.cpp"
|
||||||
"ChargeUpBehavior.cpp"
|
"ChargeUpBehavior.cpp"
|
||||||
"ClearTargetBehavior.cpp"
|
"ClearTargetBehavior.cpp"
|
||||||
|
"ConsumeItemBehavior.cpp"
|
||||||
"DamageAbsorptionBehavior.cpp"
|
"DamageAbsorptionBehavior.cpp"
|
||||||
"DamageReductionBehavior.cpp"
|
"DamageReductionBehavior.cpp"
|
||||||
"DarkInspirationBehavior.cpp"
|
"DarkInspirationBehavior.cpp"
|
||||||
|
31
dGame/dBehaviors/ConsumeItemBehavior.cpp
Normal file
31
dGame/dBehaviors/ConsumeItemBehavior.cpp
Normal file
@ -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");
|
||||||
|
}
|
17
dGame/dBehaviors/ConsumeItemBehavior.h
Normal file
17
dGame/dBehaviors/ConsumeItemBehavior.h
Normal file
@ -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;
|
||||||
|
};
|
@ -300,38 +300,26 @@ void InventoryComponent::AddItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound) {
|
bool InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInventoryType inventoryType, const bool ignoreBound, const bool silent) {
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
LOG("Attempted to remove 0 of item (%i) from the inventory!", lot);
|
LOG("Attempted to remove 0 of item (%i) from the inventory!", lot);
|
||||||
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (inventoryType == INVALID) inventoryType = Inventory::FindInventoryTypeForLot(lot);
|
||||||
if (inventoryType == INVALID) {
|
|
||||||
inventoryType = Inventory::FindInventoryTypeForLot(lot);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* inventory = GetInventory(inventoryType);
|
auto* inventory = GetInventory(inventoryType);
|
||||||
|
if (!inventory) return false;
|
||||||
if (inventory == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto left = std::min<uint32_t>(count, inventory->GetLotCount(lot));
|
auto left = std::min<uint32_t>(count, inventory->GetLotCount(lot));
|
||||||
|
if (left != count) return false;
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
auto* item = FindItemByLot(lot, inventoryType, false, ignoreBound);
|
auto* item = FindItemByLot(lot, inventoryType, false, ignoreBound);
|
||||||
|
if (!item) break;
|
||||||
if (item == nullptr) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto delta = std::min<uint32_t>(left, item->GetCount());
|
const auto delta = std::min<uint32_t>(left, item->GetCount());
|
||||||
|
item->SetCount(item->GetCount() - delta, silent);
|
||||||
item->SetCount(item->GetCount() - delta);
|
|
||||||
|
|
||||||
left -= delta;
|
left -= delta;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType inventory, const uint32_t count, const bool showFlyingLot, bool isModMoveAndEquip, const bool ignoreEquipped, const int32_t preferredSlot) {
|
void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType inventory, const uint32_t count, const bool showFlyingLot, bool isModMoveAndEquip, const bool ignoreEquipped, const int32_t preferredSlot) {
|
||||||
|
@ -118,8 +118,9 @@ public:
|
|||||||
* @param count the number of items to remove
|
* @param count the number of items to remove
|
||||||
* @param inventoryType optional inventory type to remove the item from
|
* @param inventoryType optional inventory type to remove the item from
|
||||||
* @param ignoreBound ignores bound items
|
* @param ignoreBound ignores bound items
|
||||||
|
* @param silent silently remove the item
|
||||||
*/
|
*/
|
||||||
void RemoveItem(LOT lot, uint32_t count, eInventoryType inventoryType = INVALID, bool ignoreBound = false);
|
bool RemoveItem(LOT lot, uint32_t count, eInventoryType inventoryType = INVALID, bool ignoreBound = false, bool silent = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves an existing item to an inventory of the entity
|
* Moves an existing item to an inventory of the entity
|
||||||
|
Loading…
Reference in New Issue
Block a user