Core/LFG: added new field to lfg_dungeon_rewards to specify if the first reward shall reset weekly or daily

This commit is contained in:
Ovahlord
2018-04-18 20:44:39 +02:00
parent d2acd68c67
commit 65bb5690a8
11 changed files with 101 additions and 48 deletions

View File

@@ -3,5 +3,6 @@ CREATE TABLE `character_rewardstatus_lfg`(
`guid` INT(10) NOT NULL DEFAULT 0 COMMENT 'Global Unique Identifier',
`dungeonId` SMALLINT(3) NOT NULL DEFAULT 0 COMMENT 'Dungeon ID Identifier',
`rewardCount` TINYINT(3) UNSIGNED DEFAULT 0 COMMENT 'Dungeon First Reward Count Identifier',
`dailyReset` TINYINT(1) UNSIGNED DEFAULT 0 COMMENT 'Reward Count Daily Reset Identifier',
PRIMARY KEY (`dungeonId`)
);

View File

@@ -1,8 +1,10 @@
ALTER TABLE `lfg_dungeon_rewards` ADD COLUMN `completionsPerWeek` TINYINT(3) UNSIGNED DEFAULT 0 NULL COMMENT 'Maximum amount that the first quest may be rewarded' AFTER `otherQuestId`;
ALTER TABLE `lfg_dungeon_rewards` ADD COLUMN `completionsPerPeriod` TINYINT(3) UNSIGNED DEFAULT 0 NULL COMMENT 'Maximum amount that the first quest may be rewarded' AFTER `otherQuestId`;
ALTER TABLE `lfg_dungeon_rewards` ADD COLUMN `dailyReset` TINYINT(1) UNSIGNED DEFAULT 0 NULL COMMENT 'Indicator for resetting rewards daily or weekly' AFTER `completionsPerPeriod`;
UPDATE `quest_template` SET `RewardCurrencyId1`= 0, `RewardCurrencyCount1`= 0 WHERE `ID` = 28908;
UPDATE `quest_template` SET `RewardCurrencyCount1`= 14000 WHERE `ID` = 28907;
UPDATE `quest_template` SET `Flags`= 0 WHERE `ID`= 30110;
UPDATE `lfg_dungeon_rewards` SET `completionsPerWeek`= 7 WHERE `dungeonId` NOT IN (417, 416, 434, 301);
UPDATE `lfg_dungeon_rewards` SET `completionsPerWeek`= 1 WHERE `dungeonId` IN (417, 416);
UPDATE `lfg_dungeon_rewards` SET `completionsPerPeriod`= 7 WHERE `dungeonId` NOT IN (417, 416, 434, 301);
UPDATE `lfg_dungeon_rewards` SET `completionsPerPeriod`= 1 WHERE `dungeonId` IN (417, 416);
UPDATE `lfg_dungeon_rewards` SET `completionsPerPeriod`= 1, `dailyReset`= 1 WHERE `dungeonId` IN (288, 287, 286, 285);

View File

