Implement CDZoneTable PlayerLoseCoinsOnDeath (#251)

* Implement ZoneTable PlayerLoseCoinsOnDeath

- Adds a check on death if the character should drop coins in the current zone

* Refactored PlayerLoseCoinOnDeath into dZoneManager

* Coin death drops use LootGenerator

* Refactored again with use of CDZoneTableTable

* Remove duplicate CDZone call during initialization
This commit is contained in:
cooltrain7 2022-02-05 12:27:24 +00:00 committed by GitHub
parent f7009b499b
commit 579cf590b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 29 deletions

View File

@ -26,6 +26,7 @@
#include "MissionComponent.h"
#include "CharacterComponent.h"
#include "dZoneManager.h"
DestroyableComponent::DestroyableComponent(Entity* parent) : Component(parent) {
m_iArmor = 0;
@ -796,32 +797,34 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
}
else
{
auto* character = m_Parent->GetCharacter();
uint64_t coinsTotal = character->GetCoins();
if (coinsTotal > 0)
//Check if this zone allows coin drops
if (dZoneManager::Instance()->GetPlayerLoseCoinOnDeath())
{
uint64_t coinsToLoose = 1;
auto* character = m_Parent->GetCharacter();
uint64_t coinsTotal = character->GetCoins();
if (coinsTotal >= 200)
if (coinsTotal > 0)
{
float hundreth = (coinsTotal / 100.0f);
coinsToLoose = static_cast<int>(hundreth);
uint64_t coinsToLoose = 1;
if (coinsTotal >= 200)
{
float hundreth = (coinsTotal / 100.0f);
coinsToLoose = static_cast<int>(hundreth);
}
if (coinsToLoose > 10000)
{
coinsToLoose = 10000;
}
coinsTotal -= coinsToLoose;
LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose);
character->SetCoins(coinsTotal, LOOT_SOURCE_PICKUP);
}
if (coinsToLoose > 10000)
{
coinsToLoose = 10000;
}
coinsTotal -= coinsToLoose;
LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose);
}
character->SetCoins(coinsTotal, LOOT_SOURCE_PICKUP);
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
script->OnPlayerDied(zoneControl, m_Parent);

View File

@ -26,19 +26,20 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
LOT zoneControlTemplate = 2365;
std::stringstream query;
auto result = CDClientDatabase::ExecuteQuery("SELECT zoneControlTemplate, ghostdistance_min, ghostdistance FROM ZoneTable WHERE zoneID = " + std::to_string(zoneID.GetMapID()));
CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable<CDZoneTableTable>("ZoneTable");
if (zoneTable != nullptr){
const CDZoneTable* zone = zoneTable->Query(zoneID.GetMapID());
if (!result.eof()) {
zoneControlTemplate = result.getIntField("zoneControlTemplate", 2365);
const auto min = result.getIntField("ghostdistance_min", 100);
const auto max = result.getIntField("ghostdistance", 100);
EntityManager::Instance()->SetGhostDistanceMax(max + min);
EntityManager::Instance()->SetGhostDistanceMin(max);
if (zone != nullptr) {
zoneControlTemplate = zone->zoneControlTemplate != -1 ? zone->zoneControlTemplate : 2365;
const auto min = zone->ghostdistance_min != -1.0f ? zone->ghostdistance_min : 100;
const auto max = zone->ghostdistance != -1.0f ? zone->ghostdistance : 100;
EntityManager::Instance()->SetGhostDistanceMax(max + min);
EntityManager::Instance()->SetGhostDistanceMin(min);
m_PlayerLoseCoinsOnDeath = zone->PlayerLoseCoinsOnDeath;
}
}
result.finalize();
Game::logger->Log("dZoneManager", "Creating zone control object %i\n", zoneControlTemplate);
// Create ZoneControl object

View File

@ -42,6 +42,7 @@ public:
std::vector<Spawner*> GetSpawnersInGroup(std::string group);
void Update(float deltaTime);
Entity* GetZoneControlObject() { return m_ZoneControlObject; }
bool GetPlayerLoseCoinOnDeath() { return m_PlayerLoseCoinsOnDeath; }
private:
/**
@ -57,6 +58,7 @@ private:
static dZoneManager* m_Address; //Singleton
Zone* m_pZone;
LWOZONEID m_ZoneID;
bool m_PlayerLoseCoinsOnDeath; //Do players drop coins in this zone when smashed
std::map<LWOOBJID, Spawner*> m_Spawners;
Entity* m_ZoneControlObject;