Horizon Official Technical Documentation
Horizon::Zone::Units::Player Class Reference

#include <Player.hpp>

+ Inheritance diagram for Horizon::Zone::Units::Player:
+ Collaboration diagram for Horizon::Zone::Units::Player:

Classes

struct  s_account_data
 
struct  s_char_data
 

Public Member Functions

 Player (std::shared_ptr< ZoneSession > session, uint64_t uuid)
 
 ~Player ()
 
std::shared_ptr< ZoneSessionget_session ()
 
void create (int char_id, std::string account_gender, int group_id)
 
bool initialize ()
 
bool is_initialized ()
 
void set_initialized (bool val)
 
void on_damage_received (std::shared_ptr< Unit > damage_dealer, int damage) override
 Unit functions. More...
 
virtual void on_killed (std::shared_ptr< Unit > killer, bool with_drops=false, bool with_exp=false) override
 
void update_viewport ()
 Grid applications. More...
 
void realize_unit_movement (int32_t time, std::shared_ptr< Unit > unit)
 Movement. More...
 
void realize_unit_movement_entry (int32_t time, std::shared_ptr< Unit > unit)
 
void realize_nearby_items (unit_viewport_notification_type notif_type)
 
void add_unit_to_viewport (std::shared_ptr< Unit > unit)
 
void remove_unit_from_viewport (std::shared_ptr< Unit > unit, unit_viewport_notification_type type)
 
void spawn_unit_in_viewport (std::shared_ptr< Unit > unit)
 
bool unit_is_in_viewport (std::shared_ptr< Unit > unit)
 
void notify_in_area (ByteBuffer &buf, grid_notifier_type type, uint16_t range=MAX_VIEW_RANGE)
 
bool move_to_map (std::shared_ptr< Map > map, MapCoords coords={ 0, 0 })
 
void notify_map_properties ()
 
void on_map_enter ()
 
void stop_movement () override
 
void on_pathfinding_failure () override
 
void on_movement_begin (int32_t time) override
 
void on_movement_step () override
 
void on_movement_end () override
 
bool is_overweight_50 ()
 
bool is_overweight_90 ()
 
bool save ()
 DB Synchronizations. More...
 
bool load ()
 
uint64_t new_unique_id ()
 
bool is_logged_in ()
 
bool set_logged_in (bool logged_in)
 
s_char_datacharacter ()
 
s_account_dataaccount ()
 
bool job_change (int32_t job_id)
 
void set_last_unique_id (uint64_t last_unique_id)
 Item Stores. More...
 
uint64_t last_unique_id ()
 
uint32_t get_max_inventory_size ()
 
void set_max_inventory_size (uint32_t size)
 
void on_item_equip (std::shared_ptr< const item_entry_data > item)
 
void on_item_unequip (std::shared_ptr< const item_entry_data > item)
 
std::shared_ptr< Assets::Inventoryinventory ()
 
void pickup_item (int32_t guid)
 
void throw_item (std::shared_ptr< item_entry_data > item, int32_t amount)
 
std::shared_ptr< sol::state > lua_state ()
 NPC / Script applications. More...
 
void send_npc_dialog (uint32_t npc_guid, std::string dialog)
 
void send_npc_next_dialog (uint32_t npc_guid)
 
void send_npc_close_dialog (uint32_t npc_guid)
 
void send_npc_menu_list (uint32_t npc_guid, std::string const &menu)
 
int32_t npc_contact_guid ()
 
void set_npc_contact_guid (int32_t guid)
 
std::vector< std::weak_ptr< Unit > > & get_viewport_entities ()
 
std::map< uint16_t, std::shared_ptr< skill_learnt_info > > & get_learnt_skills ()
 
std::shared_ptr< skill_learnt_infoget_learnt_skill (uint16_t skill_id)
 
void add_learnt_skill (std::shared_ptr< skill_learnt_info > i)
 
std::shared_ptr< const job_config_datajob ()
 
void set_job (std::shared_ptr< const job_config_data > j)
 
bool on_action_request (player_action_type action)
 Skills. More...
 
bool perform_action (player_action_type action)
 
bool perform_skill (int16_t skill_id, int16_t skill_lv)
 
bool on_skill_failure (int16_t skill_id, int message_type, int item_id, skill_use_fail_cause_type cause)
 
void on_status_effect_start (std::shared_ptr< status_change_entry > sce) override
 Status Effects. More...
 
void on_status_effect_end (std::shared_ptr< status_change_entry > sce) override
 
void on_status_effect_change (std::shared_ptr< status_change_entry > sce) override
 
bool attack (std::shared_ptr< Unit > e, bool continuous=false) override
 
bool stop_attack ()
 
void respawn (int hp_rate, int sp_rate)
 
std::shared_ptr< Assets::Storageget_storage (int32_t storage_id)
 
int32_t get_current_storage_id ()
 
void set_current_storage_id (int32_t id)
 
- Public Member Functions inherited from Horizon::Zone::Unit
 Unit (uint64_t uuid, unit_type type, unit_type_mask type_mask, std::shared_ptr< Map > map, MapCoords map_coords)
 
 Unit (uint64_t uuid, unit_type type, unit_type_mask type_mask)
 
virtual ~Unit ()
 
bool initialize ()
 
virtual bool finalize ()
 
bool is_initialized () const
 
bool is_finalized () const
 
void set_finalized (bool finalized)
 
MapCoords const & dest_coords () const
 Movement. More...
 
virtual bool walk_to_coordinates (int16_t x, int16_t y)
 
virtual bool walk_to_unit (std::shared_ptr< Unit > unit)
 
bool is_walking () const
 
virtual void stop_movement ()=0
 
bool stop_walking (bool cancel=false, bool notify=false)
 
uint64_t uuid () const
 Unit Data. More...
 
unit_uuid s_uuid () const
 
void set_uuid (uint64_t uuid)
 
uint32_t guid ()
 
uint16_t job_id () const
 
void set_job_id (uint16_t job_id)
 
unit_posture_type posture () const
 
void set_posture (unit_posture_type posture)
 
const std::string & name () const
 
void set_name (const std::string &name)
 
directions direction () const
 
void set_direction (directions dir)
 
std::shared_ptr< Horizon::Zone::Traits::Statusstatus ()
 
void set_status (std::shared_ptr< Horizon::Zone::Traits::Status > st)
 
void force_movement_stop_internal (bool stop=false)
 
std::shared_ptr< Mapmap ()
 Map & Map Container. More...
 
void set_map (std::shared_ptr< Map > map)
 
AStar::CoordinateList get_walk_path ()
 
unit_type type () const
 Unit applications. More...
 
unit_type_mask type_mask () const
 
bool is_of_type (int type_mask)
 
template<class T >
std::shared_ptr< T > downcast ()
 
MapCoords const & map_coords () const
 Grid applications. More...
 
void set_map_coords (MapCoords const &coords)
 
GridCoords const & grid_coords () const
 
void set_grid_coords (GridCoords const &coords)
 
bool is_in_range_of (std::shared_ptr< Unit > unit, uint8_t range=MAX_VIEW_RANGE)
 
void notify_nearby_players_of_existence (unit_viewport_notification_type notif_type)
 
void notify_nearby_players_of_spawn ()
 
void notify_nearby_players_of_movement (bool new_entry=false)
 
void notify_nearby_players_of_movement_stop (MapCoords stop_coords)
 
void notify_nearby_players_of_skill_use (grid_unit_skill_use_notification_type notification_type, s_unit_skill_use_notifier_config config)
 
void notify_nearby_players_of_basic_attack (s_grid_unit_basic_attack_config config)
 
void notify_nearby_players_of_item_drop (s_grid_notify_item_drop_entry entry)
 
std::shared_ptr< Unitget_nearby_unit (uint32_t guid)
 
uint64_t get_scheduler_task_id (unit_task_schedule_group group)
 
std::map< int16_t, std::shared_ptr< status_change_entry > > & get_status_effects ()
 
void apply_status_change_in_area (std::shared_ptr< Unit > target, s_grid_sc_apply_in_skill_area_config const &config, s_grid_apply_in_area_config const &aoe_config)
 
void remove_status_change_in_area (std::shared_ptr< Unit > target, int sc_type, s_grid_apply_in_area_config const &aoe_config)
 