@@ -93,10 +93,11 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_DEL_RESET_CHARACTER_QUESTSTATUS_MONTHLY, "DELETE FROM character_queststatus_monthly", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_RESET_CHARACTER_QUESTSTATUS_SEASONAL_BY_EVENT, "DELETE FROM character_queststatus_seasonal WHERE event = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_SEL_CHARACTER_REWARDSTATUS_LFG, "SELECT dungeonId, rewardCount FROM character_rewardstatus_lfg WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_SEL_CHARACTER_REWARDSTATUS_LFG, "SELECT dungeonId, rewardCount, dailyReset FROM character_rewardstatus_lfg WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_CHARACTER_REWARDSTATUS_LFG, "DELETE FROM character_rewardstatus_lfg WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_INS_CHARACTER_REWARDSTATUS_LFG, "INSERT INTO character_rewardstatus_lfg (guid, dungeonId, rewardCount) VALUES (?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG, "DELETE FROM character_rewardstatus_lfg", CONNECTION_ASYNC);
PrepareStatement(CHAR_INS_CHARACTER_REWARDSTATUS_LFG, "INSERT INTO character_rewardstatus_lfg (guid, dungeonId, rewardCount, dailyReset) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG_WEEKLY, "DELETE FROM character_rewardstatus_lfg WHERE dailyReset = 0", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG_DAILY, "DELETE FROM character_rewardstatus_lfg WHERE dailyReset = 1", CONNECTION_ASYNC);
PrepareStatement(CHAR_SEL_CHARACTER_REPUTATION, "SELECT faction, standing, flags FROM character_reputation WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_SEL_CHARACTER_INVENTORY, "SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, bag, slot, "

View File

@@ -85,7 +85,8 @@ enum CharacterDatabaseStatements : uint32
CHAR_SEL_CHARACTER_REWARDSTATUS_LFG,
CHAR_DEL_CHARACTER_REWARDSTATUS_LFG,
CHAR_INS_CHARACTER_REWARDSTATUS_LFG,
CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG,
CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG_WEEKLY,
CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG_DAILY,
CHAR_SEL_CHARACTER_REPUTATION,
CHAR_SEL_CHARACTER_INVENTORY,

View File

@@ -124,7 +124,7 @@ void LFGMgr::LoadRewards()
RewardMapStore.clear();
// ORDER BY is very important for GetRandomDungeonReward!
QueryResult result = WorldDatabase.Query("SELECT dungeonId, maxLevel, firstQuestId, otherQuestId, completionsPerWeek FROM lfg_dungeon_rewards ORDER BY dungeonId, maxLevel ASC");
QueryResult result = WorldDatabase.Query("SELECT dungeonId, maxLevel, firstQuestId, otherQuestId, completionsPerPeriod, dailyReset FROM lfg_dungeon_rewards ORDER BY dungeonId, maxLevel ASC");
if (!result)
{
@@ -142,7 +142,8 @@ void LFGMgr::LoadRewards()
uint32 maxLevel = fields[1].GetUInt8();
uint32 firstQuestId = fields[2].GetUInt32();
uint32 otherQuestId = fields[3].GetUInt32();
uint32 completionsPerWeek = fields[4].GetUInt8();
uint32 completionsPerPeriod = fields[4].GetUInt8();
bool dailyReset = fields[5].GetUInt8();
if (!GetLFGDungeonEntry(dungeonId))
{
@@ -168,7 +169,7 @@ void LFGMgr::LoadRewards()
otherQuestId = 0;
}
RewardMapStore.insert(LfgRewardContainer::value_type(dungeonId, new LfgReward(maxLevel, firstQuestId, otherQuestId, completionsPerWeek)));
RewardMapStore.insert(LfgRewardContainer::value_type(dungeonId, new LfgReward(maxLevel, firstQuestId, otherQuestId, completionsPerPeriod, dailyReset)));
++count;
}
while (result->NextRow());
@@ -1498,11 +1499,11 @@ void LFGMgr::FinishDungeon(ObjectGuid gguid, const uint32 dungeonId, Map const*
if (!quest)
continue;
// CanRewardQuest to check currency caps, SatisfyFirstLFGReward to check weekly reward caps for first quest
if (player->CanRewardQuest(quest, false) && player->SatisfyFirstLFGReward(rDungeonId, reward->completionsPerWeek))
// CanRewardQuest to check currency caps, SatisfyFirstLFGReward to check weekly/daily reward caps for first quest
if (player->CanRewardQuest(quest, false) && player->SatisfyFirstLFGReward(rDungeonId, reward->completionsPerPeriod))
{
if (reward->completionsPerWeek)
player->SetLFGRewardStatus(rDungeonId);
if (reward->completionsPerPeriod)
player->SetLFGRewardStatus(rDungeonId, reward->dailyReset);
player->RewardQuest(quest, 0, nullptr, false);
}

View File

@@ -220,13 +220,14 @@ struct LfgPlayerRewardData
/// Reward info
struct LfgReward
{
LfgReward(uint32 _maxLevel = 0, uint32 _firstQuest = 0, uint32 _otherQuest = 0, uint8 _completionsPerWeek = 0):
maxLevel(_maxLevel), firstQuest(_firstQuest), otherQuest(_otherQuest), completionsPerWeek(_completionsPerWeek) { }
LfgReward(uint32 _maxLevel = 0, uint32 _firstQuest = 0, uint32 _otherQuest = 0, uint8 _completionsPerPeriod = 0, bool _dailyReset = 0):
maxLevel(_maxLevel), firstQuest(_firstQuest), otherQuest(_otherQuest), completionsPerPeriod(_completionsPerPeriod), dailyReset(_dailyReset) { }
uint32 maxLevel;
uint32 firstQuest;
uint32 otherQuest;
uint8 completionsPerWeek;
uint8 completionsPerPeriod;
bool dailyReset;
};
/// Stores player data related to proposal to join

View File

@@ -16107,7 +16107,7 @@ bool Player::SatisfyFirstLFGReward(uint32 dungeonId, uint8 maxRewCount) const
{
LFGRewardStatusMap::const_iterator lfgdungeon = m_lfgrewardstatus.find(dungeonId);
if (lfgdungeon != m_lfgrewardstatus.end())
return lfgdungeon->second && lfgdungeon->second < maxRewCount;
return lfgdungeon->second.completionsThisPeriod && lfgdungeon->second.completionsThisPeriod < maxRewCount;
return true;
}
@@ -16116,7 +16116,7 @@ uint8 Player::GetFirstRewardCountForDungeonId(uint32 dungeonId)
{
LFGRewardStatusMap::const_iterator lfgdungeon = m_lfgrewardstatus.find(dungeonId);
if (lfgdungeon != m_lfgrewardstatus.end())
return lfgdungeon->second;
return lfgdungeon->second.completionsThisPeriod;
return 0;
}
@@ -19034,8 +19034,9 @@ void Player::_LoadLFGRewardStatus(PreparedQueryResult result)
Field* fields = result->Fetch();
uint32 dungeon_id = fields[0].GetUInt16();
uint8 reward_count = fields[1].GetUInt8();
uint8 daily_reset = fields[2].GetUInt8();
m_lfgrewardstatus[dungeon_id] = reward_count;
m_lfgrewardstatus[dungeon_id] = LFGRewardInfo(reward_count, daily_reset);
TC_LOG_DEBUG("entities.player.loading", "Player::_LFGQuestStatus: Loaded LFG quest first reward cooldown (DungeonID: %u) for player '%s' (%s)",
dungeon_id, GetName().c_str(), GetGUID().ToString().c_str());
} while (result->NextRow());
@@ -20554,12 +20555,14 @@ void Player::_SaveLFGRewardStatus(SQLTransaction& trans)
for (LFGRewardStatusMap::const_iterator itr = m_lfgrewardstatus.begin(); itr != m_lfgrewardstatus.end(); ++itr)
{
uint32 dungeonId = itr->first;
uint8 rewardCount = itr->second;
uint8 rewardCount = itr->second.completionsThisPeriod;
uint8 dailyReset = itr->second.isDaily;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHARACTER_REWARDSTATUS_LFG);
stmt->setUInt32(0, GetGUID().GetCounter());
stmt->setUInt32(1, dungeonId);
stmt->setUInt32(2, rewardCount);
stmt->setUInt8(2, rewardCount);
stmt->setUInt8(3, dailyReset);
trans->Append(stmt);
}
@@ -24155,14 +24158,14 @@ void Player::SetMonthlyQuestStatus(uint32 quest_id)
m_MonthlyQuestChanged = true;
}
void Player::SetLFGRewardStatus(uint32 dungeon_id)
void Player::SetLFGRewardStatus(uint32 dungeon_id, bool daily_reset)
{
LFGRewardStatusMap::iterator lfgdungeon = m_lfgrewardstatus.find(dungeon_id);
if (lfgdungeon != m_lfgrewardstatus.end())
lfgdungeon->second++;
lfgdungeon->second.completionsThisPeriod++;
else
m_lfgrewardstatus[dungeon_id] = 1;
m_lfgrewardstatus[dungeon_id] = LFGRewardInfo(1, daily_reset);
m_LFGRewardStatusChanged = true;
}
@@ -24208,12 +24211,34 @@ void Player::ResetMonthlyQuestStatus()
m_MonthlyQuestChanged = false;
}
void Player::ResetLFGRewardStatus()
void Player::ResetWeeklyLFGRewardStatus()
{
if (!m_lfgrewardstatus.empty())
return;
for (auto itr = m_lfgrewardstatus.begin(); itr != m_lfgrewardstatus.end();)
{
if (!itr->second.isDaily)
{
itr = m_lfgrewardstatus.erase(itr);
continue;
}
itr++;
}
// DB data deleted in caller
m_LFGRewardStatusChanged = false;
}
void Player::ResetDailyLFGRewardStatus()
{
for (auto itr = m_lfgrewardstatus.begin(); itr != m_lfgrewardstatus.end();)
{
if (itr->second.isDaily)
{
itr = m_lfgrewardstatus.erase(itr);
continue;
}
itr++;
}
m_lfgrewardstatus.clear();
// DB data deleted in caller
m_LFGRewardStatusChanged = false;
}

