2021-12-05 17:54:36 +00:00
|
|
|
#include "MinigameTreasureChestServer.h"
|
|
|
|
#include "ScriptedActivityComponent.h"
|
|
|
|
#include "TeamManager.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "dZoneManager.h"
|
|
|
|
|
|
|
|
void MinigameTreasureChestServer::OnUse(Entity* self, Entity* user) {
|
|
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
|
|
if (sac == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (self->GetVar<bool>(u"used"))
|
|
|
|
return;
|
|
|
|
self->SetVar<bool>(u"used", true);
|
|
|
|
|
|
|
|
if (!IsPlayerInActivity(self, user->GetObjectID()))
|
|
|
|
UpdatePlayer(self, user->GetObjectID());
|
|
|
|
|
|
|
|
auto* team = TeamManager::Instance()->GetTeam(user->GetObjectID());
|
2021-12-24 01:14:15 +00:00
|
|
|
uint32_t activityRating = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
if (team != nullptr) {
|
|
|
|
for (const auto& teamMemberID : team->members) {
|
|
|
|
auto* teamMember = EntityManager::Instance()->GetEntity(teamMemberID);
|
2021-12-24 01:14:15 +00:00
|
|
|
if (teamMember != nullptr) {
|
|
|
|
activityRating = CalculateActivityRating(self, teamMemberID);
|
|
|
|
|
|
|
|
if (self->GetLOT() == frakjawChestId) activityRating = team->members.size();
|
|
|
|
|
|
|
|
LootGenerator::Instance().DropActivityLoot(teamMember, self, sac->GetActivityID(), activityRating);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-24 01:14:15 +00:00
|
|
|
activityRating = CalculateActivityRating(self, user->GetObjectID());
|
|
|
|
|
|
|
|
if (self->GetLOT() == frakjawChestId) activityRating = 1;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
LootGenerator::Instance().DropActivityLoot(user, self, sac->GetActivityID(), activityRating);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
sac->PlayerRemove(user->GetObjectID());
|
|
|
|
|
|
|
|
auto* zoneControl = dZoneManager::Instance()->GetZoneControlObject();
|
|
|
|
if (zoneControl != nullptr) {
|
|
|
|
zoneControl->OnFireEventServerSide(self, "Survival_Update", 0);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
self->Smash(self->GetObjectID());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t MinigameTreasureChestServer::CalculateActivityRating(Entity* self, LWOOBJID playerID) {
|
|
|
|
auto* team = TeamManager::Instance()->GetTeam(playerID);
|
|
|
|
return team != nullptr ? team->members.size() * 100 : ActivityManager::CalculateActivityRating(self, playerID) * 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinigameTreasureChestServer::OnStartup(Entity* self) {
|
|
|
|
|
|
|
|
// BONS treasure chest thinks it's on FV, causing it to start a lobby
|
2022-07-05 06:00:10 +00:00
|
|
|
if (dZoneManager::Instance()->GetZoneID().GetMapID() == 1204) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* sac = self->GetComponent<ScriptedActivityComponent>();
|
|
|
|
if (sac != nullptr) {
|
|
|
|
sac->SetInstanceMapID(1204);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|