void execute_skill_in_area (std::shared_ptr< Unit > target, std::shared_ptr< SkillExecution > skill_execution, s_grid_apply_in_area_config const &aoe_config)
 
void execute_skill_in_cell (std::shared_ptr< Unit > target, MapCoords cell, std::shared_ptr< SkillExecution > skill_execution, s_grid_apply_in_area_config const &aoe_config)
 
void use_skill_on_target (int16_t skill_lv, int16_t skill_id, int target_guid)
 
void use_skill_on_ground (int16_t skill_lv, int16_t skill_id, int16_t pos_x, int16_t pos_y)
 
void use_skill_on_ground (int16_t skill_lv, int16_t skill_id, int16_t pos_x, int16_t pos_y, std::string contents)
 
bool status_effect_start (int type, int total_time, int val1, int val2, int val3, int val4)
 Status Effects. More...
 
bool status_effect_end (int type)
 
virtual void on_status_effect_start (std::shared_ptr< status_change_entry > sce)=0
 
virtual void on_status_effect_end (std::shared_ptr< status_change_entry > sce)=0
 
virtual void on_status_effect_change (std::shared_ptr< status_change_entry > sce)=0
 
std::shared_ptr< AStar::CoordinateListpath_to (std::shared_ptr< Unit > e)
 
int distance_from (std::shared_ptr< Unit > e)
 
virtual bool attack (std::shared_ptr< Unit > target, bool continuous=false)
 
virtual bool stop_attacking ()
 
bool target_is_attackable (std::shared_ptr< Unit > target)
 
void set_attacking (bool attacking)
 
bool is_attacking ()
 
void on_attack_end ()
 
bool is_dead ()
 
virtual void on_damage_received (std::shared_ptr< Unit > damage_dealer, int damage)
 
virtual void on_killed (std::shared_ptr< Unit > killer, bool with_drops=false, bool with_exp=false)
 
std::shared_ptr< Combatcombat ()
 Combat. More...
 
void set_combat (std::shared_ptr< Combat > combat)
 
void update (uint64_t tick)
 Extremely time-sensitive functions. More...
 
std::shared_ptr< CombatRegistrycombat_registry ()
 
bool has_damage_walk_delay ()
 Walk Delay. More...
 
void set_damage_walk_delay (bool delay)
 
void set_lockon_after_walk_completed (uint64_t target_guid, bool continuous=false)
 Lockon after walk completed. More...
 
void clear_lockon_after_walk_completed ()
 
uint64_t lockon_after_walk_completed_target_guid ()
 
- Public Member Functions inherited from Horizon::Zone::GridObject< Player >
virtual ~GridObject ()
 
bool has_valid_grid_reference () const
 
void add_grid_reference (GridRefManager< Player > &m)
 
void remove_grid_reference ()
 
GridReference< Player > & get_reference ()
 

Private Attributes

bool _is_initialized { false }
 
std::weak_ptr< ZoneSession_session
 
std::shared_ptr< sol::state > _lua_state
 
std::shared_ptr< Assets::Inventory_inventory
 
std::vector< std::shared_ptr< Assets::Storage > > _storages
 
int32_t _current_storage_id { 0 }
 
std::atomic< bool > _is_logged_in {false}
 
int32_t _npc_contact_guid {0}
 
std::vector< std::weak_ptr< Unit > > _viewport_entities
 
std::map< uint16_t, std::shared_ptr< skill_learnt_info > > _learnt_skills
 
s_char_data _char
 
s_account_data _account
 
std::shared_ptr< const job_config_data_job
 

Additional Inherited Members

- Protected Member Functions inherited from Horizon::Zone::Unit
bool schedule_walk ()
 
void walk ()
 
virtual void on_pathfinding_failure ()=0
 
virtual void on_movement_begin (int32_t time)=0
 
virtual void on_movement_step ()=0
 
virtual void on_movement_end ()=0
 

Constructor & Destructor Documentation

◆ Player()

Player::Player ( std::shared_ptr< ZoneSession session,
uint64_t  uuid 
)
55: Unit(uuid, UNIT_PLAYER, UNIT_MASK_PLAYER), _session(session), _lua_state(std::make_shared<sol::state>())
56{
57}
@ UNIT_PLAYER
Definition: UnitDefinitions.hpp:45
@ UNIT_MASK_PLAYER
Definition: UnitDefinitions.hpp:60
Unit(uint64_t uuid, unit_type type, unit_type_mask type_mask, std::shared_ptr< Map > map, MapCoords map_coords)
Definition: Unit.cpp:45
uint64_t uuid() const
Unit Data.
Definition: Unit.hpp:140
std::shared_ptr< sol::state > _lua_state
Definition: Player.hpp:221
std::weak_ptr< ZoneSession > _session
Definition: Player.hpp:220

◆ ~Player()

Player::~Player ( )
60{
63}
bool has_valid_grid_reference() const
Definition: GridObject.hpp:46
void remove_grid_reference()
Definition: GridObject.hpp:48

References Horizon::Zone::GridObject< Player >::has_valid_grid_reference(), and Horizon::Zone::GridObject< Player >::remove_grid_reference().

+ Here is the call graph for this function:

Member Function Documentation

◆ account()

s_account_data & Horizon::Zone::Units::Player::account ( )
inline
151{ return _account; }
s_account_data _account
Definition: Player.hpp:233

References _account.

Referenced by create(), load(), and save().

+ Here is the caller graph for this function:

◆ add_learnt_skill()

void Horizon::Zone::Units::Player::add_learnt_skill ( std::shared_ptr< skill_learnt_info i)
inline
190{ _learnt_skills.insert({ i->skill_id, i }); }
std::map< uint16_t, std::shared_ptr< skill_learnt_info > > _learnt_skills
Definition: Player.hpp:230

References _learnt_skills.

Referenced by initialize().

+ Here is the caller graph for this function:

◆ add_unit_to_viewport()

void Player::add_unit_to_viewport ( std::shared_ptr< Unit unit)
336{
337 if (unit == nullptr)
338 return;
339
340 if (unit_is_in_viewport(unit))
341 return;
342
343 if (unit->type() == UNIT_ITEM) {
344 item_viewport_entry entry = get_session()->clif()->create_viewport_item_entry(unit->downcast<Item>());
345 get_session()->clif()->notify_viewport_item_entry(entry);
346 } else {
347 unit_viewport_entry entry = get_session()->clif()->create_viewport_entry(unit);
348 get_session()->clif()->notify_viewport_add_unit(entry);
349 }
350
351 _viewport_entities.push_back(unit);
352}
@ UNIT_ITEM
Definition: UnitDefinitions.hpp:47
Definition: Item.hpp:46
std::shared_ptr< ZoneSession > get_session()
Definition: Player.hpp:95
bool unit_is_in_viewport(std::shared_ptr< Unit > unit)
Definition: Player.cpp:377
std::vector< std::weak_ptr< Unit > > _viewport_entities
Definition: Player.hpp:228
Definition: UnitDefinitions.hpp:939
Definition: UnitDefinitions.hpp:852

References _viewport_entities, get_session(), unit_is_in_viewport(), and UNIT_ITEM.

+ Here is the call graph for this function:

◆ attack()

bool Player::attack ( std::shared_ptr< Unit e,
bool  continuous = false 
)
overridevirtual

Reimplemented from Horizon::Zone::Unit.

727{
728 if (Unit::attack(target, continuous) == false)
729 return false;
730
731 return true;
732}
virtual bool attack(std::shared_ptr< Unit > target, bool continuous=false)
Definition: Unit.cpp:514

References Horizon::Zone::Unit::attack().

+ Here is the call graph for this function:

◆ character()

s_char_data & Horizon::Zone::Units::Player::character ( )
inline
150{ return _char; }
s_char_data _char
Definition: Player.hpp:232

References _char.

Referenced by create(), get_max_inventory_size(), last_unique_id(), load(), new_unique_id(), respawn(), save(), set_last_unique_id(), and set_max_inventory_size().

+ Here is the caller graph for this function:

◆ create()

void Player::create ( int  char_id,
std::string  account_gender,
int  group_id 
)
76{
77 character()._character_id = char_id;
78 account()._account_gender = account_gender;
79 account()._group_id = group_id;
80
81 load();
82}
bool load()
Definition: Player.cpp:204
s_char_data & character()
Definition: Player.hpp:150
s_account_data & account()
Definition: Player.hpp:151
int16_t _group_id
Definition: Player.hpp:88
std::string _account_gender
Definition: Player.hpp:87
int32_t _character_id
Definition: Player.hpp:64

