Horizon Official Technical Documentation
Horizon::Zone::Unit Class Referenceabstract

#include <Unit.hpp>

+ Inheritance diagram for Horizon::Zone::Unit:
+ Collaboration diagram for Horizon::Zone::Unit:

Classes

struct  s_lockon_after_walk_completed
 

Public Member Functions

 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 ()
 

Protected Member Functions

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
 

Private Attributes

bool _is_initialized {false}
 
bool _jump_walk_stop {false}
 
bool _is_finalized { false }
 
bool _is_attacking {false}
 
struct Horizon::Zone::Unit::s_lockon_after_walk_completed _lockon_after_walk_completed
 
struct Horizon::Zone::Unit::s_lockon_after_walk_completed false
 
uint64_t _uuid {0}
 
unit_uuid _s_uuid { 0 }
 
unit_type _type {UNIT_UNKNOWN}
 
unit_type_mask _type_mask {UNIT_MASK_UNKNOWN}
 
std::weak_ptr< Map_map
 
MapCoords _map_coords {0, 0}
 
GridCoords _grid_coords {0, 0}
 
MapCoords _changed_dest_pos {0, 0}
 
MapCoords _dest_pos {0, 0}
 
AStar::CoordinateList _walk_path
 
int16_t _walk_path_index {0}
 
std::shared_ptr< Horizon::Zone::Traits::Status_status
 
std::string _name {""}
 
uint16_t _job_id {0}
 
unit_posture_type _posture {POSTURE_STANDING}
 
directions _facing_dir {DIR_SOUTH}
 
std::map< int16_t, std::shared_ptr< status_change_entry > > _status_effects
 
int32_t _attackable_time {0}
 
std::shared_ptr< Combat_combat
 
std::shared_ptr< CombatRegistry_combat_registry
 
bool _damage_walk_delay {false}
 

Constructor & Destructor Documentation

◆ Unit() [1/2]

Unit::Unit ( uint64_t  uuid,
unit_type  type,
unit_type_mask  type_mask,
std::shared_ptr< Map map,
MapCoords  map_coords 
)
47{
49 set_map(map);
50}
unit_type _type
Definition: Unit.hpp:288
std::shared_ptr< Map > map()
Map & Map Container.
Definition: Unit.hpp:165
void set_map(std::shared_ptr< Map > map)
Definition: Unit.hpp:166
unit_type_mask _type_mask
Definition: Unit.hpp:289
uint64_t uuid() const
Unit Data.
Definition: Unit.hpp:140
unit_type_mask type_mask() const
Definition: Unit.hpp:174
unit_type type() const
Unit applications.
Definition: Unit.hpp:173
void set_uuid(uint64_t uuid)
Definition: Unit.cpp:60
MapCoords const & map_coords() const
Grid applications.
Definition: Unit.hpp:186
MapCoords _map_coords
Definition: Unit.hpp:291

References map(), set_map(), set_uuid(), and uuid().

+ Here is the call graph for this function:

◆ Unit() [2/2]

Unit::Unit ( uint64_t  uuid,
unit_type  type,
unit_type_mask  type_mask 
)
55{
57 // Map is set in player::load()
58}
Coordinates< MAX_CELLS_PER_MAP > MapCoords
Definition: GridDefinitions.hpp:83

References set_uuid(), and uuid().

+ Here is the call graph for this function:

◆ ~Unit()

Unit::~Unit ( )
virtual
67{
68 _combat = nullptr;
69 _combat_registry = nullptr;
70}
std::shared_ptr< Combat > _combat
Definition: Unit.hpp:311
std::shared_ptr< CombatRegistry > _combat_registry
Definition: Unit.hpp:312

References _combat, and _combat_registry.

Member Function Documentation

◆ apply_status_change_in_area()

void Unit::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 
)
582{
583 GridSCApplyInSkillArea sc_apply_in_skill_area(shared_from_this(), target, config, aoe_config);
585
586 map()->visit_in_range(map_coords(), container, MAX_VIEW_RANGE);
587}
#define MAX_VIEW_RANGE
Definition: Horizon.hpp:59
Definition: GridReferenceContainerVisitor.hpp:70
Definition: GridNotifiers.hpp:251

References map(), map_coords(), and MAX_VIEW_RANGE.

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

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

◆ attack()

bool Unit::attack ( std::shared_ptr< Unit target,
bool  continuous = false 
)
virtual

Reimplemented in Horizon::Zone::Units::Player.

515{
516 if (target == nullptr) {
517 HLog(debug) << "Unit::attack:4: target is null.";
519 return false;
520 }
521
522 set_combat(std::make_shared<Combat>(shared_from_this(), target));
523
524 map()->container()->getScheduler().Schedule(
526 [this, continuous, target](TaskContext context)
527 {
528 if (!target_is_attackable(target)) {
530 return;
531 }
532
533 std::shared_ptr<AStar::CoordinateList> wp = path_to(target);
534 if (wp && (wp->size() == 0 || wp->size() > MAX_VIEW_RANGE)) {
536 HLog(debug) << "Unit::attack:5: Path to target is invalid.";
537 return;
538 }
539
540 int range = this->status()->attack_range()->get_base();
541
542 _attackable_time = status()->attack_delay()->total();
543
544 // If target is not in range of the attacker when source is already attacking, repeat the attack.
545 if (!is_in_range_of(target, range)) {
546 if (is_attacking()) {
548 }
549 set_lockon_after_walk_completed(target->guid(), continuous);
550 walk_to_unit(target);
551 HLog(debug) << "Unit::attack:6: Target is out of range, stopped attacking and walking to target.";
552 return;
553 }
554
555 //if (!is_in_range_of(target, range) && is_walking()) {
556 // context.Repeat(Milliseconds(_attackable_time));
557 // return;
558 //}
559
560 if (is_in_range_of(target, range) && is_walking())
561 stop_walking();
562
563 if (!is_attacking())
564 set_attacking(true);
565
566 // Let the target start attacking back.
567 combat_retaliate_type result = combat()->weapon_attack();
568 if (target->type() == UNIT_MONSTER && result == CBT_RET_DEF && target->is_attacking() == false)
569 target->attack(shared_from_this(), true);
570 if (result == CBT_RET_DEF) {
571 target->set_damage_walk_delay(true);
572 }
573
574 if (continuous)
576 });
577
578 return true;
579}
combat_retaliate_type
Definition: CombatDefinitions.hpp:51
@ CBT_RET_DEF
Definition: CombatDefinitions.hpp:57
#define HLog(type)
Definition: Logger.hpp:122
std::chrono::milliseconds Milliseconds
Definition: TaskScheduler.hpp:31
@ UNIT_MONSTER
Definition: UnitDefinitions.hpp:50
@ UNIT_SCHEDULE_ATTACK
Definition: Unit.hpp:59
void on_attack_end()
Definition: Unit.cpp:263
void set_attacking(bool attacking)
Definition: Unit.hpp:234
std::shared_ptr< Combat > combat()
Combat.
Definition: Unit.hpp:246
bool is_in_range_of(std::shared_ptr< Unit > unit, uint8_t range=MAX_VIEW_RANGE)
Definition: Unit.cpp:300
int32_t _attackable_time
Definition: Unit.hpp:308
virtual bool stop_attacking()
Definition: Unit.cpp:483
bool target_is_attackable(std::shared_ptr< Unit > target)
Definition: Unit.cpp:495
bool is_walking() const
Definition: Unit.hpp:121
uint64_t get_scheduler_task_id(unit_task_schedule_group group)
Definition: Unit.hpp:204
void set_combat(std::shared_ptr< Combat > combat)
Definition: Unit.hpp:247
void set_lockon_after_walk_completed(uint64_t target_guid, bool continuous=false)
Lockon after walk completed.
Definition: Unit.hpp:268
virtual bool walk_to_unit(std::shared_ptr< Unit > unit)
Definition: Unit.cpp:286
std::shared_ptr< AStar::CoordinateList > path_to(std::shared_ptr< Unit > e)
Definition: Unit.cpp:93
bool stop_walking(bool cancel=false, bool notify=false)
Definition: Unit.cpp:247
std::shared_ptr< Horizon::Zone::Traits::Status > status()
Definition: Unit.hpp:158
bool is_attacking()
Definition: Unit.hpp:235
Definition: TaskScheduler.hpp:487
TaskContext & Repeat(std::chrono::duration< _Rep, _Period > const &duration)
Repeats the event and sets a new duration. std::chrono::seconds(5) for example. This will consume the...
Definition: TaskScheduler.hpp:560

