GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/playerinfo.h Lines: 3 3 100.0 %
Date: 2018-11-12 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2010  The Mana Developers
4
 *  Copyright (C) 2011-2018  The ManaPlus Developers
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#ifndef BEING_PLAYERINFO_H
23
#define BEING_PLAYERINFO_H
24
25
#include "equipment.h"
26
27
#include "enums/guildpositionflags.h"
28
#include "enums/state.h"
29
30
#include "enums/being/attributes.h"
31
32
#include "enums/simpletypes/beingid.h"
33
#include "enums/simpletypes/keep.h"
34
#include "enums/simpletypes/notify.h"
35
#include "enums/simpletypes/sfx.h"
36
#include "enums/simpletypes/trading.h"
37
38
#include "utils/intmap.h"
39
40
#include <string>
41
42
/**
43
 * Stat information storage structure.
44
 */
45
struct Stat final
46
{
47
    A_DEFAULT_COPY(Stat)
48
49
    int base;
50
    int mod;
51
    int exp;
52
    int expNeed;
53
};
54
55
typedef std::map<AttributesT, int64_t> AtrIntMap;
56
typedef std::map<AttributesT, Stat> StatMap;
57
58
/**
59
 * Backend for core player information.
60
 */
61
4
struct PlayerInfoBackend final
62
{
63
1
    PlayerInfoBackend() :
64
        mAttributes(),
65
        mStats(),
66
4
        mSkills()
67
    {
68
    }
69
70
    A_DEFAULT_COPY(PlayerInfoBackend)
71
72
    AtrIntMap mAttributes;
73
    StatMap mStats;
74
    IntMap mSkills;
75
};
76
77
class Being;
78
class FloorItem;
79
class Inventory;
80
class Item;
81
82
struct HomunculusInfo;
83
struct MercenaryInfo;
84
struct PetInfo;
85
86
/**
87
 * A database like namespace which holds global info about the localplayer
88
 *
89
 */
