1 /*
2  * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Solarus is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for 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 #ifndef SOLARUS_EQUIPMENT_H
18 #define SOLARUS_EQUIPMENT_H
19 
20 #include "solarus/core/Common.h"
21 #include "solarus/core/Ability.h"
22 #include <map>
23 #include <memory>
24 #include <string>
25 
26 struct lua_State;
27 
28 namespace Solarus {
29 
30 class EquipmentItem;
31 class Game;
32 class Map;
33 class Savegame;
34 
35 /**
36  * \brief Represents the hero's equipment.
37  *
38  * This class gives access to the equipment data saved and the properties of
39  * items.
40  * You should call this class to get information about the current equipment
41  * (sword, money, items...) and to modify it.
42  */
43 class SOLARUS_API Equipment {
44 
45   public:
46 
47     // creation and destruction
48     explicit Equipment(Savegame& savegame);
49 
50     Savegame& get_savegame();
51     Game* get_game();
52     void notify_game_started();
53     void notify_game_finished();
54     void notify_map_changed(Map& map);
55 
56     void update();
57     void set_suspended(bool suspended);
58 
59     // money
60     int get_max_money() const;
61     void set_max_money(int max_money);
62 
63     int get_money() const;
64     void set_money(int money);
65     void add_money(int money_to_add);
66     void remove_money(int money_to_remove);
67 
68     // life
69     int get_max_life() const;
70     void set_max_life(int max_life);
71 
72     int get_life() const;
73     void set_life(int life);
74     void add_life(int life_to_add);
75     void remove_life(int life_to_remove);
76     void restore_all_life();
77 
78     // magic
79     int get_max_magic() const;
80     void set_max_magic(int max_magic);
81 
82     int get_magic() const;
83     void set_magic(int magic);
84     void add_magic(int magic_to_add);
85     void remove_magic(int magic_to_remove);
86     void restore_all_magic();
87 
88     // equipment items
89     void load_items();
90     bool item_exists(const std::string& item_name) const;
91     EquipmentItem& get_item(const std::string& item_name);
92     const EquipmentItem& get_item(const std::string& item_name) const;
93     EquipmentItem* get_item_assigned(int slot);
94     const EquipmentItem* get_item_assigned(int slot) const;
95     void set_item_assigned(int slot, EquipmentItem* item);
96     int get_item_slot(const EquipmentItem& item) const;
97 
98     // built-in abilities
99     // TODO make notify_ability_changed
100     bool has_ability(Ability ability, int level = 1) const;
101     int get_ability(Ability ability) const;
102     void set_ability(Ability ability, int level);
103     void notify_ability_used(Ability ability);
104 
105   private:
106 
107     Savegame& savegame;                          /**< The savegame encapsulated by this equipment object. */
108     bool suspended;                              /**< Indicates that the game is suspended. */
109 
110     // items
111     std::map<std::string, std::shared_ptr<EquipmentItem>>
112         items;                                   /**< Each item (properties loaded from item scripts). */
113 
114     std::string get_ability_savegame_variable(Ability ability) const;
115 
116 };
117 
118 }
119 
120 #endif
121 
122