Horizon Official Technical Documentation
Horizon::Zone::SkillExecution Class Reference

#include <SkillExecution.hpp>

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

Public Member Functions

 SkillExecution (std::shared_ptr< Unit > initial_source, int16_t skill_id, int16_t skill_lv)
 
 ~SkillExecution ()
 
void execute (int initial_target_guid)
 
void execute (MapCoords map_coords)
 
void execute (int16_t x, int16_t y)
 
void execute (MapCoords map_coords, std::string message)
 
void execute (int16_t x, int16_t y, std::string message)
 
sol::table get_skill_cast_data ()
 

Private Member Functions

void start_execution (enum skill_target_type target_type)
 
std::shared_ptr< Mapmap ()
 
void set_map (std::shared_ptr< Map > map)
 
std::shared_ptr< GameLogicProcessmap_container ()
 
std::shared_ptr< ScriptManagerlua_manager ()
 
std::shared_ptr< sol::state > lua_state ()
 

Private Attributes

std::weak_ptr< Map_map
 
std::weak_ptr< GameLogicProcess_map_container_thread
 
std::weak_ptr< ScriptManager_lua_mgr
 
std::weak_ptr< sol::state > _lua_state
 
std::shared_ptr< Unit_initial_source {nullptr}
 
std::shared_ptr< Unit_initial_target {nullptr}
 
int16_t _skill_id
 
int16_t _skill_lv
 
MapCoords _map_coords
 
std::string _message
 
sol::table _scd
 

Constructor & Destructor Documentation

◆ SkillExecution()

SkillExecution::SkillExecution ( std::shared_ptr< Unit initial_source,
int16_t  skill_id,
int16_t  skill_lv 
)
16: _initial_source(initial_source), _skill_id(skill_id), _skill_lv(skill_lv), _map_coords(MapCoords(0, 0)), _message("")
17{
18 set_map(initial_source->map());
19}
Coordinates< MAX_CELLS_PER_MAP > MapCoords
Definition: GridDefinitions.hpp:83
int16_t _skill_lv
Definition: SkillExecution.hpp:44
std::shared_ptr< Unit > _initial_source
Definition: SkillExecution.hpp:41
std::string _message
Definition: SkillExecution.hpp:46
int16_t _skill_id
Definition: SkillExecution.hpp:43
MapCoords _map_coords
Definition: SkillExecution.hpp:45
void set_map(std::shared_ptr< Map > map)
Definition: SkillExecution.cpp:104

References set_map().

+ Here is the call graph for this function:

◆ ~SkillExecution()

SkillExecution::~SkillExecution ( )
22{
23}

Member Function Documentation

◆ execute() [1/5]

void SkillExecution::execute ( int  initial_target_guid)
77{
78 _initial_target = _initial_source->get_nearby_unit(initial_target_guid);
80}
@ SKTT_SINGLE_TARGETED
Definition: SkillDefinitions.hpp:344
std::shared_ptr< Unit > _initial_target
Definition: SkillExecution.hpp:42
void start_execution(enum skill_target_type target_type)
Definition: SkillExecution.cpp:25

References _initial_source, _initial_target, SKTT_SINGLE_TARGETED, and start_execution().

Referenced by execute(), and Horizon::Zone::SkillComponent::sync_data_types().

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

◆ execute() [2/5]

void SkillExecution::execute ( int16_t  x,
int16_t  y 
)
83{
84 execute(MapCoords(x, y));
85}
void execute(int initial_target_guid)
Definition: SkillExecution.cpp:76

References execute().

+ Here is the call graph for this function:

◆ execute() [3/5]

void SkillExecution::execute ( int16_t  x,
int16_t  y,
std::string  message 
)
93{
94 execute(MapCoords(x, y), message);
95}

References execute().

+ Here is the call graph for this function:

◆ execute() [4/5]

void SkillExecution::execute ( MapCoords  map_coords)
87{
88 _map_coords = map_coords;
90}
@ SKTT_GROUND_TARGETED
Definition: SkillDefinitions.hpp:345

References _map_coords, SKTT_GROUND_TARGETED, and start_execution().

+ Here is the call graph for this function:

◆ execute() [5/5]

void SkillExecution::execute ( MapCoords  map_coords,
std::string  message 
)
97{
98 _map_coords = map_coords;
99 _message = message;
101}

References _map_coords, _message, SKTT_GROUND_TARGETED, and start_execution().

+ Here is the call graph for this function:

◆ get_skill_cast_data()

sol::table Horizon::Zone::SkillExecution::get_skill_cast_data ( )
inline
28{ return _scd; }
sol::table _scd
Definition: SkillExecution.hpp:47

References _scd.

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

+ Here is the caller graph for this function:

◆ lua_manager()

std::shared_ptr< ScriptManager > Horizon::Zone::SkillExecution::lua_manager ( )
inlineprivate
34{ return _lua_mgr.lock(); }
std::weak_ptr< ScriptManager > _lua_mgr
Definition: SkillExecution.hpp:39

References _lua_mgr.

◆ lua_state()

std::shared_ptr< sol::state > Horizon::Zone::SkillExecution::lua_state ( )
inlineprivate
35{ return _lua_state.lock(); }
std::weak_ptr< sol::state > _lua_state
Definition: SkillExecution.hpp:40

References _lua_state.