References _attackable_time, CBT_RET_DEF, combat(), get_scheduler_task_id(), HLog, is_attacking(), is_in_range_of(), is_walking(), map(), MAX_VIEW_RANGE, on_attack_end(), path_to(), TaskContext::Repeat(), set_attacking(), set_combat(), set_lockon_after_walk_completed(), status(), stop_attacking(), stop_walking(), target_is_attackable(), UNIT_MONSTER, UNIT_SCHEDULE_ATTACK, and walk_to_unit().

Referenced by Horizon::Zone::Units::Player::attack(), Horizon::Zone::Units::Monster::behavior_active(), and walk().

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

◆ clear_lockon_after_walk_completed()

void Horizon::Zone::Unit::clear_lockon_after_walk_completed ( )
inline
struct Horizon::Zone::Unit::s_lockon_after_walk_completed _lockon_after_walk_completed
uint64_t target_guid
Definition: Unit.hpp:282

References _lockon_after_walk_completed, and Horizon::Zone::Unit::s_lockon_after_walk_completed::target_guid.

Referenced by walk().

+ Here is the caller graph for this function:

◆ combat()

std::shared_ptr< Combat > Horizon::Zone::Unit::combat ( )
inline

Combat.

246{ return _combat; }

References _combat.

Referenced by attack(), set_combat(), stop_attacking(), and Horizon::Zone::UnitComponent::sync_data_types().

+ Here is the caller graph for this function:

◆ combat_registry()

std::shared_ptr< CombatRegistry > Horizon::Zone::Unit::combat_registry ( )
inline
257{ return _combat_registry; }

References _combat_registry.

Referenced by Horizon::Zone::UnitComponent::sync_data_types(), and update().

+ Here is the caller graph for this function:

◆ dest_coords()

MapCoords const & Horizon::Zone::Unit::dest_coords ( ) const
inline

Movement.

118{ return _dest_pos; }
MapCoords _dest_pos
Definition: Unit.hpp:294

References _dest_pos.

Referenced by is_walking(), Horizon::Zone::Units::Player::on_movement_begin(), and Horizon::Zone::UnitComponent::sync_data_types().

+ Here is the caller graph for this function:

◆ direction()

directions Horizon::Zone::Unit::direction ( ) const
inline
155{ return _facing_dir; }
directions _facing_dir
Definition: Unit.hpp:304

References _facing_dir.

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

+ Here is the caller graph for this function:

◆ distance_from()

int Horizon::Zone::Unit::distance_from ( std::shared_ptr< Unit e)
inline
228{ return path_to(e)->size(); }

References path_to().

Referenced by Horizon::Zone::Units::Monster::behavior_active().

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

◆ downcast()

template<class T >
std::shared_ptr< T > Horizon::Zone::Unit::downcast ( )
inline
179 {
180 return std::dynamic_pointer_cast<T>(shared_from_this());
181 }

◆ execute_skill_in_area()

void Unit::execute_skill_in_area ( std::shared_ptr< Unit target,
std::shared_ptr< SkillExecution skill_execution,
s_grid_apply_in_area_config const &  aoe_config 
)
598{
599 GridExecuteSkillInArea execute_skill_in_area(shared_from_this(), target, skill_execution, aoe_config);
601
602 map()->visit_in_range(map_coords(), container, MAX_VIEW_RANGE);
603}
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)
Definition: Unit.cpp:597
Definition: GridNotifiers.hpp:305

References execute_skill_in_area(), map(), map_coords(), and MAX_VIEW_RANGE.

Referenced by execute_skill_in_area(), and Horizon::Zone::UnitComponent::sync_data_types().

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

◆ execute_skill_in_cell()

void Unit::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 
)
606{
607 GridExecuteSkillInCell execute_skill_in_cell(shared_from_this(), cell, skill_execution, aoe_config);
609
610 map()->visit_in_range(map_coords(), container, MAX_VIEW_RANGE);
611}
Cell cell[MAP_WIDTH][MAP_HEIGHT]
Definition: AStarTest.cpp:52
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)
Definition: Unit.cpp:605
Definition: GridNotifiers.hpp:335

References cell, execute_skill_in_cell(), map(), map_coords(), and MAX_VIEW_RANGE.

Referenced by execute_skill_in_cell(), and Horizon::Zone::UnitComponent::sync_data_types().

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

◆ finalize()

bool Unit::finalize ( )
virtual

Reimplemented in Horizon::Zone::Units::Item, Horizon::Zone::Units::Monster, and Horizon::Zone::Units::Mob.

87{
88 set_finalized(true);
89
90 return _is_finalized;
91}
void set_finalized(bool finalized)
Definition: Unit.hpp:113
bool _is_finalized
Definition: Unit.hpp:277

References _is_finalized, and set_finalized().

Referenced by Horizon::Zone::Units::Mob::finalize().

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

◆ force_movement_stop_internal()

void Horizon::Zone::Unit::force_movement_stop_internal ( bool  stop = false)
inline
161{ _jump_walk_stop = stop; }
bool _jump_walk_stop
Definition: Unit.hpp:277

References _jump_walk_stop.

Referenced by Horizon::Zone::Units::Player::move_to_map(), Horizon::Zone::UnitComponent::sync_data_types(), and walk().

