GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/playerinfo.h Lines: 3 3 100.0 %
Date: 2017-11-29 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-2017  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
8
struct PlayerInfoBackend final
62
{
63
2
    PlayerInfoBackend() :
64
        mAttributes(),
65
        mStats(),
66
8
        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 = Notify_true);
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 = Notify_true);
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 = Notify_true);
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
     * Changes the level of the given stat.
146
     */
147
    void setStatLevel(AttributesT id, int value, Notify notify = Notify_true);
148
149
    /**
150
     * Returns the experience of the given stat.
151
     */
152
    const std::pair<int, int> getStatExperience(const AttributesT id)
153
                                                A_WARN_UNUSED;
154
155
    /**
156
     * Changes the experience of the given stat.
157
     */
158
    void setStatExperience(const AttributesT id,
159
                           const int have,
160
                           const int need,
161
                           const Notify notify = Notify_true);
162
163
// --- Inventory / Equipment --------------------------------------------------
164
165
    /**
166
     * Returns the player's inventory.
167
     */
168
    Inventory *getInventory() A_WARN_UNUSED;
169
170
    Inventory *getStorageInventory() A_WARN_UNUSED;
171
172
    Inventory *getCartInventory() A_WARN_UNUSED;
173
174
    /**
175
     * Clears the player's inventory and equipment.
176
     */
177
    void clearInventory();
178
179
    void clear();
180
181
    /**
182
     * Returns the player's equipment.
183
     */
184
    Equipment *getEquipment() A_WARN_UNUSED;
185
186
    /**
187
     * Returns the player's equipment at the given slot.
188
     */
189
    const Item *getEquipment(const unsigned int slot) A_WARN_UNUSED;
190
191
// --- Misc -------------------------------------------------------------------
192
193
    /**
194
     * Changes the internal PlayerInfoBackend reference;
195
     */
196
    void setBackend(const PlayerInfoBackend &backend);
197
198
    void setCharId(const int charId);
199
200
    int getCharId();
201
202
    /**
203
     * Returns true if the player is involved in a trade at the moment, false
204
     * otherwise.
205
     */
206
    Trading isTrading();
207
208
    /**
209
     * Sets whether the player is currently involved in trade or not.
210
     */
211
    void setTrading(const Trading trading);
212
213
    void updateAttrs();
214
215
    /**
216
     * Initializes some internals.
217
     */
218
    void init() A_CONST;
219
220
    void deinit();
221
222
    void loadData();
223
224
    bool isTalking();
225
226
    void gameDestroyed();
227
228
    void stateChange(const StateT state);
229
230
    void triggerAttr(const AttributesT id,
231
                     const int64_t old);
232
233
    void triggerStat(const AttributesT id,
234
                     const int old1,
235
                     const int old2);
236
237
    void setEquipmentBackend(Equipment::Backend *const backend);
238
239
    void equipItem(const Item *const item, const Sfx sfx);
240
241
    void unequipItem(const Item *const item, const Sfx sfx);
242
243
    void useItem(const Item *const item, const Sfx sfx);
244
245
    void useEquipItem(const Item *const item,
246
                      const int16_t useType,
247
                      const Sfx sfx);
248
249
    void useEquipItem2(const Item *const item,
250
                       const int16_t useType,
251
                       const Sfx sfx);
252
253
    void dropItem(const Item *const item, const int amount, const Sfx sfx);
254
255
    void pickUpItem(const FloorItem *const item, const Sfx sfx);
256
257
    void protectItem(const int id);
258
259
    void unprotectItem(const int id);
260
261
    bool isItemProtected(const int id);
262
263
    MercenaryInfo *getMercenary();
264
265
    void setMercenary(MercenaryInfo *const info);
266
267
    void setMercenaryBeing(Being *const being);
268
269
    PetInfo *getPet();
270
271
    void setPet(PetInfo *const info);
272
273
    void setPetBeing(Being *const being);
274
275
    BeingId getPetBeingId();
276
277
    HomunculusInfo *getHomunculus();
278
279
    void setHomunculus(HomunculusInfo *const info);
280
281
    void setHomunculusBeing(Being *const being);
282
283
    void setElemental(const BeingId id);
284
285
    BeingId getHomunculusId();
286
287
    BeingId getMercenaryId();
288
289
    BeingId getElementalId();
290
291
    void updateAttackAi(const BeingId targetId,
292
                        const Keep keep);
293
294
    std::string getRoomName();
295
296
    void setRoomName(const std::string &name);
297
298
    bool isInRoom();
299
300
    void setGuildPositionFlags(const GuildPositionFlags::Type pos);
301
302
    GuildPositionFlags::Type getGuildPositionFlags();
303
304
    void enableVending(const bool b);
305
306
    bool isVending() A_WARN_UNUSED;
307
308
    void setServerLanguage(const int lang);
309
310
    int getServerLanguage() A_WARN_UNUSED;
311
}  // namespace PlayerInfo
312
313
#endif  // BEING_PLAYERINFO_H