References Horizon::Zone::Units::Player::s_account_data::_account_gender, Horizon::Zone::Units::Player::s_char_data::_character_id, Horizon::Zone::Units::Player::s_account_data::_group_id, account(), character(), and load().

+ Here is the call graph for this function:

◆ get_current_storage_id()

int32_t Horizon::Zone::Units::Player::get_current_storage_id ( )
inline
216{ return _current_storage_id; }
int32_t _current_storage_id
Definition: Player.hpp:224

References _current_storage_id.

◆ get_learnt_skill()

std::shared_ptr< skill_learnt_info > Horizon::Zone::Units::Player::get_learnt_skill ( uint16_t  skill_id)
inline
182 {
183 try {
184 return _learnt_skills.at(skill_id);
185 } catch (std::exception e) {
186 return nullptr;
187 }
188 }

References _learnt_skills.

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the caller graph for this function:

◆ get_learnt_skills()

std::map< uint16_t, std::shared_ptr< skill_learnt_info > > & Horizon::Zone::Units::Player::get_learnt_skills ( )
inline
180{ return _learnt_skills; }

References _learnt_skills.

◆ get_max_inventory_size()

uint32_t Horizon::Zone::Units::Player::get_max_inventory_size ( )
inline
160{ return character()._max_inventory_size; }
int32_t _max_inventory_size
Definition: Player.hpp:68

References Horizon::Zone::Units::Player::s_char_data::_max_inventory_size, and character().

Referenced by initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_session()

◆ get_storage()

std::shared_ptr< Horizon::Zone::Assets::Storage > Player::get_storage ( int32_t  storage_id)
289{
290 for (auto s : _storages) {
291 if (s->get_storage_id() == storage_id)
292 return s;
293 }
294
295 return nullptr;
296}
std::vector< std::shared_ptr< Assets::Storage > > _storages
Definition: Player.hpp:223

References _storages.

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the caller graph for this function:

◆ get_viewport_entities()

std::vector< std::weak_ptr< Unit > > & Horizon::Zone::Units::Player::get_viewport_entities ( )
inline
178{ return _viewport_entities; }

References _viewport_entities.

Referenced by on_map_enter().

+ Here is the caller graph for this function:

◆ initialize()

bool Player::initialize ( )
84{
85 if (Unit::initialize() == false)
86 return false;
87
88 // Inventory.
89 _inventory = std::make_shared<Assets::Inventory>(downcast<Player>(), get_max_inventory_size());
90 _inventory->load();
91
92 for (auto s : StorageDB->get_storage_db()) {
93 std::shared_ptr<const storage_config_data> storage_config = s.second;
94 std::shared_ptr<Assets::Storage> storage = std::make_shared<Assets::Storage>(downcast<Player>(), storage_config->storage_id, storage_config->name, storage_config->capacity);
95 storage->load();
96 _storages.push_back(storage);
97 }
98
99 // Initialize Status, after inventory is loaded to compute EquipAtk etc.
100 status()->initialize(shared_from_this()->downcast<Player>());
101 status()->size()->set_base(ESZ_MEDIUM);
102
103 // Inventory is initialized for the player, notifying weight etc.
104 _inventory->initialize();
105
106 // Populate skill tree.
107 std::vector<std::shared_ptr<const skill_tree_config>> sktree = SkillDB->get_skill_tree_by_job_id((job_class_type) job_id());
108
109 for (auto s : sktree) {
111 info.skill_id = s->skill_id;
112 info.level = 0;
114 add_learnt_skill(std::make_shared<skill_learnt_info>(info));
115 }
116
117 // On map entry processing.
118 on_map_enter();
119
120 // @TODO (multithreaded support, multi-segment support) Initialize Player, npc and monster components for player's lua state.
121 sZone->get_component_of_type<Horizon::Zone::ScriptManager>(Horizon::System::RUNTIME_SCRIPTVM)->initialize_player_state(lua_state());
122
123 // required for npc component definitions upon triggering
124 sZone->get_component_of_type<Horizon::Zone::ScriptManager>(Horizon::System::RUNTIME_SCRIPTVM)->initialize_npc_state(lua_state());
125
126 // required for triggering monster components upon monster kill events etc.
127 sZone->get_component_of_type<Horizon::Zone::ScriptManager>(Horizon::System::RUNTIME_SCRIPTVM)->initialize_monster_state(lua_state());
128
129 try {
130 std::string script_root_path = sZone->config().get_script_root_path().string();
131 sol::load_result fx = lua_state()->load_file(script_root_path + "internal/on_login_event.lua");
132 sol::protected_function_result result = fx(shared_from_this()->downcast<Player>(), VER_PRODUCTVERSION_STR);
133 if (!result.valid()) {
134 sol::error err = result;
135 HLog(error) << "Player::initialize: " << err.what();
136 return false;
137 }
138 } catch (sol::error &e) {
139 HLog(error) << "Player::initialize: " << e.what();
140 return false;
141 }
142
143
144 // Ensure grid for unit.
145 map()->ensure_grid_for_unit(this, map_coords());
146 map()->add_user_count();
147
148 set_initialized(true);
149
150 return true;
151}
#define HLog(type)
Definition: Logger.hpp:122
#define SkillDB
Definition: SkillDB.hpp:145
@ SKILL_LEARN_PERMANENT
Definition: SkillDefinitions.hpp:153
#define StorageDB
Definition: StorageDB.hpp:79
job_class_type
Definition: UnitDefinitions.hpp:474
@ ESZ_MEDIUM
Definition: UnitDefinitions.hpp:38
#define sZone
Definition: Zone.hpp:247
Definition: ScriptManager.hpp:60
uint16_t job_id() const
Definition: Unit.hpp:146
std::shared_ptr< Map > map()
Map & Map Container.
Definition: Unit.hpp:165
bool initialize()
Definition: Unit.cpp:72
std::shared_ptr< Horizon::Zone::Traits::Status > status()
Definition: Unit.hpp:158
MapCoords const & map_coords() const
Grid applications.
Definition: Unit.hpp:186
void on_map_enter()
Definition: Player.cpp:546
uint32_t get_max_inventory_size()
Definition: Player.hpp:160
std::shared_ptr< sol::state > lua_state()
NPC / Script applications.
Definition: Player.hpp:170
void set_initialized(bool val)
Definition: Player.hpp:101
std::shared_ptr< Assets::Inventory > _inventory
Definition: Player.hpp:222
void add_learnt_skill(std::shared_ptr< skill_learnt_info > i)
Definition: Player.hpp:190
@ RUNTIME_SCRIPTVM
Definition: System.hpp:87
Definition: SkillDefinitions.hpp:252
int16_t level
Definition: SkillDefinitions.hpp:254
skill_learn_type learn_type
Definition: SkillDefinitions.hpp:255
int16_t skill_id
Definition: SkillDefinitions.hpp:253

References _inventory, _storages, add_learnt_skill(), ESZ_MEDIUM, get_max_inventory_size(), HLog, Horizon::Zone::Unit::initialize(), Horizon::Zone::Unit::job_id(), skill_learnt_info::learn_type, skill_learnt_info::level, lua_state(), Horizon::Zone::Unit::map(), Horizon::Zone::Unit::map_coords(), on_map_enter(), Horizon::System::RUNTIME_SCRIPTVM, set_initialized(), skill_learnt_info::skill_id, SKILL_LEARN_PERMANENT, SkillDB, Horizon::Zone::Unit::status(), StorageDB, and sZone.

+ Here is the call graph for this function:

◆ inventory()

std::shared_ptr< Assets::Inventory > Horizon::Zone::Units::Player::inventory ( )
inline

◆ is_initialized()

bool Horizon::Zone::Units::Player::is_initialized ( )
inline
100{ return _is_initialized; }
bool _is_initialized
Definition: Player.hpp:219

References _is_initialized.

Referenced by on_map_enter().

+ Here is the caller graph for this function:

◆ is_logged_in()

bool Horizon::Zone::Units::Player::is_logged_in ( )
inline
147{ return _is_logged_in; }
std::atomic< bool > _is_logged_in
Definition: Player.hpp:225