+ Here is the caller graph for this function:

◆ get_nearby_unit()

std::shared_ptr< Unit > Unit::get_nearby_unit ( uint32_t  guid)
309{
310 GridUnitSearcher searcher(guid);
312
313 map()->visit_in_range(map_coords(), search_visitor);
314
315 return searcher.get_result();
316}
uint32_t guid()
Definition: Unit.hpp:144
Definition: GridNotifiers.hpp:117

References GridUnitSearcher::get_result(), guid(), map(), and map_coords().

Referenced by Horizon::Zone::Units::Player::pickup_item(), Horizon::Zone::UnitComponent::sync_data_types(), and walk().

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

◆ get_scheduler_task_id()

uint64_t Horizon::Zone::Unit::get_scheduler_task_id ( unit_task_schedule_group  group)
inline
204{ return ((uint64_t) guid() << 32) + (int) group; }

References guid().

Referenced by attack(), Horizon::Zone::Units::Monster::initialize(), status_effect_start(), Horizon::Zone::Units::Player::stop_attack(), stop_attacking(), stop_walking(), and walk().

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

◆ get_status_effects()

std::map< int16_t, std::shared_ptr< status_change_entry > > & Horizon::Zone::Unit::get_status_effects ( )
inline
205{ return _status_effects; }
std::map< int16_t, std::shared_ptr< status_change_entry > > _status_effects
Definition: Unit.hpp:306

References _status_effects.

Referenced by status_effect_end(), and status_effect_start().

+ Here is the caller graph for this function:

◆ get_walk_path()

AStar::CoordinateList Horizon::Zone::Unit::get_walk_path ( )
inline
168{ return _walk_path; }
AStar::CoordinateList _walk_path
Definition: Unit.hpp:295

References _walk_path.

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

+ Here is the caller graph for this function:

◆ grid_coords()

GridCoords const & Horizon::Zone::Unit::grid_coords ( ) const
inline
189{ return _grid_coords; }
GridCoords _grid_coords
Definition: Unit.hpp:292

References _grid_coords.

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

+ Here is the caller graph for this function:

◆ guid()

◆ has_damage_walk_delay()

bool Horizon::Zone::Unit::has_damage_walk_delay ( )
inline

Walk Delay.

262{ return _damage_walk_delay; }
bool _damage_walk_delay
Definition: Unit.hpp:315

References _damage_walk_delay.

◆ initialize()

bool Unit::initialize ( )
73{
74 if (type() == UNIT_ITEM || type() == UNIT_SKILL) {
75 _is_initialized = true;
76 return _is_initialized;
77 }
78
79 _status = std::make_shared<Horizon::Zone::Traits::Status>(shared_from_this(), type());
80 _combat_registry = std::make_shared<CombatRegistry>(shared_from_this());
81 _is_initialized = true;
82
83 return _is_initialized;
84}
@ UNIT_SKILL
Definition: UnitDefinitions.hpp:48
@ UNIT_ITEM
Definition: UnitDefinitions.hpp:47
std::shared_ptr< Horizon::Zone::Traits::Status > _status
Definition: Unit.hpp:298
bool _is_initialized
Definition: Unit.hpp:277

References _combat_registry, _is_initialized, _status, type(), UNIT_ITEM, and UNIT_SKILL.

Referenced by Horizon::Zone::Units::Item::initialize(), Horizon::Zone::Units::Monster::initialize(), Horizon::Zone::Units::NPC::initialize(), Horizon::Zone::Units::Player::initialize(), and Horizon::Zone::Units::Mob::initialize().

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

◆ is_attacking()

bool Horizon::Zone::Unit::is_attacking ( )
inline
235{ return _is_attacking; }
bool _is_attacking
Definition: Unit.hpp:278

References _is_attacking.

Referenced by attack(), Horizon::Zone::Units::Monster::behavior_passive(), stop_attacking(), and walk_to_coordinates().

+ Here is the caller graph for this function:

◆ is_dead()

bool Unit::is_dead ( )
459{
460 if (status() == nullptr)
461 return true;
462
463 return status()->current_hp()->get_base() <= 0;
464}

References status().

Referenced by Horizon::Zone::Units::Player::on_map_enter(), Horizon::Zone::Units::Player::remove_unit_from_viewport(), Horizon::Zone::Units::Player::respawn(), Horizon::Zone::UnitComponent::sync_data_types(), and target_is_attackable().

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

◆ is_finalized()

bool Horizon::Zone::Unit::is_finalized ( ) const
inline
112{ return _is_finalized; }

References _is_finalized.

◆ is_in_range_of()

bool Unit::is_in_range_of ( std::shared_ptr< Unit unit,
uint8_t  range = MAX_VIEW_RANGE 
)
301{
302 if (e->map()->get_name().compare(map()->get_name()))
303 return false;
304
305 return map_coords().is_within_range(e->map_coords(), range);
306}
bool is_within_range(Coordinates< BOUNDS > const &bounds, int range) const
Definition: Coordinates.hpp:82

References Coordinates< MAX_COORDINATES >::is_within_range(), map(), and map_coords().

Referenced by attack(), and Horizon::Zone::UnitComponent::sync_data_types().

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

◆ is_initialized()

bool Horizon::Zone::Unit::is_initialized ( ) const
inline
111{ return _is_initialized; }

References _is_initialized.

Referenced by update().

+ Here is the caller graph for this function:

◆ is_of_type()

bool Horizon::Zone::Unit::is_of_type ( int  type_mask)
inline
175{ return !((type_mask & (int) _type_mask) == 0); }

References _type_mask, and type_mask().

+ Here is the call graph for this function:

◆ is_walking()

bool Horizon::Zone::Unit::is_walking ( ) const
inline
121{ return (dest_coords() != MapCoords(0, 0)) || ((_changed_dest_pos) != MapCoords(0, 0)); }
MapCoords _changed_dest_pos
Definition: Unit.hpp:294
MapCoords const & dest_coords() const
Movement.
Definition: Unit.hpp:118

References _changed_dest_pos, and dest_coords().

Referenced by attack(), Horizon::Zone::Units::Monster::behavior_passive(), Horizon::Zone::Units::Player::move_to_map(), and Horizon::Zone::UnitComponent::sync_data_types().

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

◆ job_id()

uint16_t Horizon::Zone::Unit::job_id ( ) const
inline

◆ lockon_after_walk_completed_target_guid()

uint64_t Horizon::Zone::Unit::lockon_after_walk_completed_target_guid ( )
inline

References _lockon_after_walk_completed, and Horizon::Zone::Unit::s_lockon_after_walk_completed::target_guid.

Referenced by walk().

+ Here is the caller graph for this function:

◆ map()

std::shared_ptr< Map > Horizon::Zone::Unit::map ( )
inline

Map & Map Container.

