Honor flush and GetDateToday() method fix

This commit is contained in:
stormrage-project 2015-09-02 20:22:33 +02:00 committed by Antz
parent 1e7d9cc605
commit 6acf9c9d66
4 changed files with 30 additions and 20 deletions

View File

@ -2638,7 +2638,7 @@ void ObjectMgr::LoadStandingList(uint32 dateBegin)
Field* fields = NULL; Field* fields = NULL;
QueryResult* result2 = NULL; QueryResult* result2 = NULL;
// this query create an ordered standing list // this query create an ordered standing list
QueryResult* result = CharacterDatabase.PQuery("SELECT guid,SUM(honor) as honor_sum FROM character_honor_cp WHERE TYPE = %u AND date BETWEEN %u AND %u GROUP BY guid ORDER BY honor_sum DESC", HONORABLE, dateBegin, dateBegin + 7); QueryResult* result = CharacterDatabase.PQuery("SELECT guid,SUM(honor) as honor_sum FROM character_honor_cp WHERE TYPE = %u AND date BETWEEN %u AND %u AND used=0 GROUP BY guid ORDER BY honor_sum DESC", HONORABLE, dateBegin, dateBegin + 7);
if (result) if (result)
{ {
BarGoLink bar(result->GetRowCount()); BarGoLink bar(result->GetRowCount());
@ -2651,7 +2651,7 @@ void ObjectMgr::LoadStandingList(uint32 dateBegin)
kills = 0; kills = 0;
// kills count with victim setted ( not zero value ) // kills count with victim setted ( not zero value )
result2 = CharacterDatabase.PQuery("SELECT COUNT(*) FROM character_honor_cp WHERE guid = %u AND victim>0 AND TYPE = %u AND date BETWEEN %u AND %u", guid, HONORABLE, dateBegin, dateBegin + 7); result2 = CharacterDatabase.PQuery("SELECT COUNT(*) FROM character_honor_cp WHERE guid = %u AND victim>0 AND TYPE = %u AND date BETWEEN %u AND %u AND used=0", guid, HONORABLE, dateBegin, dateBegin + 7);
if (result2) if (result2)
{ kills = result2->Fetch()->GetUInt32(); } { kills = result2->Fetch()->GetUInt32(); }
@ -2695,11 +2695,10 @@ void ObjectMgr::LoadStandingList()
sLog.outString(">> Loaded %lu Horde and %lu Ally honor standing definitions", HordeHonorStandingList.size(), AllyHonorStandingList.size()); sLog.outString(">> Loaded %lu Horde and %lu Ally honor standing definitions", HordeHonorStandingList.size(), AllyHonorStandingList.size());
} }
void ObjectMgr::FlushRankPoints(uint32 dateTop) void ObjectMgr::FlushRankPoints(uint32 dateTop)
{ {
// FLUSH CP // FLUSH CP
QueryResult* result = CharacterDatabase.PQuery("SELECT date FROM character_honor_cp WHERE TYPE = %u AND date <= %u GROUP BY date ORDER BY date DESC", HONORABLE, dateTop); QueryResult* result = CharacterDatabase.PQuery("SELECT date FROM character_honor_cp WHERE TYPE = %u AND date <= %u AND used=0 GROUP BY date ORDER BY date DESC", HONORABLE, dateTop);
if (result) if (result)
{ {
uint32 date; uint32 date;
@ -2721,21 +2720,25 @@ void ObjectMgr::FlushRankPoints(uint32 dateTop)
{ {
LoadStandingList(WeekBegin); LoadStandingList(WeekBegin);
flush = WeekBegin < dateTop - 7; // flush only with date < lastweek flush = WeekBegin <= dateTop - 7; // flush only with date < lastweek
DistributeRankPoints(ALLIANCE, WeekBegin, flush); DistributeRankPoints(ALLIANCE, WeekBegin, flush);
DistributeRankPoints(HORDE, WeekBegin, flush); DistributeRankPoints(HORDE, WeekBegin, flush);
WeekBegin += 7; WeekBegin += 7;
} }
delete result;
} }
// FLUSH KILLS // FLUSH KILLS
CharacterDatabase.BeginTransaction(); static SqlStatementID updHonorable;
static SqlStatementID updDishonorable;
// process only HK ( victim_type > 0 ) // process only HK ( victim_type > 0 )
result = CharacterDatabase.PQuery("SELECT guid,TYPE,COUNT(*) AS kills FROM character_honor_cp WHERE date <= %u AND victim_type>0 GROUP BY guid,type", dateTop - 7); result = CharacterDatabase.PQuery("SELECT guid,TYPE,COUNT(*) AS kills FROM character_honor_cp WHERE date <= %u AND victim_type>0 AND used=0 GROUP BY guid,type", dateTop - 7);
if (result) if (result)
{ {
CharacterDatabase.BeginTransaction();
uint32 guid, kills; uint32 guid, kills;
uint8 type; uint8 type;
Field* fields = NULL; Field* fields = NULL;
@ -2747,21 +2750,28 @@ void ObjectMgr::FlushRankPoints(uint32 dateTop)
kills = fields[2].GetUInt32(); kills = fields[2].GetUInt32();
if (type == HONORABLE) if (type == HONORABLE)
{ CharacterDatabase.PExecute("UPDATE characters SET stored_honorable_kills = stored_honorable_kills + %u WHERE guid = %u", kills, guid); } {
SqlStatement stmt = CharacterDatabase.CreateStatement(updHonorable, "UPDATE characters SET stored_honorable_kills = stored_honorable_kills + %u WHERE guid = %u");
stmt.PExecute(kills, guid);
}
else if (type == DISHONORABLE) else if (type == DISHONORABLE)
{ CharacterDatabase.PExecute("UPDATE characters SET stored_dishonorable_kills = stored_dishonorable_kills + %u WHERE guid = %u", kills, guid); } {
SqlStatement stmt = CharacterDatabase.CreateStatement(updDishonorable, "UPDATE characters SET stored_dishonorable_kills = stored_dishonorable_kills + %u WHERE guid = %u");
stmt.PExecute(kills, guid);
}
} }
while (result->NextRow()); while (result->NextRow());
}
// cleanin ALL cp before dateTop // cleaning ALL cp before dateTop
CharacterDatabase.PExecute("DELETE FROM character_honor_cp WHERE date <= %u", dateTop - 7); CharacterDatabase.PExecute("DELETE FROM character_honor_cp WHERE date <= %u", dateTop - 7);
CharacterDatabase.CommitTransaction(); CharacterDatabase.CommitTransaction();
delete result;
}
else
CharacterDatabase.PExecute("DELETE FROM character_honor_cp WHERE date <= %u AND used=1", dateTop - 7);
sLog.outString(); sLog.outString();
sLog.outString(">> Flushed all ranking points"); sLog.outString(">> Flushed all ranking points");
delete result;
} }
void ObjectMgr::DistributeRankPoints(uint32 team, uint32 dateBegin , bool flush /*false*/) void ObjectMgr::DistributeRankPoints(uint32 team, uint32 dateBegin , bool flush /*false*/)
@ -2795,7 +2805,7 @@ void ObjectMgr::DistributeRankPoints(uint32 team, uint32 dateBegin , bool flush
if (flush) if (flush)
{ {
CharacterDatabase.BeginTransaction(); CharacterDatabase.BeginTransaction();
CharacterDatabase.PExecute("DELETE FROM character_honor_cp WHERE guid = %u AND TYPE = %u AND date BETWEEN %u AND %u", itr->guid, HONORABLE, dateBegin, dateBegin + 7); CharacterDatabase.PExecute("UPDATE character_honor_cp SET used=1 WHERE guid = %u AND TYPE = %u AND date BETWEEN %u AND %u", itr->guid, HONORABLE, dateBegin, dateBegin + 7);
CharacterDatabase.PExecute("UPDATE characters SET stored_honor_rating = %f , stored_honorable_kills = %u WHERE guid = %u", finiteAlways(RP + itr->rpEarning), HK + itr->honorKills, itr->guid); CharacterDatabase.PExecute("UPDATE characters SET stored_honor_rating = %f , stored_honorable_kills = %u WHERE guid = %u", finiteAlways(RP + itr->rpEarning), HK + itr->honorKills, itr->guid);
CharacterDatabase.CommitTransaction(); CharacterDatabase.CommitTransaction();
} }

View File

@ -110,7 +110,7 @@ bool LoginQueryHolder::Initialize()
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS, "SELECT caster_guid,item_guid,spell,stackcount,remaincharges,basepoints0,basepoints1,basepoints2,periodictime0,periodictime1,periodictime2,maxduration,remaintime,effIndexMask FROM character_aura WHERE guid = '%u'", m_guid.GetCounter()); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS, "SELECT caster_guid,item_guid,spell,stackcount,remaincharges,basepoints0,basepoints1,basepoints2,periodictime0,periodictime1,periodictime2,maxduration,remaintime,effIndexMask FROM character_aura WHERE guid = '%u'", m_guid.GetCounter());
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS, "SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'", m_guid.GetCounter()); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS, "SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'", m_guid.GetCounter());
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS, "SELECT quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4 FROM character_queststatus WHERE guid = '%u'", m_guid.GetCounter()); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS, "SELECT quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4 FROM character_queststatus WHERE guid = '%u'", m_guid.GetCounter());
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADHONORCP, "SELECT victim_type,victim,honor,date,type FROM character_honor_cp WHERE guid = '%u'", m_guid.GetCounter()); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADHONORCP, "SELECT victim_type,victim,honor,date,type FROM character_honor_cp WHERE used=0 AND guid = '%u'", m_guid.GetCounter());
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", m_guid.GetCounter()); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", m_guid.GetCounter());
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY, "SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", m_guid.GetCounter()); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY, "SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", m_guid.GetCounter());
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADITEMLOOT, "SELECT guid,itemid,amount,property FROM item_loot WHERE owner_guid = '%u'", m_guid.GetCounter()); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADITEMLOOT, "SELECT guid,itemid,amount,property FROM item_loot WHERE owner_guid = '%u'", m_guid.GetCounter());