View File

@@ -1394,12 +1394,13 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void SetWeeklyQuestStatus(uint32 quest_id);
void SetMonthlyQuestStatus(uint32 quest_id);
void SetSeasonalQuestStatus(uint32 quest_id);
void SetLFGRewardStatus(uint32 dungeon_id);
void SetLFGRewardStatus(uint32 dungeon_id, bool daily_reset);
void ResetDailyQuestStatus();
void ResetWeeklyQuestStatus();
void ResetMonthlyQuestStatus();
void ResetSeasonalQuestStatus(uint16 event_id);
void ResetLFGRewardStatus();
void ResetWeeklyLFGRewardStatus();
void ResetDailyLFGRewardStatus();
uint16 FindQuestSlot(uint32 quest_id) const;
uint32 GetQuestSlotQuestId(uint16 slot) const;
@@ -2402,7 +2403,17 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
typedef std::set<uint32> QuestSet;
typedef std::set<uint32> SeasonalQuestSet;
typedef std::unordered_map<uint32, SeasonalQuestSet> SeasonalEventQuestMap;
typedef std::unordered_map<uint32, uint8> LFGRewardStatusMap;
struct LFGRewardInfo
{
LFGRewardInfo(uint8 _completionsThisPeriod = 0, bool _isDaily = false) :
completionsThisPeriod(_completionsThisPeriod), isDaily(_isDaily) { }
uint8 completionsThisPeriod;
bool isDaily;
};
typedef std::unordered_map<uint32, LFGRewardInfo> LFGRewardStatusMap;
QuestSet m_timedquests;
QuestSet m_weeklyquests;

