TrinityCore
PersonalPhaseTracker.h
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#ifndef PersonalPhaseTracker_h__
19#define PersonalPhaseTracker_h__
20
21#include "Common.h"
22#include "Duration.h"
23#include "GridDefines.h"
24#include "ObjectGuid.h"
25#include "Optional.h"
26
27class Map;
28class PhaseShift;
29class WorldObject;
30struct Cell;
31
33{
34 static constexpr Milliseconds DELETE_TIME_DEFAULT = 1min;
35
36 std::unordered_set<WorldObject*> Objects;
37 std::unordered_set<uint16> Grids;
39
40 bool IsEmpty() const { return Objects.empty() && Grids.empty(); }
41};
42
43/* Tracks personal phases for a single owner */
45{
46public:
47 void RegisterTrackedObject(uint32 phaseId, WorldObject* object);
49
50 void OnOwnerPhasesChanged(WorldObject const* owner);
52
53 void Update(Map* map, uint32 diff);
54
55 bool IsGridLoadedForPhase(uint32 gridId, uint32 phaseId) const;
56 void SetGridLoadedForPhase(uint32 gridId, uint32 phaseId);
57 void SetGridUnloaded(uint32 gridId);
58
59 bool IsEmpty() const { return _spawns.empty(); }
60
61private:
62 void DespawnPhase(Map* map, PersonalPhaseSpawns& spawns);
63
64 std::unordered_map<uint32 /*phaseId*/, PersonalPhaseSpawns> _spawns;
65};
66
67/* Handles personal phase trackers for all owners */
69{
70 void LoadGrid(PhaseShift const& phaseShift, NGridType& grid, Map* map, Cell const& cell);
71 void UnloadGrid(NGridType& grid);
72
73 void RegisterTrackedObject(uint32 phaseId, ObjectGuid const& phaseOwner, WorldObject* object);
75
76 void OnOwnerPhaseChanged(WorldObject const* phaseOwner, NGridType* grid, Map* map, Cell const& cell);
77 void MarkAllPhasesForDeletion(ObjectGuid const& phaseOwner);
78
79 void Update(Map* map, uint32 diff);
80
81private:
82 std::unordered_map<ObjectGuid /*owner*/, PlayerPersonalPhasesTracker> _playerData;
83};
84
85#endif // PersonalPhaseTracker_h__
uint32_t uint32
Definition: Define.h:142
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:29
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
Definition: Map.h:189
Definition: NGrid.h:70
Definition: Cell.h:47
void Update(Map *map, uint32 diff)
std::unordered_map< ObjectGuid, PlayerPersonalPhasesTracker > _playerData
void MarkAllPhasesForDeletion(ObjectGuid const &phaseOwner)
void RegisterTrackedObject(uint32 phaseId, ObjectGuid const &phaseOwner, WorldObject *object)
void LoadGrid(PhaseShift const &phaseShift, NGridType &grid, Map *map, Cell const &cell)
void UnregisterTrackedObject(WorldObject *object)
void UnloadGrid(NGridType &grid)
void OnOwnerPhaseChanged(WorldObject const *phaseOwner, NGridType *grid, Map *map, Cell const &cell)
static constexpr Milliseconds DELETE_TIME_DEFAULT
Optional< Milliseconds > DurationRemaining
std::unordered_set< WorldObject * > Objects
std::unordered_set< uint16 > Grids
void UnregisterTrackedObject(WorldObject *object)
void SetGridLoadedForPhase(uint32 gridId, uint32 phaseId)
void RegisterTrackedObject(uint32 phaseId, WorldObject *object)
bool IsGridLoadedForPhase(uint32 gridId, uint32 phaseId) const
void Update(Map *map, uint32 diff)
void OnOwnerPhasesChanged(WorldObject const *owner)
std::unordered_map< uint32, PersonalPhaseSpawns > _spawns
void DespawnPhase(Map *map, PersonalPhaseSpawns &spawns)