References _is_logged_in.

◆ is_overweight_50()

bool Player::is_overweight_50 ( )
324{ return status()->current_weight()->total() * 100 >= status()->max_weight()->total() * 50; }

References Horizon::Zone::Unit::status().

+ Here is the call graph for this function:

◆ is_overweight_90()

bool Player::is_overweight_90 ( )
325{ return status()->current_weight()->total() * 10 >= status()->max_weight()->total() * 9; }

References Horizon::Zone::Unit::status().

+ Here is the call graph for this function:

◆ job()

std::shared_ptr< const job_config_data > Horizon::Zone::Units::Player::job ( )
inline
192{ return _job; }
std::shared_ptr< const job_config_data > _job
Definition: Player.hpp:235

References _job.

Referenced by job_change().

+ Here is the caller graph for this function:

◆ job_change()

bool Player::job_change ( int32_t  job_id)
646{
647 std::shared_ptr<const job_config_data> job = JobDB->get_job_by_id(job_id);
648
649 if (job == nullptr) {
650 HLog(error) << "Player::job_change: Invalid job_id " << job_id << " provided, job was not found or not supported.";
651 return false;
652 }
653
655 status()->on_job_changed(job_id);
656
657 return true;
658}
#define JobDB
Definition: JobDB.hpp:87
void set_job_id(uint16_t job_id)
Definition: Unit.hpp:147
std::shared_ptr< const job_config_data > job()
Definition: Player.hpp:192

References HLog, job(), Horizon::Zone::Unit::job_id(), JobDB, Horizon::Zone::Unit::set_job_id(), and Horizon::Zone::Unit::status().

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ last_unique_id()

uint64_t Horizon::Zone::Units::Player::last_unique_id ( )
inline
159{ return character()._last_unique_id; }
int64_t _last_unique_id
Definition: Player.hpp:69

References Horizon::Zone::Units::Player::s_char_data::_last_unique_id, and character().

Referenced by set_last_unique_id().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load()

bool Player::load ( )

Set map and coordinates for unit.

205{
206 std::shared_ptr<boost::mysql::tcp_ssl_connection> conn = sZone->get_database_connection();
207
208 try {
209 boost::mysql::statement stmt = conn->prepare_statement("SELECT `id`, `account_id`, `slot`, `name`, `font`, `gender`, `last_unique_id`, `saved_map`, `saved_x`, `saved_y`, "
210 "`current_map`, `current_x`, `current_y` FROM `characters` WHERE id = ?");
211 auto b1 = stmt.bind(character()._character_id);
212 boost::mysql::results results;
213 conn->execute(b1, results);
214
215 if (results.rows().empty()) {
216 HLog(error) << "Error loading player, character with ID " << character()._character_id << " does not exist.";
217 return false;
218 }
219
220 auto r = results.rows()[0];
221 /* Initialize Player Model */
222 character()._character_id = r[0].as_uint64();
223 account()._account_id = r[1].as_uint64();
224 character()._slot = r[2].as_int64();
225 set_name(r[3].as_string());
227 character()._font = r[4].as_uint64();
228
229 std::string char_gender = r[5].as_string();
230
231 character()._gender = strcmp(char_gender.c_str(), "U") == 0
232 ? (strcmp(account()._account_gender.c_str(), "M") == 0 ? UNIT_GENDER_MALE : UNIT_GENDER_FEMALE)
233 : strcmp(char_gender.c_str(), "M") == 0 ? UNIT_GENDER_MALE : UNIT_GENDER_FEMALE;
234
235 character()._online = 1;
236 set_last_unique_id((uint64_t)r[6].as_uint64());
237
238 character()._saved_map = r[7].as_string();
239 character()._saved_x = r[8].as_uint64();
240 character()._saved_y = r[9].as_uint64();
241
245 // @TODO
246 MapCoords mcoords(r[11].as_uint64(), r[12].as_uint64());
247 int segment_number = sZone->get_segment_number_for_resource<Horizon::Zone::GameLogicProcess, RESOURCE_PRIORITY_PRIMARY, std::string, std::shared_ptr<Map>>(Horizon::System::RUNTIME_GAMELOGIC, r[10].as_string(), nullptr);
248
249 if (segment_number == 0)
250 return false;
251
252 auto container = sZone->get_component_of_type<Horizon::Zone::GameLogicProcess>(Horizon::System::RUNTIME_GAMELOGIC, segment_number);
253
254 std::shared_ptr<Map> map = container->get_resource_manager().template get_resource<RESOURCE_PRIORITY_PRIMARY, std::string, std::shared_ptr<Map>>(r[10].as_string(), nullptr);
255
256 if (map == nullptr) {
257 HLog(warning) << "Player::load: Map " << r[10].as_string() << " does not exist, setting to default map.";
258 segment_number = sZone->get_segment_number_for_resource<Horizon::Zone::GameLogicProcess, RESOURCE_PRIORITY_PRIMARY, std::string, std::shared_ptr<Map>>(Horizon::System::RUNTIME_GAMELOGIC, "prontera", nullptr);
259
260 if (segment_number == 0)
261 return false;
262
263 map = container->get_resource_manager().template get_resource<RESOURCE_PRIORITY_PRIMARY, std::string, std::shared_ptr<Map>>("prontera", nullptr);
264
265 if (map == nullptr) {
266 HLog(error) << "Player::load: Default map prontera does not exist.";
267 return false;
268 }
269 }
270
271 get_session()->set_map_name(map->get_name());
272
273 set_map(map);
274 set_map_coords(mcoords);
275 }
276 catch (boost::mysql::error_with_diagnostics &error) {
277 HLog(error) << "Player::load:" << error.what();
278 return false;
279 }
280 catch (std::exception& error) {
281 HLog(error) << "Player::load:" << error.what();
282 return false;
283 }
284
285 return true;
286}
uint32_t _character_id
4
Definition: Client.hpp:0
@ RESOURCE_PRIORITY_PRIMARY
Definition: Server.hpp:79
@ POSTURE_STANDING
Definition: UnitDefinitions.hpp:468
@ UNIT_GENDER_FEMALE
Definition: UnitDefinitions.hpp:989
@ UNIT_GENDER_MALE
Definition: UnitDefinitions.hpp:990
Definition: GameLogicProcess.hpp:48
void set_map_coords(MapCoords const &coords)
Definition: Unit.hpp:187
void set_map(std::shared_ptr< Map > map)
Definition: Unit.hpp:166
void set_posture(unit_posture_type posture)
Definition: Unit.hpp:150
void set_name(const std::string &name)
Definition: Unit.hpp:153
void set_last_unique_id(uint64_t last_unique_id)
Item Stores.
Definition: Player.hpp:158
@ RUNTIME_GAMELOGIC
Definition: System.hpp:86
int32_t _account_id
Definition: Player.hpp:86
std::string _saved_map
Definition: Player.hpp:81
int16_t _slot
Definition: Player.hpp:65
int32_t _saved_y
Definition: Player.hpp:82
int32_t _saved_x
Definition: Player.hpp:82
int8_t _online
Definition: Player.hpp:66
unit_gender_types _gender
Definition: Player.hpp:67
int8_t _font
Definition: Player.hpp:70

References Horizon::Zone::Units::Player::s_account_data::_account_id, _character_id, Horizon::Zone::Units::Player::s_char_data::_character_id, Horizon::Zone::Units::Player::s_char_data::_font, Horizon::Zone::Units::Player::s_char_data::_gender, Horizon::Zone::Units::Player::s_char_data::_online, Horizon::Zone::Units::Player::s_char_data::_saved_map, Horizon::Zone::Units::Player::s_char_data::_saved_x, Horizon::Zone::Units::Player::s_char_data::_saved_y, Horizon::Zone::Units::Player::s_char_data::_slot, account(), character(), get_session(), HLog, Horizon::Zone::Unit::map(), POSTURE_STANDING, RESOURCE_PRIORITY_PRIMARY, Horizon::System::RUNTIME_GAMELOGIC, set_last_unique_id(), Horizon::Zone::Unit::set_map(), Horizon::Zone::Unit::set_map_coords(), Horizon::Zone::Unit::set_name(), Horizon::Zone::Unit::set_posture(), sZone, UNIT_GENDER_FEMALE, and UNIT_GENDER_MALE.