Referenced by set_map(), and start_execution().

+ Here is the caller graph for this function:

◆ map()

std::shared_ptr< Map > Horizon::Zone::SkillExecution::map ( )
inlineprivate
31{ return _map.expired() ? nullptr : _map.lock(); }
std::weak_ptr< Map > _map
Definition: SkillExecution.hpp:37

References _map.

Referenced by set_map().

+ Here is the caller graph for this function:

◆ map_container()

std::shared_ptr< GameLogicProcess > Horizon::Zone::SkillExecution::map_container ( )
inlineprivate
33{ return _map_container_thread.lock(); }
std::weak_ptr< GameLogicProcess > _map_container_thread
Definition: SkillExecution.hpp:38

References _map_container_thread.

◆ set_map()

void SkillExecution::set_map ( std::shared_ptr< Map map)
private
105{
106 _map = map;
107 _map_container_thread = map->container();
110}
#define sZone
Definition: Zone.hpp:247
Definition: ScriptManager.hpp:60
std::shared_ptr< Map > map()
Definition: SkillExecution.hpp:31
std::shared_ptr< sol::state > lua_state()
Definition: SkillExecution.hpp:35
@ RUNTIME_SCRIPTVM
Definition: System.hpp:87

References _lua_mgr, _lua_state, _map, _map_container_thread, lua_state(), map(), Horizon::System::RUNTIME_SCRIPTVM, and sZone.

Referenced by SkillExecution().

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

◆ start_execution()

void SkillExecution::start_execution ( enum skill_target_type  target_type)
private
26{
27 std::shared_ptr<const struct skill_config_data> skd = SkillDB->get_skill_by_id(_skill_id);
28
29 if (target_type == SKTT_SINGLE_TARGETED && _initial_target == nullptr)
30 return;
31
32 if (!skd) {
33 HLog(debug) << "SkillExecution::start_execution: Could not find skill with id '" << _skill_id << "' in the database. Ignoring skill usage...";
34 return;
35 }
36
37 try {
38 sol::load_result fx = lua_state()->load_file(sZone->config().get_script_root_path().string() + "skills/" + skd->name + ".lua");
39 sol::protected_function_result result = fx();
40 if (!result.valid()) {
41 sol::error err = result;
42 HLog(error) << "SkillExecution::start_execution: " << err.what();
43 return;
44 }
45
46 sol::table skill_functions = result;
47 sol::protected_function initiate_skill_use = skill_functions["initiate_skill_use"];
48
49 _scd = lua_state()->create_table();
50 _scd["skill_execution"] = shared_from_this(); // ptr to self.
51 _scd["initial_source"] = _initial_source;
52 _scd["skill_id"] = _skill_id;
53 _scd["skill_lv"] = _skill_lv;
54 _scd["target_type"] = target_type;
55
56 if (target_type == SKTT_SINGLE_TARGETED) {
57 _scd["initial_target"] = _initial_target;
58 } else {
59 _scd["map_coords"] = _map_coords;
60 if (_message.empty() == false)
61 _scd["message"] = _message;
62 }
63
64 result = initiate_skill_use(_scd, skd);
65 if (!result.valid()) {
66 sol::error err = result;
67 HLog(error) << "SkillExecution::start_execution: Error on initiate_skill_use function: " << err.what();
68 return;
69 }
70 } catch (sol::error &e) {
71 HLog(error) << "SkillExecution::start_execution: " << e.what();
72 return;
73 }
74}
#define HLog(type)
Definition: Logger.hpp:122
#define SkillDB
Definition: SkillDB.hpp:145

References _initial_source, _initial_target, _map_coords, _message, _scd, _skill_id, _skill_lv, HLog, lua_state(), SkillDB, SKTT_SINGLE_TARGETED, and sZone.

Referenced by execute().

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

Member Data Documentation

◆ _initial_source

std::shared_ptr<Unit> Horizon::Zone::SkillExecution::_initial_source {nullptr}
private

Referenced by execute(), and start_execution().

◆ _initial_target

std::shared_ptr<Unit> Horizon::Zone::SkillExecution::_initial_target {nullptr}
private

Referenced by execute(), and start_execution().

◆ _lua_mgr

std::weak_ptr<ScriptManager> Horizon::Zone::SkillExecution::_lua_mgr
private

Referenced by lua_manager(), and set_map().

◆ _lua_state

std::weak_ptr<sol::state> Horizon::Zone::SkillExecution::_lua_state
private

Referenced by lua_state(), and set_map().

◆ _map

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

Referenced by map(), and set_map().

◆ _map_container_thread

std::weak_ptr<GameLogicProcess> Horizon::Zone::SkillExecution::_map_container_thread
private

Referenced by map_container(), and set_map().

◆ _map_coords

MapCoords Horizon::Zone::SkillExecution::_map_coords
private

Referenced by execute(), and start_execution().

◆ _message

std::string Horizon::Zone::SkillExecution::_message
private

Referenced by execute(), and start_execution().

◆ _scd

sol::table Horizon::Zone::SkillExecution::_scd
private

◆ _skill_id

int16_t Horizon::Zone::SkillExecution::_skill_id
private

Referenced by start_execution().

◆ _skill_lv

int16_t Horizon::Zone::SkillExecution::_skill_lv
private

Referenced by start_execution().


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