mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 15:07:28 +00:00
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:
parent
f7009b499b
commit
579cf590b4
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "MissionComponent.h"
|
#include "MissionComponent.h"
|
||||||
#include "CharacterComponent.h"
|
#include "CharacterComponent.h"
|
||||||
|
#include "dZoneManager.h"
|
||||||
|
|
||||||
DestroyableComponent::DestroyableComponent(Entity* parent) : Component(parent) {
|
DestroyableComponent::DestroyableComponent(Entity* parent) : Component(parent) {
|
||||||
m_iArmor = 0;
|
m_iArmor = 0;
|
||||||
@ -796,32 +797,34 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto* character = m_Parent->GetCharacter();
|
//Check if this zone allows coin drops
|
||||||
|
if (dZoneManager::Instance()->GetPlayerLoseCoinOnDeath())
|
||||||
uint64_t coinsTotal = character->GetCoins();
|
|
||||||
|
|
||||||
if (coinsTotal > 0)
|
|
||||||
{
|
{
|
||||||
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);
|
uint64_t coinsToLoose = 1;
|
||||||
coinsToLoose = static_cast<int>(hundreth);
|
|
||||||
|
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();
|
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
|
||||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||||
script->OnPlayerDied(zoneControl, m_Parent);
|
script->OnPlayerDied(zoneControl, m_Parent);
|
||||||
|
@ -26,19 +26,20 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
|
|||||||
|
|
||||||
LOT zoneControlTemplate = 2365;
|
LOT zoneControlTemplate = 2365;
|
||||||
|
|
||||||
std::stringstream query;
|
CDZoneTableTable* zoneTable = CDClientManager::Instance()->GetTable<CDZoneTableTable>("ZoneTable");
|
||||||
auto result = CDClientDatabase::ExecuteQuery("SELECT zoneControlTemplate, ghostdistance_min, ghostdistance FROM ZoneTable WHERE zoneID = " + std::to_string(zoneID.GetMapID()));
|
if (zoneTable != nullptr){
|
||||||
|
const CDZoneTable* zone = zoneTable->Query(zoneID.GetMapID());
|
||||||
|
|
||||||
if (!result.eof()) {
|
if (zone != nullptr) {
|
||||||
zoneControlTemplate = result.getIntField("zoneControlTemplate", 2365);
|
zoneControlTemplate = zone->zoneControlTemplate != -1 ? zone->zoneControlTemplate : 2365;
|
||||||
const auto min = result.getIntField("ghostdistance_min", 100);
|
const auto min = zone->ghostdistance_min != -1.0f ? zone->ghostdistance_min : 100;
|
||||||
const auto max = result.getIntField("ghostdistance", 100);
|
const auto max = zone->ghostdistance != -1.0f ? zone->ghostdistance : 100;
|
||||||
EntityManager::Instance()->SetGhostDistanceMax(max + min);
|
EntityManager::Instance()->SetGhostDistanceMax(max + min);
|
||||||
EntityManager::Instance()->SetGhostDistanceMin(max);
|
EntityManager::Instance()->SetGhostDistanceMin(min);
|
||||||
|
m_PlayerLoseCoinsOnDeath = zone->PlayerLoseCoinsOnDeath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.finalize();
|
|
||||||
|
|
||||||
Game::logger->Log("dZoneManager", "Creating zone control object %i\n", zoneControlTemplate);
|
Game::logger->Log("dZoneManager", "Creating zone control object %i\n", zoneControlTemplate);
|
||||||
|
|
||||||
// Create ZoneControl object
|
// Create ZoneControl object
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
std::vector<Spawner*> GetSpawnersInGroup(std::string group);
|
std::vector<Spawner*> GetSpawnersInGroup(std::string group);
|
||||||
void Update(float deltaTime);
|
void Update(float deltaTime);
|
||||||
Entity* GetZoneControlObject() { return m_ZoneControlObject; }
|
Entity* GetZoneControlObject() { return m_ZoneControlObject; }
|
||||||
|
bool GetPlayerLoseCoinOnDeath() { return m_PlayerLoseCoinsOnDeath; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@ -57,6 +58,7 @@ private:
|
|||||||
static dZoneManager* m_Address; //Singleton
|
static dZoneManager* m_Address; //Singleton
|
||||||
Zone* m_pZone;
|
Zone* m_pZone;
|
||||||
LWOZONEID m_ZoneID;
|
LWOZONEID m_ZoneID;
|
||||||
|
bool m_PlayerLoseCoinsOnDeath; //Do players drop coins in this zone when smashed
|
||||||
std::map<LWOOBJID, Spawner*> m_Spawners;
|
std::map<LWOOBJID, Spawner*> m_Spawners;
|
||||||
|
|
||||||
Entity* m_ZoneControlObject;
|
Entity* m_ZoneControlObject;
|
||||||
|
Loading…
Reference in New Issue
Block a user