Admin
2024-07-20 08:39:29Overview
The Solocraft mod is designed to enhance the experience of solo players in World of Warcraft (WoW) by dynamically adjusting the player's stats and buffs when they enter group content like dungeons and raids. This allows solo players to tackle content that would typically require a group.
How It Works
Initialization
Class Definition:
The solocraft_player_instance_handler class inherits from PlayerScript. This class handles various player-related events, such as logging in and changing maps (instances).
Constructor:
The constructor logs a message indicating that the Solocraft player instance handler has been loaded.
solocraft_player_instance_handler() : PlayerScript("solocraft_player_instance_handler") {
TC_LOG_INFO("scripts.solocraft.player.instance", "[Solocraft] solocraft_player_instance_handler Loaded");
}
Event Handling
OnLogin:
When a player logs in, a system message is sent to welcome them to the Solocraft mod.
void OnLogin(Player* player, bool /*firstLogin*/) override {
ChatHandler(player->GetSession()).SendSysMessage("Welcome to #1 Europe WoW Solocraft Mod");
}
OnMapChanged:
When a player changes maps (enters a new instance), the mod calculates the difficulty of the instance and the number of players in the group. It then applies appropriate buffs to the player to adjust for solo play.
void OnMapChanged(Player* player) override {
Map* map = player->GetMap();
int difficulty = CalculateDifficulty(map, player);
int numInGroup = GetNumInGroup(player);
ApplyBuffs(player, map, difficulty, numInGroup);
}
Supporting Methods
CalculateDifficulty:
This method determines the difficulty of the current map based on the type of instance (e.g., 25-man raid, heroic dungeon).
int CalculateDifficulty(Map* map, Player* /*player*/) {
int difficulty = 1;
if (map) {
if (map->Is25ManRaid()) {
difficulty = 25;
} else if (map->IsHeroic()) {
difficulty = 10;
} else if (map->IsRaid()) {
difficulty = 40;
} else if (map->IsDungeon()) {
difficulty = 5;
}
}
return difficulty;
}
GetNumInGroup:
This method returns the number of players in the player's group. If the player is not in a group, it returns 1.
int GetNumInGroup(Player* player) {
int numInGroup = 1;
Group* group = player->GetGroup();
if (group) {
Group::MemberSlotList const& groupMembers = group->GetMemberSlots();
numInGroup = groupMembers.size();
}
return numInGroup;
}
ApplyBuffs:
This method applies buffs to the player based on the calculated difficulty and the number of players in the group. It adjusts the player's stats to compensate for the lack of group members.
void ApplyBuffs(Player* player, Map* map, int difficulty, int /*numInGroup*/) {
ClearBuffs(player, map);
if (difficulty > 1) {
ChatHandler(player->GetSession()).PSendSysMessage("Entered %s (difficulty = %d, numInGroup = %d)",
map->GetMapName(), difficulty, 1);
_unitDifficulty[player->GetGUID()] = difficulty;
for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i) {
float baseStat = player->GetStat(Stats(i));
float bonus = baseStat * (float(difficulty) - 1.0f);
player->HandleStatFlatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, bonus, true);
}
player->SetFullHealth();
if (player->GetPowerType() == POWER_MANA) {
player->SetPower(POWER_MANA, player->GetMaxPower(POWER_MANA));
}
}
}
ClearBuffs:
This method removes any previously applied buffs when the player leaves an instance or the difficulty changes.
void ClearBuffs(Player* player, Map* map) {
auto unitDifficultyIterator = _unitDifficulty.find(player->GetGUID());
if (unitDifficultyIterator != _unitDifficulty.end()) {
int difficulty = unitDifficultyIterator->second;
_unitDifficulty.erase(unitDifficultyIterator);
ChatHandler(player->GetSession()).PSendSysMessage("Left %s (removing difficulty = %d)",
map->GetMapName(), difficulty);
for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i) {
float baseStat = player->GetStat(Stats(i));
float bonus = baseStat * (float(difficulty) - 1.0f);
player->HandleStatFlatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_VALUE, -bonus, false);
}
}
}
The Solocraft mod dynamically adjusts a player's stats and provides buffs when they enter group content, allowing solo players to tackle dungeons and raids designed for groups. It does this by listening to events such as logging in and changing maps, calculating the appropriate difficulty, and applying or clearing buffs accordingly. This enhances the solo gameplay experience by making group content more manageable for solo players.