165{ return _map.expired() ? nullptr : _map.lock(); }
std::weak_ptr< Map > _map
Definition: Unit.hpp:290

References _map.

Referenced by apply_status_change_in_area(), attack(), Horizon::Zone::Units::Monster::behavior_active(), Horizon::Zone::Units::Monster::behavior_passive(), execute_skill_in_area(), execute_skill_in_cell(), get_nearby_unit(), Horizon::Zone::Units::Item::initialize(), Horizon::Zone::Units::Monster::initialize(), Horizon::Zone::Units::NPC::initialize(), Horizon::Zone::Units::Player::initialize(), is_in_range_of(), Horizon::Zone::Units::Player::load(), Horizon::Zone::Units::Player::move_to_map(), Horizon::Zone::Units::Player::notify_in_area(), notify_nearby_players_of_basic_attack(), notify_nearby_players_of_existence(), notify_nearby_players_of_item_drop(), notify_nearby_players_of_movement(), notify_nearby_players_of_movement_stop(), notify_nearby_players_of_skill_use(), notify_nearby_players_of_spawn(), Horizon::Zone::Units::Monster::on_killed(), Horizon::Zone::Units::Monster::on_movement_step(), Horizon::Zone::Units::NPC::on_movement_step(), Horizon::Zone::Units::Player::on_movement_step(), path_to(), remove_status_change_in_area(), Horizon::Zone::Units::Player::respawn(), Horizon::Zone::Units::Player::save(), schedule_walk(), set_map(), status_effect_start(), Horizon::Zone::Units::Player::stop_attack(), stop_attacking(), stop_walking(), Horizon::Zone::UnitComponent::sync_data_types(), Horizon::Zone::Units::Player::throw_item(), Unit(), Horizon::Zone::Units::Player::update_viewport(), and walk().

+ Here is the caller graph for this function:

◆ map_coords()

◆ name()

const std::string & Horizon::Zone::Unit::name ( ) const
inline
152{ return _name; }
std::string _name
Definition: Unit.hpp:301

References _name.

Referenced by Horizon::Zone::Units::Monster::behavior_active(), Horizon::Zone::Units::NPC::NPC(), Horizon::Zone::Units::Player::save(), set_name(), and Horizon::Zone::UnitComponent::sync_data_types().

+ Here is the caller graph for this function:

◆ notify_nearby_players_of_basic_attack()

void Unit::notify_nearby_players_of_basic_attack ( s_grid_unit_basic_attack_config  config)
359{
360 GridUnitBasicAttackNotifier notifier(shared_from_this(), config);
362
363 map()->visit_in_range(map_coords(), basic_attack_notifier);
364}
Definition: GridNotifiers.hpp:398

References map(), and map_coords().

+ Here is the call graph for this function:

◆ notify_nearby_players_of_existence()

void Unit::notify_nearby_players_of_existence ( unit_viewport_notification_type  notif_type)
319{
320 GridUnitExistenceNotifier existence_notify(shared_from_this(), notif_type);
322
323 map()->visit_in_range(map_coords(), unit_visitor);
324}
Definition: GridNotifiers.hpp:64

References map(), and map_coords().

Referenced by Horizon::Zone::Units::Player::move_to_map(), on_killed(), Horizon::Zone::UnitComponent::sync_data_types(), and walk().

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

◆ notify_nearby_players_of_item_drop()

void Unit::notify_nearby_players_of_item_drop ( s_grid_notify_item_drop_entry  entry)
367{
368 GridUnitItemDropNotifier notifier(entry);
370
371 map()->visit_in_range(map_coords(), item_drop_notifier);
372}
Definition: GridNotifiers.hpp:440

References map(), and map_coords().

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

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

◆ notify_nearby_players_of_movement()

void Unit::notify_nearby_players_of_movement ( bool  new_entry = false)
335{
336 GridUnitMovementNotifier movement_notify(shared_from_this(), new_entry);
338
339 map()->visit_in_range(map_coords(), unit_visitor);
340}
Definition: GridNotifiers.hpp:99

References map(), and map_coords().

Referenced by schedule_walk(), and Horizon::Zone::UnitComponent::sync_data_types().

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

◆ notify_nearby_players_of_movement_stop()

void Unit::notify_nearby_players_of_movement_stop ( MapCoords  stop_coords)
343{
344 GridUnitMovementStopNotifier movement_stop_notify(guid(), stop_coords.x(), stop_coords.y());
346
347 map()->visit_in_range(map_coords(), unit_visitor);
348}
int16_t y() const
Definition: Coordinates.hpp:120
int16_t x() const
Definition: Coordinates.hpp:119
Definition: GridNotifiers.hpp:416

References guid(), map(), map_coords(), Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

Referenced by stop_walking().

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

◆ notify_nearby_players_of_skill_use()

void Unit::notify_nearby_players_of_skill_use ( grid_unit_skill_use_notification_type  notification_type,
s_unit_skill_use_notifier_config  config 
)
351{
352 GridUnitSkillUseNotifier notifier(shared_from_this(), notification_type, config);
354
355 map()->visit_in_range(map_coords(), skill_use_notifier);
356}
Definition: GridNotifiers.hpp:374

References map(), and map_coords().

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

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

◆ notify_nearby_players_of_spawn()

void Unit::notify_nearby_players_of_spawn ( )
327{
328 GridUnitSpawnNotifier spawn_notify(shared_from_this());
330
331 map()->visit_in_range(map_coords(), unit_visitor);
332}
Definition: GridNotifiers.hpp:82

References map(), and map_coords().

Referenced by Horizon::Zone::Units::Player::on_map_enter(), and Horizon::Zone::UnitComponent::sync_data_types().

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

◆ on_attack_end()

void Unit::on_attack_end ( )
264{
266 stop_walking(true, false);
267}

References stop_attacking(), and stop_walking().

Referenced by attack().

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

◆ on_damage_received()

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

Reimplemented in Horizon::Zone::Units::Monster, Horizon::Zone::Units::Mob, and Horizon::Zone::Units::Player.

467{
468 if (status()->current_hp()->total() < damage)
469 {
470 status()->current_hp()->set_base(0);
471 on_killed(damage_dealer);
472 return;
473 }
474}
virtual void on_killed(std::shared_ptr< Unit > killer, bool with_drops=false, bool with_exp=false)
Definition: Unit.cpp:476

References on_killed(), and status().

Referenced by Horizon::Zone::Units::Mob::on_damage_received(), and Horizon::Zone::Units::Player::on_damage_received().

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

◆ on_killed()

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

Reimplemented in Horizon::Zone::Units::Monster, Horizon::Zone::Units::Mob, and Horizon::Zone::Units::Player.

477{
478 stop_walking();
481}
@ EVP_NOTIFY_DEAD
Definition: UnitDefinitions.hpp:839
void notify_nearby_players_of_existence(unit_viewport_notification_type notif_type)
Definition: Unit.cpp:318

