Skip to content

Commit 9fcb820

Browse files
committed
breaking-change: transition to using playersettings to store score
1 parent 34a883e commit 9fcb820

3 files changed

+70
-76
lines changed

src/ZoneDifficulty.h

+25-18
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,6 @@ int32 const MODE_HARD = 64;
7979
// EVENT_GROUP is used for unit->m_Events.AddEventAtOffset
8080
uint8 const EVENT_GROUP = 64;
8181

82-
int32 const TYPE_VANILLA = 1;
83-
int32 const TYPE_RAID_MC = 2;
84-
int32 const TYPE_RAID_ONY = 3;
85-
int32 const TYPE_RAID_BWL = 4;
86-
int32 const TYPE_RAID_ZG = 5;
87-
int32 const TYPE_RAID_AQ20 = 6;
88-
int32 const TYPE_RAID_AQ40 = 7;
89-
int32 const TYPE_HEROIC_TBC = 8;
90-
int32 const TYPE_RAID_T4 = 9;
91-
int32 const TYPE_RAID_T5 = 10;
92-
int32 const TYPE_RAID_T6 = 11;
93-
int32 const TYPE_HEROIC_WOTLK = 12;
94-
int32 const TYPE_RAID_T7 = 13;
95-
int32 const TYPE_RAID_T8 = 14;
96-
int32 const TYPE_RAID_T9 = 15;
97-
int32 const TYPE_RAID_T10 = 16;
98-
9982
uint32 const ITEMTYPE_MISC = 1;
10083
uint32 const ITEMTYPE_CLOTH = 2;
10184
uint32 const ITEMTYPE_LEATHER = 3;
@@ -115,6 +98,30 @@ uint32 const TARGET_PLAYER_DISTANCE = 18; // a random player within T
11598
const std::string REWARD_MAIL_SUBJECT = "Chromie's Reward for you";
11699
const std::string REWARD_MAIL_BODY = "Enjoy your new item!";
117100

101+
const std::string ModZoneDifficultyString = "mod-zone-difficulty#";
102+
103+
enum ZoneDifficultySettings
104+
{
105+
// Score settings
106+
TYPE_NONE = 0,
107+
TYPE_VANILLA = 1,
108+
TYPE_RAID_MC = 2,
109+
TYPE_RAID_ONY = 3,
110+
TYPE_RAID_BWL = 4,
111+
TYPE_RAID_ZG = 5,
112+
TYPE_RAID_AQ20 = 6,
113+
TYPE_RAID_AQ40 = 7,
114+
TYPE_HEROIC_TBC = 8,
115+
TYPE_RAID_T4 = 9,
116+
TYPE_RAID_T5 = 10,
117+
TYPE_RAID_T6 = 11,
118+
TYPE_HEROIC_WOTLK = 12,
119+
TYPE_RAID_T7 = 13,
120+
TYPE_RAID_T8 = 14,
121+
TYPE_RAID_T9 = 15,
122+
TYPE_RAID_T10 = 16
123+
};
124+
118125
class ZoneDifficulty
119126
{
120127
public:
@@ -168,7 +175,7 @@ class ZoneDifficulty
168175
typedef std::map<uint32, std::vector<ZoneDifficultyMythicmodeMapData> > ZoneDifficultyMythicmodeLootMap;
169176
ZoneDifficultyMythicmodeLootMap MythicmodeLoot;
170177
typedef std::map<uint32, std::map<uint32, uint32> > ZoneDifficultyDualUintMap;
171-
ZoneDifficultyDualUintMap MythicmodeScore;
178+
ZoneDifficultyDualUintMap MythicmodeScore; // Deprecated, to be removed.
172179
typedef std::map<uint32, std::map<uint32, std::vector<ZoneDifficultyRewardData> > > ZoneDifficultyRewardMap;
173180
ZoneDifficultyRewardMap Rewards;
174181
typedef std::map<uint32, std::vector<ZoneDifficultyHAI> > ZoneDifficultyHAIMap;

src/mod_zone_difficulty_handler.cpp

+9-23
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ ZoneDifficulty* ZoneDifficulty::instance()
2929
void ZoneDifficulty::LoadMapDifficultySettings()
3030
{
3131
if (!sZoneDifficulty->IsEnabled)
32-
{
3332
return;
34-
}
3533

3634
sZoneDifficulty->Rewards.clear();
3735
sZoneDifficulty->MythicmodeAI.clear();
@@ -155,7 +153,7 @@ void ZoneDifficulty::LoadMapDifficultySettings()
155153
do
156154
{
157155
std::vector<uint32> debuffs;
158-
uint32 mapId;
156+
uint32 mapId = 0;
159157
if ((*result)[2].Get<bool>())
160158
{
161159
std::string spellString = (*result)[1].Get<std::string>();
@@ -165,19 +163,13 @@ void ZoneDifficulty::LoadMapDifficultySettings()
165163
for (auto token : tokens)
166164
{
167165
if (token.empty())
168-
{
169166
continue;
170-
}
171167

172-
uint32 spell;
168+
uint32 spell = 0;
173169
if ((spell = Acore::StringTo<uint32>(token).value()))
174-
{
175170
debuffs.push_back(spell);
176-
}
177171
else
178-
{
179172
LOG_ERROR("module", "MOD-ZONE-DIFFICULTY: Disabling buffs for spell '{}' is invalid, skipped.", spell);
180-
}
181173
}
182174
sZoneDifficulty->DisallowedBuffs[mapId] = debuffs;
183175
}
@@ -402,6 +394,7 @@ void ZoneDifficulty::LoadMythicmodeScoreData()
402394

403395
} while (result->NextRow());
404396
}
397+
405398
if (QueryResult result = CharacterDatabase.Query("SELECT `Map`, `BossId`, `PlayerGuid` FROM zone_difficulty_encounter_logs WHERE `Mode` = 64"))
406399
{
407400
do
@@ -440,9 +433,7 @@ void ZoneDifficulty::SendWhisperToRaid(std::string message, Creature* creature,
440433
if (creature && player)
441434
{
442435
if (mapPlayer->IsInSameGroupWith(player))
443-
{
444436
creature->Whisper(message, LANG_UNIVERSAL, mapPlayer);
445-
}
446437
}
447438
});
448439
}
@@ -557,16 +548,10 @@ void ZoneDifficulty::AddMythicmodeScore(Map* map, uint32 type, uint32 score)
557548

