TrinityCore
Loading...
Searching...
No Matches
duel_reset.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include "
ScriptMgr.h
"
19
#include "
GameTime.h
"
20
#include "
Pet.h
"
21
#include "
Player.h
"
22
#include "
SpellHistory.h
"
23
#include "
SpellInfo.h
"
24
#include "
SpellMgr.h
"
25
#include "
World.h
"
26
27
class
DuelResetScript
:
public
PlayerScript
28
{
29
public
:
30
DuelResetScript
() :
PlayerScript
(
"DuelResetScript"
) { }
31
32
// Called when a duel starts (after 3s countdown)
33
void
OnDuelStart
(
Player
* player1,
Player
* player2)
override
34
{
35
// Cooldowns reset
36
if
(
sWorld
->getBoolConfig(
CONFIG_RESET_DUEL_COOLDOWNS
))
37
{
38
player1->
GetSpellHistory
()->
SaveCooldownStateBeforeDuel
();
39
player2->
GetSpellHistory
()->
SaveCooldownStateBeforeDuel
();
40
41
ResetSpellCooldowns
(player1,
true
);
42
ResetSpellCooldowns
(player2,
true
);
43
}
44
45
// Health and mana reset
46
if
(
sWorld
->getBoolConfig(
CONFIG_RESET_DUEL_HEALTH_MANA
))
47
{
48
player1->
SaveHealthBeforeDuel
();
49
player1->
SaveManaBeforeDuel
();
50
player1->
ResetAllPowers
();
51
52
player2->
SaveHealthBeforeDuel
();
53
player2->
SaveManaBeforeDuel
();
54
player2->
ResetAllPowers
();
55
}
56
}
57
58
// Called when a duel ends
59
void
OnDuelEnd
(
Player
* winner,
Player
* loser,
DuelCompleteType
type)
override
60
{
61
// do not reset anything if DUEL_INTERRUPTED or DUEL_FLED
62
if
(type ==
DUEL_WON
)
63
{
64
// Cooldown restore
65
if
(
sWorld
->getBoolConfig(
CONFIG_RESET_DUEL_COOLDOWNS
))
66
{
67
ResetSpellCooldowns
(winner,
false
);
68
ResetSpellCooldowns
(loser,
false
);
69
70
winner->
GetSpellHistory
()->
RestoreCooldownStateAfterDuel
();
71
loser->
GetSpellHistory
()->
RestoreCooldownStateAfterDuel
();
72
}
73
74
// Health and mana restore
75
if
(
sWorld
->getBoolConfig(
CONFIG_RESET_DUEL_HEALTH_MANA
))
76
{
77
winner->
RestoreHealthAfterDuel
();
78
loser->
RestoreHealthAfterDuel
();
79
80
// check if player1 class uses mana
81
if
(winner->
GetPowerType
() ==
POWER_MANA
|| winner->
GetClass
() ==
CLASS_DRUID
)
82
winner->
RestoreManaAfterDuel
();
83
84
// check if player2 class uses mana
85
if
(loser->
GetPowerType
() ==
POWER_MANA
|| loser->
GetClass
() ==
CLASS_DRUID
)
86
loser->
RestoreManaAfterDuel
();
87
}
88
}
89
}
90
91
static
void
ResetSpellCooldowns
(
Player
* player,
bool
onStartDuel)
92
{
93
// remove cooldowns on spells that have < 10 min CD > 30 sec and has no onHold
94
player->
GetSpellHistory
()->
ResetCooldowns
([player, onStartDuel](
SpellHistory::CooldownEntry
const
& cooldown) ->
bool
95
{
96
SpellInfo
const
* spellInfo =
sSpellMgr
->AssertSpellInfo(cooldown.
SpellId
,
DIFFICULTY_NONE
);
97
Milliseconds
remainingCooldown = player->
GetSpellHistory
()->
GetRemainingCooldown
(spellInfo);
98
Milliseconds
totalCooldown =
Milliseconds
(spellInfo->
RecoveryTime
);
99
Milliseconds
categoryCooldown =
Milliseconds
(spellInfo->
CategoryRecoveryTime
);
100
101
auto
applySpellMod = [&](
Milliseconds
& value)
102
{
103
int32
intValue = value.count();
104
player->
ApplySpellMod
(spellInfo,
SpellModOp::Cooldown
, intValue,
nullptr
);
105
value =
Milliseconds
(intValue);
106
};
107
108
applySpellMod(totalCooldown);
109
110
if
(
int32
cooldownMod = player->
GetTotalAuraModifier
(
SPELL_AURA_MOD_COOLDOWN
))
111
totalCooldown +=
Milliseconds
(cooldownMod);
112
113
if
(!spellInfo->
HasAttribute
(
SPELL_ATTR6_NO_CATEGORY_COOLDOWN_MODS
))
114
applySpellMod(categoryCooldown);
115
116
return
remainingCooldown > 0ms
117
&& !cooldown.
OnHold
118
&&
Milliseconds
(totalCooldown) < 10min
119
&&
Milliseconds
(categoryCooldown) < 10min
120
&&
Milliseconds
(remainingCooldown) < 10min
121
&& (onStartDuel ? totalCooldown - remainingCooldown > 30s :
true
)
122
&& (onStartDuel ? categoryCooldown - remainingCooldown > 30s :
true
);
123
},
true
);
124
125
// pet cooldowns
126
if
(
Pet
* pet = player->
GetPet
())
127
pet->GetSpellHistory()->ResetAllCooldowns();
128
}
129
};
130
131
void
AddSC_duel_reset
()
132
{
133
new
DuelResetScript
();
134
}
DIFFICULTY_NONE
@ DIFFICULTY_NONE
Definition
DBCEnums.h:933
int32
int32_t int32
Definition
Define.h:150
Milliseconds
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition
Duration.h:24
GameTime.h
Pet.h
Player.h
ScriptMgr.h
CLASS_DRUID
@ CLASS_DRUID
Definition
SharedDefines.h:166
POWER_MANA
@ POWER_MANA
Definition
SharedDefines.h:295
DuelCompleteType
DuelCompleteType
Definition
SharedDefines.h:7115
DUEL_WON
@ DUEL_WON
Definition
SharedDefines.h:7117
SPELL_ATTR6_NO_CATEGORY_COOLDOWN_MODS
@ SPELL_ATTR6_NO_CATEGORY_COOLDOWN_MODS
Definition
SharedDefines.h:690
SPELL_AURA_MOD_COOLDOWN
@ SPELL_AURA_MOD_COOLDOWN
Definition
SpellAuraDefines.h:283
SpellModOp::Cooldown
@ Cooldown
SpellHistory.h
SpellInfo.h
SpellMgr.h
sSpellMgr
#define sSpellMgr
Definition
SpellMgr.h:812
World.h
DuelResetScript
Definition
duel_reset.cpp:28
DuelResetScript::OnDuelEnd
void OnDuelEnd(Player *winner, Player *loser, DuelCompleteType type) override
Definition
duel_reset.cpp:59
DuelResetScript::DuelResetScript
DuelResetScript()
Definition
duel_reset.cpp:30
DuelResetScript::OnDuelStart
void OnDuelStart(Player *player1, Player *player2) override
Definition
duel_reset.cpp:33
DuelResetScript::ResetSpellCooldowns
static void ResetSpellCooldowns(Player *player, bool onStartDuel)
Definition
duel_reset.cpp:91
Pet
Definition
Pet.h:40
PlayerScript
Definition
ScriptMgr.h:692
Player
Definition
Player.h:1233
Player::SaveHealthBeforeDuel
void SaveHealthBeforeDuel()
Definition
Player.h:2462
Player::ApplySpellMod
void ApplySpellMod(SpellInfo const *spellInfo, SpellModOp op, T &basevalue, Spell *spell=nullptr) const
Definition
Player.cpp:22893
Player::GetPet
Pet * GetPet() const
Definition
Player.cpp:22060
Player::RestoreManaAfterDuel
void RestoreManaAfterDuel()
Definition
Player.h:2465
Player::RestoreHealthAfterDuel
void RestoreHealthAfterDuel()
Definition
Player.h:2464
Player::SaveManaBeforeDuel
void SaveManaBeforeDuel()
Definition
Player.h:2463
Player::ResetAllPowers
void ResetAllPowers()
Definition
Player.cpp:1859
SpellHistory::GetRemainingCooldown
Duration GetRemainingCooldown(SpellInfo const *spellInfo) const
Definition
SpellHistory.cpp:737
SpellHistory::RestoreCooldownStateAfterDuel
void RestoreCooldownStateAfterDuel()
Definition
SpellHistory.cpp:1173
SpellHistory::SaveCooldownStateBeforeDuel
void SaveCooldownStateBeforeDuel()
Definition
SpellHistory.cpp:1168
SpellHistory::ResetCooldowns
void ResetCooldowns(Predicate &&predicate, bool update=false)
Definition
SpellHistory.h:154
SpellInfo
Definition
SpellInfo.h:324
SpellInfo::RecoveryTime
uint32 RecoveryTime
Definition
SpellInfo.h:371
SpellInfo::CategoryRecoveryTime
uint32 CategoryRecoveryTime
Definition
SpellInfo.h:372
SpellInfo::HasAttribute
bool HasAttribute(SpellAttr0 attribute) const
Definition
SpellInfo.h:456
Unit::GetClass
uint8 GetClass() const
Definition
Unit.h:764
Unit::GetPowerType
Powers GetPowerType() const
Definition
Unit.h:811
Unit::GetTotalAuraModifier
float GetTotalAuraModifier(AuraType auraType) const
Definition
Unit.cpp:5069
Unit::GetSpellHistory
SpellHistory * GetSpellHistory()
Definition
Unit.h:1498
AddSC_duel_reset
void AddSC_duel_reset()
Definition
duel_reset.cpp:131
sWorld
#define sWorld
Definition
World.h:916
CONFIG_RESET_DUEL_HEALTH_MANA
@ CONFIG_RESET_DUEL_HEALTH_MANA
Definition
World.h:179
CONFIG_RESET_DUEL_COOLDOWNS
@ CONFIG_RESET_DUEL_COOLDOWNS
Definition
World.h:178
SpellHistory::CooldownEntry
Definition
SpellHistory.h:66
SpellHistory::CooldownEntry::OnHold
bool OnHold
Definition
SpellHistory.h:72
SpellHistory::CooldownEntry::SpellId
uint32 SpellId
Definition
SpellHistory.h:67
server
scripts
World
duel_reset.cpp
Generated on Sun May 10 2026 02:09:15 for TrinityCore by
1.9.8