References EVP_NOTIFY_DEAD, notify_nearby_players_of_existence(), stop_attacking(), and stop_walking().

Referenced by on_damage_received(), Horizon::Zone::Units::Mob::on_killed(), and Horizon::Zone::Units::Player::on_killed().

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

◆ on_movement_begin()

virtual void Horizon::Zone::Unit::on_movement_begin ( int32_t  time)
protectedpure virtual

◆ on_movement_end()

◆ on_movement_step()

virtual void Horizon::Zone::Unit::on_movement_step ( )
protectedpure virtual

◆ on_pathfinding_failure()

virtual void Horizon::Zone::Unit::on_pathfinding_failure ( )
protectedpure virtual

◆ on_status_effect_change()

virtual void Horizon::Zone::Unit::on_status_effect_change ( std::shared_ptr< status_change_entry sce)
pure virtual

◆ on_status_effect_end()

virtual void Horizon::Zone::Unit::on_status_effect_end ( std::shared_ptr< status_change_entry sce)
pure virtual

◆ on_status_effect_start()

virtual void Horizon::Zone::Unit::on_status_effect_start ( std::shared_ptr< status_change_entry sce)
pure virtual

◆ path_to()

std::shared_ptr< AStar::CoordinateList > Unit::path_to ( std::shared_ptr< Unit e)
94{
95 std::shared_ptr<AStar::CoordinateList> wp = std::make_shared<AStar::CoordinateList>(map()->get_pathfinder().findPath(map_coords(), e->map_coords()));
96
97 if (wp->size() == 0 || wp->empty())
98 return nullptr;
99
100 return std::move(wp);
101}

References map(), and map_coords().

Referenced by attack(), and distance_from().

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

◆ posture()

unit_posture_type Horizon::Zone::Unit::posture ( ) const
inline
149{ return _posture; }
unit_posture_type _posture
Definition: Unit.hpp:303

References _posture.

Referenced by set_posture(), and Horizon::Zone::UnitComponent::sync_data_types().

+ Here is the caller graph for this function:

◆ remove_status_change_in_area()

void Unit::remove_status_change_in_area ( std::shared_ptr< Unit target,
int  sc_type,
s_grid_apply_in_area_config const &  aoe_config 
)
590{
591 GridSCRemoveInSkillArea sc_remove_in_skill_area(shared_from_this(), target, sc_type, aoe_config);
593
594 map()->visit_in_range(map_coords(), container, MAX_VIEW_RANGE);
595}
Definition: GridNotifiers.hpp:278

References map(), map_coords(), and MAX_VIEW_RANGE.

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

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

◆ s_uuid()

unit_uuid Horizon::Zone::Unit::s_uuid ( ) const
inline
141{ return _s_uuid; }

References _s_uuid.

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

+ Here is the caller graph for this function:

◆ schedule_walk()

bool Unit::schedule_walk ( )
protected

~1us

104{
105 MapCoords source_pos = {map_coords().x(), map_coords().y()};
106
107 if (!_walk_path.empty())
108 _walk_path.clear();
109
110 if (!map())
111 {
112 // HLog(error) << "Reference to map object has been lost for unit " << (void *) this << ".";
113 _dest_pos = {0, 0};
114 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:2: Map object has been lost.";
115 return false;
116 }
117
118 // This method returns vector of coordinates from target to source.
119 _walk_path = map()->get_pathfinder().findPath(source_pos, _dest_pos); // ~5us
120
121 _changed_dest_pos = {0, 0};
122
123 // If destination was a collision, nothing is returned.
124 if (_walk_path.size() == 0)
125 {
126 // HLog(warning) << "Unit::schedule_walk: Destination was a collision, no walk path available.";
127 _dest_pos = {0, 0};
128 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:3: Destination was a collision.";
129 return false;
130 }
131
133 std::reverse(_walk_path.begin(), _walk_path.end());
134 _walk_path.erase(_walk_path.begin());
136
137 if (_walk_path.empty())
138 {
140 // HLog(warning) << "Unit::schedule_walk: Path too short or empty, failed to schedule movement.";
141 _dest_pos = {0, 0};
142 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:4: Path too short or empty.";
143 return false;
144 }
145 // 0us
147 walk(); // 3~6 us
148 return true;
149}
@ UNIT_PLAYER
Definition: UnitDefinitions.hpp:45
void notify_nearby_players_of_movement(bool new_entry=false)
Definition: Unit.cpp:334
virtual void on_pathfinding_failure()=0
void walk()
Definition: Unit.cpp:153

References _changed_dest_pos, _dest_pos, _type, _walk_path, HLog, map(), map_coords(), notify_nearby_players_of_movement(), on_pathfinding_failure(), UNIT_PLAYER, walk(), Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

Referenced by walk(), and walk_to_coordinates().

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

◆ set_attacking()

void Horizon::Zone::Unit::set_attacking ( bool  attacking)
inline
234{ _is_attacking = attacking; }

References _is_attacking.

Referenced by attack(), and stop_attacking().

+ Here is the caller graph for this function:

◆ set_combat()

void Horizon::Zone::Unit::set_combat ( std::shared_ptr< Combat combat)
inline
248 {
249 _combat = combat;
250 }

References _combat, and combat().

Referenced by attack().

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

◆ set_damage_walk_delay()

void Horizon::Zone::Unit::set_damage_walk_delay ( bool  delay)
inline
263{ _damage_walk_delay = delay; }

References _damage_walk_delay.

◆ set_direction()

void Horizon::Zone::Unit::set_direction ( directions  dir)
inline
156{ _facing_dir = dir; }

References _facing_dir.

Referenced by Horizon::Zone::Units::Monster::Monster(), and Horizon::Zone::Units::NPC::NPC().

+ Here is the caller graph for this function:

◆ set_finalized()

void Horizon::Zone::Unit::set_finalized ( bool  finalized)
inline
113{ _is_finalized = finalized; }

References _is_finalized.

Referenced by finalize().

+ Here is the caller graph for this function:

◆ set_grid_coords()

void Horizon::Zone::Unit::set_grid_coords ( GridCoords const &  coords)
inline
190{ _grid_coords = coords; }

References _grid_coords.

◆ set_job_id()

void Horizon::Zone::Unit::set_job_id ( uint16_t  job_id)
inline
147{ _job_id = job_id; }
uint16_t job_id() const
Definition: Unit.hpp:146

References _job_id, and job_id().

Referenced by Horizon::Zone::Units::Player::job_change(), Horizon::Zone::Units::Monster::Monster(), and Horizon::Zone::Units::NPC::NPC().

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

◆ set_lockon_after_walk_completed()

void Horizon::Zone::Unit::set_lockon_after_walk_completed ( uint64_t  target_guid,
bool  continuous = false 
)
inline

Lockon after walk completed.

269 {
272 }

References _lockon_after_walk_completed, Horizon::Zone::Unit::s_lockon_after_walk_completed::continuous, and Horizon::Zone::Unit::s_lockon_after_walk_completed::target_guid.