View File

@@ -324,8 +324,8 @@ void WorldSession::SendLfgPlayerLockInfo()
if (Quest const* firstQuest = sObjectMgr->GetQuestTemplate(reward->firstQuest))
{
firstCompletion = player->CanRewardQuest(firstQuest, false);
if (reward->completionsPerWeek)
firstCompletion = player->SatisfyFirstLFGReward(dungeonId & 0x00FFFFFF, reward->completionsPerWeek);
if (reward->completionsPerPeriod)
firstCompletion = player->SatisfyFirstLFGReward(dungeonId & 0x00FFFFFF, reward->completionsPerPeriod);
if (firstCompletion)
currentQuest = firstQuest;
@@ -350,7 +350,7 @@ void WorldSession::SendLfgPlayerLockInfo()
CurrencyTypesEntry const* currency = sCurrencyTypesStore.LookupEntry(CURRENCY_TYPE_VALOR_POINTS);
if (currency && rewValorPoints && !reward->completionsPerWeek)
if (currency && rewValorPoints && !reward->completionsPerPeriod)
{
data << uint32(rewValorPoints); // currencyQuantity (valor points from selected dungeon)
data << uint32(player->GetCurrencyWeekCap(currency)); // some sort of overall cap/weekly cap
@@ -365,15 +365,15 @@ void WorldSession::SendLfgPlayerLockInfo()
data << uint32(0); // purseLimit
data << uint32(rewValorPoints); // some sort of reward for completion
}
else if (firstCompletion && reward && reward->completionsPerWeek)
else if (firstCompletion && reward && reward->completionsPerPeriod && !reward->dailyReset)
{
data << uint32(1); // currencyQuantity
data << uint32(reward->completionsPerWeek); // some sort of overall cap/weekly cap
data << uint32(reward->completionsPerPeriod); // some sort of overall cap/weekly cap
data << uint32(0); // currencyID
data << uint32(0); // tier1Quantity
data << uint32(reward->completionsPerWeek); // tier1Limit
data << uint32(reward->completionsPerPeriod); // tier1Limit
data << uint32(player->GetFirstRewardCountForDungeonId(dungeonId & 0x00FFFFFF)); // overallQuantity
data << uint32(reward->completionsPerWeek); // overallLimit
data << uint32(reward->completionsPerPeriod); // overallLimit
data << uint32(0); // periodPurseQuantity
data << uint32(0); // periodPurseLimit
data << uint32(0); // purseQuantity
@@ -400,7 +400,7 @@ void WorldSession::SendLfgPlayerLockInfo()
bool isCallToArmsEligible = sLFGMgr->IsCallToArmsEligible(level, dungeonId & 0x00FFFFFF);
data << uint8(isCallToArmsEligible); // Call to Arms eligible
data << uint8(isCallToArmsEligible); // Call to Arms eligible
Quest const* ctaQuest = sObjectMgr->GetQuestTemplate(lfg::LFG_CALL_TO_ARMS_QUEST);
if (isCallToArmsEligible && ctaQuest)

View File

@@ -2194,7 +2194,7 @@ void World::Update(uint32 diff)
/// Handle daily quests reset time
if (currentGameTime > m_NextDailyQuestReset)
{
ResetDailyQuests();
ResetDailyQuestsAndRewards();
InitDailyQuestResetTime(false);
}
@@ -3158,16 +3158,26 @@ void World::InitCurrencyResetTime()
sWorld->setWorldState(WS_CURRENCY_RESET_TIME, uint64(m_NextCurrencyReset));
}
void World::ResetDailyQuests()
void World::ResetDailyQuestsAndRewards()
{
TC_LOG_INFO("misc", "Daily quests reset for all characters.");
TC_LOG_INFO("misc", "Daily quests and rewards reset for all characters.");
// Reset daily quest status
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RESET_CHARACTER_QUESTSTATUS_DAILY);
CharacterDatabase.Execute(stmt);
// Reset daily lfg rewards
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG_DAILY);
CharacterDatabase.Execute(stmt);
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
{
if (itr->second->GetPlayer())
{
itr->second->GetPlayer()->ResetDailyQuestStatus();
itr->second->GetPlayer()->ResetDailyLFGRewardStatus();
}
}
// change available dailies
sPoolMgr->ChangeDailyQuests();
@@ -3208,12 +3218,12 @@ void World::ResetWeeklyQuestsAndRewards()
{
TC_LOG_INFO("misc", "Weekly quests and rewards reset for all characters.");
// Reset Weekly quests
// Reset weekly quests
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RESET_CHARACTER_QUESTSTATUS_WEEKLY);
CharacterDatabase.Execute(stmt);
// Reset Weekly lfg rewards
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG);
// Reset weekly lfg rewards
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_RESET_CHARACTER_REWARDSTATUS_LFG_WEEKLY);
CharacterDatabase.Execute(stmt);
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
@@ -3221,7 +3231,7 @@ void World::ResetWeeklyQuestsAndRewards()
if (itr->second->GetPlayer())
{
itr->second->GetPlayer()->ResetWeeklyQuestStatus();
itr->second->GetPlayer()->ResetLFGRewardStatus();
itr->second->GetPlayer()->ResetWeeklyLFGRewardStatus();
}
}

View File

@@ -821,7 +821,7 @@ class TC_GAME_API World
void InitRandomBGResetTime();
void InitGuildResetTime();
void InitCurrencyResetTime();
void ResetDailyQuests();
void ResetDailyQuestsAndRewards();
void ResetWeeklyQuestsAndRewards();
void ResetMonthlyQuests();
void ResetRandomBG();