558549
map->DoForAllPlayers([&](Player* player)
559550
{
560-
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) == sZoneDifficulty->MythicmodeScore.end())
561-
sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] = score;
562-
else if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(type) == sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
563-
sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] = score;
564-
else
565-
sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] + score;
566-
551+
uint32 previousScore = player->GetPlayerSetting(ModZoneDifficultyString + "score", type).value;
552+
player->UpdatePlayerSetting(ModZoneDifficultyString + "score", type, previousScore + score);
567553
std::string typestring = sZoneDifficulty->GetContentTypeString(type);
568-
ChatHandler(player->GetSession()).PSendSysMessage("You have received Mythicmode score {} New score: {}", typestring, sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type]);
569-
CharacterDatabase.Execute("REPLACE INTO zone_difficulty_mythicmode_score VALUES({}, {}, {})", player->GetGUID().GetCounter(), type, sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type]);
554+
ChatHandler(player->GetSession()).PSendSysMessage("You have received Mythicmode score {} New score: {}", typestring, previousScore + score);
570555
});
571556
}
572557

@@ -583,8 +568,9 @@ void ZoneDifficulty::DeductMythicmodeScore(Player* player, uint32 type, uint32 s
583568
{
584569
LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Reducing score with type {} from player with guid {} by {}.", type, player->GetGUID().GetCounter(), score);
585570
}
586-
sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] - score;
587-
CharacterDatabase.Execute("REPLACE INTO zone_difficulty_mythicmode_score VALUES({}, {}, {})", player->GetGUID().GetCounter(), type, sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type]);
571+
572+
uint32 val = player->GetPlayerSetting(ModZoneDifficultyString + "score", type).value - score;
573+
player->UpdatePlayerSetting(ModZoneDifficultyString + "score", type, val);
588574
}
589575

