TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DuelResetScript Class Reference

Public Member Functions

 DuelResetScript ()
 
void OnDuelStart (Player *player1, Player *player2) override
 
void OnDuelEnd (Player *winner, Player *loser, DuelCompleteType type) override
 
- Public Member Functions inherited from PlayerScript
virtual void OnPVPKill (Player *, Player *)
 
virtual void OnCreatureKill (Player *, Creature *)
 
virtual void OnPlayerKilledByCreature (Creature *, Player *)
 
virtual void OnLevelChanged (Player *, uint8)
 
virtual void OnFreeTalentPointsChanged (Player *, uint32)
 
virtual void OnTalentsReset (Player *, bool)
 
virtual void OnMoneyChanged (Player *, int64 &)
 
virtual void OnMoneyLimit (Player *, int64)
 
virtual void OnGiveXP (Player *, uint32 &, Unit *)
 
virtual void OnReputationChange (Player *, uint32, int32 &, bool)
 
virtual void OnDuelRequest (Player *, Player *)
 
virtual void OnChat (Player *, uint32, uint32, std::string &)
 
virtual void OnChat (Player *, uint32, uint32, std::string &, Player *)
 
virtual void OnChat (Player *, uint32, uint32, std::string &, Group *)
 
virtual void OnChat (Player *, uint32, uint32, std::string &, Guild *)
 
virtual void OnChat (Player *, uint32, uint32, std::string &, Channel *)
 
virtual void OnClearEmote (Player *)
 
virtual void OnTextEmote (Player *, uint32, uint32, ObjectGuid)
 
virtual void OnSpellCast (Player *, Spell *, bool)
 
virtual void OnLogin (Player *, bool)
 
virtual void OnLogout (Player *)
 
virtual void OnCreate (Player *)
 
virtual void OnDelete (ObjectGuid, uint32)
 
virtual void OnFailedDelete (ObjectGuid, uint32)
 
virtual void OnSave (Player *)
 
virtual void OnBindToInstance (Player *, Difficulty, uint32, bool, uint8)
 
virtual void OnUpdateZone (Player *, uint32, uint32)
 
virtual void OnMapChanged (Player *)
 
virtual void OnQuestStatusChange (Player *, uint32, QuestStatus)
 
- Public Member Functions inherited from UnitScript
virtual void OnHeal (Unit *, Unit *, uint32 &)
 
virtual void OnDamage (Unit *, Unit *, uint32 &)
 
virtual void ModifyPeriodicDamageAurasTick (Unit *, Unit *, uint32 &)
 
virtual void ModifyMeleeDamage (Unit *, Unit *, uint32 &)
 
virtual void ModifySpellDamageTaken (Unit *, Unit *, int32 &)
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static void ResetSpellCooldowns (Player *player, bool onStartDuel)
 

Additional Inherited Members

- Protected Member Functions inherited from PlayerScript
 PlayerScript (const char *name)
 
- Protected Member Functions inherited from UnitScript
 UnitScript (const char *name, bool addToScripts=true)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()
 

Constructor & Destructor Documentation

DuelResetScript::DuelResetScript ( )
inline
26 : PlayerScript("DuelResetScript") { }
PlayerScript(const char *name)
Definition: ScriptMgr.cpp:1664

Member Function Documentation

void DuelResetScript::OnDuelEnd ( Player winner,
Player loser,
DuelCompleteType  type 
)
inlineoverridevirtual

Reimplemented from PlayerScript.

68  {
69  // do not reset anything if DUEL_INTERRUPTED or DUEL_FLED
70  if (type == DUEL_WON)
71  {
72  // Cooldown restore
73  if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_COOLDOWNS))
74  {
75  ResetSpellCooldowns(winner, false);
76  ResetSpellCooldowns(loser, false);
77 
78  winner->GetSpellHistory()->RestoreCooldownStateAfterDuel();
79  loser->GetSpellHistory()->RestoreCooldownStateAfterDuel();
80  }
81 
82  // Health and mana restore
83  if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_HEALTH_MANA))
84  {
85  winner->RestoreHealthAfterDuel();
86  loser->RestoreHealthAfterDuel();
87 
88  // check if player1 class uses mana
89  if (winner->getPowerType() == POWER_MANA || winner->getClass() == CLASS_DRUID)
90  winner->RestoreManaAfterDuel();
91 
92  // check if player2 class uses mana
93  if (loser->getPowerType() == POWER_MANA || loser->getClass() == CLASS_DRUID)
94  loser->RestoreManaAfterDuel();
95  }
96  }
97  }
Definition: World.h:180
#define sWorld
Definition: World.h:887
Definition: SharedDefines.h:4727
static void ResetSpellCooldowns(Player *player, bool onStartDuel)
Definition: duel_reset.cpp:99
Definition: World.h:179
Definition: SharedDefines.h:177
Definition: SharedDefines.h:248