Referenced by attack().

+ Here is the caller graph for this function:

◆ set_map()

void Horizon::Zone::Unit::set_map ( std::shared_ptr< Map map)
inline
166{ _map = map; }

References _map, and map().

Referenced by Horizon::Zone::Units::Player::load(), Horizon::Zone::Units::Player::move_to_map(), and Unit().

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

◆ set_map_coords()

void Horizon::Zone::Unit::set_map_coords ( MapCoords const &  coords)
inline
187{ _map_coords = coords; }

References _map_coords.

Referenced by Horizon::Zone::Units::Player::load(), Horizon::Zone::Units::Player::move_to_map(), and walk().

+ Here is the caller graph for this function:

◆ set_name()

void Horizon::Zone::Unit::set_name ( const std::string &  name)
inline
153{ _name = name; }
const std::string & name() const
Definition: Unit.hpp:152

References _name, and name().

Referenced by Horizon::Zone::Units::Player::load(), Horizon::Zone::Units::Monster::Monster(), and Horizon::Zone::Units::NPC::NPC().

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

◆ set_posture()

void Horizon::Zone::Unit::set_posture ( unit_posture_type  posture)
inline
150{ _posture = posture; }
unit_posture_type posture() const
Definition: Unit.hpp:149

References _posture, and posture().

Referenced by Horizon::Zone::Units::Player::load(), and Horizon::Zone::UnitComponent::sync_data_types().

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

◆ set_status()

void Horizon::Zone::Unit::set_status ( std::shared_ptr< Horizon::Zone::Traits::Status st)
inline
159{ _status = st; }

References _status.

◆ set_uuid()

void Unit::set_uuid ( uint64_t  uuid)
61{
63 _uuid = uuid;
64}
#define sZone
Definition: Zone.hpp:247
uint64_t _uuid
Definition: Unit.hpp:286
uint8_t uid3
Definition: Unit.hpp:84
uint16_t uid2
Definition: Unit.hpp:83
uint8_t type
Definition: Unit.hpp:81

References _s_uuid, _uuid, unit_uuid::guid, sZone, unit_uuid::type, unit_uuid::uid2, unit_uuid::uid3, and uuid().

Referenced by Horizon::Zone::UnitComponent::sync_data_types(), and Unit().

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

◆ status()

◆ status_effect_end()

bool Unit::status_effect_end ( int  type)
442{
443 std::map<int16_t, std::shared_ptr<status_change_entry>>::iterator it = get_status_effects().find(type);
444
445 if (it == get_status_effects().end())
446 {
447 HLog(warning) << "Trying to end status effect that doesn't exist. ID " << type << ", ignoring...";
448 return false;
449 }
450
451 on_status_effect_end(it->second);
452
453 get_status_effects().erase(it);
454
455 return true;
456}
virtual void on_status_effect_end(std::shared_ptr< status_change_entry > sce)=0
std::map< int16_t, std::shared_ptr< status_change_entry > > & get_status_effects()
Definition: Unit.hpp:205

References get_status_effects(), HLog, on_status_effect_end(), and type().

Referenced by status_effect_start(), and Horizon::Zone::UnitComponent::sync_data_types().

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

◆ status_effect_start()

bool Unit::status_effect_start ( int  type,
int  total_time,
int  val1,
int  val2,
int  val3,
int  val4 
)

Status Effects.

375{
376 std::map<int16_t, std::shared_ptr<status_change_entry>>::iterator it = get_status_effects().find(type);
377
378 if (it == get_status_effects().end())
379 {
380 std::shared_ptr<status_change_entry> sce = std::make_shared<status_change_entry>();
381 sce->type = type;
382 sce->val1 = val1;
383 sce->val2 = val2;
384 sce->val3 = val3;
385 sce->val4 = val4;
386
387 if (total_time < 0)
388 {
389 sce->infinite_duration = true;
390 sce->current_time = 0;
391 sce->total_time = 0;
392 }
393 else
394 {
395 sce->current_time = std::time(nullptr) + total_time;
396 sce->total_time = total_time;
397 }
398
399 get_status_effects().insert(std::pair(type, sce));
401 }
402 else
403 {
404 std::shared_ptr<status_change_entry> sce = it->second;
405 sce->current_time = std::time(nullptr) + total_time;
406 sce->total_time = total_time;
407
409 }
410
411 if (map()->container()->getScheduler().Count(get_scheduler_task_id(UNIT_SCHEDULE_STATUS_EFFECT_CLEAR)) == 0)
412 map()->container()->getScheduler().Schedule(
415 [this](TaskContext context)
416 {
417 std::map<int16_t, std::shared_ptr<status_change_entry>>::iterator it = get_status_effects().begin();
418
419 int infinite_statuses = 0;
420 for (; it != get_status_effects().end(); it++)
421 {
422 std::shared_ptr<status_change_entry> sce = it->second;
423
424 if (sce->infinite_duration == false)
425 {
426 infinite_statuses++;
427 continue;
428 }
429
430 if (sce->current_time - std::time(nullptr) <= 0)
431 status_effect_end(sce->type);
432 }
433
434 if (get_status_effects().size() > infinite_statuses)
436 });
437
438 return true;
439}
#define UNIT_STATUS_EFFECT_CHECK_TIME
Definition: Unit.hpp:70
@ UNIT_SCHEDULE_STATUS_EFFECT_CLEAR
Definition: Unit.hpp:57
virtual void on_status_effect_start(std::shared_ptr< status_change_entry > sce)=0
virtual void on_status_effect_change(std::shared_ptr< status_change_entry > sce)=0
bool status_effect_end(int type)
Definition: Unit.cpp:441

References get_scheduler_task_id(), get_status_effects(), map(), on_status_effect_change(), on_status_effect_start(), TaskContext::Repeat(), status_effect_end(), type(), UNIT_SCHEDULE_STATUS_EFFECT_CLEAR, and UNIT_STATUS_EFFECT_CHECK_TIME.

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

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

◆ stop_attacking()

bool Unit::stop_attacking ( )
virtual
484{
485 if (!is_attacking())
486 return false;
487
488 set_attacking(false);
489 map()->container()->getScheduler().CancelGroup(get_scheduler_task_id(UNIT_SCHEDULE_ATTACK));
490 combat().reset();
491
492 return true;
493}

References combat(), get_scheduler_task_id(), is_attacking(), map(), set_attacking(), and UNIT_SCHEDULE_ATTACK.

Referenced by attack(), on_attack_end(), on_killed(), and walk_to_coordinates().

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

◆ stop_movement()

◆ stop_walking()

