[12150] Drop arena point distribution, implement currency week count reset.

- Fix missing currency load.
- Some cleanup.

Signed-off-by: Yaki Khadafi <elsoldollo@gmail.com>
This commit is contained in:
Yaki Khadafi 2012-08-30 12:20:06 +03:00 committed by Antz
parent 7177f4cc07
commit 8e5d609e1e
21 changed files with 166 additions and 220 deletions

View file

@ -35,6 +35,7 @@
#include "SkillDiscovery.h"
#include "AccountMgr.h"
#include "AchievementMgr.h"
#include "ArenaTeam.h"
#include "AuctionHouseMgr.h"
#include "ObjectMgr.h"
#include "CreatureEventAIMgr.h"
@ -95,6 +96,7 @@ World::World()
m_startTime = m_gameTime;
m_maxActiveSessionCount = 0;
m_maxQueuedSessionCount = 0;
m_NextCurrencyReset = 0;
m_NextDailyQuestReset = 0;
m_NextWeeklyQuestReset = 0;
@ -596,9 +598,13 @@ void World::LoadConfigSettings(bool reload)
setConfigMinMax(CONFIG_UINT32_START_PLAYER_MONEY, "StartPlayerMoney", 0, 0, MAX_MONEY_AMOUNT);
setConfig(CONFIG_UINT32_START_HONOR_POINTS, "StartHonorPoints", 0);
setConfig(CONFIG_UINT32_CONQUEST_POINTS_DEFAULT_WEEK_CAP, "ConquestPointsDefaultWeekCap", 1350 * 100); // with precision
setConfig(CONFIG_UINT32_START_CONQUEST_POINTS, "StartConquestPoints", 0);
setConfigMinMax(CONFIG_UINT32_CURRENCY_RESET_TIME_HOUR, "Currency.ResetHour", 6, 0, 23);
setConfigMinMax(CONFIG_UINT32_CURRENCY_RESET_TIME_WEEK_DAY, "Currency.ResetWeekDay", 3, 0, 6);
setConfigMin(CONFIG_UINT32_CURRENCY_RESET_INTERVAL, "Currency.ResetInterval", 7, 1);
setConfig(CONFIG_UINT32_CURRENCY_START_CONQUEST_POINTS, "Currency.StartConquestPoints", 0);
setConfig(CONFIG_UINT32_CURRENCY_START_HONOR_POINTS, "Currency.StartHonorPoints", 0);
setConfig(CONFIG_UINT32_CURRENCY_CONQUEST_POINTS_DEFAULT_WEEK_CAP, "Currency.ConquestPointsDefaultWeekCap", 1350 * 100); // with precision
setConfig(CONFIG_UINT32_CURRENCY_ARENA_CONQUEST_POINTS_REWARD, "Currency.ConquestPointsArenaReward", 120 * 100); // with precision
setConfig(CONFIG_BOOL_ALL_TAXI_PATHS, "AllFlightPaths", false);
@ -747,8 +753,6 @@ void World::LoadConfigSettings(bool reload)
setConfig(CONFIG_UINT32_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH, "BattleGround.PremadeGroupWaitForMatch", 30 * MINUTE * IN_MILLISECONDS);
setConfig(CONFIG_UINT32_ARENA_MAX_RATING_DIFFERENCE, "Arena.MaxRatingDifference", 150);
setConfig(CONFIG_UINT32_ARENA_RATING_DISCARD_TIMER, "Arena.RatingDiscardTimer", 10 * MINUTE * IN_MILLISECONDS);
setConfig(CONFIG_BOOL_ARENA_AUTO_DISTRIBUTE_POINTS, "Arena.AutoDistributePoints", false);
setConfig(CONFIG_UINT32_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS, "Arena.AutoDistributeInterval", 7);
setConfig(CONFIG_BOOL_ARENA_QUEUE_ANNOUNCER_JOIN, "Arena.QueueAnnouncer.Join", false);
setConfig(CONFIG_BOOL_ARENA_QUEUE_ANNOUNCER_EXIT, "Arena.QueueAnnouncer.Exit", false);
setConfig(CONFIG_UINT32_ARENA_SEASON_ID, "Arena.ArenaSeason.ID", 1);
@ -1380,7 +1384,6 @@ void World::SetInitialWorldSettings()
///- Initialize Battlegrounds
sLog.outString("Starting BattleGround System");
sBattleGroundMgr.CreateInitialBattleGrounds();
sBattleGroundMgr.InitAutomaticArenaPointDistribution();
///- Initialize Outdoor PvP
sLog.outString("Starting Outdoor PvP System");
@ -1393,6 +1396,9 @@ void World::SetInitialWorldSettings()
sLog.outString("Deleting expired bans...");
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
sLog.outString("Calculate next currency reset time...");
InitCurrencyResetTime();
sLog.outString("Calculate next daily quest reset time...");
InitDailyQuestResetTime();
@ -1494,6 +1500,10 @@ void World::Update(uint32 diff)
if (m_gameTime > m_NextMonthlyQuestReset)
ResetMonthlyQuests();
/// Handle monthly quests reset time
if (m_gameTime > m_NextCurrencyReset)
ResetCurrencyWeekCounts();
/// <ul><li> Handle auctions when the timer has passed
if (m_timers[WUPDATE_AUCTIONS].Passed())
{
@ -2132,6 +2142,44 @@ void World::SetMonthlyQuestResetTime(bool initialize)
CharacterDatabase.PExecute("UPDATE saved_variables SET NextMonthlyQuestResetTime = '" UI64FMTD "'", uint64(m_NextMonthlyQuestReset));
}
void World::InitCurrencyResetTime()
{
QueryResult* result = CharacterDatabase.Query("SELECT `NextCurrenciesResetTime` FROM `saved_variables`");
if (!result)
m_NextCurrencyReset = time_t(time(NULL)); // game time not yet init
else
m_NextCurrencyReset = time_t((*result)[0].GetUInt64());
// re-init case or not exists
if (!m_NextCurrencyReset)
{
// generate time by config
time_t curTime = time(NULL);
tm localTm = *localtime(&curTime);
int week_day_offset = localTm.tm_wday - int(getConfig(CONFIG_UINT32_CURRENCY_RESET_TIME_WEEK_DAY));
// current week reset time
localTm.tm_hour = getConfig(CONFIG_UINT32_CURRENCY_RESET_TIME_HOUR);
localTm.tm_min = 0;
localTm.tm_sec = 0;
time_t nextWeekResetTime = mktime(&localTm);
nextWeekResetTime -= week_day_offset * DAY;
// next reset time before current moment
if (curTime >= nextWeekResetTime)
nextWeekResetTime += getConfig(CONFIG_UINT32_CURRENCY_RESET_INTERVAL) * DAY;
// normalize reset time
m_NextCurrencyReset = m_NextCurrencyReset < curTime ? nextWeekResetTime - getConfig(CONFIG_UINT32_CURRENCY_RESET_INTERVAL) * DAY : nextWeekResetTime;
}
if (!result)
CharacterDatabase.PExecute("INSERT INTO `saved_variables` (`NextCurrenciesResetTime`) VALUES ('" UI64FMTD "')", uint64(m_NextCurrencyReset));
else
delete result;
}
void World::ResetDailyQuests()
{
DETAIL_LOG("Daily quests reset for all characters.");
@ -2168,6 +2216,29 @@ void World::ResetMonthlyQuests()
SetMonthlyQuestResetTime(false);
}
void World::ResetCurrencyWeekCounts()
{
CharacterDatabase.Execute("UPDATE `character_currencies` SET `weekCount` = 0");
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
if (itr->second->GetPlayer())
itr->second->GetPlayer()->ResetCurrencyWeekCounts();
for(ObjectMgr::ArenaTeamMap::iterator titr = sObjectMgr.GetArenaTeamMapBegin(); titr != sObjectMgr.GetArenaTeamMapEnd(); ++titr)
{
if (ArenaTeam * at = titr->second)
{
at->FinishWeek(); // set played this week etc values to 0 in memory, too
at->SaveToDB(); // save changes
at->NotifyStatsChanged(); // notify the players of the changes
}
}
m_NextCurrencyReset = time_t(m_NextCurrencyReset + DAY * sWorld.getConfig(CONFIG_UINT32_CURRENCY_RESET_INTERVAL));
CharacterDatabase.PExecute("UPDATE saved_variables SET `NextCurrenciesResetTime` = '" UI64FMTD "'", uint64(m_NextCurrencyReset));
}
void World::SetPlayerLimit(int32 limit, bool needUpdate)
{
if (limit < -SEC_ADMINISTRATOR)