aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Player/RestMgr.h
blob: b3d991a16770012003671c9ea0538dae4fa28511 (plain)
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
92
93
94
95
96
97
98
99
100
/*
 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef RestMgr_h__
#define RestMgr_h__

#include "Define.h"
#include "Optional.h"
#include <ctime>

class Player;

enum RestTypes : uint8
{
    REST_TYPE_XP    = 0,
    REST_TYPE_HONOR = 1,
    REST_TYPE_MAX
};

enum PlayerRestInfoOffsets : uint8
{
    REST_STATE_XP       = 0,
    REST_RESTED_XP      = 1,
    REST_STATE_HONOR    = 2,
    REST_RESTED_HONOR   = 3,

    MAX_REST_INFO
};

// Exhaustion.db2 ids
enum PlayerRestState : uint8
{
    REST_STATE_RESTED           = 1,
    REST_STATE_NORMAL           = 2,
    REST_STATE_RAF_LINKED       = 6
};

enum RestFlag : uint32
{
    REST_FLAG_IN_TAVERN         = 0x1,
    REST_FLAG_IN_CITY           = 0x2,
    REST_FLAG_IN_FACTION_AREA   = 0x4 // used with AREA_FLAG_REST_ZONE_*
};

struct InnAreaTrigger
{
    bool IsDBC = true;
    uint32 AreaTriggerEntryId = 0;
};

class TC_GAME_API RestMgr
{
    friend class Player;
public:
    explicit RestMgr(Player* player);
    ~RestMgr() { }

    float GetRestBonus(RestTypes restType) const { return _restBonus[restType]; }

    void SetRestBonus(RestTypes restType, float restBonus);
    void AddRestBonus(RestTypes restType, float restBonus);

    bool HasRestFlag(RestFlag restFlag) const { return (_restFlagMask & restFlag) != 0; }
    void SetRestFlag(RestFlag restFlag);
    void RemoveRestFlag(RestFlag restFlag);

    uint32 GetRestBonusFor(RestTypes restType, uint32 xp);
    Optional<InnAreaTrigger> GetInnTrigger() const { return _innAreaTrigger; }
    void SetInnTrigger(Optional<InnAreaTrigger> trigger) { _innAreaTrigger = trigger; }

    void Update(time_t now);

    float CalcExtraPerSec(RestTypes restType, float bubble) const;

protected:
    void LoadRestBonus(RestTypes restType, PlayerRestState state, float restBonus);

private:
    Player* _player;
    time_t _restTime;
    Optional<InnAreaTrigger> _innAreaTrigger;
    float _restBonus[REST_TYPE_MAX];
    uint32 _restFlagMask;
};

#endif // RestMgr_h__