30#ifndef HORIZON_ZONE_GAME_UNIT_HPP
31#define HORIZON_ZONE_GAME_UNIT_HPP
46#define MIN_RANDOM_TRAVEL_TIME 4000
47#define MOB_LAZY_MOVE_RATE 1000
48#define MOB_MIN_THINK_TIME 100
49#define MOB_MIN_THINK_TIME_LAZY (MOB_MIN_THINK_TIME * 10)
70#define UNIT_STATUS_EFFECT_CHECK_TIME 1000
101class Unit :
public std::enable_shared_from_this<Unit>
125 bool stop_walking(
bool cancel =
false,
bool notify =
false);
165 std::shared_ptr<Map>
map() {
return _map.expired() ? nullptr :
_map.lock(); }
180 return std::dynamic_pointer_cast<T>(shared_from_this());
214 void use_skill_on_ground(int16_t skill_lv, int16_t skill_id, int16_t pos_x, int16_t pos_y);
215 void use_skill_on_ground(int16_t skill_lv, int16_t skill_id, int16_t pos_x, int16_t pos_y, std::string contents);
227 std::shared_ptr<AStar::CoordinateList>
path_to(std::shared_ptr<Unit> e);
230 virtual bool attack(std::shared_ptr<Unit> target,
bool continuous =
false);
241 virtual void on_killed(std::shared_ptr<Unit> killer,
bool with_drops =
false,
bool with_exp =
false);
255 void update(uint64_t tick);
298 std::shared_ptr<Horizon::Zone::Traits::Status>
_status;
Cell cell[MAP_WIDTH][MAP_HEIGHT]
Definition: AStarTest.cpp:52
Coordinates< MAX_CELLS_PER_MAP > MapCoords
Definition: GridDefinitions.hpp:83
grid_unit_skill_use_notification_type
Definition: GridDefinitions.hpp:88
#define MAX_VIEW_RANGE
Definition: Horizon.hpp:59
#define NPC_START_GUID
Definition: NPCDefinitions.hpp:38
unit_type
Definition: UnitDefinitions.hpp:44
@ UNIT_UNKNOWN
Definition: UnitDefinitions.hpp:49
unit_viewport_notification_type
Definition: UnitDefinitions.hpp:836
unit_type_mask
Definition: UnitDefinitions.hpp:59
@ UNIT_MASK_UNKNOWN
Definition: UnitDefinitions.hpp:64
directions
Definition: UnitDefinitions.hpp:75
@ DIR_SOUTH
Definition: UnitDefinitions.hpp:80
unit_posture_type
Definition: UnitDefinitions.hpp:467
@ POSTURE_STANDING
Definition: UnitDefinitions.hpp:468
static std::atomic< int32_t > _last_np_unit_guid(NPC_START_GUID)
unit_walk_state
Definition: Unit.hpp:65
@ UNIT_WALK_MOVING
Definition: Unit.hpp:67
@ UNIT_WALK_STOPPED
Definition: Unit.hpp:66
unit_task_schedule_group
Definition: Unit.hpp:52
@ UNIT_SCHEDULE_AI_ACTIVE
Definition: Unit.hpp:58
@ UNIT_SCHEDULE_ATTACK
Definition: Unit.hpp:59
@ UNIT_SCHEDULE_STATUS_EFFECT_CLEAR
Definition: Unit.hpp:57
@ UNIT_SCHEDULE_AI_THINK
Definition: Unit.hpp:55
@ UNIT_SCHEDULE_SKILL_CAST
Definition: Unit.hpp:60
@ UNIT_SCHEDULE_WALK
Definition: Unit.hpp:53
@ UNIT_SCHEDULE_MONSTER_RESPAWN
Definition: Unit.hpp:61
@ UNIT_SCHEDULE_SAVE
Definition: Unit.hpp:54
@ UNIT_SCHEDULE_AI_WALK
Definition: Unit.hpp:56
virtual bool finalize()
Definition: Unit.cpp:86
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
std::shared_ptr< Combat > _combat
Definition: Unit.hpp:311
uint16_t job_id() const
Definition: Unit.hpp:146
unit_type _type
Definition: Unit.hpp:288
void set_map_coords(MapCoords const &coords)
Definition: Unit.hpp:187
void use_skill_on_target(int16_t skill_lv, int16_t skill_id, int target_guid)
Definition: Unit.cpp:613
void set_finalized(bool finalized)
Definition: Unit.hpp:113
void on_attack_end()
Definition: Unit.cpp:263
std::shared_ptr< Map > map()
Map & Map Container.
Definition: Unit.hpp:165
Unit(uint64_t uuid, unit_type type, unit_type_mask type_mask, std::shared_ptr< Map > map, MapCoords map_coords)
Definition: Unit.cpp:45
AStar::CoordinateList get_walk_path()
Definition: Unit.hpp:168
std::shared_ptr< Horizon::Zone::Traits::Status > _status
Definition: Unit.hpp:298
virtual void on_damage_received(std::shared_ptr< Unit > damage_dealer, int damage)
Definition: Unit.cpp:466
void set_map(std::shared_ptr< Map > map)
Definition: Unit.hpp:166
bool _is_initialized
Definition: Unit.hpp:277
void notify_nearby_players_of_movement(bool new_entry=false)
Definition: Unit.cpp:334
bool status_effect_start(int type, int total_time, int val1, int val2, int val3, int val4)
Status Effects.
Definition: Unit.cpp:374
void notify_nearby_players_of_spawn()
Definition: Unit.cpp:326
bool _damage_walk_delay
Definition: Unit.hpp:315
bool is_of_type(int type_mask)
Definition: Unit.hpp:175
void set_attacking(bool attacking)
Definition: Unit.hpp:234
uint32_t guid()
Definition: Unit.hpp:144
unit_type_mask _type_mask
Definition: Unit.hpp:289
uint64_t uuid() const
Unit Data.
Definition: Unit.hpp:140
void remove_status_change_in_area(std::shared_ptr< Unit > target, int sc_type, s_grid_apply_in_area_config const &aoe_config)
Definition: Unit.cpp:589
std::shared_ptr< Combat > combat()
Combat.
Definition: Unit.hpp:246
void notify_nearby_players_of_existence(unit_viewport_notification_type notif_type)
Definition: Unit.cpp:318
bool is_in_range_of(std::shared_ptr< Unit > unit, uint8_t range=MAX_VIEW_RANGE)
Definition: Unit.cpp:300
bool _is_finalized
Definition: Unit.hpp:277
virtual bool attack(std::shared_ptr< Unit > target, bool continuous=false)
Definition: Unit.cpp:514
unit_type_mask type_mask() const
Definition: Unit.hpp:174
directions direction() const
Definition: Unit.hpp:155
std::shared_ptr< T > downcast()
Definition: Unit.hpp:178
AStar::CoordinateList _walk_path
Definition: Unit.hpp:295
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)
Definition: Unit.cpp:581
bool _jump_walk_stop
Definition: Unit.hpp:277
std::weak_ptr< Map > _map
Definition: Unit.hpp:290
virtual void on_status_effect_start(std::shared_ptr< status_change_entry > sce)=0
void use_skill_on_ground(int16_t skill_lv, int16_t skill_id, int16_t pos_x, int16_t pos_y)
Definition: Unit.cpp:619
void set_status(std::shared_ptr< Horizon::Zone::Traits::Status > st)
Definition: Unit.hpp:159
uint16_t _job_id
Definition: Unit.hpp:302
void set_job_id(uint16_t job_id)
Definition: Unit.hpp:147
virtual ~Unit()
Definition: Unit.cpp:66
uint64_t lockon_after_walk_completed_target_guid()
Definition: Unit.hpp:274
int32_t _attackable_time
Definition: Unit.hpp:308
unit_type type() const
Unit applications.
Definition: Unit.hpp:173
virtual bool stop_attacking()
Definition: Unit.cpp:483
virtual void stop_movement()=0
std::shared_ptr< CombatRegistry > combat_registry()
Definition: Unit.hpp:257
unit_posture_type posture() const
Definition: Unit.hpp:149
virtual void on_status_effect_change(std::shared_ptr< status_change_entry > sce)=0
bool is_initialized() const
Definition: Unit.hpp:111
bool has_damage_walk_delay()
Walk Delay.
Definition: Unit.hpp:262
void set_uuid(uint64_t uuid)
Definition: Unit.cpp:60
MapCoords _dest_pos
Definition: Unit.hpp:294
virtual void on_movement_begin(int32_t time)=0
void set_damage_walk_delay(bool delay)
Definition: Unit.hpp:263
bool is_dead()
Definition: Unit.cpp:458
const std::string & name() const
Definition: Unit.hpp:152
void force_movement_stop_internal(bool stop=false)
Definition: Unit.hpp:161
bool initialize()
Definition: Unit.cpp:72
directions _facing_dir
Definition: Unit.hpp:304
std::string _name
Definition: Unit.hpp:301
bool target_is_attackable(std::shared_ptr< Unit > target)
Definition: Unit.cpp:495
virtual void on_pathfinding_failure()=0
void set_grid_coords(GridCoords const &coords)
Definition: Unit.hpp:190
bool is_walking() const
Definition: Unit.hpp:121
unit_uuid _s_uuid
Definition: Unit.hpp:287
void notify_nearby_players_of_movement_stop(MapCoords stop_coords)
Definition: Unit.cpp:342
void walk()
Definition: Unit.cpp:153
uint64_t get_scheduler_task_id(unit_task_schedule_group group)
Definition: Unit.hpp:204
virtual void on_killed(std::shared_ptr< Unit > killer, bool with_drops=false, bool with_exp=false)
Definition: Unit.cpp:476
bool _is_attacking
Definition: Unit.hpp:278
std::shared_ptr< CombatRegistry > _combat_registry
Definition: Unit.hpp:312
bool is_finalized() const
Definition: Unit.hpp:112
virtual void on_movement_end()=0
GridCoords const & grid_coords() const
Definition: Unit.hpp:189
virtual void on_status_effect_end(std::shared_ptr< status_change_entry > sce)=0
unit_posture_type _posture
Definition: Unit.hpp:303
MapCoords _changed_dest_pos
Definition: Unit.hpp:294
bool schedule_walk()
Definition: Unit.cpp:103
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
std::map< int16_t, std::shared_ptr< status_change_entry > > _status_effects
Definition: Unit.hpp:306
void set_combat(std::shared_ptr< Combat > combat)
Definition: Unit.hpp:247
void update(uint64_t tick)
Extremely time-sensitive functions.
Definition: Unit.cpp:634
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
int16_t _walk_path_index
Definition: Unit.hpp:296
std::shared_ptr< AStar::CoordinateList > path_to(std::shared_ptr< Unit > e)
Definition: Unit.cpp:93
void set_posture(unit_posture_type posture)
Definition: Unit.hpp:150
virtual bool walk_to_coordinates(int16_t x, int16_t y)
Definition: Unit.cpp:269
void set_direction(directions dir)
Definition: Unit.hpp:156
std::shared_ptr< Unit > get_nearby_unit(uint32_t guid)
Definition: Unit.cpp:308
bool stop_walking(bool cancel=false, bool notify=false)
Definition: Unit.cpp:247
void clear_lockon_after_walk_completed()
Definition: Unit.hpp:273
std::shared_ptr< Horizon::Zone::Traits::Status > status()
Definition: Unit.hpp:158
bool status_effect_end(int type)
Definition: Unit.cpp:441
struct Horizon::Zone::Unit::s_lockon_after_walk_completed _lockon_after_walk_completed
virtual void on_movement_step()=0
uint64_t _uuid
Definition: Unit.hpp:286
GridCoords _grid_coords
Definition: Unit.hpp:292
MapCoords const & map_coords() const
Grid applications.
Definition: Unit.hpp:186
void notify_nearby_players_of_skill_use(grid_unit_skill_use_notification_type notification_type, s_unit_skill_use_notifier_config config)
Definition: Unit.cpp:350
void set_name(const std::string &name)
Definition: Unit.hpp:153
MapCoords const & dest_coords() const
Movement.
Definition: Unit.hpp:118
unit_uuid s_uuid() const
Definition: Unit.hpp:141
void notify_nearby_players_of_basic_attack(s_grid_unit_basic_attack_config config)
Definition: Unit.cpp:358
MapCoords _map_coords
Definition: Unit.hpp:291
int distance_from(std::shared_ptr< Unit > e)
Definition: Unit.hpp:228
void notify_nearby_players_of_item_drop(s_grid_notify_item_drop_entry entry)
Definition: Unit.cpp:366
bool is_attacking()
Definition: Unit.hpp:235
std::map< int16_t, std::shared_ptr< status_change_entry > > & get_status_effects()
Definition: Unit.hpp:205
std::vector< MapCoords > CoordinateList
We use a vector because the AStar algorithm is only searching on small datasets. Other data structure...
Definition: AStar.hpp:77
Definition: Element.hpp:7
bool continuous
Definition: Unit.hpp:283
uint64_t target_guid
Definition: Unit.hpp:282
Definition: GridNotifiers.hpp:243
Definition: GridNotifiers.hpp:434
Definition: GridNotifiers.hpp:238
Definition: GridNotifiers.hpp:393
Definition: GridNotifiers.hpp:364
uint32_t guid
Definition: Unit.hpp:82
uint8_t uid3
Definition: Unit.hpp:84
uint16_t uid2
Definition: Unit.hpp:83
uint8_t type
Definition: Unit.hpp:81