-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsolocraft.cpp
More file actions
91 lines (78 loc) · 2.41 KB
/
solocraft.cpp
File metadata and controls
91 lines (78 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "ScriptMgr.h"
#include "Player.h"
#include "Map.h"
#include "Group.h"
class solocraft_player_instance_handler : public PlayerScript
{
public:
solocraft_player_instance_handler() : PlayerScript("solocraft_player_instance_handler") { }
void OnMapChanged(Player* player) override
{
Map* map = player->GetMap();
int difficulty = CalculateDifficulty(map, player);
int numInGroup = GetNumInGroup(player);
ApplyBuffs(player, map, difficulty, numInGroup);
}
private:
int CalculateDifficulty(Map *map, Player *player)
{
int difficulty = 1;
if (map)
{
if (map->Is25ManRaid())
{
difficulty = 25;
}
else if (map->IsMythic())
{
difficulty = 20;
}
else if (map->IsHeroic())
{
difficulty = 10;
}
else if (map->IsRaid())
{
difficulty = 40;
}
else if (map->IsDungeon())
{
difficulty = 5;
}
}
return difficulty;
}
int GetNumInGroup(Player *player)
{
int numInGroup = 1;
if (Group* group = player->GetGroup())
numInGroup = group->GetMemberSlots().size();
return numInGroup;
}
void ApplyBuffs(Player* player, Map* map, int difficulty, int numInGroup)
{
ClearBuffs(player, map);
if (difficulty > 1)
{
player->Variables.Set("SoloCraftDifficulty", difficulty);
for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(difficulty * 100), true);
player->SetFullHealth();
if (player->GetPowerType() == POWER_MANA)
player->SetPower(POWER_MANA, player->GetMaxPower(POWER_MANA));
}
}
void ClearBuffs(Player* player, Map* map)
{
if (player->Variables.Exist("SoloCraftDifficulty"))
{
int difficulty = player->Variables.GetValue<int>("SoloCraftDifficulty", 1);
for (int32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, float(difficulty * 100), false);
}
}
};
void AddSC_solocraft()
{
new solocraft_player_instance_handler();
}