bool Unit::stop_walking ( bool  cancel = false,
bool  notify = false 
)
248{
249 _dest_pos = {0, 0};
250 _changed_dest_pos = {0, 0};
251
252 if (cancel)
253 map()->container()->getScheduler().CancelGroup(get_scheduler_task_id(UNIT_SCHEDULE_WALK));
254
255 if (notify)
257
259
260 return true;
261}
@ UNIT_SCHEDULE_WALK
Definition: Unit.hpp:53
void notify_nearby_players_of_movement_stop(MapCoords stop_coords)
Definition: Unit.cpp:342
virtual void on_movement_end()=0

References _changed_dest_pos, _dest_pos, get_scheduler_task_id(), map(), map_coords(), notify_nearby_players_of_movement_stop(), on_movement_end(), and UNIT_SCHEDULE_WALK.

Referenced by attack(), on_attack_end(), on_killed(), and walk().

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

◆ target_is_attackable()

bool Unit::target_is_attackable ( std::shared_ptr< Unit target)
496{
497 if (target == nullptr) {
498 HLog(debug) << "Unit::attack:1: Attack target is null.";
499 return false;
500 }
501
502 if (is_dead()) {
503 HLog(debug) << "Unit::attack:2: Attacker is dead.";
504 return false;
505 }
506
507 if (target->is_dead()) {
508 HLog(debug) << "Unit::attack:3: Target is dead.";
509 return false;
510 }
511
512 return true;
513}
bool is_dead()
Definition: Unit.cpp:458

References HLog, and is_dead().

Referenced by attack(), and walk().

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

◆ type()

unit_type Horizon::Zone::Unit::type ( ) const
inline

◆ type_mask()

unit_type_mask Horizon::Zone::Unit::type_mask ( ) const
inline
174{ return _type_mask; }

References _type_mask.

Referenced by is_of_type().

+ Here is the caller graph for this function:

◆ update()

void Unit::update ( uint64_t  tick)

Extremely time-sensitive functions.

Extremely time-sensitive, do not use for any other purpose than to check for very small calculations.