590576
/**

src/mod_zone_difficulty_scripts.cpp

+36-35
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,28 @@ class mod_zone_difficulty_playerscript : public PlayerScript
413413
}
414414
}
415415
}
416+
417+
void OnLogin(Player* player) override
418+
{
419+
if (sZoneDifficulty->MythicmodeScore.empty())
420+
return;
421+
422+
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
423+
{
424+
for (int i = 1; i <= 16; ++i)
425+
{
426+
uint32 availableScore = 0;
427+
428+
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(i) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
429+
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][i];
430+
431+
player->UpdatePlayerSetting(ModZoneDifficultyString + "score", i, availableScore);
432+
}
433+
434+
sZoneDifficulty->MythicmodeScore.erase(player->GetGUID().GetCounter());
435+
CharacterDatabase.Execute("DELETE FROM zone_difficulty_mythicmode_score WHERE GUID = {}", player->GetGUID().GetCounter());
436+
}
437+
}
416438
};
417439

418440
class mod_zone_difficulty_petscript : public PetScript
@@ -607,25 +629,19 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
607629
if (action == 999999)
608630
{
609631
npcText = NPC_TEXT_SCORE;
632+
bool hasAnyScore = false;
610633
for (int i = 1; i <= 16; ++i)
611634
{
612-
std::string whisper;
613-
whisper.append("Your score is ");
614-
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) == sZoneDifficulty->MythicmodeScore.end())
635+
if (uint32 score = player->GetPlayerSetting(ModZoneDifficultyString + "score", i).value)
615636
{
616-
continue;
637+
creature->Whisper(Acore::StringFormat("Your score is {} {}", score, sZoneDifficulty->GetContentTypeString(i)), LANG_UNIVERSAL, player);
638+
hasAnyScore = true;
617639
}
618-
else if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(i) == sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
619-
{
620-
continue;
621-
}
622-
else
623-
{
624-
whisper.append(std::to_string(sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][i])).append(" ");
625-
}
626-
whisper.append(sZoneDifficulty->GetContentTypeString(i));
627-
creature->Whisper(whisper, LANG_UNIVERSAL, player);
628640
}
641+
642+
if (!hasAnyScore)
643+
creature->Whisper("You don't have any score in any category.", LANG_UNIVERSAL, player);
644+
629645
return true;
630646
}
631647

@@ -636,14 +652,8 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
636652
uint32 category = action - 99001000;
637653

638654
// Check (again) if the player has enough score in the respective category.
639-
uint32 availableScore = 0;
640-
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
641-
{
642-
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(category) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
643-
{
644-
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][category];
645-
}
646-
}
655+
uint32 availableScore = player->GetPlayerSetting(ModZoneDifficultyString + "score", category).value;
656+
647657
if (availableScore < sZoneDifficulty->TierRewards[category].Price)
648658
{
649659
CloseGossipMenuFor(player);
@@ -671,10 +681,7 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
671681
if (sZoneDifficulty->HasCompletedFullTier(category, player->GetGUID().GetCounter()))
672682
{
673683
// Check if the player has enough score in the respective category.
674-
uint32 availableScore = 0;
675-
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
676-
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(category) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
677-
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][category];
684+
uint32 availableScore = player->GetPlayerSetting(ModZoneDifficultyString + "score", category).value;
678685

679686
if (availableScore < sZoneDifficulty->TierRewards[category].Price)
680687
{
@@ -762,18 +769,15 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
762769
//LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Handling item with category {}, itemType {}, counter {}", category, itemType, counter);
763770

764771
// Check if the player has enough score in the respective category.
765-
uint32 availableScore = 0;
766-
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
767-
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(category) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
768-
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][category];
772+
uint32 availableScore = player->GetPlayerSetting(ModZoneDifficultyString + "score", category).value;
769773

770774
if (availableScore < sZoneDifficulty->Rewards[category][itemType][counter].Price)
771775
{
772776
npcText = NPC_TEXT_DENIED;
773777
SendGossipMenuFor(player, npcText, creature);
774778
std::string whisper = Acore::StringFormat("I am sorry, time-traveler. This item costs {} but you only have {} {}",
775779
sZoneDifficulty->Rewards[category][itemType][counter].Price,
776-
sZoneDifficulty->MythicmodeScore[category][player->GetGUID().GetCounter()],
780+
availableScore,
777781
sZoneDifficulty->GetContentTypeString(category));
778782
creature->Whisper(whisper, LANG_UNIVERSAL, player);
779783
return true;
@@ -808,10 +812,7 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
808812
}
809813

810814
// Check (again) if the player has enough score in the respective category.
811-
uint32 availableScore = 0;
812-
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
813-
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(category) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
814-
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][category];
815+
uint32 availableScore = player->GetPlayerSetting(ModZoneDifficultyString + "score", category).value;
815816

816817
if (availableScore < sZoneDifficulty->Rewards[category][itemType][counter].Price)
817818
return true;

0 commit comments

Comments
 (0)