Horizon Official Technical Documentation
Storage.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_STORAGE_HPP
31#define HORIZON_ZONE_GAME_ASSETS_STORAGE_HPP
32
34
35namespace Horizon
36{
37namespace Zone
38{
40{
47};
49{
56};
58{
61};
62namespace Units
63{
64 class Player;
65 class Item;
66}
67namespace Assets
68{
70{
71 typedef std::vector<std::shared_ptr<item_entry_data>> storage_type;
72public:
73 Storage(std::shared_ptr<Horizon::Zone::Units::Player> player, int32_t storage_id, std::string name, uint32_t max_storage);
74 virtual ~Storage();
75
76 int32_t load();
77 int32_t save();
78
79 int16_t get_free_index();
80 int32_t get_storage_id() { return _storage_id; }
81 std::string name() { return _name; }
82 int32_t max_storage() { return _max_storage; }
83 std::shared_ptr<Horizon::Zone::Units::Player> player() { return _player.lock(); }
84
85
86 storage_add_item_result_type add_item(std::shared_ptr<item_entry_data> item, int amount);
87 storage_remove_item_result_type remove_item(int32_t index, int amount);
88
89 std::shared_ptr<item_entry_data> get_item(int32_t storage_index);
90 storage_add_item_result_type add_item_from_inventory(int16_t inventory_index, int amount);
91 storage_to_inventory_result_type add_item_to_inventory(int storage_index, int amount);
92
93 void notify_all();
94 void notify_normal();
95 void notify_equips();
96
97private:
98 int32_t _storage_id{ 0 };
99 std::string _name{""};
100 int32_t _max_storage{ 0 };
101 std::weak_ptr<Horizon::Zone::Units::Player> _player;
103};
104}
105}
106}
107
108#endif // HORIZON_ZONE_GAME_ASSETS_STORAGE_HPP
Definition: Storage.hpp:70
int32_t _max_storage
Definition: Storage.hpp:100
int32_t save()
Definition: Storage.cpp:231
storage_remove_item_result_type remove_item(int32_t index, int amount)
Definition: Storage.cpp:170
int16_t get_free_index()
Definition: Storage.cpp:51
std::string _name
Definition: Storage.hpp:99
Storage(std::shared_ptr< Horizon::Zone::Units::Player > player, int32_t storage_id, std::string name, uint32_t max_storage)
Definition: Storage.cpp:42
std::shared_ptr< item_entry_data > get_item(int32_t storage_index)
Definition: Storage.cpp:157
std::weak_ptr< Horizon::Zone::Units::Player > _player
Definition: Storage.hpp:101
virtual ~Storage()
Definition: Storage.cpp:47
void notify_all()
Definition: Storage.cpp:191
int32_t max_storage()
Definition: Storage.hpp:82
int32_t get_storage_id()
Definition: Storage.hpp:80
std::shared_ptr< Horizon::Zone::Units::Player > player()
Definition: Storage.hpp:83
storage_add_item_result_type add_item(std::shared_ptr< item_entry_data > item, int amount)
Definition: Storage.cpp:84
storage_type _storage_items
Definition: Storage.hpp:102
storage_add_item_result_type add_item_from_inventory(int16_t inventory_index, int amount)
Definition: Storage.cpp:62
void notify_normal()
Definition: Storage.cpp:203
int32_t _storage_id
Definition: Storage.hpp:98
void notify_equips()
Definition: Storage.cpp:217
storage_to_inventory_result_type add_item_to_inventory(int storage_index, int amount)
Definition: Storage.cpp:138
storage_type _saved_storage_items
Definition: Storage.hpp:102
int32_t load()
Definition: Storage.cpp:319
std::vector< std::shared_ptr< item_entry_data > > storage_type
Definition: Storage.hpp:71
std::string name()
Definition: Storage.hpp:81
Definition: ReferenceListTest.cpp:114
storage_remove_item_result_type
Definition: Storage.hpp:58
@ STORAGE_REMOVE_SUCCESS
Definition: Storage.hpp:59
@ STORAGE_REMOVE_INVALID
Success.
Definition: Storage.hpp:60
storage_to_inventory_result_type
Definition: Storage.hpp:40
@ STORAGE_TO_INVENTORY_INVALID
Success.
Definition: Storage.hpp:42
@ STORAGE_TO_INVENTORY_OVER_QUANTITY
No free place found.
Definition: Storage.hpp:45
@ STORAGE_TO_INVENTORY_NO_INV_SPACE
Overweight.
Definition: Storage.hpp:44
@ STORAGE_TO_INVENTORY_OVER_STACK_LIMIT
Max amount reached.
Definition: Storage.hpp:46
@ STORAGE_TO_INVENTORY_OVER_WEIGHT
Invalid itemid not found or negative amount.
Definition: Storage.hpp:43
@ STORAGE_TO_INVENTORY_SUCCESS
Definition: Storage.hpp:41
storage_add_item_result_type
Definition: Storage.hpp:49
@ STORAGE_ADD_SUCCESS
Definition: Storage.hpp:50
@ STORAGE_ADD_OVER_STACK_LIMIT
Max amount reached.
Definition: Storage.hpp:55
@ STORAGE_ADD_NO_INV_SPACE
Overweight.
Definition: Storage.hpp:53
@ STORAGE_ADD_OVER_WEIGHT
Invalid itemid not found or negative amount.
Definition: Storage.hpp:52
@ STORAGE_ADD_OVER_QUANTITY
No free place found.
Definition: Storage.hpp:54
@ STORAGE_ADD_INVALID
Success.
Definition: Storage.hpp:51
Definition: Element.hpp:7