[10655] Add support for monthly quests

Quest that can repeated each month are set by quest_template.SpecialFlags |0x04 flag
Quest are reset at midnight the first day of each month.
Note: for the time being, quest must also be set repeatable (SpecialFlags |0x01)

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-10-29 20:38:09 +02:00
parent 331a7e7f5b
commit a38f97f71c
12 changed files with 218 additions and 13 deletions

View file

@ -13275,7 +13275,8 @@ bool Player::CanSeeStartQuest(Quest const *pQuest) const
if (SatisfyQuestClass(pQuest, false) && SatisfyQuestRace(pQuest, false) && SatisfyQuestSkill(pQuest, false) &&
SatisfyQuestExclusiveGroup(pQuest, false) && SatisfyQuestReputation(pQuest, false) &&
SatisfyQuestPreviousQuest(pQuest, false) && SatisfyQuestNextChain(pQuest, false) &&
SatisfyQuestPrevChain(pQuest, false) && SatisfyQuestDay(pQuest, false) && SatisfyQuestWeek(pQuest, false))
SatisfyQuestPrevChain(pQuest, false) && SatisfyQuestDay(pQuest, false) && SatisfyQuestWeek(pQuest, false) &&
SatisfyQuestMonth(pQuest, false))
{
return getLevel() + sWorld.getConfig(CONFIG_UINT32_QUEST_HIGH_LEVEL_HIDE_DIFF) >= pQuest->GetMinLevel();
}
@ -13290,7 +13291,7 @@ bool Player::CanTakeQuest(Quest const *pQuest, bool msg) const
SatisfyQuestSkill(pQuest, msg) && SatisfyQuestReputation(pQuest, msg) &&
SatisfyQuestPreviousQuest(pQuest, msg) && SatisfyQuestTimed(pQuest, msg) &&
SatisfyQuestNextChain(pQuest, msg) && SatisfyQuestPrevChain(pQuest, msg) &&
SatisfyQuestDay(pQuest, msg) && SatisfyQuestWeek(pQuest, msg);
SatisfyQuestDay(pQuest, msg) && SatisfyQuestWeek(pQuest, msg) && SatisfyQuestMonth(pQuest, msg);
}
bool Player::CanAddQuest(Quest const *pQuest, bool msg) const
@ -13409,7 +13410,7 @@ bool Player::CanRewardQuest(Quest const *pQuest, bool msg) const
return false;
// daily quest can't be rewarded (25 daily quest already completed)
if (!SatisfyQuestDay(pQuest, true) || !SatisfyQuestWeek(pQuest, true))
if (!SatisfyQuestDay(pQuest, true) || !SatisfyQuestWeek(pQuest, true) || !SatisfyQuestMonth(pQuest, true))
return false;
// rewarded and not repeatable quest (only cheating case, then ignore without message)
@ -13695,6 +13696,9 @@ void Player::RewardQuest(Quest const *pQuest, uint32 reward, Object* questGiver,
if (pQuest->IsWeekly())
SetWeeklyQuestStatus(quest_id);
if (pQuest->IsMonthly())
SetMonthlyQuestStatus(quest_id);
if (!pQuest->IsRepeatable())
SetQuestStatus(quest_id, QUEST_STATUS_COMPLETE);
else
@ -14133,6 +14137,15 @@ bool Player::SatisfyQuestWeek(Quest const* qInfo, bool msg) const
return m_weeklyquests.find(qInfo->GetQuestId()) == m_weeklyquests.end();
}
bool Player::SatisfyQuestMonth(Quest const* qInfo, bool msg) const
{
if (!qInfo->IsMonthly() || m_monthlyquests.empty())
return true;
// if not found in cooldown list
return m_monthlyquests.find(qInfo->GetQuestId()) == m_monthlyquests.end();
}
bool Player::CanGiveQuestSourceItem( Quest const *pQuest, ItemPosCountVec* dest ) const
{
uint32 srcitem = pQuest->GetSrcItemId();
@ -15458,6 +15471,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
_LoadQuestStatus(holder->GetResult(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS));
_LoadDailyQuestStatus(holder->GetResult(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS));
_LoadWeeklyQuestStatus(holder->GetResult(PLAYER_LOGIN_QUERY_LOADWEEKLYQUESTSTATUS));
_LoadMonthlyQuestStatus(holder->GetResult(PLAYER_LOGIN_QUERY_LOADMONTHLYQUESTSTATUS));
_LoadTalents(holder->GetResult(PLAYER_LOGIN_QUERY_LOADTALENTS));
@ -16291,6 +16305,36 @@ void Player::_LoadWeeklyQuestStatus(QueryResult *result)
m_WeeklyQuestChanged = false;
}
void Player::_LoadMonthlyQuestStatus(QueryResult *result)
{
m_monthlyquests.clear();
//QueryResult *result = CharacterDatabase.PQuery("SELECT quest FROM character_queststatus_weekly WHERE guid = '%u'", GetGUIDLow());
if (result)
{
do
{
Field *fields = result->Fetch();
uint32 quest_id = fields[0].GetUInt32();
Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id);
if (!pQuest)
continue;
m_monthlyquests.insert(quest_id);
DEBUG_LOG("Monthly quest {%u} cooldown for player (GUID: %u)", quest_id, GetGUIDLow());
}
while( result->NextRow() );
delete result;
}
m_MonthlyQuestChanged = false;
}
void Player::_LoadSpells(QueryResult *result)
{
//QueryResult *result = CharacterDatabase.PQuery("SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'",GetGUIDLow());
@ -16911,6 +16955,7 @@ void Player::SaveToDB()
_SaveQuestStatus();
_SaveDailyQuestStatus();
_SaveWeeklyQuestStatus();
_SaveMonthlyQuestStatus();
_SaveSpells();
_SaveSpellCooldowns();
_SaveActions();
@ -17239,6 +17284,24 @@ void Player::_SaveWeeklyQuestStatus()
m_WeeklyQuestChanged = false;
}
void Player::_SaveMonthlyQuestStatus()
{
if (!m_MonthlyQuestChanged || m_monthlyquests.empty())
return;
// we don't need transactions here.
CharacterDatabase.PExecute("DELETE FROM character_queststatus_monthly WHERE guid = '%u'", GetGUIDLow());
for (QuestSet::const_iterator iter = m_monthlyquests.begin(); iter != m_monthlyquests.end(); ++iter)
{
uint32 quest_id = *iter;
CharacterDatabase.PExecute("INSERT INTO character_queststatus_monthly (guid, quest) VALUES ('%u', '%u')", GetGUIDLow(), quest_id);
}
m_MonthlyQuestChanged = false;
}
void Player::_SaveSkills()
{
// we don't need transactions here.
@ -19941,6 +20004,12 @@ void Player::SetWeeklyQuestStatus( uint32 quest_id )
m_WeeklyQuestChanged = true;
}
void Player::SetMonthlyQuestStatus(uint32 quest_id)
{
m_monthlyquests.insert(quest_id);
m_MonthlyQuestChanged = true;
}
void Player::ResetDailyQuestStatus()
{
for(uint32 quest_daily_idx = 0; quest_daily_idx < PLAYER_MAX_DAILY_QUESTS; ++quest_daily_idx)
@ -19960,6 +20029,16 @@ void Player::ResetWeeklyQuestStatus()
m_WeeklyQuestChanged = false;
}
void Player::ResetMonthlyQuestStatus()
{
if (m_monthlyquests.empty())
return;
m_monthlyquests.clear();
// DB data deleted in caller
m_MonthlyQuestChanged = false;
}
BattleGround* Player::GetBattleGround() const
{
if(GetBattleGroundId()==0)