+ Here is the call graph for this function:

void DuelResetScript::OnDuelStart ( Player player1,
Player player2 
)
inlineoverridevirtual

Reimplemented from PlayerScript.

30  {
31  // Cooldowns reset
32  if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_COOLDOWNS))
33  {
34  player1->GetSpellHistory()->SaveCooldownStateBeforeDuel();
35  player2->GetSpellHistory()->SaveCooldownStateBeforeDuel();
36 
37  ResetSpellCooldowns(player1, true);
38  ResetSpellCooldowns(player2, true);
39  }
40 
41  // Health and mana reset
42  if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_HEALTH_MANA))
43  {
44  player1->SaveHealthBeforeDuel();
45  player1->SetHealth(player1->GetMaxHealth());
46 
47  player2->SaveHealthBeforeDuel();
48  player2->SetHealth(player2->GetMaxHealth());
49 
50  // check if player1 class uses mana
51  if (player1->getPowerType() == POWER_MANA || player1->getClass() == CLASS_DRUID)
52  {
53  player1->SaveManaBeforeDuel();
54  player1->SetPower(POWER_MANA, player1->GetMaxPower(POWER_MANA));
55  }
56 
57  // check if player2 class uses mana
58  if (player2->getPowerType() == POWER_MANA || player2->getClass() == CLASS_DRUID)
59  {
60  player2->SaveManaBeforeDuel();
61  player2->SetPower(POWER_MANA, player2->GetMaxPower(POWER_MANA));
62  }
63  }
64  }
Definition: World.h:180
#define sWorld
Definition: World.h:887
static void ResetSpellCooldowns(Player *player, bool onStartDuel)
Definition: duel_reset.cpp:99
Definition: World.h:179
Definition: SharedDefines.h:177
Definition: SharedDefines.h:248

+ Here is the call graph for this function:

static void DuelResetScript::ResetSpellCooldowns ( Player player,
bool  onStartDuel 
)
inlinestatic
100  {
101  if (onStartDuel)
102  {
103  // remove cooldowns on spells that have < 10 min CD > 30 sec and has no onHold
104  player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
105  {
106  SpellHistory::Clock::time_point now = SpellHistory::Clock::now();
107  uint32 cooldownDuration = itr->second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count() : 0;
108  SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(itr->first);
109  return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS
110  && spellInfo->CategoryRecoveryTime < 10 * MINUTE * IN_MILLISECONDS
111  && !itr->second.OnHold
112  && cooldownDuration > 0
113  && ( spellInfo->RecoveryTime - cooldownDuration ) > (MINUTE / 2) * IN_MILLISECONDS
114  && ( spellInfo->CategoryRecoveryTime - cooldownDuration ) > (MINUTE / 2) * IN_MILLISECONDS;
115  }, true);
116  }
117  else
118  {
119  // remove cooldowns on spells that have < 10 min CD and has no onHold
120  player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
121  {
122  SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(itr->first);
123  return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS
124  && spellInfo->CategoryRecoveryTime < 10 * MINUTE * IN_MILLISECONDS
125  && !itr->second.OnHold;
126  }, true);
127  }
128 
129  // pet cooldowns
130  if (Pet* pet = player->GetPet())
131  pet->GetSpellHistory()->ResetAllCooldowns();
132  }
Definition: SpellInfo.h:326
Definition: Common.h:97
uint32 RecoveryTime
Definition: SpellInfo.h:363
#define sSpellMgr
Definition: SpellMgr.h:756
uint32_t uint32
Definition: Define.h:150
float milliseconds()
Definition: units.h:92
Definition: Common.h:103
uint32 CategoryRecoveryTime
Definition: SpellInfo.h:364
Definition: Pet.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: