perk program full work ui now of vendor
This commit is contained in:
@@ -18685,7 +18685,7 @@ bool Player::LoadFromDB(ObjectGuid guid, CharacterDatabaseQueryHolder const& hol
|
||||
_LoadMonthlyQuestStatus(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_MONTHLY_QUEST_STATUS));
|
||||
_LoadRandomBGStatus(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_RANDOM_BG));
|
||||
//WowCommunity
|
||||
// _LoadWorldQuestStatus(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOADWORLDQUESTSTATUS)); todo thor
|
||||
// _LoadWorldQuestStatus(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOADWORLDQUESTSTATUS)); todo thor
|
||||
//WowCommunity
|
||||
|
||||
// after spell and quest load
|
||||
|
||||
@@ -10,11 +10,8 @@
|
||||
#include "Containers.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "DB2Stores.h"
|
||||
#include <sstream>
|
||||
#include "GameTime.h"
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
|
||||
PerkProgramDataStoreMgr::PerkProgramDataStoreMgr() {};
|
||||
|
||||
@@ -38,47 +35,61 @@ void PerkProgramDataStoreMgr::Initialize()
|
||||
LoadActivities();
|
||||
}
|
||||
|
||||
void _LoadTemplates(Field* fields)
|
||||
{
|
||||
time_t curTime = GameTime::GetGameTime();
|
||||
tm timeInfo;
|
||||
localtime_r(&curTime, &timeInfo);
|
||||
|
||||
PerkProgramData::PerkVendorItem vendorItem;
|
||||
|
||||
uint32 entry = fields[0].GetUInt32();
|
||||
if (PerksVendorItemEntry const* itemVendor = sPerksVendorItemStore.LookupEntry(entry))
|
||||
{
|
||||
vendorItem.Id = entry;
|
||||
vendorItem.ItemID = fields[1].GetUInt32();;
|
||||
vendorItem.MountSpellID = fields[2].GetUInt32();
|
||||
vendorItem.PetSpellID = fields[3].GetUInt32();
|
||||
vendorItem.TransmogSet = fields[4].GetUInt32();
|
||||
vendorItem.ItemModifiedAppearanceID = fields[5].GetUInt32();
|
||||
vendorItem.ToyItem = fields[6].GetUInt32();
|
||||
uint32 Cost = fields[7].GetUInt32();
|
||||
vendorItem.CategoryId = itemVendor->PerksVendorCategoryID;
|
||||
|
||||
if (Cost)
|
||||
vendorItem.Cost = Cost;
|
||||
else
|
||||
vendorItem.Cost = itemVendor->Cost;
|
||||
|
||||
vendorItem.ItemID = itemVendor->ItemID;
|
||||
|
||||
uint32 mon = fields[8].GetUInt32();
|
||||
|
||||
_vendorTemplates.insert(std::make_pair(entry, vendorItem));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PerkProgramDataStoreMgr::LoadPerkVendorItem()
|
||||
{
|
||||
TC_LOG_INFO("server.loading", "Loading PerkPrograms Vendor Items Templates ...");
|
||||
_vendorTemplates.clear();
|
||||
|
||||
if (!sPerksVendorItemStore.GetNumRows())
|
||||
{
|
||||
TC_LOG_WARN("server.loading", ">> PerksVendorItem store is empty, skipping vendor items");
|
||||
auto result = WorldDatabase.PQuery("SELECT `Id`, `ItemID`, `MountSpellID`, `PetSpellID`, `TransmogSet`, `ItemModifiedAppearanceID`, `ToyItem`, `Cost`, `Mon` FROM `perk_programs_vendor_items`");
|
||||
if (!result)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 validCount = 0;
|
||||
for (PerksVendorItemEntry const* itemVendor : sPerksVendorItemStore)
|
||||
auto oldMsTime = getMSTime();
|
||||
|
||||
_vendorTemplates.rehash(result->GetRowCount());
|
||||
do
|
||||
{
|
||||
if (!itemVendor)
|
||||
continue;
|
||||
Field* fields = result->Fetch();
|
||||
_LoadTemplates(fields);
|
||||
} while (result->NextRow());
|
||||
|
||||
// Validate item data
|
||||
if (itemVendor->Cost > 1000000) // Reasonable maximum cost
|
||||
{
|
||||
TC_LOG_WARN("server.loading", ">> PerksVendorItem {} has excessive cost {}, skipping", itemVendor->ID, itemVendor->Cost);
|
||||
continue;
|
||||
}
|
||||
|
||||
PerkProgramData::PerkVendorItem vendorItem;
|
||||
vendorItem.Id = itemVendor->ID;
|
||||
vendorItem.ItemID = itemVendor->ItemID;
|
||||
vendorItem.MountSpellID = itemVendor->Unknown010001;
|
||||
vendorItem.PetSpellID = itemVendor->Unknown020001;
|
||||
vendorItem.TransmogSet = 0;
|
||||
vendorItem.ItemModifiedAppearanceID = 0;
|
||||
vendorItem.ToyItem = 0;
|
||||
vendorItem.AvailableUntil = 0; // Initialize to 0 (no expiration)
|
||||
vendorItem.Cost = itemVendor->Cost;
|
||||
vendorItem.CategoryId = itemVendor->PerksVendorCategoryID;
|
||||
|
||||
_vendorTemplates.insert(std::make_pair(itemVendor->ID, vendorItem));
|
||||
validCount++;
|
||||
}
|
||||
|
||||
TC_LOG_INFO("server.loading", ">> Loaded {} PerkPrograms Vendor Items Templates ({} valid)", uint32(_vendorTemplates.size()), validCount);
|
||||
TC_LOG_INFO("server.loading", ">> Loaded {} PerkPrograms Vendor Items Templates in {} ms", uint64(_vendorTemplates.size()), GetMSTimeDiffToNow(oldMsTime));
|
||||
}
|
||||
|
||||
std::unordered_map<uint32, PerkProgramData::PerkVendorItem> PerkProgramDataStoreMgr::GetVendorItems()
|
||||
@@ -88,24 +99,18 @@ std::unordered_map<uint32, PerkProgramData::PerkVendorItem> PerkProgramDataStore
|
||||
|
||||
PerkProgramData::PerkVendorItem const* PerkProgramDataStoreMgr::GetVendorItem(uint32 entry)
|
||||
{
|
||||
auto itr = _vendorTemplates.find(entry);
|
||||
std::unordered_map<uint32, PerkProgramData::PerkVendorItem>::const_iterator itr = _vendorTemplates.find(entry);
|
||||
if (itr != _vendorTemplates.end())
|
||||
return &itr->second;
|
||||
return &(itr->second);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PerkProgramData::PerkVendorItem const* PerkProgramDataStoreMgr::GetRandomVendorItem()
|
||||
{
|
||||
if (_vendorTemplates.empty())
|
||||
return nullptr;
|
||||
int random_index = rand() % _vendorTemplates.size();
|
||||
|
||||
// Use proper random number generation
|
||||
static thread_local std::mt19937 generator(std::random_device{}());
|
||||
std::uniform_int_distribution<size_t> distribution(0, _vendorTemplates.size() - 1);
|
||||
auto it = _vendorTemplates.begin();
|
||||
std::advance(it, distribution(generator));
|
||||
return &it->second;
|
||||
return GetVendorItem(random_index);
|
||||
}
|
||||
|
||||
std::vector<PerkProgramData::ActivityTemplate> PerkProgramDataStoreMgr::GetActivities()
|
||||
@@ -115,21 +120,25 @@ std::vector<PerkProgramData::ActivityTemplate> PerkProgramDataStoreMgr::GetActiv
|
||||
|
||||
uint32 PerkProgramDataStoreMgr::GetActivityCriteriatree(uint32 activityId)
|
||||
{
|
||||
for (auto const& ac : m_activeActivity)
|
||||
{
|
||||
if (ac.ActivityID == activityId)
|
||||
return ac.CriteriaTree;
|
||||
}
|
||||
auto itr = std::find_if(m_activeActivity.begin(), m_activeActivity.end(), [&](PerkProgramData::ActivityTemplate tem)
|
||||
{
|
||||
return tem.ActivityID == activityId;
|
||||
});
|
||||
if (itr != m_activeActivity.end())
|
||||
return itr->CriteriaTree;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32 PerkProgramDataStoreMgr::GetActivityCurrencyAmount(uint32 activityId)
|
||||
{
|
||||
for (auto const& ac : m_activeActivity)
|
||||
{
|
||||
if (ac.ActivityID == activityId)
|
||||
return ac.CurrencyAmount;
|
||||
}
|
||||
auto itr = std::find_if(m_activeActivity.begin(), m_activeActivity.end(), [&](PerkProgramData::ActivityTemplate tem)
|
||||
{
|
||||
return tem.ActivityID == activityId;
|
||||
});
|
||||
if (itr != m_activeActivity.end())
|
||||
return itr->CurrencyAmount;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -143,39 +152,43 @@ void PerkProgramDataStoreMgr::LoadActivities()
|
||||
GenerateRandomActivities(false);
|
||||
return;
|
||||
}
|
||||
do
|
||||
/* do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 activityId = fields[0].GetUInt32();
|
||||
PerksActivityEntry const* entry = sPerksActivityStore.LookupEntry(activityId);
|
||||
PerkProgramActivityEntry const* entry = sPerkProgramActivityStore.LookupEntry(activityId);
|
||||
if (!entry)
|
||||
continue;
|
||||
return;
|
||||
PerkProgramData::ActivityTemplate ac;
|
||||
ac.ActivityID = entry->ID;
|
||||
ac.ActivityID = entry->Id;
|
||||
ac.CriteriaTree = entry->CriteriaTreeID;
|
||||
ac.CurrencyAmount = entry->ThresholdContributionAmount;
|
||||
ac.Priority = entry->Priority;
|
||||
ac.Priority = 0;
|
||||
m_activeActivity.push_back(ac);
|
||||
|
||||
} while (result->NextRow());
|
||||
} while (result->NextRow());*/ //TODO
|
||||
}
|
||||
|
||||
void PerkProgramDataStoreMgr::GenerateRandomActivities(bool /*clearOld*/)
|
||||
void PerkProgramDataStoreMgr::GenerateRandomActivities(bool clearOld)
|
||||
{
|
||||
if (clearOld)
|
||||
{
|
||||
}
|
||||
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PERK_PROGRAM_ACTIVITY);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
m_activeActivity.clear();
|
||||
|
||||
for (PerksActivityEntry const* db : sDB2Manager.GetRandomActivitiesXTag())
|
||||
for (auto db : sDB2Manager.GetRandomActivitiesXTag())
|
||||
{
|
||||
PerkProgramData::ActivityTemplate ac;
|
||||
ac.ActivityID = db->ID;
|
||||
ac.CriteriaTree = db->CriteriaTreeID;
|
||||
ac.CurrencyAmount = db->ThresholdContributionAmount;
|
||||
ac.Priority = db->Priority;
|
||||
ac.Priority = 0;
|
||||
m_activeActivity.push_back(ac);
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_PERK_PROGRAM_ACTIVITY);
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_PERK_PROGRAM_ACTIVITY);
|
||||
stmt->setUInt32(0, ac.ActivityID);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
@@ -2535,11 +2535,7 @@ class TC_GAME_API WorldSession
|
||||
private:
|
||||
std::shared_ptr<PerkProgramManager> _perkProgramMgr;
|
||||
public:
|
||||
PerkProgramManager* GetPerkProgramMgr() const {
|
||||
if (!_perkProgramMgr)
|
||||
_perkProgramMgr = std::make_shared<PerkProgramManager>(const_cast<WorldSession*>(this));
|
||||
return _perkProgramMgr.get();
|
||||
}
|
||||
PerkProgramManager* GetPerkProgramMgr() const { return _perkProgramMgr.get(); }
|
||||
//WowCommunity
|
||||
|
||||
WorldSession(WorldSession const& right) = delete;
|
||||
|
||||
Reference in New Issue
Block a user