Guest User

solocraft.cpp

a guest
Jul 4th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.92 KB | None | 0 0
  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. #include "Chat.h"
  12. #include "Log.h"
  13.  
  14.  
  15. /*
  16. * TODO:
  17. * 1. Dispel target regeneration
  18. * 2. Provide unlimited http://www.wowhead.com/item=17333/aqual-quintessence
  19. */
  20.  
  21. namespace {
  22.  
  23.     class solocraft_player_instance_handler : public PlayerScript {
  24.     public:
  25.         solocraft_player_instance_handler() : PlayerScript("solocraft_player_instance_handler") {
  26.             TC_LOG_INFO("scripts.solocraft.player.instance", "[Solocraft] solocraft_player_instance_handler Loaded");
  27.         }
  28.  
  29.         void OnLogin(Player *player, bool firstLogin) override {
  30.             ChatHandler(player->GetSession()).SendSysMessage("Welcome to World of Solocraft");
  31.         }
  32.  
  33.         void OnMapChanged(Player *player) override {
  34.             Map *map = player->GetMap();
  35.             int difficulty = CalculateDifficulty(map, player);
  36.             int numInGroup = GetNumInGroup(player);
  37.             ApplyBuffs(player, map, difficulty, numInGroup);
  38.         }
  39.     private:
  40.         std::map<ObjectGuid, int> _unitDifficulty;
  41.  
  42.         int CalculateDifficulty(Map *map, Player *player) {
  43.             int difficulty = 1;
  44.             if (map) {
  45.                 if (map->Is25ManRaid()) {
  46.                     difficulty = 25;
  47.                 }
  48.                 else if (map->IsHeroic()) {
  49.                     difficulty = 10;
  50.                 }
  51.                 else if (map->IsRaid()) {
  52.                     difficulty = 40;
  53.                 }
  54.                 else if (map->IsDungeon()) {
  55.                     difficulty = 5;
  56.                 }
  57.             }
  58.             return difficulty;
  59.         }
  60.  
  61.         int GetNumInGroup(Player *player) {
  62.             int numInGroup = 1;
  63.             Group *group = player->GetGroup();
  64.             if (group) {
  65.                 Group::MemberSlotList const& groupMembers = group->GetMemberSlots();
  66.                 numInGroup = groupMembers.size();
  67.             }
  68.             return numInGroup;
  69.         }
  70.  
  71.         void ApplyBuffs(Player *player, Map *map, int difficulty, int numInGroup) {
  72.             ClearBuffs(player, map);
  73.             if (difficulty > 1) {
  74.                 //InstanceMap *instanceMap = map->ToInstanceMap();
  75.                 //InstanceScript *instanceScript = instanceMap->GetInstanceScript();
  76.  
  77.                 ChatHandler(player->GetSession()).PSendSysMessage("Entered %s (difficulty = %d, numInGroup = %d)",
  78.                     map->GetMapName(), difficulty, numInGroup);
  79.  
  80.                 _unitDifficulty[player->GetGUID()] = difficulty;
  81.                 for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i) {
  82.                     player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(difficulty * 100), true);
  83.                 }
  84.                 player->SetFullHealth();
  85.                 if (player->getPowerType() == POWER_MANA) {
  86.                     player->SetPower(POWER_MANA, player->GetMaxPower(POWER_MANA));
  87.                 }
  88.             }
  89.         }
  90.  
  91.         void ClearBuffs(Player *player, Map *map) {
  92.             std::map<ObjectGuid, int>::iterator unitDifficultyIterator = _unitDifficulty.find(player->GetGUID());
  93.             if (unitDifficultyIterator != _unitDifficulty.end()) {
  94.                 int difficulty = unitDifficultyIterator->second;
  95.                 _unitDifficulty.erase(unitDifficultyIterator);
  96.  
  97.                 ChatHandler(player->GetSession()).PSendSysMessage("Left to %s (removing difficulty = %d)",
  98.                     map->GetMapName(), difficulty);
  99.  
  100.                 for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i) {
  101.                     player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(difficulty * 100), false);
  102.                 }
  103.             }
  104.         }
  105.     };
  106.  
  107. }
  108.  
  109. void AddSC_solocraft() {
  110.     new solocraft_player_instance_handler();
  111. }
Advertisement
Add Comment
Please, Sign In to add comment