TrinityCore
Loading...
Searching...
No Matches
MirrorTimer.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 "MirrorTimer.h"
19
21{
22 if (IsActive() && value != GetValue())
24
25 m_value = value;
26}
27
29{
30 if (!maxValue)
31 Stop();
32
33 if (!IsActive())
34 return;
35
36 if (maxValue != GetMaxValue())
38
39 m_maxValue = maxValue;
40 SetValue(std::min(GetValue(), GetMaxValue()));
41}
42
44{
45 if (!scale)
46 return SetPaused(true);
47
48 if (IsActive() && scale != GetScale())
50
51 m_scale = scale;
52}
53
54void MirrorTimer::SetPaused(bool state)
55{
56 if (IsActive() && state != IsPaused())
58
59 if (state)
61 else
63}
64
65void MirrorTimer::Start(int32 maxValue, int32 spellId)
66{
67 if (m_scale < 0)
68 {
69 m_value = maxValue;
70 m_maxValue = maxValue;
71 m_spellId = spellId;
74 }
75 else
76 Stop();
77}
78
79void MirrorTimer::Start(int32 value, int32 maxValue, int32 spellId)
80{
81 Start(maxValue, spellId);
82
83 if (IsActive())
84 m_value = value;
85}
86
88{
89 if (!IsActive())
90 return;
91
92 m_value = 0;
93 m_maxValue = 0;
95}
96
98{
99 if (!IsActive() || IsPaused())
101
102 int32 delta = int32(diff) * GetScale();
103
104 if (delta < 0) // Timer running out
105 {
106 if (GetValue() > -delta)
107 {
108 m_value += delta;
110 }
111
112 if (!m_value) // subsequent ticks after expiration
113 {
114 if (!m_expiredTick.Update(diff))
116 }
117 else
118 m_value = 0;
119
121 }
122 else // Timer regenerating
123 {
124 if (GetValue() + delta < GetMaxValue())
125 {
126 m_value += delta;
128 }
129 else
130 Stop();
131
133 }
134}
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
MirrorTimerFlags
Definition MirrorTimer.h:35
void Start(int32 maxValue, int32 spellId)
static constexpr Milliseconds ExpiredTickPeriod
Definition MirrorTimer.h:91
int32 m_maxValue
Definition MirrorTimer.h:86
PeriodicTimer m_expiredTick
Definition MirrorTimer.h:92
int32 m_value
Definition MirrorTimer.h:85
void SetPaused(bool state)
void SetScale(int32 scale)
int32 GetMaxValue() const
Definition MirrorTimer.h:53
int32 GetScale() const
Definition MirrorTimer.h:56
bool IsPaused() const
Definition MirrorTimer.h:61
int32 m_scale
Definition MirrorTimer.h:87
int32 GetValue() const
Definition MirrorTimer.h:50
void SetMaxValue(int32 maxValue)
int32 m_spellId
Definition MirrorTimer.h:88
UpdateResult Update(uint32 diff)
bool IsActive() const
Definition MirrorTimer.h:47
EnumFlag< MirrorTimerFlags > m_flags
Definition MirrorTimer.h:89
void SetValue(int32 value)
bool Update(const uint32 diff)
Definition Timer.h:164
void SetPeriodic(int32 period, int32 start_time)
Definition Timer.h:173