635{
636 if (_combat_registry != nullptr)
637 combat_registry()->process_queue();
638 if (status() != nullptr && status()->is_initialized() != false) {
639 status()->status_registry()->process_queue();
640 status()->update(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
641 }
642}
std::shared_ptr< CombatRegistry > combat_registry()
Definition: Unit.hpp:257
bool is_initialized() const
Definition: Unit.hpp:111
size_t count(GridTypeListContainer< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: GridReferenceContainer.hpp:100

References _combat_registry, combat_registry(), GridTypeListIterator::count(), is_initialized(), and status().

+ Here is the call graph for this function:

◆ use_skill_on_ground() [1/2]

void Unit::use_skill_on_ground ( int16_t  skill_lv,
int16_t  skill_id,
int16_t  pos_x,
int16_t  pos_y 
)
620{
621 auto ske = std::make_shared<SkillExecution>(shared_from_this(), skill_id, skill_lv);
622 ske->execute(pos_x, pos_y);
623}

◆ use_skill_on_ground() [2/2]

void Unit::use_skill_on_ground ( int16_t  skill_lv,
int16_t  skill_id,
int16_t  pos_x,
int16_t  pos_y,
std::string  contents 
)
626{
627 auto ske = std::make_shared<SkillExecution>(shared_from_this(), skill_id, skill_lv);
628 ske->execute(pos_x, pos_y, contents);
629}

◆ use_skill_on_target()

void Unit::use_skill_on_target ( int16_t  skill_lv,
int16_t  skill_id,
int  target_guid 
)
614{
615 auto ske = std::make_shared<SkillExecution>(shared_from_this(), skill_id, skill_lv);
616 ske->execute(target_guid);
617}

◆ uuid()

uint64_t Horizon::Zone::Unit::uuid ( ) const
inline

Unit Data.

140{ return _uuid; }

References _uuid.

Referenced by Horizon::Zone::Units::Monster::on_killed(), set_uuid(), Horizon::Zone::UnitComponent::sync_data_types(), and Unit().

+ Here is the caller graph for this function:

◆ walk()

void Unit::walk ( )
protected
154{
155 map()->container()->getScheduler().CancelGroup(get_scheduler_task_id(UNIT_SCHEDULE_WALK));
156
157 if (status() == nullptr || status()->movement_speed() == nullptr) {
158 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:5: Status or movement speed is null.";
159 return;
160 }
161
162 if (_walk_path.size() == 1) {
163 stop_walking();
164 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:6: Walk path size is 1.";
165 return;
166 }
167
168 MapCoords c = _walk_path.at(0); // for the first step.
169
170 // @NOTE It is possible that at the time of begining movement, that a creature is not in the viewport of the player.
171 on_movement_begin((int32_t) get_sys_time());
172
173 map()->container()->getScheduler().Schedule(
174 Milliseconds(status()->movement_speed()->get_with_cost(_walk_path.at(1).move_cost())), get_scheduler_task_id(UNIT_SCHEDULE_WALK),
175 [this](TaskContext context)
176 {
177 if (_walk_path.size() == 0) { // to fix the "invalid vector subscript" error.
178 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:7:1: Walk path size is 0.";
179 return;
180 }
181
182 MapCoords c = _walk_path.at(0);
183
184 // Force stop as the current coordinates might asynchronously update after map has changed
185 // and co-ordinates are reset to something in a previous walk path.
186 // This force stop will return before changing co-ordinates and
187 // prevent further movement updates after map has changed.
188 if (_jump_walk_stop)
189 {
190 stop_walking(true);
192 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:7:2: Jump walk stop.";
193 return;
194 }
195
196 MapCoords step_coords(c.x(), c.y());
197
198 // set_direction((directions) my_coords.direction_to(step_coords));
199
201 set_map_coords(step_coords);
204
205 _walk_path.erase(_walk_path.begin());
206
207 if (_changed_dest_pos != MapCoords(0, 0))
208 {
210 _changed_dest_pos = {0, 0};
212 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:7:3: Destination changed, rescheduling...";
213 return;
214 }
215 else if (_dest_pos == MapCoords(c.x(), c.y()) || _walk_path.size() == 1)
216 {
217 stop_walking();
218 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:7:4: Destination reached.";
220 {
221 std::shared_ptr<Unit> target = get_nearby_unit(lockon_after_walk_completed_target_guid());
222 if (target_is_attackable(target))
223 {
226 }
227 }
228 return;
229 }
230
231 // std::chrono::milliseconds walk_delay = std::chrono::milliseconds(status()->movement_speed()->get_with_cost(_walk_path.at(1).move_cost()));
232
233 // if (has_damage_walk_delay() && is_dead() == false)
234 // walk_delay += std::chrono::milliseconds(status()->damage_walk_delay()->total());
235
236 // set_damage_walk_delay(false);
237
238 if (!_walk_path.empty())
239 context.Repeat();
240 });
241}
@ EVP_NOTIFY_IN_SIGHT
Definition: UnitDefinitions.hpp:837
@ EVP_NOTIFY_OUT_OF_SIGHT
Definition: UnitDefinitions.hpp:838
int64_t get_sys_time()
Definition: Utility.cpp:68
void set_map_coords(MapCoords const &coords)
Definition: Unit.hpp:187
virtual bool attack(std::shared_ptr< Unit > target, bool continuous=false)
Definition: Unit.cpp:514
uint64_t lockon_after_walk_completed_target_guid()
Definition: Unit.hpp:274
virtual void on_movement_begin(int32_t time)=0
void force_movement_stop_internal(bool stop=false)
Definition: Unit.hpp:161
bool schedule_walk()
Definition: Unit.cpp:103
std::shared_ptr< Unit > get_nearby_unit(uint32_t guid)
Definition: Unit.cpp:308
void clear_lockon_after_walk_completed()
Definition: Unit.hpp:273
virtual void on_movement_step()=0

References _changed_dest_pos, _dest_pos, _jump_walk_stop, _lockon_after_walk_completed, _type, _walk_path, attack(), clear_lockon_after_walk_completed(), Horizon::Zone::Unit::s_lockon_after_walk_completed::continuous, EVP_NOTIFY_IN_SIGHT, EVP_NOTIFY_OUT_OF_SIGHT, force_movement_stop_internal(), get_nearby_unit(), get_scheduler_task_id(), get_sys_time(), HLog, lockon_after_walk_completed_target_guid(), map(), notify_nearby_players_of_existence(), on_movement_begin(), on_movement_step(), TaskContext::Repeat(), schedule_walk(), set_map_coords(), status(), stop_walking(), target_is_attackable(), UNIT_PLAYER, UNIT_SCHEDULE_WALK, Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

Referenced by schedule_walk().

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

◆ walk_to_coordinates()

bool Unit::walk_to_coordinates ( int16_t  x,
int16_t  y 
)
virtual
270{
271 if (_dest_pos.x() != 0 && _dest_pos.y() != 0 && _dest_pos.x() != x && _dest_pos.y() != y)
272 {
273 _changed_dest_pos = {x, y};
274 if (_type == UNIT_PLAYER) HLog(debug) << "Unit::walking:1: Destination changed to (" << x << ", " << y << ").";
275 return true;
276 }
277
278 if (is_attacking())
280
281 _dest_pos = {x, y};
282
283 return schedule_walk();
284}

References _changed_dest_pos, _dest_pos, _type, HLog, is_attacking(), schedule_walk(), stop_attacking(), UNIT_PLAYER, Coordinates< MAX_COORDINATES >::x(), and Coordinates< MAX_COORDINATES >::y().

Referenced by Horizon::Zone::Units::Monster::behavior_passive(), Horizon::Zone::UnitComponent::sync_data_types(), and walk_to_unit().

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

◆ walk_to_unit()

bool Unit::walk_to_unit ( std::shared_ptr< Unit unit)
virtual
287{
288 if (unit == nullptr)
289 return false;
290
291 if (walk_to_coordinates(unit->map_coords().x(), unit->map_coords().y()))
292 {
293 // HLog(warning) << "Unit (" << guid() << ") could not walk to (" << unit->guid() << ").";
294 return false;
295 }
296
297 return true;
298}
virtual bool walk_to_coordinates(int16_t x, int16_t y)
Definition: Unit.cpp:269

References walk_to_coordinates().

Referenced by attack().

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

Member Data Documentation

◆ _attackable_time

int32_t Horizon::Zone::Unit::_attackable_time {0}
private

Referenced by attack().

◆ _changed_dest_pos

MapCoords Horizon::Zone::Unit::_changed_dest_pos {0, 0}
private

◆ _combat

std::shared_ptr<Combat> Horizon::Zone::Unit::_combat
private

Referenced by combat(), set_combat(), and ~Unit().

◆ _combat_registry

std::shared_ptr<CombatRegistry> Horizon::Zone::Unit::_combat_registry
private

◆ _damage_walk_delay

bool Horizon::Zone::Unit::_damage_walk_delay {false}
private

◆ _dest_pos

MapCoords Horizon::Zone::Unit::_dest_pos {0, 0}
private

◆ _facing_dir

directions Horizon::Zone::Unit::_facing_dir {DIR_SOUTH}
private

Referenced by direction(), and set_direction().

◆ _grid_coords

GridCoords Horizon::Zone::Unit::_grid_coords {0, 0}
private

Referenced by grid_coords(), and set_grid_coords().

◆ _is_attacking

bool Horizon::Zone::Unit::_is_attacking {false}
private

Referenced by is_attacking(), and set_attacking().

◆ _is_finalized

bool Horizon::Zone::Unit::_is_finalized { false }
private

◆ _is_initialized

bool Horizon::Zone::Unit::_is_initialized {false}
private

Referenced by initialize(), and is_initialized().

◆ _job_id

uint16_t Horizon::Zone::Unit::_job_id {0}
private

Referenced by job_id(), and set_job_id().

◆ _jump_walk_stop

bool Horizon::Zone::Unit::_jump_walk_stop {false}
private

◆ _lockon_after_walk_completed

◆ _map

std::weak_ptr<Map> Horizon::Zone::Unit::_map
private

Referenced by map(), and set_map().

◆ _map_coords

MapCoords Horizon::Zone::Unit::_map_coords {0, 0}
private

Referenced by map_coords(), and set_map_coords().

◆ _name

std::string Horizon::Zone::Unit::_name {""}
private

Referenced by name(), and set_name().

◆ _posture

unit_posture_type Horizon::Zone::Unit::_posture {POSTURE_STANDING}
private

Referenced by posture(), and set_posture().

◆ _s_uuid

unit_uuid Horizon::Zone::Unit::_s_uuid { 0 }
private

Referenced by guid(), s_uuid(), and set_uuid().

◆ _status

std::shared_ptr<Horizon::Zone::Traits::Status> Horizon::Zone::Unit::_status
private

Referenced by initialize(), set_status(), and status().

◆ _status_effects

std::map<int16_t, std::shared_ptr<status_change_entry> > Horizon::Zone::Unit::_status_effects
private

Referenced by get_status_effects().

◆ _type

unit_type Horizon::Zone::Unit::_type {UNIT_UNKNOWN}
private

◆ _type_mask

unit_type_mask Horizon::Zone::Unit::_type_mask {UNIT_MASK_UNKNOWN}
private

Referenced by is_of_type(), and type_mask().

◆ _uuid

uint64_t Horizon::Zone::Unit::_uuid {0}
private

Referenced by set_uuid(), and uuid().

◆ _walk_path

AStar::CoordinateList Horizon::Zone::Unit::_walk_path
private

Referenced by get_walk_path(), schedule_walk(), and walk().

◆ _walk_path_index

int16_t Horizon::Zone::Unit::_walk_path_index {0}
private

◆ false

struct Horizon::Zone::Unit::s_lockon_after_walk_completed Horizon::Zone::Unit::false
private

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