Referenced by create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lua_state()

std::shared_ptr< sol::state > Horizon::Zone::Units::Player::lua_state ( )
inline

NPC / Script applications.

170{ return _lua_state; }

References _lua_state.

Referenced by initialize(), on_action_request(), and perform_skill().

+ Here is the caller graph for this function:

◆ move_to_map()

bool Player::move_to_map ( std::shared_ptr< Map map,
MapCoords  coords = { 0, 0 } 
)
424{
425 if (dest_map == nullptr)
426 return false;
427
428 if (is_walking())
430
431 std::shared_ptr<Player> myself = downcast<Player>();
432
434
435 {
436 // If the map is not managed by the destination container,
437 // remove the session from the current container and add it to the destination container
438 if (dest_map->container()->get_resource_manager().template get_resource<RESOURCE_PRIORITY_PRIMARY, std::string, std::shared_ptr<Map>>(map()->get_name(), nullptr) == nullptr) {
439 map()->container()->get_resource_manager().remove<RESOURCE_PRIORITY_TERTIARY>(myself->uuid());
440 dest_map->container()->get_resource_manager().add<RESOURCE_PRIORITY_TERTIARY>(myself->uuid(), myself);
441
442 map()->container()->get_resource_manager().remove<RESOURCE_PRIORITY_SECONDARY>(myself->uuid());
443 dest_map->container()->get_resource_manager().add<RESOURCE_PRIORITY_SECONDARY>(myself->uuid(), myself);
444 }
445
446 map()->sub_user_count();
447 dest_map->add_user_count();
448
449 get_session()->set_map_name(dest_map->get_name());
450
451 if (coords == MapCoords(0, 0))
452 coords = dest_map->get_random_accessible_coordinates();
453
454 dest_map->ensure_grid_for_unit(this, coords);
455
456 set_map(dest_map);
457 set_map_coords(coords);
458 }
459
460 get_session()->clif()->notify_move_to_map(dest_map->get_name(), coords.x(), coords.y());
461
462 on_map_enter();
463
464 return true;
465}
Coordinates< MAX_CELLS_PER_MAP > MapCoords
Definition: GridDefinitions.hpp:83
@ RESOURCE_PRIORITY_SECONDARY
Definition: Server.hpp:80
@ RESOURCE_PRIORITY_TERTIARY
Definition: Server.hpp:81
@ EVP_NOTIFY_TELEPORT
Definition: UnitDefinitions.hpp:841
int16_t y() const
Definition: Coordinates.hpp:120
int16_t x() const
Definition: Coordinates.hpp:119
void notify_nearby_players_of_existence(unit_viewport_notification_type notif_type)
Definition: Unit.cpp:318
void force_movement_stop_internal(bool stop=false)
Definition: Unit.hpp:161
bool is_walking() const
Definition: Unit.hpp:121

References EVP_NOTIFY_TELEPORT, Horizon::Zone::Unit::force_movement_stop_internal(), get_session(), Horizon::Zone::Unit::is_walking(), Horizon::Zone::Unit::map(), Horizon::Zone::Unit::notify_nearby_players_of_existence(), on_map_enter(), RESOURCE_PRIORITY_PRIMARY, RESOURCE_PRIORITY_SECONDARY, RESOURCE_PRIORITY_TERTIARY, Horizon::Zone::Unit::set_map(), Horizon::Zone::Unit::set_map_coords(), Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

Referenced by respawn(), and Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ new_unique_id()

uint64_t Player::new_unique_id ( )
66{
67 int64_t char_id = (int64_t) character()._character_id;
68
69 if (character()._last_unique_id > 0)
70 return ++character()._last_unique_id;
71
72 return (character()._last_unique_id = (char_id << 32));
73}

References Horizon::Zone::Units::Player::s_char_data::_character_id, Horizon::Zone::Units::Player::s_char_data::_last_unique_id, and character().

+ Here is the call graph for this function:

◆ notify_in_area()

void Player::notify_in_area ( ByteBuffer buf,
grid_notifier_type  type,
uint16_t  range = MAX_VIEW_RANGE 
)
638{
639 GridPlayerNotifier notifier(buf, static_cast<Unit *>(this)->shared_from_this(), type);
641
642 map()->visit_in_range(map_coords(), container, range);
643}
Definition: GridReferenceContainerVisitor.hpp:70
unit_type type() const
Unit applications.
Definition: Unit.hpp:173
Definition: GridNotifiers.hpp:220

References Horizon::Zone::Unit::map(), Horizon::Zone::Unit::map_coords(), and Horizon::Zone::Unit::type().

+ Here is the call graph for this function:

◆ notify_map_properties()

void Player::notify_map_properties ( )
526{
528
529 // TODO: Should not be responsibility of player to do that. Working on it.
530 mp.pvp = 0;
531 mp.gvg = 0;
532 mp.siege = 0;
533 mp.no_effects = 0;
534 mp.party_pvp = 0;
535 mp.pvp_kill_counter = 0;
536 mp.disallow_party = 0;
537 mp.battleground = 0;
538 mp.no_costume = 0;
539 mp.allow_carts = 1;
541 mp.spare_bits = 0;
542
543 get_session()->clif()->notify_map_properties(mp);
544}
Definition: ClientDefinitions.hpp:294
unsigned party_pvp
Definition: ClientDefinitions.hpp:299
unsigned battleground
Definition: ClientDefinitions.hpp:302
unsigned siege
Definition: ClientDefinitions.hpp:297
unsigned disallow_party
Definition: ClientDefinitions.hpp:301
unsigned no_effects
Definition: ClientDefinitions.hpp:298
unsigned gvg
Definition: ClientDefinitions.hpp:296
unsigned pvp_kill_counter
Definition: ClientDefinitions.hpp:300
unsigned no_costume
Definition: ClientDefinitions.hpp:303
unsigned pvp
Definition: ClientDefinitions.hpp:295
unsigned spare_bits
Definition: ClientDefinitions.hpp:306
unsigned stargladiator_miracles
Definition: ClientDefinitions.hpp:305
unsigned allow_carts
Definition: ClientDefinitions.hpp:304

References zc_map_properties::allow_carts, zc_map_properties::battleground, zc_map_properties::disallow_party, get_session(), zc_map_properties::gvg, zc_map_properties::no_costume, zc_map_properties::no_effects, zc_map_properties::party_pvp, zc_map_properties::pvp, zc_map_properties::pvp_kill_counter, zc_map_properties::siege, zc_map_properties::spare_bits, and zc_map_properties::stargladiator_miracles.

Referenced by on_map_enter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ npc_contact_guid()

int32_t Horizon::Zone::Units::Player::npc_contact_guid ( )
inline
175{ return _npc_contact_guid; }
int32_t _npc_contact_guid
Definition: Player.hpp:226

References _npc_contact_guid.

◆ on_action_request()

bool Player::on_action_request ( player_action_type  action)

Skills.

692{
693 try {
694 sol::load_result fx = lua_state()->load_file(sZone->config().get_script_root_path().string() + "internal/on_player_action.lua");
695 sol::protected_function_result result = fx(shared_from_this()->downcast<Player>(), action);
696 if (!result.valid()) {
697 sol::error err = result;
698 HLog(error) << "Player::on_action_request: " << err.what();
699 }
700 } catch (sol::error &e) {
701 HLog(error) << "Player::on_action_request: " << e.what();
702 }
703 return true;
704}

References HLog, lua_state(), and sZone.

+ Here is the call graph for this function:

◆ on_damage_received()

void Player::on_damage_received ( std::shared_ptr< Unit damage_dealer,
int  damage 
)
overridevirtual

Unit functions.

Reimplemented from Horizon::Zone::Unit.

578{
579 Unit::on_damage_received(damage_dealer, damage);
580
581 if (status()->current_hp()->total() <= damage) {
582 status()->current_hp()->set_base(0);
583 on_killed(damage_dealer);
584 return;
585 }
586}
virtual void on_damage_received(std::shared_ptr< Unit > damage_dealer, int damage)
Definition: Unit.cpp:466
virtual void on_killed(std::shared_ptr< Unit > killer, bool with_drops=false, bool with_exp=false) override
Definition: Player.cpp:742

