|
| 1 | +#include <map> |
| 2 | + |
| 3 | +#include "Config.h" |
| 4 | +#include "ScriptMgr.h" |
| 5 | +#include "Unit.h" |
| 6 | +#include "Player.h" |
| 7 | +#include "Pet.h" |
| 8 | +#include "Map.h" |
| 9 | +#include "Group.h" |
| 10 | +#include "InstanceScript.h" |
| 11 | + |
| 12 | +/* |
| 13 | + * TODO: |
| 14 | + * 1. Dispel target regeneration |
| 15 | + * 2. Provide unlimited http://www.wowhead.com/item=17333/aqual-quintessence |
| 16 | + */ |
| 17 | + |
| 18 | +namespace { |
| 19 | + |
| 20 | +class solocraft_player_instance_handler : public PlayerScript { |
| 21 | +public: |
| 22 | + solocraft_player_instance_handler() : PlayerScript("solocraft_player_instance_handler") { |
| 23 | + sLog->outString("scripts.solocraft.player.instance", "[Solocraft] solocraft_player_instance_handler Loaded"); |
| 24 | + } |
| 25 | + |
| 26 | + void OnLogin(Player *player) override { |
| 27 | + if (sConfigMgr->GetBoolDefault("Solocraft.Enable", true)) |
| 28 | + { |
| 29 | + ChatHandler(player->GetSession()).SendSysMessage("This server is running a Solocraft Module."); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + void OnMapChanged(Player *player) override { |
| 34 | + if (sConfigMgr->GetBoolDefault("Solocraft.Enable", true)) { |
| 35 | + Map *map = player->GetMap(); |
| 36 | + int difficulty = CalculateDifficulty(map, player); |
| 37 | + int numInGroup = GetNumInGroup(player); |
| 38 | + ApplyBuffs(player, map, difficulty, numInGroup); |
| 39 | + } |
| 40 | + } |
| 41 | +private: |
| 42 | + std::map<uint32, int> _unitDifficulty; |
| 43 | + |
| 44 | + int CalculateDifficulty(Map *map, Player *player) { |
| 45 | + int difficulty = 1; |
| 46 | + if (map) { |
| 47 | + if (map->Is25ManRaid()) { |
| 48 | + difficulty = 25; |
| 49 | + } else if (map->IsHeroic()) { |
| 50 | + difficulty = 10; |
| 51 | + } else if (map->IsRaid()) { |
| 52 | + difficulty = 40; |
| 53 | + } else if (map->IsDungeon()) { |
| 54 | + difficulty = 5; |
| 55 | + } |
| 56 | + } |
| 57 | + return difficulty; |
| 58 | + } |
| 59 | + |
| 60 | + int GetNumInGroup(Player *player) { |
| 61 | + int numInGroup = 1; |
| 62 | + Group *group = player->GetGroup(); |
| 63 | + if (group) { |
| 64 | + Group::MemberSlotList const& groupMembers = group->GetMemberSlots(); |
| 65 | + numInGroup = groupMembers.size(); |
| 66 | + } |
| 67 | + return numInGroup; |
| 68 | + } |
| 69 | + |
| 70 | + void ApplyBuffs(Player *player, Map *map, int difficulty, int numInGroup) { |
| 71 | + ClearBuffs(player, map); |
| 72 | + if (difficulty > 1) { |
| 73 | + //InstanceMap *instanceMap = map->ToInstanceMap(); |
| 74 | + //InstanceScript *instanceScript = instanceMap->GetInstanceScript(); |
| 75 | + |
| 76 | + ChatHandler(player->GetSession()).PSendSysMessage("Entered %s (difficulty = %d, numInGroup = %d)", |
| 77 | + map->GetMapName(), difficulty, numInGroup); |
| 78 | + |
| 79 | + _unitDifficulty[player->GetGUID()] = difficulty; |
| 80 | + for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i) { |
| 81 | + player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(difficulty * 100), true); |
| 82 | + } |
| 83 | + player->SetFullHealth(); |
| 84 | + if (player->getPowerType() == POWER_MANA) { |
| 85 | + player->SetPower(POWER_MANA, player->GetMaxPower(POWER_MANA)); |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + void ClearBuffs(Player *player, Map *map) { |
| 91 | + std::map<uint32, int>::iterator unitDifficultyIterator = _unitDifficulty.find(player->GetGUID()); |
| 92 | + if (unitDifficultyIterator != _unitDifficulty.end()) { |
| 93 | + int difficulty = unitDifficultyIterator->second; |
| 94 | + _unitDifficulty.erase(unitDifficultyIterator); |
| 95 | + |
| 96 | + ChatHandler(player->GetSession()).PSendSysMessage("Left to %s (removing difficulty = %d)", |
| 97 | + map->GetMapName(), difficulty); |
| 98 | + |
| 99 | + for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i) { |
| 100 | + player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(difficulty * 100), false); |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +}; |
| 105 | + |
| 106 | +} |
| 107 | + |
| 108 | +class SolocraftWorld : public WorldScript |
| 109 | +{ |
| 110 | +public: |
| 111 | + SolocraftWorld() : WorldScript("SolocraftWorld") { } |
| 112 | + |
| 113 | + void OnBeforeConfigLoad(bool reload) override |
| 114 | + { |
| 115 | + if (!reload) { |
| 116 | + std::string conf_path = _CONF_DIR; |
| 117 | + std::string cfg_file = conf_path + "/Solocraft.conf"; |
| 118 | +#ifdef WIN32 |
| 119 | + cfg_file = "Solocraft.conf"; |
| 120 | +#endif |
| 121 | + std::string cfg_def_file = cfg_file +".dist"; |
| 122 | + sConfigMgr->LoadMore(cfg_def_file.c_str()); |
| 123 | + |
| 124 | + sConfigMgr->LoadMore(cfg_file.c_str()); |
| 125 | + } |
| 126 | + } |
| 127 | +}; |
| 128 | + |
| 129 | + |
| 130 | +void AddSolocraftScripts() { |
| 131 | + new SolocraftWorld(); |
| 132 | + new solocraft_player_instance_handler(); |
| 133 | +} |
0 commit comments