Skip to content

Commit

Permalink
feat(SoloCraft): exclude map/instance from Solocraft scaling with conf (
Browse files Browse the repository at this point in the history
#50)

* Exclude map/instance from Solocraft scaling with conf

* include cstdint
  • Loading branch information
valsan-azerty-boi authored Sep 6, 2024
1 parent 2b8193e commit a1902a8
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ local.properties
.loadpath
.project
.cproject

#
# Visual Studio Code
#
.vscode/
12 changes: 12 additions & 0 deletions conf/Solocraft.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,15 @@ Solocraft.QuarryOfTears.Level = 78
Solocraft.HallsOfReflection.Level = 78
# The Ruby Sanctum
Solocraft.ChamberOfAspectsRed.Level = 80

###################################################################################################
# Misc
###################################################################################################

# Map excluded
# This settings excludes some maps from the Solocraft instance scaling

# Example:
# Solocraft.Instance.Excluded = "30,489,529,559,562,566,572,607,617,618,628"
# This example excludes scaling in PvP BG & Arena maps
Solocraft.Instance.Excluded = ""
31 changes: 25 additions & 6 deletions src/Solocraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#include <math.h>
#include <unordered_map>
#include "ObjectGuid.h"
#include "utils/Utils.h"
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>

bool SoloCraftEnable = 1;
bool SoloCraftAnnounceModule = 1;
Expand All @@ -28,6 +33,7 @@ std::unordered_map<uint8, uint32> classes;
std::unordered_map<uint32, uint32> dungeons;
std::unordered_map<uint32, float> diff_Multiplier;
std::unordered_map<uint32, float> diff_Multiplier_Heroics;
std::vector<uint32_t> SolocraftInstanceExcluded;

float D5 = 1.0;
float D10 = 1.0;
Expand Down Expand Up @@ -305,6 +311,9 @@ class SolocraftConfig : public WorldScript
//Unique Raids beyond the heroic and normal versions of themselves
D649H10 = sConfigMgr->GetOption<float>("Solocraft.ArgentTournamentRaidH10", 10.0); //Trial of the Crusader 10 Heroic
D649H25 = sConfigMgr->GetOption<float>("Solocraft.ArgentTournamentRaidH25", 25.0); //Trial of the Crusader 25 Heroic

//Get from conf excluded map for Solocraft scaling
LoadList(sConfigMgr->GetOption<std::string>("Solocraft.Instance.Excluded", ""), SolocraftInstanceExcluded);
}
};

Expand Down Expand Up @@ -361,6 +370,11 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
{
public:
SolocraftPlayerInstanceHandler() : PlayerScript("SolocraftPlayerInstanceHandler") {}

bool IsInSolocraftInstanceExcludedList(uint32 id)
{
return find(SolocraftInstanceExcluded.begin(), SolocraftInstanceExcluded.end(), id) != SolocraftInstanceExcluded.end();
}

void OnMapChanged(Player* player) override
{
Expand All @@ -380,6 +394,11 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
{
if (map)
{
if (IsInSolocraftInstanceExcludedList(map->GetId()))
{
return 0;
}

if (map->Is25ManRaid())
{
if (map->IsHeroic() && map->GetId() == 649)
Expand Down Expand Up @@ -536,8 +555,12 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
// Apply the player buffs
void ApplyBuffs(Player* player, Map* map, float difficulty, int dunLevel, int numInGroup, int classBalance)
{
// Check whether to buff the player or check to debuff back to normal
if (difficulty != 0)
// Check whether to debuff back to normal or check to buff the player
if (difficulty == 0 || IsInSolocraftInstanceExcludedList(map->GetId()))
{
ClearBuffs(player); // Check to revert player back to normal - Moving this here fixed logout and login while in instance buff and debuff issues
}
else
{
std::ostringstream ss;

Expand Down Expand Up @@ -709,10 +732,6 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
ClearBuffs(player); // Check to revert player back to normal
}
}
else
{
ClearBuffs(player); // Check to revert player back to normal - Moving this here fixed logout and login while in instance buff and debuff issues
}
}

private:
Expand Down
16 changes: 16 additions & 0 deletions src/utils/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "Utils.h"
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

std::vector<std::string> split(const std::string& str, char delimiter) {
std::vector<std::string> res;
if (str.empty()) return res;
std::string token;
std::istringstream tokenStream(str);
while (std::getline(tokenStream, token, delimiter)) {
res.push_back(token);
}
return res;
}
21 changes: 21 additions & 0 deletions src/utils/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef UTILS_H
#define UTILS_H

#include <cstdint>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>

std::vector<std::string> split(const std::string& str, char delimiter);

template <class T>
void LoadList(const std::string& value, T& list) {
std::vector<std::string> ids = split(value, ',');
for (const std::string& id_str : ids) {
uint32_t id = static_cast<uint32_t>(std::atoi(id_str.c_str()));
list.push_back(id);
}
}

#endif

0 comments on commit a1902a8

Please sign in to comment.