2021-12-05 17:54:36 +00:00
|
|
|
#include "NjScrollChestServer.h"
|
|
|
|
#include "InventoryComponent.h"
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void NjScrollChestServer::OnUse(Entity* self, Entity* user) {
|
|
|
|
const auto keyLOT = self->GetVar<LOT>(u"KeyNum");
|
|
|
|
const auto rewardItemLOT = self->GetVar<LOT>(u"openItemID");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
auto* playerInventory = user->GetComponent<InventoryComponent>();
|
|
|
|
if (playerInventory != nullptr && playerInventory->GetLotCount(keyLOT) == 1) {
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// Check for the key and remove
|
|
|
|
playerInventory->RemoveItem(keyLOT, 1);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
// Reward the player with the item set
|
|
|
|
playerInventory->AddItem(rewardItemLOT, 1, eLootSourceType::LOOT_SOURCE_NONE);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|