References Horizon::Zone::Unit::on_damage_received(), on_killed(), and Horizon::Zone::Unit::status().

+ Here is the call graph for this function:

◆ on_item_equip()

void Player::on_item_equip ( std::shared_ptr< const item_entry_data item)
488{
489 status()->on_equipment_changed(true, item);
490}

References Horizon::Zone::Unit::status().

+ Here is the call graph for this function:

◆ on_item_unequip()

void Player::on_item_unequip ( std::shared_ptr< const item_entry_data item)
493{
494 status()->on_equipment_changed(false, item);
495}

References Horizon::Zone::Unit::status().

+ Here is the call graph for this function:

◆ on_killed()

void Player::on_killed ( std::shared_ptr< Unit killer,
bool  with_drops = false,
bool  with_exp = false 
)
overridevirtual

Reimplemented from Horizon::Zone::Unit.

743{
744 Unit::on_killed(killer, with_drops, with_exp);
745 remove_unit_from_viewport(shared_from_this(), EVP_NOTIFY_DEAD);
746}
@ EVP_NOTIFY_DEAD
Definition: UnitDefinitions.hpp:839
virtual void on_killed(std::shared_ptr< Unit > killer, bool with_drops=false, bool with_exp=false)
Definition: Unit.cpp:476
void remove_unit_from_viewport(std::shared_ptr< Unit > unit, unit_viewport_notification_type type)
Definition: Player.cpp:354

References EVP_NOTIFY_DEAD, Horizon::Zone::Unit::on_killed(), and remove_unit_from_viewport().

Referenced by on_damage_received().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ on_map_enter()

void Player::on_map_enter ( )
547{
548 //get_packet_handler()->Send_ZC_MAPPROPERTY_R2(get_map());
549
550 if (!is_initialized()) {
551 return;
552 }
553
554 inventory()->notify_all();
555
556 // Notify Weight.
557 status()->current_weight()->notify();
558 status()->max_weight()->notify();
559
560 // clear viewport
561 get_viewport_entities().clear();
562
565
567
568 // Notify learnt skill list.
569 get_session()->clif()->notify_learnt_skill_list();
570
571 if (is_dead()) {
572 remove_unit_from_viewport(shared_from_this(), EVP_NOTIFY_DEAD);
573 }
574}
void notify_nearby_players_of_spawn()
Definition: Unit.cpp:326
bool is_dead()
Definition: Unit.cpp:458
std::vector< std::weak_ptr< Unit > > & get_viewport_entities()
Definition: Player.hpp:178
void update_viewport()
Grid applications.
Definition: Player.cpp:327
std::shared_ptr< Assets::Inventory > inventory()
Definition: Player.hpp:164
void notify_map_properties()
Definition: Player.cpp:525
bool is_initialized()
Definition: Player.hpp:100

References EVP_NOTIFY_DEAD, get_session(), get_viewport_entities(), inventory(), Horizon::Zone::Unit::is_dead(), is_initialized(), notify_map_properties(), Horizon::Zone::Unit::notify_nearby_players_of_spawn(), remove_unit_from_viewport(), Horizon::Zone::Unit::status(), and update_viewport().

Referenced by initialize(), and move_to_map().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ on_movement_begin()

void Player::on_movement_begin ( int32_t  time)
overridevirtual

Implements Horizon::Zone::Unit.

304{
305 get_session()->clif()->notify_player_movement(time, map_coords(), dest_coords());
306}
MapCoords const & dest_coords() const
Movement.
Definition: Unit.hpp:118

References Horizon::Zone::Unit::dest_coords(), get_session(), and Horizon::Zone::Unit::map_coords().

+ Here is the call graph for this function:

◆ on_movement_end()

void Player::on_movement_end ( )
overridevirtual

Implements Horizon::Zone::Unit.

309{
310}

◆ on_movement_step()

void Player::on_movement_step ( )
overridevirtual

Implements Horizon::Zone::Unit.

313{
314 GridNPCTrigger npc_trigger(shared_from_this());
316
317 map()->ensure_grid_for_unit(this, map_coords());
318
320
321 map()->visit_in_range(map_coords(), npc_trigger_performer, MAX_NPC_TRIGGER_RANGE);
322}
#define MAX_NPC_TRIGGER_RANGE
Definition: Horizon.hpp:60
Definition: GridNotifiers.hpp:202

References Horizon::Zone::Unit::map(), Horizon::Zone::Unit::map_coords(), MAX_NPC_TRIGGER_RANGE, and update_viewport().

+ Here is the call graph for this function:

◆ on_pathfinding_failure()

void Player::on_pathfinding_failure ( )
overridevirtual

Implements Horizon::Zone::Unit.

299{
300 //HLog(debug) << "Player " << name() << " has failed to find path from (" << map_coords().x() << "," << map_coords().y() << ") to (" << dest_coords().x() << ", " << dest_coords().y() << ").";
301}

◆ on_skill_failure()

bool Player::on_skill_failure ( int16_t  skill_id,
int  message_type,
int  item_id,
skill_use_fail_cause_type  cause 
)
686{
687 get_session()->clif()->notify_skill_fail(skill_id, message_type, item_id, cause);
688 return true;
689}

References get_session().

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ on_status_effect_change()

void Player::on_status_effect_change ( std::shared_ptr< status_change_entry sce)
overridevirtual

Implements Horizon::Zone::Unit.

633{
634
635}

◆ on_status_effect_end()

void Player::on_status_effect_end ( std::shared_ptr< status_change_entry sce)
overridevirtual

Implements Horizon::Zone::Unit.

628{
629 get_session()->clif()->notify_status_change_end(sce->type, guid(), 0);
630}
uint32_t guid()
Definition: Unit.hpp:144

References get_session(), and Horizon::Zone::Unit::guid().

+ Here is the call graph for this function:

◆ on_status_effect_start()

void Player::on_status_effect_start ( std::shared_ptr< status_change_entry sce)
overridevirtual

Status Effects.

Implements Horizon::Zone::Unit.

623{
624 get_session()->clif()->notify_status_change(sce->type, guid(), 1, sce->current_time, sce->val1, sce->val2, sce->val3);
625}

References get_session(), and Horizon::Zone::Unit::guid().

+ Here is the call graph for this function:

◆ perform_action()

bool Player::perform_action ( player_action_type  action)
707{
708 switch(action)
709 {
710 case PLAYER_ACT_SIT:
711 get_session()->clif()->notify_action(PLAYER_ACT_SIT);
712 break;
713 case PLAYER_ACT_STAND:
714 get_session()->clif()->notify_action(PLAYER_ACT_STAND);
715 break;
718 break;
719 default:
720 break;
721 };
722
723 return true;
724}
@ PLAYER_ACT_SIT
Definition: PlayerDefinitions.hpp:36
@ PLAYER_ACT_ATTACK_REPEAT
Definition: PlayerDefinitions.hpp:41
@ PLAYER_ACT_STAND
Definition: PlayerDefinitions.hpp:37
@ PLAYER_ACT_ATTACK
Definition: PlayerDefinitions.hpp:34

References get_session(), PLAYER_ACT_ATTACK, PLAYER_ACT_ATTACK_REPEAT, PLAYER_ACT_SIT, and PLAYER_ACT_STAND.

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ perform_skill()

bool Player::perform_skill ( int16_t  skill_id,
int16_t  skill_lv 
)
661{
662 std::shared_ptr<const skill_config_data> sk_d = SkillDB->get_skill_by_id(skill_id);
663
664 if (sk_d == nullptr) {
665 HLog(warning) << "Tried to perform skill for non-existent id " << skill_id << ", ignoring...";
666 return false;
667 }
668
669 try {
670 std::string script_root_path = sZone->config().get_script_root_path().string();
671 sol::load_result fx = lua_state()->load_file(script_root_path + "skills/" + sk_d->name + ".lua");
672 sol::protected_function_result result = fx(shared_from_this(), skill_id, skill_lv);
673 if (!result.valid()) {
674 sol::error err = result;
675 HLog(error) << "Unit::perform_skill: " << err.what();
676 }
677 } catch (sol::error &e) {
678 HLog(error) << "Unit::perform_skill: " << e.what();
679 return false;
680 }
681
682 return true;
683}

References HLog, lua_state(), SkillDB, and sZone.

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pickup_item()

