Horizon Official Technical Documentation
Player.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_ENTITIES_PLAYER_HPP
31#define HORIZON_ZONE_GAME_ENTITIES_PLAYER_HPP
32
33#include "Server/Common/Configuration/Horizon.hpp" // MAX_INVENTORY_SIZE
39#include "Server/Zone/Definitions/UnitDefinitions.hpp" // unit_gender_types
43
44
45
46class ByteBuffer;
47
48namespace Horizon
49{
50namespace Zone
51{
52class ZoneSession;
53namespace Assets
54{
55 class Inventory;
56 class Storage;
57}
58class Map;
59namespace Units
60{
61class Player : public Unit, public GridObject<Player>
62{
63 struct s_char_data {
64 int32_t _character_id{0};
65 int16_t _slot{0};
66 int8_t _online{0};
69 int64_t _last_unique_id{0};
70 int8_t _font{0};
71 int32_t _unban_time{0};
72 int32_t _rename_count{0};
75 int8_t _show_equip{0};
76 int8_t _allow_party{0};
77 int32_t _partner_aid{0};
79 int32_t _party_id{0}, _guild_id{0};
80 int32_t _homun_id{0}, _pet_id{0}, _elemental_id{0};
81 std::string _saved_map{""};
82 int32_t _saved_x{0}, _saved_y{0};
83 };
84
86 int32_t _account_id{0};
87 std::string _account_gender{""};
88 int16_t _group_id{0};
89 };
90
91public:
92 Player(std::shared_ptr<ZoneSession> session, uint64_t uuid);
93 ~Player();
94
95 std::shared_ptr<ZoneSession> get_session() { return _session.lock(); }
96
97 void create(int char_id, std::string account_gender, int group_id);
98
99 bool initialize();
101 void set_initialized(bool val) { _is_initialized = val; }
102
106 void on_damage_received(std::shared_ptr<Unit> damage_dealer, int damage) override;
107 virtual void on_killed(std::shared_ptr<Unit> killer, bool with_drops = false, bool with_exp = false) override;
108
112 void update_viewport();
113
117 void realize_unit_movement(int32_t time, std::shared_ptr<Unit> unit);
118 void realize_unit_movement_entry(int32_t time, std::shared_ptr<Unit> unit);
120
121 void add_unit_to_viewport(std::shared_ptr<Unit> unit);
122 void remove_unit_from_viewport(std::shared_ptr<Unit> unit, unit_viewport_notification_type type);
123 void spawn_unit_in_viewport(std::shared_ptr<Unit> unit);
124 bool unit_is_in_viewport(std::shared_ptr<Unit> unit);
125
126 void notify_in_area(ByteBuffer &buf, grid_notifier_type type, uint16_t range = MAX_VIEW_RANGE);
127 bool move_to_map(std::shared_ptr<Map> map, MapCoords coords = { 0, 0 });
129 void on_map_enter();
130
131 void stop_movement() override;
132 void on_pathfinding_failure() override;
133 void on_movement_begin(int32_t time) override;
134 void on_movement_step() override;
135 void on_movement_end() override;
136
137 bool is_overweight_50();
138 bool is_overweight_90();
142 bool save();
143 bool load();
144
145 uint64_t new_unique_id();
146
147 bool is_logged_in() { return _is_logged_in; }
148 bool set_logged_in(bool logged_in) { return _is_logged_in.exchange(logged_in); }
149
152
153 bool job_change(int32_t job_id);
154
159 uint64_t last_unique_id() { return character()._last_unique_id; }
161 void set_max_inventory_size(uint32_t size) { character()._max_inventory_size = size; }
162 void on_item_equip(std::shared_ptr<const item_entry_data> item);
163 void on_item_unequip(std::shared_ptr<const item_entry_data> item);
164 std::shared_ptr<Assets::Inventory> inventory() { return _inventory; }
165 void pickup_item(int32_t guid);
166 void throw_item(std::shared_ptr<item_entry_data> item, int32_t amount);
170 std::shared_ptr<sol::state> lua_state() { return _lua_state; }
171 void send_npc_dialog(uint32_t npc_guid, std::string dialog);
172 void send_npc_next_dialog(uint32_t npc_guid);
173 void send_npc_close_dialog(uint32_t npc_guid);
174 void send_npc_menu_list(uint32_t npc_guid, std::string const &menu);
177
178 std::vector<std::weak_ptr<Unit>> &get_viewport_entities() { return _viewport_entities; }
179
180 std::map<uint16_t, std::shared_ptr<skill_learnt_info>> &get_learnt_skills() { return _learnt_skills; }
181 std::shared_ptr<skill_learnt_info> get_learnt_skill(uint16_t skill_id)
182 {
183 try {
184 return _learnt_skills.at(skill_id);
185 } catch (std::exception e) {
186 return nullptr;
187 }
188 }
189
190 void add_learnt_skill(std::shared_ptr<skill_learnt_info> i) { _learnt_skills.insert({ i->skill_id, i }); }
191
192 std::shared_ptr<const job_config_data> job() { return _job; }
193 void set_job(std::shared_ptr<const job_config_data> j) { _job = j; }
194
200 bool perform_skill(int16_t skill_id, int16_t skill_lv);
201 bool on_skill_failure(int16_t skill_id, int message_type, int item_id, skill_use_fail_cause_type cause);
205 void on_status_effect_start(std::shared_ptr<status_change_entry> sce) override;
206 void on_status_effect_end(std::shared_ptr<status_change_entry> sce) override;
207 void on_status_effect_change(std::shared_ptr<status_change_entry> sce) override;
208
209 bool attack(std::shared_ptr<Unit> e, bool continuous = false) override;
210 bool stop_attack();
211
212 void respawn(int hp_rate, int sp_rate);
213
214 std::shared_ptr<Assets::Storage> get_storage(int32_t storage_id);
215
218private:
219 bool _is_initialized{ false };
220 std::weak_ptr<ZoneSession> _session;
221 std::shared_ptr<sol::state> _lua_state;
222 std::shared_ptr<Assets::Inventory> _inventory;
223 std::vector<std::shared_ptr<Assets::Storage>> _storages;
225 std::atomic<bool> _is_logged_in{false};
227
228 std::vector<std::weak_ptr<Unit>> _viewport_entities;
229
230 std::map<uint16_t, std::shared_ptr<skill_learnt_info>> _learnt_skills;
231
234
235 std::shared_ptr<const job_config_data> _job;
236};
237}
238}
239}
240
241#endif /* HORIZON_ZONE_GAME_ENTITIES_PLAYER_HPP */
grid_notifier_type
Definition: ClientDefinitions.hpp:80
#define MAX_VIEW_RANGE
Definition: Horizon.hpp:59
#define MAX_INVENTORY_SIZE
Definition: ItemDefinitions.hpp:54
player_action_type
Client action types.
Definition: PlayerDefinitions.hpp:33
skill_use_fail_cause_type
Definition: SkillDefinitions.hpp:163
unit_viewport_notification_type
Definition: UnitDefinitions.hpp:836
unit_gender_types
Definition: UnitDefinitions.hpp:988
@ UNIT_GENDER_FEMALE
Definition: UnitDefinitions.hpp:989
Definition: ByteBuffer.hpp:78
Definition: GridObject.hpp:42
Definition: Unit.hpp:102
uint16_t job_id() const
Definition: Unit.hpp:146
std::shared_ptr< Map > map()
Map & Map Container.
Definition: Unit.hpp:165
uint32_t guid()
Definition: Unit.hpp:144
uint64_t uuid() const
Unit Data.
Definition: Unit.hpp:140
unit_type type() const
Unit applications.
Definition: Unit.hpp:173
Definition: Player.hpp:62
void on_map_enter()
Definition: Player.cpp:546
std::shared_ptr< sol::state > _lua_state
Definition: Player.hpp:221
void pickup_item(int32_t guid)
Definition: Player.cpp:497
std::map< uint16_t, std::shared_ptr< skill_learnt_info > > & get_learnt_skills()
Definition: Player.hpp:180
void send_npc_next_dialog(uint32_t npc_guid)
Definition: Player.cpp:472
bool attack(std::shared_ptr< Unit > e, bool continuous=false) override
Definition: Player.cpp:726
uint32_t get_max_inventory_size()
Definition: Player.hpp:160
bool set_logged_in(bool logged_in)
Definition: Player.hpp:148
std::weak_ptr< ZoneSession > _session
Definition: Player.hpp:220
bool is_overweight_50()
Definition: Player.cpp:324
bool perform_action(player_action_type action)
Definition: Player.cpp:706
bool is_overweight_90()
Definition: Player.cpp:325
void on_pathfinding_failure() override
Definition: Player.cpp:298
int32_t _npc_contact_guid
Definition: Player.hpp:226
s_char_data _char
Definition: Player.hpp:232
std::shared_ptr< sol::state > lua_state()
NPC / Script applications.
Definition: Player.hpp:170
std::vector< std::shared_ptr< Assets::Storage > > _storages
Definition: Player.hpp:223
bool load()
Definition: Player.cpp:204
void create(int char_id, std::string account_gender, int group_id)
Definition: Player.cpp:75
void notify_in_area(ByteBuffer &buf, grid_notifier_type type, uint16_t range=MAX_VIEW_RANGE)
Definition: Player.cpp:637
void on_status_effect_end(std::shared_ptr< status_change_entry > sce) override
Definition: Player.cpp:627
void set_initialized(bool val)
Definition: Player.hpp:101
void realize_nearby_items(unit_viewport_notification_type notif_type)
void add_unit_to_viewport(std::shared_ptr< Unit > unit)
Definition: Player.cpp:335
std::map< uint16_t, std::shared_ptr< skill_learnt_info > > _learnt_skills
Definition: Player.hpp:230
void send_npc_close_dialog(uint32_t npc_guid)
Definition: Player.cpp:477
virtual void on_killed(std::shared_ptr< Unit > killer, bool with_drops=false, bool with_exp=false) override
Definition: Player.cpp:742
void realize_unit_movement(int32_t time, std::shared_ptr< Unit > unit)
Movement.
Definition: Player.cpp:396
void send_npc_dialog(uint32_t npc_guid, std::string dialog)
Definition: Player.cpp:467
uint64_t new_unique_id()
Definition: Player.cpp:65
void set_npc_contact_guid(int32_t guid)
Definition: Player.hpp:176
void on_item_equip(std::shared_ptr< const item_entry_data > item)
Definition: Player.cpp:487
void on_movement_step() override
Definition: Player.cpp:312
void respawn(int hp_rate, int sp_rate)
Definition: Player.cpp:588
void set_last_unique_id(uint64_t last_unique_id)
Item Stores.
Definition: Player.hpp:158
bool on_skill_failure(int16_t skill_id, int message_type, int item_id, skill_use_fail_cause_type cause)
Definition: Player.cpp:685
std::shared_ptr< Assets::Inventory > _inventory
Definition: Player.hpp:222
void send_npc_menu_list(uint32_t npc_guid, std::string const &menu)
Definition: Player.cpp:482
std::shared_ptr< const job_config_data > job()
Definition: Player.hpp:192
~Player()
Definition: Player.cpp:59
bool initialize()
Definition: Player.cpp:83
void on_movement_begin(int32_t time) override
Definition: Player.cpp:303
uint64_t last_unique_id()
Definition: Player.hpp:159
bool save()
DB Synchronizations.
Definition: Player.cpp:159
std::vector< std::weak_ptr< Unit > > & get_viewport_entities()
Definition: Player.hpp:178
void update_viewport()
Grid applications.
Definition: Player.cpp:327
bool is_logged_in()
Definition: Player.hpp:147
void set_max_inventory_size(uint32_t size)
Definition: Player.hpp:161
std::shared_ptr< const job_config_data > _job
Definition: Player.hpp:235
std::shared_ptr< skill_learnt_info > get_learnt_skill(uint16_t skill_id)
Definition: Player.hpp:181
s_char_data & character()
Definition: Player.hpp:150
int32_t npc_contact_guid()
Definition: Player.hpp:175
void spawn_unit_in_viewport(std::shared_ptr< Unit > unit)
Definition: Player.cpp:414
void set_current_storage_id(int32_t id)
Definition: Player.hpp:217
void stop_movement() override
Definition: Player.cpp:153
void on_movement_end() override
Definition: Player.cpp:308
std::shared_ptr< ZoneSession > get_session()
Definition: Player.hpp:95
s_account_data & account()
Definition: Player.hpp:151
Player(std::shared_ptr< ZoneSession > session, uint64_t uuid)
Definition: Player.cpp:54
s_account_data _account
Definition: Player.hpp:233
std::shared_ptr< Assets::Inventory > inventory()
Definition: Player.hpp:164
void on_damage_received(std::shared_ptr< Unit > damage_dealer, int damage) override
Unit functions.
Definition: Player.cpp:577
bool stop_attack()
Definition: Player.cpp:734
void notify_map_properties()
Definition: Player.cpp:525
void on_status_effect_change(std::shared_ptr< status_change_entry > sce) override
Definition: Player.cpp:632
bool perform_skill(int16_t skill_id, int16_t skill_lv)
Definition: Player.cpp:660
bool unit_is_in_viewport(std::shared_ptr< Unit > unit)
Definition: Player.cpp:377
void remove_unit_from_viewport(std::shared_ptr< Unit > unit, unit_viewport_notification_type type)
Definition: Player.cpp:354
bool job_change(int32_t job_id)
Definition: Player.cpp:645
int32_t _current_storage_id
Definition: Player.hpp:224
std::atomic< bool > _is_logged_in
Definition: Player.hpp:225
void realize_unit_movement_entry(int32_t time, std::shared_ptr< Unit > unit)
Definition: Player.cpp:404
int32_t get_current_storage_id()
Definition: Player.hpp:216
bool move_to_map(std::shared_ptr< Map > map, MapCoords coords={ 0, 0 })
Definition: Player.cpp:423
bool on_action_request(player_action_type action)
Skills.
Definition: Player.cpp:691
std::vector< std::weak_ptr< Unit > > _viewport_entities
Definition: Player.hpp:228
void on_status_effect_start(std::shared_ptr< status_change_entry > sce) override
Status Effects.
Definition: Player.cpp:622
bool is_initialized()
Definition: Player.hpp:100
void set_job(std::shared_ptr< const job_config_data > j)
Definition: Player.hpp:193
void add_learnt_skill(std::shared_ptr< skill_learnt_info > i)
Definition: Player.hpp:190
bool _is_initialized
Definition: Player.hpp:219
void on_item_unequip(std::shared_ptr< const item_entry_data > item)
Definition: Player.cpp:492
std::shared_ptr< Assets::Storage > get_storage(int32_t storage_id)
Definition: Player.cpp:288
void throw_item(std::shared_ptr< item_entry_data > item, int32_t amount)
Definition: Player.cpp:520
Definition: Element.hpp:7
int32_t _account_id
Definition: Player.hpp:86
int16_t _group_id
Definition: Player.hpp:88
std::string _account_gender
Definition: Player.hpp:87
int32_t _rename_count
Definition: Player.hpp:72
int8_t _allow_party
Definition: Player.hpp:76
std::string _saved_map
Definition: Player.hpp:81
int8_t _show_equip
Definition: Player.hpp:75
int32_t _guild_id
Definition: Player.hpp:79
int32_t _change_slot_count
Definition: Player.hpp:74
int32_t _party_id
Definition: Player.hpp:79
int32_t _mother_aid
Definition: Player.hpp:78
int32_t _unban_time
Definition: Player.hpp:71
int32_t _partner_aid
Definition: Player.hpp:77
int16_t _slot
Definition: Player.hpp:65
int32_t _saved_y
Definition: Player.hpp:82
int32_t _pet_id
Definition: Player.hpp:80
int32_t _father_aid
Definition: Player.hpp:78
int32_t _saved_x
Definition: Player.hpp:82
int8_t _online
Definition: Player.hpp:66
int32_t _max_inventory_size
Definition: Player.hpp:68
int64_t _last_unique_id
Definition: Player.hpp:69
int32_t _child_aid
Definition: Player.hpp:78
int32_t _homun_id
Definition: Player.hpp:80
unit_gender_types _gender
Definition: Player.hpp:67
int32_t _elemental_id
Definition: Player.hpp:80
int8_t _font
Definition: Player.hpp:70
int32_t _character_id
Definition: Player.hpp:64
int16_t _hotkey_row_index
Definition: Player.hpp:73