DarkflameServer/dScripts/TreasureChestDragonServer.cpp

43 lines
1.1 KiB
C++
Raw Normal View History

#include "TreasureChestDragonServer.h"
#include "ScriptedActivityComponent.h"
#include "TeamManager.h"
#include "EntityManager.h"
2022-07-28 13:39:57 +00:00
void TreasureChestDragonServer::OnStartup(Entity* self) {
}
2022-07-28 13:39:57 +00:00
void TreasureChestDragonServer::OnUse(Entity* self, Entity* user) {
if (self->GetVar<bool>(u"bUsed")) {
return;
}
2022-07-28 13:39:57 +00:00
self->SetVar<bool>(u"bUsed", true);
2022-07-28 13:39:57 +00:00
auto* scriptedActivityComponent = self->GetComponent<ScriptedActivityComponent>();
2022-07-28 13:39:57 +00:00
if (scriptedActivityComponent == nullptr) {
return;
}
2022-07-28 13:39:57 +00:00
auto rating = 1;
2022-07-28 13:39:57 +00:00
auto* team = TeamManager::Instance()->GetTeam(user->GetObjectID());
2022-07-28 13:39:57 +00:00
if (team != nullptr) {
rating = team->members.size();
2022-07-28 13:39:57 +00:00
for (const auto member : team->members) {
auto* memberObject = EntityManager::Instance()->GetEntity(member);
2022-07-28 13:39:57 +00:00
if (memberObject == nullptr) continue;
2022-07-28 13:39:57 +00:00
LootGenerator::Instance().DropActivityLoot(memberObject, self, scriptedActivityComponent->GetActivityID(), rating);
}
} else {
LootGenerator::Instance().DropActivityLoot(user, self, scriptedActivityComponent->GetActivityID(), rating);
}
2022-07-28 13:39:57 +00:00
self->Smash(self->GetObjectID());
}