void Player::pickup_item ( int32_t  guid)
498{
499 std::shared_ptr<Horizon::Zone::Unit> unit = get_nearby_unit(guid);
500
501 if (unit == nullptr)
502 return;
503
504 if (unit->type() != UNIT_ITEM)
505 return;
506
507 if (unit->is_in_range_of(shared_from_this(), 1) == false)
508 return;
509
510 std::shared_ptr<Item> item = unit->downcast<Item>();
511
513 item->finalize();
514 std::shared_ptr<GameLogicProcess> container = item->map()->container();
515 container->get_resource_manager().remove<RESOURCE_PRIORITY_TERTIARY>(item->uuid());
516 get_session()->clif()->notify_item_removal_from_floor(item->guid());
517 get_session()->clif()->notify_action(item->guid(), PLAYER_ACT_ITEM_PICKUP);
518 }
519}
@ PLAYER_ACT_ITEM_PICKUP
Definition: PlayerDefinitions.hpp:35
std::shared_ptr< Unit > get_nearby_unit(uint32_t guid)
Definition: Unit.cpp:308
bool finalize() override
Definition: Item.cpp:61
@ INVENTORY_ADD_SUCCESS
Definition: Inventory.hpp:48

References Horizon::Zone::Units::Item::finalize(), Horizon::Zone::Unit::get_nearby_unit(), get_session(), Horizon::Zone::Unit::guid(), inventory(), Horizon::Zone::Assets::INVENTORY_ADD_SUCCESS, PLAYER_ACT_ITEM_PICKUP, RESOURCE_PRIORITY_TERTIARY, and UNIT_ITEM.

+ Here is the call graph for this function:

◆ realize_nearby_items()

void Horizon::Zone::Units::Player::realize_nearby_items ( unit_viewport_notification_type  notif_type)

◆ realize_unit_movement()

void Player::realize_unit_movement ( int32_t  time,
std::shared_ptr< Unit unit 
)

Movement.

397{
398 if (unit == nullptr)
399 return;
400
401 get_session()->clif()->notify_unit_move(unit->guid(), time, unit->map_coords(), unit->dest_coords());
402}

References get_session().

+ Here is the call graph for this function:

◆ realize_unit_movement_entry()

void Player::realize_unit_movement_entry ( int32_t  time,
std::shared_ptr< Unit unit 
)
405{
406 if (unit == nullptr)
407 return;
408
409 unit_viewport_entry entry = get_session()->clif()->create_viewport_entry(unit);
410 entry.move_start_time = time;
411 get_session()->clif()->notify_viewport_moving_unit(entry);
412}
int32_t move_start_time
Definition: UnitDefinitions.hpp:935

References get_session(), and unit_viewport_entry::move_start_time.

+ Here is the call graph for this function:

◆ remove_unit_from_viewport()

void Player::remove_unit_from_viewport ( std::shared_ptr< Unit unit,
unit_viewport_notification_type  type 
)
355{
356 if (is_dead()) {
357 get_session()->clif()->notify_viewport_remove_unit(unit, EVP_NOTIFY_DEAD);
358 return;
359 } else if (!unit_is_in_viewport(unit)) {
360 return;
361 }
362
363 _viewport_entities.erase(std::remove_if(_viewport_entities.begin(), _viewport_entities.end(),
364 [unit] (std::weak_ptr<Unit> wp_e) {
365 if (wp_e.expired())
366 return false;
367 return wp_e.lock()->guid() == unit->guid();
368 }
369 ), _viewport_entities.end());
370
371 if (unit->type() == UNIT_ITEM)
372 get_session()->clif()->notify_item_removal_from_floor(unit->guid());
373 else
374 get_session()->clif()->notify_viewport_remove_unit(unit, type);
375}

References _viewport_entities, EVP_NOTIFY_DEAD, get_session(), Horizon::Zone::Unit::is_dead(), Horizon::Zone::Unit::type(), unit_is_in_viewport(), and UNIT_ITEM.

Referenced by on_killed(), and on_map_enter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ respawn()

void Player::respawn ( int  hp_rate,
int  sp_rate 
)
589{
590 if (is_dead() == false)
591 return;
592
593
594 if (status()->current_hp()->total() <= 0)
595 status()->current_hp()->set_base(1);
596
597 if (status()->current_sp()->total() <= 0)
598 status()->current_sp()->set_base(1);
599
600 if (hp_rate && hp_rate > 100) {
601 hp_rate = 100;
602 status()->current_hp()->set_base(status()->max_hp()->total() * hp_rate / 100);
603 }
604 if (sp_rate && sp_rate > 100) {
605 sp_rate = 100;
606 status()->current_sp()->set_base(status()->max_sp()->total() * sp_rate / 100);
607 }
608
609 int segment_number = sZone->get_segment_number_for_resource<Horizon::Zone::GameLogicProcess, RESOURCE_PRIORITY_PRIMARY, std::string, std::shared_ptr<Map>>(Horizon::System::RUNTIME_GAMELOGIC, character()._saved_map, nullptr);
610 if (segment_number > 0) {
611 std::shared_ptr<Map> map = sZone->get_component_of_type<Horizon::Zone::GameLogicProcess>(Horizon::System::RUNTIME_GAMELOGIC, segment_number)->get_resource_manager().template get_resource<RESOURCE_PRIORITY_PRIMARY, std::string, std::shared_ptr<Map>>(character()._saved_map, nullptr);
612 if (map == nullptr) {
613 get_session()->clif()->notify_resurrection(guid(), 0);
614 return;
615 }
616 move_to_map(map, MapCoords(character()._saved_x, character()._saved_y));
617 } else {
618 get_session()->clif()->notify_resurrection(guid(), 0);
619 }
620}
bool move_to_map(std::shared_ptr< Map > map, MapCoords coords={ 0, 0 })
Definition: Player.cpp:423

References Horizon::Zone::Units::Player::s_char_data::_saved_map, character(), get_session(), Horizon::Zone::Unit::guid(), Horizon::Zone::Unit::is_dead(), Horizon::Zone::Unit::map(), move_to_map(), RESOURCE_PRIORITY_PRIMARY, Horizon::System::RUNTIME_GAMELOGIC, Horizon::Zone::Unit::status(), and sZone.

+ Here is the call graph for this function:

◆ save()

bool Player::save ( )

DB Synchronizations.

160{
161 std::shared_ptr<boost::mysql::tcp_ssl_connection> conn = sZone->get_database_connection();
162
163 try {
164 boost::mysql::statement stmt = conn->prepare_statement("UPDATE `characters` SET `account_id` = ?, `slot` = ?, `name` = ?, `online` = ?, `gender` = ?, `unban_time` = ?, `rename_count` = ?,"
165 "`last_unique_id` = ?, `hotkey_row_index` = ?, `change_slot_count` = ?, `font` = ?, `show_equip` = ?, `allow_party` = ?, `partner_aid` = ?, `father_aid` = ?, `mother_aid` = ?,"
166 "`child_aid` = ?, `party_id` = ?, `guild_id` = ?, `pet_id` = ?, `homun_id` = ?, `elemental_id` = ?, `current_map` = ?, `current_x` = ?, `current_y` = ?,"
167 "`saved_map` = ?, `saved_x` = ?, `saved_y` = ? "
168 "WHERE `id` = ?");
169 auto b1 = stmt.bind(account()._account_id, character()._slot, name(), character()._online, character()._gender == UNIT_GENDER_MALE ? "M" : "F", character()._unban_time, character()._rename_count,
170 character()._last_unique_id, character()._hotkey_row_index, character()._change_slot_count, character()._font, character()._show_equip, character()._allow_party,
171 character()._partner_aid, character()._father_aid, character()._mother_aid, character()._child_aid, character()._party_id, character()._guild_id, character()._pet_id,
172 character()._homun_id, character()._elemental_id, map()->get_name(), map_coords().x(), map_coords().y(), character()._saved_map, character()._saved_x, character()._saved_y,
174 );
175 boost::mysql::results results;
176 conn->execute(b1, results);
177
178 // Status
179 if (status() != nullptr)
180 status()->save(shared_from_this()->downcast<Player>());
181
182 // Inventory
183 if (inventory() != nullptr)
184 inventory()->save();
185
186 // Storages
187 if (_storages.size() > 0) {
188 for (auto s : _storages)
189 s->save();
190 }
191 }
192 catch (boost::mysql::error_with_diagnostics &error) {
193 HLog(error) << "Player::save:" << error.what();
194 return false;
195 }
196 catch (std::exception& error) {
197 HLog(error) << "Player::save:" << error.what();
198 return false;
199 }
200
201 return true;
202}
const std::string & name() const
Definition: Unit.hpp:152

