Skip to content

Commit

Permalink
breaking-change: transition to using playersettings to store score
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyeriah committed Sep 19, 2024
1 parent 34a883e commit 9fcb820
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 76 deletions.
43 changes: 25 additions & 18 deletions src/ZoneDifficulty.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,6 @@ int32 const MODE_HARD = 64;
// EVENT_GROUP is used for unit->m_Events.AddEventAtOffset
uint8 const EVENT_GROUP = 64;

int32 const TYPE_VANILLA = 1;
int32 const TYPE_RAID_MC = 2;
int32 const TYPE_RAID_ONY = 3;
int32 const TYPE_RAID_BWL = 4;
int32 const TYPE_RAID_ZG = 5;
int32 const TYPE_RAID_AQ20 = 6;
int32 const TYPE_RAID_AQ40 = 7;
int32 const TYPE_HEROIC_TBC = 8;
int32 const TYPE_RAID_T4 = 9;
int32 const TYPE_RAID_T5 = 10;
int32 const TYPE_RAID_T6 = 11;
int32 const TYPE_HEROIC_WOTLK = 12;
int32 const TYPE_RAID_T7 = 13;
int32 const TYPE_RAID_T8 = 14;
int32 const TYPE_RAID_T9 = 15;
int32 const TYPE_RAID_T10 = 16;

uint32 const ITEMTYPE_MISC = 1;
uint32 const ITEMTYPE_CLOTH = 2;
uint32 const ITEMTYPE_LEATHER = 3;
Expand All @@ -115,6 +98,30 @@ uint32 const TARGET_PLAYER_DISTANCE = 18; // a random player within T
const std::string REWARD_MAIL_SUBJECT = "Chromie's Reward for you";
const std::string REWARD_MAIL_BODY = "Enjoy your new item!";

const std::string ModZoneDifficultyString = "mod-zone-difficulty#";

enum ZoneDifficultySettings
{
// Score settings
TYPE_NONE = 0,
TYPE_VANILLA = 1,
TYPE_RAID_MC = 2,
TYPE_RAID_ONY = 3,
TYPE_RAID_BWL = 4,
TYPE_RAID_ZG = 5,
TYPE_RAID_AQ20 = 6,
TYPE_RAID_AQ40 = 7,
TYPE_HEROIC_TBC = 8,
TYPE_RAID_T4 = 9,
TYPE_RAID_T5 = 10,
TYPE_RAID_T6 = 11,
TYPE_HEROIC_WOTLK = 12,
TYPE_RAID_T7 = 13,
TYPE_RAID_T8 = 14,
TYPE_RAID_T9 = 15,
TYPE_RAID_T10 = 16
};

class ZoneDifficulty
{
public:
Expand Down Expand Up @@ -168,7 +175,7 @@ class ZoneDifficulty
typedef std::map<uint32, std::vector<ZoneDifficultyMythicmodeMapData> > ZoneDifficultyMythicmodeLootMap;
ZoneDifficultyMythicmodeLootMap MythicmodeLoot;
typedef std::map<uint32, std::map<uint32, uint32> > ZoneDifficultyDualUintMap;
ZoneDifficultyDualUintMap MythicmodeScore;
ZoneDifficultyDualUintMap MythicmodeScore; // Deprecated, to be removed.
typedef std::map<uint32, std::map<uint32, std::vector<ZoneDifficultyRewardData> > > ZoneDifficultyRewardMap;
ZoneDifficultyRewardMap Rewards;
typedef std::map<uint32, std::vector<ZoneDifficultyHAI> > ZoneDifficultyHAIMap;
Expand Down
32 changes: 9 additions & 23 deletions src/mod_zone_difficulty_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ ZoneDifficulty* ZoneDifficulty::instance()
void ZoneDifficulty::LoadMapDifficultySettings()
{
if (!sZoneDifficulty->IsEnabled)
{
return;
}

sZoneDifficulty->Rewards.clear();
sZoneDifficulty->MythicmodeAI.clear();
Expand Down Expand Up @@ -155,7 +153,7 @@ void ZoneDifficulty::LoadMapDifficultySettings()
do
{
std::vector<uint32> debuffs;
uint32 mapId;
uint32 mapId = 0;
if ((*result)[2].Get<bool>())
{
std::string spellString = (*result)[1].Get<std::string>();
Expand All @@ -165,19 +163,13 @@ void ZoneDifficulty::LoadMapDifficultySettings()
for (auto token : tokens)
{
if (token.empty())
{
continue;
}

uint32 spell;
uint32 spell = 0;
if ((spell = Acore::StringTo<uint32>(token).value()))
{
debuffs.push_back(spell);
}
else
{
LOG_ERROR("module", "MOD-ZONE-DIFFICULTY: Disabling buffs for spell '{}' is invalid, skipped.", spell);
}
}
sZoneDifficulty->DisallowedBuffs[mapId] = debuffs;
}
Expand Down Expand Up @@ -402,6 +394,7 @@ void ZoneDifficulty::LoadMythicmodeScoreData()

} while (result->NextRow());
}

if (QueryResult result = CharacterDatabase.Query("SELECT `Map`, `BossId`, `PlayerGuid` FROM zone_difficulty_encounter_logs WHERE `Mode` = 64"))
{
do
Expand Down Expand Up @@ -440,9 +433,7 @@ void ZoneDifficulty::SendWhisperToRaid(std::string message, Creature* creature,
if (creature && player)
{
if (mapPlayer->IsInSameGroupWith(player))
{
creature->Whisper(message, LANG_UNIVERSAL, mapPlayer);
}
}
});
}
Expand Down Expand Up @@ -557,16 +548,10 @@ void ZoneDifficulty::AddMythicmodeScore(Map* map, uint32 type, uint32 score)