View File

@ -500,7 +500,7 @@ class World
uint32 GetUptime() const { return uint32(m_gameTime - m_startTime); } uint32 GetUptime() const { return uint32(m_gameTime - m_startTime); }
tm* GetLocalTimeByTime(time_t now) const { return localtime(&now); } tm* GetLocalTimeByTime(time_t now) const { return localtime(&now); }
uint32 GetDateByLocalTime(tm* now) const { return ((uint32)(now->tm_year << 16) | (uint32)(now->tm_yday)); } uint32 GetDateByLocalTime(tm* now) const { return uint32(now->tm_year*365 + (now->tm_year-1)/4 + now->tm_yday); }
uint32 GetDateToday() const { return GetDateByLocalTime(GetLocalTimeByTime(m_gameTime)); } uint32 GetDateToday() const { return GetDateByLocalTime(GetLocalTimeByTime(m_gameTime)); }
uint32 GetDateThisWeekBegin() const { return GetDateToday() - GetLocalTimeByTime(m_gameTime)->tm_wday; } uint32 GetDateThisWeekBegin() const { return GetDateToday() - GetLocalTimeByTime(m_gameTime)->tm_wday; }
uint32 GetDateLastMaintenanceDay() const uint32 GetDateLastMaintenanceDay() const

View File

@ -32,9 +32,9 @@
#define REALMD_DB_UPDATE_DESCRIPTION "revision_refactor" #define REALMD_DB_UPDATE_DESCRIPTION "revision_refactor"
#define CHAR_DB_VERSION_NR 21 #define CHAR_DB_VERSION_NR 21
#define CHAR_DB_STRUCTURE_NR 1 #define CHAR_DB_STRUCTURE_NR 2
#define CHAR_DB_CONTENT_NR 0 #define CHAR_DB_CONTENT_NR 0
#define CHAR_DB_UPDATE_DESCRIPTION "revision_refactor" #define CHAR_DB_UPDATE_DESCRIPTION "honor_counting"
#define WORLD_DB_VERSION_NR 21 #define WORLD_DB_VERSION_NR 21
#define WORLD_DB_STRUCTURE_NR 1 #define WORLD_DB_STRUCTURE_NR 1