DarkflameServer/dScripts/TreasureChestDragonServer.cpp
Jett 0531365cb5
Make loot accurate to the loot drop rates during live. (#216)
* loot fix (broken)

* Fixed loot

* Update SlashCommandHandler.cpp

* Remove debug command

* Roll loot command

* Remove debug log

* Added const references
When this commit is applied it adds const references to the loot system avoid some unnecessary copies.

Co-authored-by: wincent <wincent.holm@gmail.com>
Co-authored-by: Avery <averysumner@gmail.com>
2021-12-20 02:25:45 -08:00

52 lines
1.2 KiB
C++

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