DarkflameServer/dScripts/02_server/Map/NS/NsTokenConsoleServer.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.6 KiB
C++
Raw Normal View History

#include "NsTokenConsoleServer.h"
#include "InventoryComponent.h"
#include "GameMessages.h"
#include "Character.h"
#include "MissionComponent.h"
#include "RebuildComponent.h"
void NsTokenConsoleServer::OnStartup(Entity* self) {
2022-07-28 13:39:57 +00:00
}
void NsTokenConsoleServer::OnUse(Entity* self, Entity* user) {
auto* rebuildComponent = self->GetComponent<RebuildComponent>();
2022-07-28 13:39:57 +00:00
if (rebuildComponent == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
if (rebuildComponent->GetState() != REBUILD_COMPLETED) {
return;
}
2022-07-28 13:39:57 +00:00
auto* inventoryComponent = user->GetComponent<InventoryComponent>();
auto* missionComponent = user->GetComponent<MissionComponent>();
auto* character = user->GetCharacter();
2022-07-28 13:39:57 +00:00
if (inventoryComponent == nullptr || missionComponent == nullptr || character == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
if (inventoryComponent->GetLotCount(6194) < 25) {
return;
}
2022-07-28 13:39:57 +00:00
inventoryComponent->RemoveItem(6194, 25);
2022-07-28 13:39:57 +00:00
const auto useSound = self->GetVar<std::string>(u"sound1");
2022-07-28 13:39:57 +00:00
if (!useSound.empty()) {
GameMessages::SendPlayNDAudioEmitter(self, UNASSIGNED_SYSTEM_ADDRESS, useSound);
}
2022-07-28 13:39:57 +00:00
// Player must be in faction to interact with this entity.
LOT tokenLOT = 0;
2022-07-28 13:39:57 +00:00
if (character->GetPlayerFlag(46)) {
tokenLOT = 8321;
} else if (character->GetPlayerFlag(47)) {
tokenLOT = 8318;
} else if (character->GetPlayerFlag(48)) {
tokenLOT = 8320;
} else if (character->GetPlayerFlag(49)) {
tokenLOT = 8319;
}
2022-07-28 13:39:57 +00:00
inventoryComponent->AddItem(tokenLOT, 5, eLootSourceType::LOOT_SOURCE_NONE);
2022-07-28 13:39:57 +00:00
missionComponent->ForceProgressTaskType(863, 1, 1, false);
2022-07-28 13:39:57 +00:00
GameMessages::SendTerminateInteraction(user->GetObjectID(), FROM_INTERACTION, self->GetObjectID());
}