map->DoForAllPlayers([&](Player* player)
{
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) == sZoneDifficulty->MythicmodeScore.end())
sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] = score;
else if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(type) == sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] = score;
else
sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] + score;

uint32 previousScore = player->GetPlayerSetting(ModZoneDifficultyString + "score", type).value;
player->UpdatePlayerSetting(ModZoneDifficultyString + "score", type, previousScore + score);
std::string typestring = sZoneDifficulty->GetContentTypeString(type);
ChatHandler(player->GetSession()).PSendSysMessage("You have received Mythicmode score {} New score: {}", typestring, sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type]);
CharacterDatabase.Execute("REPLACE INTO zone_difficulty_mythicmode_score VALUES({}, {}, {})", player->GetGUID().GetCounter(), type, sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type]);
ChatHandler(player->GetSession()).PSendSysMessage("You have received Mythicmode score {} New score: {}", typestring, previousScore + score);
});
}

Expand All @@ -583,8 +568,9 @@ void ZoneDifficulty::DeductMythicmodeScore(Player* player, uint32 type, uint32 s
{
LOG_INFO("module", "MOD-ZONE-DIFFICULTY: Reducing score with type {} from player with guid {} by {}.", type, player->GetGUID().GetCounter(), score);
}
sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type] - score;
CharacterDatabase.Execute("REPLACE INTO zone_difficulty_mythicmode_score VALUES({}, {}, {})", player->GetGUID().GetCounter(), type, sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][type]);

uint32 val = player->GetPlayerSetting(ModZoneDifficultyString + "score", type).value - score;
player->UpdatePlayerSetting(ModZoneDifficultyString + "score", type, val);
}

/**
Expand Down
71 changes: 36 additions & 35 deletions src/mod_zone_difficulty_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,28 @@ class mod_zone_difficulty_playerscript : public PlayerScript
}
}
}

void OnLogin(Player* player) override
{
if (sZoneDifficulty->MythicmodeScore.empty())
return;

if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
{
for (int i = 1; i <= 16; ++i)
{
uint32 availableScore = 0;

if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(i) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][i];

player->UpdatePlayerSetting(ModZoneDifficultyString + "score", i, availableScore);
}

sZoneDifficulty->MythicmodeScore.erase(player->GetGUID().GetCounter());
CharacterDatabase.Execute("DELETE FROM zone_difficulty_mythicmode_score WHERE GUID = {}", player->GetGUID().GetCounter());
}
}
};

class mod_zone_difficulty_petscript : public PetScript
Expand Down Expand Up @@ -607,25 +629,19 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
if (action == 999999)
{
npcText = NPC_TEXT_SCORE;
bool hasAnyScore = false;
for (int i = 1; i <= 16; ++i)
{
std::string whisper;
whisper.append("Your score is ");
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) == sZoneDifficulty->MythicmodeScore.end())
if (uint32 score = player->GetPlayerSetting(ModZoneDifficultyString + "score", i).value)
{
continue;
creature->Whisper(Acore::StringFormat("Your score is {} {}", score, sZoneDifficulty->GetContentTypeString(i)), LANG_UNIVERSAL, player);
hasAnyScore = true;
}
else if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(i) == sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
{
continue;
}
else
{
whisper.append(std::to_string(sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][i])).append(" ");
}
whisper.append(sZoneDifficulty->GetContentTypeString(i));
creature->Whisper(whisper, LANG_UNIVERSAL, player);
}

if (!hasAnyScore)
creature->Whisper("You don't have any score in any category.", LANG_UNIVERSAL, player);

return true;
}

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

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

if (availableScore < sZoneDifficulty->TierRewards[category].Price)
{
CloseGossipMenuFor(player);
Expand Down Expand Up @@ -671,10 +681,7 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
if (sZoneDifficulty->HasCompletedFullTier(category, player->GetGUID().GetCounter()))
{
// Check if the player has enough score in the respective category.
uint32 availableScore = 0;
if (sZoneDifficulty->MythicmodeScore.find(player->GetGUID().GetCounter()) != sZoneDifficulty->MythicmodeScore.end())
if (sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].find(category) != sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()].end())
availableScore = sZoneDifficulty->MythicmodeScore[player->GetGUID().GetCounter()][category];
uint32 availableScore = player->GetPlayerSetting(ModZoneDifficultyString + "score", category).value;

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

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

if (availableScore < sZoneDifficulty->Rewards[category][itemType][counter].Price)
{
npcText = NPC_TEXT_DENIED;
SendGossipMenuFor(player, npcText, creature);
std::string whisper = Acore::StringFormat("I am sorry, time-traveler. This item costs {} but you only have {} {}",
sZoneDifficulty->Rewards[category][itemType][counter].Price,
sZoneDifficulty->MythicmodeScore[category][player->GetGUID().GetCounter()],
availableScore,
sZoneDifficulty->GetContentTypeString(category));
creature->Whisper(whisper, LANG_UNIVERSAL, player);
return true;
Expand Down Expand Up @@ -808,10 +812,7 @@ class mod_zone_difficulty_rewardnpc : public CreatureScript
}

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

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

0 comments on commit 9fcb820

Please sign in to comment.