Horizon Official Technical Documentation
Inventory.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_GAME_ASSETS_INVENTORY_HPP
31#define HORIZON_ZONE_GAME_ASSETS_INVENTORY_HPP
32
34
35namespace Horizon
36{
37namespace Zone
38{
39namespace Units
40{
41 class Player;
42 class Item;
43}
44namespace Assets
45{
47{
54};
55
57{
60};
61
63{
72};
74{
75 typedef std::vector<std::shared_ptr<item_entry_data>> storage_type;
76public:
77 Inventory(std::shared_ptr<Horizon::Zone::Units::Player> player, uint32_t max_storage);
78 virtual ~Inventory();
79
80 int16_t get_free_index();
81
82 std::shared_ptr<Horizon::Zone::Units::Player> player() { return _player.lock(); }
83 inventory_addition_result_type add_item(std::shared_ptr<Horizon::Zone::Units::Item> floor_item);
84 inventory_addition_result_type add_item(uint32_t item_id, uint16_t amount, bool is_identified = false);
85 inventory_addition_result_type add_item(std::shared_ptr<item_entry_data> item, int amount);
86 std::shared_ptr<item_entry_data> get_item(uint32_t inventory_index);
87 inventory_removal_result_type remove_item(int16_t inventory_index, int amount, item_deletion_reason_type reason = ITEM_DEL_NORMAL);
88 void drop_item(uint32_t inventory_index, uint16_t amount);
89
90 void initialize();
91
92 bool use_item(uint32_t inventory_index, uint32_t guid);
93 bool can_equip(uint32_t inventory_index);
94 item_equip_result_type equip_item(uint32_t inventory_index, uint16_t equip_location_mask);
95 item_unequip_result_type unequip_item(uint32_t inventory_index);
97 void add_to_equipment_list(std::shared_ptr<item_entry_data> item);
98 void remove_from_equipment_list(std::shared_ptr<item_entry_data> item);
99
100 void notify_all();
103 void notify_add(std::shared_ptr<item_entry_data> const &item, uint16_t amount, inventory_addition_result_type fail);
104 void notify_deletion(uint16_t idx, uint16_t amount, inventory_deletion_reason_type reason);
105 void notify_drop(uint16_t idx, uint16_t amount);
106 void notify_move_fail(uint16_t idx, bool silent);
107
108 int32_t save();
109 int32_t load();
110
112 uint32_t max_storage() { return _max_storage; }
113
114 void print_inventory();
115
116protected:
117 uint32_t calculate_current_equip_location_mask(std::shared_ptr<const item_config_data> item);
118private:
120 std::weak_ptr<Horizon::Zone::Units::Player> _player;
123};
124}
125}
126}
127#endif /* HORIZON_ZONE_GAME_ASSETS_INVENTORY_HPP */
item_equip_result_type
Definition: ItemDefinitions.hpp:321
item_deletion_reason_type
Definition: ItemDefinitions.hpp:309
@ ITEM_DEL_NORMAL
Definition: ItemDefinitions.hpp:310
item_unequip_result_type
Definition: ItemDefinitions.hpp:328
std::array< std::pair< item_equip_location_mask, std::weak_ptr< item_entry_data > >, IT_EQPI_MAX > EquipmentListType
Definition: ItemDefinitions.hpp:577
std::atomic< bool > fail
Definition: LockedLookupTableTest.cpp:49
Definition: Inventory.hpp:74
inventory_removal_result_type remove_item(int16_t inventory_index, int amount, item_deletion_reason_type reason=ITEM_DEL_NORMAL)
Definition: Inventory.cpp:426
std::shared_ptr< item_entry_data > get_item(uint32_t inventory_index)
Definition: Inventory.cpp:448
EquipmentListType & equipments()
Definition: Inventory.hpp:96
uint32_t max_storage()
Definition: Inventory.hpp:112
bool use_item(uint32_t inventory_index, uint32_t guid)
Definition: Inventory.cpp:91
inventory_addition_result_type add_item(std::shared_ptr< Horizon::Zone::Units::Item > floor_item)
Definition: Inventory.cpp:306
void add_to_equipment_list(std::shared_ptr< item_entry_data > item)
Definition: Inventory.cpp:186
void drop_item(uint32_t inventory_index, uint16_t amount)
Definition: Inventory.cpp:453
int32_t _max_storage
Definition: Inventory.hpp:119
storage_type _inventory_items
Definition: Inventory.hpp:122
item_unequip_result_type unequip_item(uint32_t inventory_index)
Definition: Inventory.cpp:161
void remove_from_equipment_list(std::shared_ptr< item_entry_data > item)
Definition: Inventory.cpp:201
std::shared_ptr< Horizon::Zone::Units::Player > player()
Definition: Inventory.hpp:82
virtual ~Inventory()
Definition: Inventory.cpp:76
void initialize()
Inventory initialization for player, called after Status is computed and notified.
Definition: Inventory.cpp:84
void notify_without_equipments()
Definition: Inventory.cpp:270
void notify_only_equipments()
Definition: Inventory.cpp:283
std::vector< std::shared_ptr< item_entry_data > > storage_type
Definition: Inventory.hpp:75
item_equip_result_type equip_item(uint32_t inventory_index, uint16_t equip_location_mask)
Definition: Inventory.cpp:107
int16_t get_free_index()
Definition: Inventory.cpp:295
void notify_move_fail(uint16_t idx, bool silent)
Definition: Inventory.cpp:504
storage_type _saved_inventory_items
Definition: Inventory.hpp:122
void notify_drop(uint16_t idx, uint16_t amount)
Definition: Inventory.cpp:499
uint32_t calculate_current_equip_location_mask(std::shared_ptr< const item_config_data > item)
Definition: Inventory.cpp:214
Inventory(std::shared_ptr< Horizon::Zone::Units::Player > player, uint32_t max_storage)
Definition: Inventory.cpp:50
void set_max_storage(uint32_t max_storage)
Definition: Inventory.hpp:111
void notify_all()
Definition: Inventory.cpp:262
std::weak_ptr< Horizon::Zone::Units::Player > _player
Definition: Inventory.hpp:120
void notify_add(std::shared_ptr< item_entry_data > const &item, uint16_t amount, inventory_addition_result_type fail)
Definition: Inventory.cpp:477
EquipmentListType _equipments
Definition: Inventory.hpp:121
bool can_equip(uint32_t inventory_index)
int32_t load()
Definition: Inventory.cpp:595
void print_inventory()
Definition: Inventory.cpp:245
void notify_deletion(uint16_t idx, uint16_t amount, inventory_deletion_reason_type reason)
Definition: Inventory.cpp:494
int32_t save()
Definition: Inventory.cpp:509
Definition: ReferenceListTest.cpp:114
inventory_deletion_reason_type
Definition: Inventory.hpp:63
@ INVENTORY_DEL_FAILREFINE
Item used for a skill.
Definition: Inventory.hpp:66
@ INVENTORY_DEL_SKILLUSE
Normal.
Definition: Inventory.hpp:65
@ INVENTORY_DEL_MATERIALCHANGE
Refine failed.
Definition: Inventory.hpp:67
@ INVENTORY_DEL_NORMAL
Definition: Inventory.hpp:64
@ INVENTORY_DEL_ANALYSIS
Item sold.
Definition: Inventory.hpp:71
@ INVENTORY_DEL_TOSTORAGE
Material changed.
Definition: Inventory.hpp:68
@ INVENTORY_DEL_TOCART
Moved to storage.
Definition: Inventory.hpp:69
@ INVENTORY_DEL_SOLD
Moved to cart.
Definition: Inventory.hpp:70
inventory_removal_result_type
Definition: Inventory.hpp:57
@ INVENTORY_REMOVE_SUCCESS
Definition: Inventory.hpp:58
@ INVENTORY_REMOVE_INVALID
Success.
Definition: Inventory.hpp:59
inventory_addition_result_type
Definition: Inventory.hpp:47
@ INVENTORY_ADD_OVER_STACK_LIMIT
Max amount reached.
Definition: Inventory.hpp:53
@ INVENTORY_ADD_SUCCESS
Definition: Inventory.hpp:48
@ INVENTORY_ADD_INVALID
Success.
Definition: Inventory.hpp:49
@ INVENTORY_ADD_OVER_WEIGHT
Invalid itemid not found or negative amount.
Definition: Inventory.hpp:50
@ INVENTORY_ADD_OVER_QUANTITY
No free place found.
Definition: Inventory.hpp:52
@ INVENTORY_ADD_NO_INV_SPACE
Overweight.
Definition: Inventory.hpp:51
Definition: Element.hpp:7