90
namespace PlayerInfo
91
{
92
// --- Attributes -------------------------------------------------------------
93
94
    /**
95
     * Returns the value of the given attribute.
96
     */
97
    int64_t getAttribute64(const AttributesT id) A_WARN_UNUSED;
98
99
    int32_t getAttribute(const AttributesT id) A_WARN_UNUSED;
100
101
    /**
102
     * Changes the value of the given attribute.
103
     */
104
    void setAttribute(const AttributesT id,
105
                      const int64_t value,
106
                      const Notify notify);
107
108
    int getSkillLevel(const int id) A_WARN_UNUSED;
109
110
    void setSkillLevel(const int id, const int value);
111
112
// --- Stats ------------------------------------------------------------------
113
114
    /**
115
     * Returns the base value of the given stat.
116
     */
117
    int getStatBase(const AttributesT id) A_WARN_UNUSED;
118
119
    /**
120
     * Changes the base value of the given stat.
121
     */
122
    void setStatBase(const AttributesT id,
123
                     const int value,
124
                     const Notify notify);
125
126
    /**
127
     * Returns the modifier for the given stat.
128
     */
129
    int getStatMod(const AttributesT id) A_WARN_UNUSED;
130
131
    /**
132
     * Changes the modifier for the given stat.
133
     */
134
    void setStatMod(const AttributesT id,
135
                    const int value,
136
                    const Notify notify);
137
138
    /**
139
     * Returns the current effective value of the given stat. Effective is base
140
     * + mod
141
     */
142
    int getStatEffective(const AttributesT id) A_WARN_UNUSED;
143
144
    /**
145
     * Returns the experience of the given stat.
146
     */
147
    const std::pair<int, int> getStatExperience(const AttributesT id)
148
                                                A_WARN_UNUSED;
149
150
// --- Inventory / Equipment --------------------------------------------------
151
152
    /**
153
     * Returns the player's inventory.
154
     */
155
    Inventory *getInventory() A_WARN_UNUSED;
156
157
    Inventory *getStorageInventory() A_WARN_UNUSED;
158
159
    Inventory *getCartInventory() A_WARN_UNUSED;
160
161
    /**
162
     * Clears the player's inventory and equipment.
163
     */
164
    void clearInventory();
165
166
    void clear();
167
168
    /**
169
     * Returns the player's equipment.
170
     */
171
    Equipment *getEquipment() A_WARN_UNUSED;
172
173
    /**
174
     * Returns the player's equipment at the given slot.
175
     */
176
    const Item *getEquipment(const unsigned int slot) A_WARN_UNUSED;
177
178
// --- Misc -------------------------------------------------------------------
179
180
    /**
181
     * Changes the internal PlayerInfoBackend reference;
182
     */
183
    void setBackend(const PlayerInfoBackend &backend);
184
185
    void setCharId(const int charId);
186
187
    int getCharId();
188
189
    /**
190
     * Returns true if the player is involved in a trade at the moment, false
191
     * otherwise.
192
     */
193
    Trading isTrading();
194
195
    /**
196
     * Sets whether the player is currently involved in trade or not.
197
     */
198
    void setTrading(const Trading trading);
199
200
    void updateAttrs();
201
202
    /**
203
     * Initializes some internals.
204
     */
205
    void init();
206
207
    void deinit();
208
209
    void loadData();
210
211
    bool isTalking();
212
213
    void gameDestroyed();
214
215
    void stateChange(const StateT state);
216
217
    void triggerAttr(const AttributesT id,
218
                     const int64_t old);
219
220
    void triggerStat(const AttributesT id,
221
                     const int old1,
222
                     const int old2);
223
224
    void setEquipmentBackend(Equipment::Backend *const backend);
225
226
    void equipItem(const Item *const item, const Sfx sfx);
227
228
    void unequipItem(const Item *const item, const Sfx sfx);
229
230
    void useItem(const Item *const item, const Sfx sfx);
231
232
    void useEquipItem(const Item *const item,
233
                      const int16_t useType,
234
                      const Sfx sfx);
235
236
    void useEquipItem2(const Item *const item,
237
                       const int16_t useType,
238
                       const Sfx sfx);
239
240
    void dropItem(const Item *const item, const int amount, const Sfx sfx);
241
242
    void pickUpItem(const FloorItem *const item, const Sfx sfx);
243
244
    void protectItem(const int id);
245
246
    void unprotectItem(const int id);
247
248
    bool isItemProtected(const int id);
249
250
    MercenaryInfo *getMercenary();
251
252
    void setMercenary(MercenaryInfo *const info);
253
254
    void setMercenaryBeing(Being *const being);
255
256
    PetInfo *getPet();
257
258
    void setPet(PetInfo *const info);
259
260
    void setPetBeing(Being *const being);
261
262
    BeingId getPetBeingId();
263
264
    HomunculusInfo *getHomunculus();
265
266
    void setHomunculus(HomunculusInfo *const info);
267
268
    void setHomunculusBeing(Being *const being);
269
270
    void setElemental(const BeingId id);
271
272
    BeingId getHomunculusId();
273
274
    BeingId getMercenaryId();
275
276
    BeingId getElementalId();
277
278
    void updateAttackAi(const BeingId targetId,
279
                        const Keep keep);
280
281
    std::string getRoomName();
282
283
    void setRoomName(const std::string &name);
284
285
    bool isInRoom();
286
287
    void setGuildPositionFlags(const GuildPositionFlags::Type pos);
288
289
    GuildPositionFlags::Type getGuildPositionFlags();
290
291
    void enableVending(const bool b);
292
293
    bool isVending() A_WARN_UNUSED;
294
295
    void setServerLanguage(const int lang);
296
297
    int getServerLanguage() A_WARN_UNUSED;
298
}  // namespace PlayerInfo
299
300
#endif  // BEING_PLAYERINFO_H