References _character_id, _storages, account(), character(), HLog, inventory(), Horizon::Zone::Unit::map(), Horizon::Zone::Unit::map_coords(), Horizon::Zone::Unit::name(), Horizon::Zone::Unit::status(), sZone, and UNIT_GENDER_MALE.

+ Here is the call graph for this function:

◆ send_npc_close_dialog()

void Player::send_npc_close_dialog ( uint32_t  npc_guid)
478{
479 get_session()->clif()->notify_npc_close_dialog(npc_guid);
480}

References get_session().

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_npc_dialog()

void Player::send_npc_dialog ( uint32_t  npc_guid,
std::string  dialog 
)
468{
469 get_session()->clif()->notify_npc_dialog(npc_guid, dialog);
470}

References get_session().

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_npc_menu_list()

void Player::send_npc_menu_list ( uint32_t  npc_guid,
std::string const &  menu 
)
483{
484 get_session()->clif()->notify_npc_menu_list(npc_guid, menu);
485}

References get_session().

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_npc_next_dialog()

void Player::send_npc_next_dialog ( uint32_t  npc_guid)
473{
474 get_session()->clif()->notify_npc_next_dialog(npc_guid);
475}

References get_session().

Referenced by Horizon::Zone::PlayerComponent::sync_data_types().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_current_storage_id()

void Horizon::Zone::Units::Player::set_current_storage_id ( int32_t  id)
inline
217{ _current_storage_id = id; }

References _current_storage_id.

◆ set_initialized()

void Horizon::Zone::Units::Player::set_initialized ( bool  val)
inline
101{ _is_initialized = val; }

References _is_initialized.

Referenced by initialize().

+ Here is the caller graph for this function:

◆ set_job()

void Horizon::Zone::Units::Player::set_job ( std::shared_ptr< const job_config_data j)
inline
193{ _job = j; }

References _job.

◆ set_last_unique_id()

void Horizon::Zone::Units::Player::set_last_unique_id ( uint64_t  last_unique_id)
inline

Item Stores.

uint64_t last_unique_id()
Definition: Player.hpp:159

References Horizon::Zone::Units::Player::s_char_data::_last_unique_id, character(), and last_unique_id().

Referenced by load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_logged_in()

bool Horizon::Zone::Units::Player::set_logged_in ( bool  logged_in)
inline
148{ return _is_logged_in.exchange(logged_in); }

References _is_logged_in.

◆ set_max_inventory_size()

void Horizon::Zone::Units::Player::set_max_inventory_size ( uint32_t  size)
inline
161{ character()._max_inventory_size = size; }

References Horizon::Zone::Units::Player::s_char_data::_max_inventory_size, and character().

+ Here is the call graph for this function:

◆ set_npc_contact_guid()

void Horizon::Zone::Units::Player::set_npc_contact_guid ( int32_t  guid)
inline

References _npc_contact_guid, and Horizon::Zone::Unit::guid().

+ Here is the call graph for this function:

◆ spawn_unit_in_viewport()

void Player::spawn_unit_in_viewport ( std::shared_ptr< Unit unit)
415{
416 if (unit == nullptr)
417 return;
418
419 unit_viewport_entry entry = get_session()->clif()->create_viewport_entry(unit);
420 get_session()->clif()->notify_viewport_spawn_unit(entry);
421}

References get_session().

+ Here is the call graph for this function:

◆ stop_attack()

bool Player::stop_attack ( )
735{
736 if (map()->container()->getScheduler().Count(get_scheduler_task_id(UNIT_SCHEDULE_ATTACK)) > 0)
737 map()->container()->getScheduler().CancelGroup(get_scheduler_task_id(UNIT_SCHEDULE_ATTACK));
738
739 return true;
740}
@ UNIT_SCHEDULE_ATTACK
Definition: Unit.hpp:59
uint64_t get_scheduler_task_id(unit_task_schedule_group group)
Definition: Unit.hpp:204

References Horizon::Zone::Unit::get_scheduler_task_id(), Horizon::Zone::Unit::map(), and UNIT_SCHEDULE_ATTACK.

+ Here is the call graph for this function:

◆ stop_movement()

void Player::stop_movement ( )
overridevirtual

Implements Horizon::Zone::Unit.

154{
155 MapCoords const &coords = map_coords();
156 get_session()->clif()->notify_movement_stop(guid(), coords.x(), coords.y());
157}

References get_session(), Horizon::Zone::Unit::guid(), Horizon::Zone::Unit::map_coords(), Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

+ Here is the call graph for this function:

◆ throw_item()

void Player::throw_item ( std::shared_ptr< item_entry_data item,
int32_t  amount 
)
521{
522 inventory()->drop_item(item->index.inventory, amount);
523 map()->add_item_drop(item, amount, map_coords());
524}

References inventory(), Horizon::Zone::Unit::map(), and Horizon::Zone::Unit::map_coords().

+ Here is the call graph for this function:

◆ unit_is_in_viewport()

bool Player::unit_is_in_viewport ( std::shared_ptr< Unit unit)
378{
379 if (unit == nullptr)
380 return false;
381
382 std::vector<std::weak_ptr<Unit>>::iterator it = std::find_if (_viewport_entities.begin(), _viewport_entities.end(),
383 [unit] (const std::weak_ptr<Unit> &vp_ew) {
384 std::shared_ptr<Unit> vp_es = vp_ew.lock();
385
386 if (vp_es == nullptr || unit == nullptr)
387 return false;
388
389 return (vp_es->guid() == unit->guid());
390 }
391 );
392
393 return (it != _viewport_entities.end());
394}

References _viewport_entities.

Referenced by add_unit_to_viewport(), and remove_unit_from_viewport().

+ Here is the caller graph for this function:

◆ update_viewport()

void Player::update_viewport ( )

Grid applications.

328{
329 GridViewPortUpdater updater(shared_from_this());
331
332 map()->visit_in_range(map_coords(), update_caller);
333}
Definition: GridNotifiers.hpp:41

References Horizon::Zone::Unit::map(), and Horizon::Zone::Unit::map_coords().

Referenced by on_map_enter(), and on_movement_step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _account

s_account_data Horizon::Zone::Units::Player::_account
private

Referenced by account().

◆ _char

s_char_data Horizon::Zone::Units::Player::_char
private

Referenced by character().

◆ _current_storage_id

int32_t Horizon::Zone::Units::Player::_current_storage_id { 0 }
private

◆ _inventory

std::shared_ptr<Assets::Inventory> Horizon::Zone::Units::Player::_inventory
private

Referenced by initialize(), and inventory().

◆ _is_initialized

bool Horizon::Zone::Units::Player::_is_initialized { false }
private

Referenced by is_initialized(), and set_initialized().

◆ _is_logged_in

std::atomic<bool> Horizon::Zone::Units::Player::_is_logged_in {false}
private

Referenced by is_logged_in(), and set_logged_in().

◆ _job

std::shared_ptr<const job_config_data> Horizon::Zone::Units::Player::_job
private

Referenced by job(), and set_job().

◆ _learnt_skills

std::map<uint16_t, std::shared_ptr<skill_learnt_info> > Horizon::Zone::Units::Player::_learnt_skills
private

◆ _lua_state

std::shared_ptr<sol::state> Horizon::Zone::Units::Player::_lua_state
private

Referenced by lua_state().

◆ _npc_contact_guid

int32_t Horizon::Zone::Units::Player::_npc_contact_guid {0}
private

◆ _session

std::weak_ptr<ZoneSession> Horizon::Zone::Units::Player::_session
private

Referenced by get_session().

◆ _storages

std::vector<std::shared_ptr<Assets::Storage> > Horizon::Zone::Units::Player::_storages
private

Referenced by get_storage(), initialize(), and save().

◆ _viewport_entities

std::vector<std::weak_ptr<Unit> > Horizon::Zone::Units::Player::_viewport_entities
private

The documentation for this class was generated from the following files: