Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/sql/db-characters/mod_solo_craft.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ CREATE TABLE IF NOT EXISTS `custom_solocraft_character_stats` (
`SpellPower` int unsigned NOT NULL DEFAULT '0',
`Stats` float NOT NULL DEFAULT '100',
PRIMARY KEY (`GUID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
91 changes: 25 additions & 66 deletions src/Solocraft.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#include <map>
#include "Log.h"
#include "utils/Utils.h"
#include "Chat.h"
#include "Config.h"
#include "ScriptMgr.h"
#include "Unit.h"
#include "Player.h"
#include "Pet.h"
#include "Map.h"
#include "Group.h"
#include "InstanceScript.h"
#include "Chat.h"
#include <math.h>
#include <unordered_map>
#include "Log.h"
#include "Map.h"
#include "ObjectGuid.h"
#include "utils/Utils.h"
#include "Pet.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "Unit.h"
#include <cstdint>
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <string>
#include <cstdint>
#include <unordered_map>
#include <vector>

bool SoloCraftEnable = 1;
bool SoloCraftAnnounceModule = 1;
Expand Down Expand Up @@ -45,7 +45,9 @@ float D649H25 = 1.0;
class SolocraftConfig : public WorldScript
{
public:
SolocraftConfig() : WorldScript("SolocraftConfig") {}
SolocraftConfig() : WorldScript("SolocraftConfig", {
WORLDHOOK_ON_BEFORE_CONFIG_LOAD
}) {}

void OnBeforeConfigLoad(bool /*reload*/) override
{
Expand Down Expand Up @@ -323,14 +325,17 @@ class SolocraftAnnounce : public PlayerScript
std::map<ObjectGuid, bool> playerInInstanceMap;

public:
SolocraftAnnounce() : PlayerScript("SolocraftAnnounce") {}
SolocraftAnnounce() : PlayerScript("SolocraftAnnounce", {
PLAYERHOOK_ON_LOGIN,
PLAYERHOOK_ON_LOGOUT,
PLAYERHOOK_ON_MAP_CHANGED,
PLAYERHOOK_ON_GIVE_EXP
}) {}

void OnPlayerLogin(Player* player) override
{
if (SoloCraftEnable && SoloCraftAnnounceModule)
{
ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00SoloCraft |rmodule.");
}
}

void OnPlayerLogout(Player* player) override
Expand All @@ -347,13 +352,9 @@ class SolocraftAnnounce : public PlayerScript
void OnPlayerMapChanged(Player* player) override
{
if (player->GetMap()->IsDungeon() || player->GetMap()->IsRaid())
{
playerInInstanceMap[player->GetGUID()] = true;
}
else
{
playerInInstanceMap[player->GetGUID()] = false;
}
}

void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
Expand All @@ -369,7 +370,9 @@ class SolocraftAnnounce : public PlayerScript
class SolocraftPlayerInstanceHandler : public PlayerScript
{
public:
SolocraftPlayerInstanceHandler() : PlayerScript("SolocraftPlayerInstanceHandler") {}
SolocraftPlayerInstanceHandler() : PlayerScript("SolocraftPlayerInstanceHandler", {
PLAYERHOOK_ON_MAP_CHANGED
}) {}

bool IsInSolocraftInstanceExcludedList(uint32 id)
{
Expand All @@ -395,48 +398,34 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
if (map)
{
if (IsInSolocraftInstanceExcludedList(map->GetId()))
{
return 0;
}

if (map->Is25ManRaid())
{
if (map->IsHeroic() && map->GetId() == 649)
{
return D649H25;
}
else if (diff_Multiplier_Heroics.find(map->GetId()) == diff_Multiplier_Heroics.end())
{
return D25;
}
else
return diff_Multiplier_Heroics[map->GetId()];
}

if (map->IsHeroic())
{
if (map->GetId() == 649)
{
return D649H10;
}
else if (diff_Multiplier_Heroics.find(map->GetId()) == diff_Multiplier_Heroics.end())
{
return D10;
}
else
return diff_Multiplier_Heroics[map->GetId()];
}

if (diff_Multiplier.find(map->GetId()) == diff_Multiplier.end())
{
if (map->IsDungeon())
{
return D5;
}
else if (map->IsRaid())
{
return D40;
}
}
else
return diff_Multiplier[map->GetId()];
Expand All @@ -449,13 +438,9 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
uint32 CalculateDungeonLevel(Map* map)
{
if (dungeons.find(map->GetId()) == dungeons.end())
{
return SolocraftDungeonLevel;
}
else
{
return dungeons[map->GetId()];
}
}

// Get the group's size
Expand All @@ -479,13 +464,9 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
uint32 classBalance = 100;

if (classes.find(player->getClass()) == classes.end())
{
return classBalance;
}
else if (classes[player->getClass()] >= 0 && classes[player->getClass()] <= 100)
{
return classes[player->getClass()];
}
else
return classBalance;
}
Expand All @@ -507,9 +488,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
if (result)
{
if ((*result)[1].Get<float>() > 0)
{
GroupDifficulty = GroupDifficulty + (*result)[1].Get<float>();
}
}
}
}
Expand All @@ -533,33 +512,25 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
SoloCraftXPMod = 1.0;

for (uint32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
{
player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, difficulty * StatsMultPct, false);
}

if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN) && !SolocraftNoXPFlag)
{
player->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
}

SolocraftNoXPFlag = 0;
CharacterDatabase.Execute("DELETE FROM custom_solocraft_character_stats WHERE GUID = {}", player->GetGUID().GetCounter());
}

if (player->getPowerType() == POWER_MANA || player->getClass() == CLASS_DRUID)
{
player->ApplySpellPowerBonus(SpellPowerBonus, false);
}
}

// Apply the player buffs
void ApplyBuffs(Player* player, Map* map, float difficulty, int dunLevel, int numInGroup, int classBalance)
{
// 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 All @@ -568,9 +539,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript

// Check for an existing No XP Gain flag - other mod compatibility
if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN))
{
SolocraftNoXPFlag = 1;
}

// If a player is too high level for dungeon don't buff but if in a group will count towards the group offset balancing.
if (player->GetLevel() <= dunLevel + SolocraftLevelDiff)
Expand All @@ -589,9 +558,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript

// Disable player XP gain if debuff applied
if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN) && SolocraftXPBalEnabled)
{
player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
}
}
else
{
Expand All @@ -610,16 +577,12 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
{
SoloCraftXPMod = 0;
if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN) && SolocraftXPBalEnabled)
{
player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
}
}

// Check XP modifier for over max limit and adjust
if (SoloCraftXPMod > 1)
{
SoloCraftXPMod = 1.0;
}
}

// Check Database for a current dungeon entry
Expand All @@ -631,9 +594,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
{
// Check for Dungeon to Dungeon Transfer and remove old buff
if (result)
{
player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, (*result)[1].Get<float>() * (*result)[4].Get<float>(), false);
}
// Buff the player
// Unitmods enum UNIT_MOD_STAT_START defined in Unit.h line 391
player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, difficulty * SoloCraftStatsMult, true);
Expand Down Expand Up @@ -678,9 +639,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
{
SoloCraftXPMod = 0;
if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN))
{
player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
}
}

// Announcements
Expand Down
9 changes: 5 additions & 4 deletions src/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include <string>
#include <vector>

std::vector<std::string> split(const std::string& str, char delimiter) {
std::vector<std::string> split(const std::string& str, char delimiter)
{
std::vector<std::string> res;
if (str.empty()) return res;
if (str.empty())
return res;
std::string token;
std::istringstream tokenStream(str);
while (std::getline(tokenStream, token, delimiter)) {
while (std::getline(tokenStream, token, delimiter))
res.push_back(token);
}
return res;
}
10 changes: 6 additions & 4 deletions src/utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

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

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

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