Horizon Official Technical Documentation
ScriptManager.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_SCRIPTMANAGER
31#define HORIZON_ZONE_SCRIPTMANAGER
32
35
37
48
49namespace Horizon
50{
51namespace Zone
52{
53namespace Units
54{
55 class NPC;
56 class Player;
57 class Monster;
58}
60{
61public:
64
65 void initialize_basic_state(std::shared_ptr<sol::state> state);
66 void initialize_player_state(std::shared_ptr<sol::state> state);
67 void initialize_npc_state(std::shared_ptr<sol::state> state);
68 void initialize_monster_state(std::shared_ptr<sol::state> state);
69
70 std::shared_ptr<PlayerComponent> player() { return _player_component; }
71 std::shared_ptr<NPCComponent> npc() { return _npc_component; }
72 std::shared_ptr<MonsterComponent> monster() { return _monster_component; }
73 std::shared_ptr<MapComponent> map() { return _map_component; }
74 std::shared_ptr<ItemComponent> item() { return _item_component; }
75 std::shared_ptr<UnitComponent> unit() { return _unit_component; }
76 std::shared_ptr<SkillComponent> skill() { return _skill_component; }
77 std::shared_ptr<StatusEffectComponent> status_effect() { return _status_effect_component; }
78 std::shared_ptr<CombatComponent> combat() { return _combat_component; }
79
80 std::shared_ptr<sol::state> lua_state() { return _lua_state; }
81
82 bool is_initialized() override { return _is_initialized.load(); }
83 bool is_finalized() override { return _is_finalized.load(); }
84
85 void initialize(int segment_number = 1) override;
86 void finalize() override;
87 void prepare_lua_state(std::shared_ptr<sol::state> &lua);
88
89 void start();
90 void update(uint64_t diff);
91
93
94private:
95 void load_constants();
96 void load_scripts();
98
99 std::vector<std::string> _script_files;
100 std::shared_ptr<sol::state> _lua_state;
101
102 std::shared_ptr<PlayerComponent> _player_component;
103 std::shared_ptr<NPCComponent> _npc_component;
104 std::shared_ptr<MonsterComponent> _monster_component;
105 std::shared_ptr<MapComponent> _map_component;
106 std::shared_ptr<ItemComponent> _item_component;
107 std::shared_ptr<UnitComponent> _unit_component;
108 std::shared_ptr<SkillComponent> _skill_component;
109 std::shared_ptr<StatusEffectComponent> _status_effect_component;
110 std::shared_ptr<CombatComponent> _combat_component;
111
112 std::thread _thread;
113protected:
114 std::atomic<bool> _is_initialized{false};
115 std::atomic<bool> _is_finalized{false};
116
117 using PrimaryResource = SharedPriorityResourceMedium<s_segment_storage<uint64_t /*NPC GUID*/, std::shared_ptr<Units::NPC>>>;
121public:
123};
124}
125}
126
127#endif /* HORIZON_ZONE_SCRIPTMANAGER */
Definition: ScriptManager.hpp:60
void initialize_monster_state(std::shared_ptr< sol::state > state)
Definition: ScriptManager.cpp:261
void load_constants()
Definition: ScriptManager.cpp:308
~ScriptManager()
Definition: ScriptManager.cpp:64
std::shared_ptr< SkillComponent > _skill_component
Definition: ScriptManager.hpp:108
std::shared_ptr< PlayerComponent > _player_component
Definition: ScriptManager.hpp:102
void start()
Definition: ScriptManager.cpp:108
std::atomic< bool > _is_finalized
Definition: ScriptManager.hpp:115
std::shared_ptr< SkillComponent > skill()
Definition: ScriptManager.hpp:76
void update(uint64_t diff)
Definition: ScriptManager.cpp:117
std::atomic< bool > _is_initialized
Definition: ScriptManager.hpp:114
std::shared_ptr< UnitComponent > unit()
Definition: ScriptManager.hpp:75
std::shared_ptr< CombatComponent > combat()
Definition: ScriptManager.hpp:78
std::thread _thread
Definition: ScriptManager.hpp:112
std::shared_ptr< NPCComponent > npc()
Definition: ScriptManager.hpp:71
bool is_finalized() override
Definition: ScriptManager.hpp:83
std::shared_ptr< PlayerComponent > player()
Definition: ScriptManager.hpp:70
void initialize(int segment_number=1) override
Definition: ScriptManager.cpp:70
std::shared_ptr< CombatComponent > _combat_component
Definition: ScriptManager.hpp:110
TaskScheduler _scheduler
Definition: ScriptManager.hpp:120
std::shared_ptr< ItemComponent > _item_component
Definition: ScriptManager.hpp:106
std::shared_ptr< MonsterComponent > monster()
Definition: ScriptManager.hpp:72
void finalize() override
Definition: ScriptManager.cpp:91
bool is_initialized() override
Definition: ScriptManager.hpp:82
ResourceManager _resource_manager
Definition: ScriptManager.hpp:119
void initialize_basic_state(std::shared_ptr< sol::state > state)
Definition: ScriptManager.cpp:139
ResourceManager & get_resource_manager()
Definition: ScriptManager.hpp:122
void initialize_player_state(std::shared_ptr< sol::state > state)
Definition: ScriptManager.cpp:236
void load_scripts()
Definition: ScriptManager.cpp:276
TaskScheduler & getScheduler()
Definition: ScriptManager.hpp:92
std::shared_ptr< ItemComponent > item()
Definition: ScriptManager.hpp:74
std::shared_ptr< MonsterComponent > _monster_component
Definition: ScriptManager.hpp:104
std::shared_ptr< MapComponent > _map_component
Definition: ScriptManager.hpp:105
std::shared_ptr< MapComponent > map()
Definition: ScriptManager.hpp:73
std::shared_ptr< StatusEffectComponent > status_effect()
Definition: ScriptManager.hpp:77
std::shared_ptr< UnitComponent > _unit_component
Definition: ScriptManager.hpp:107
void initialize_npc_state(std::shared_ptr< sol::state > state)
Definition: ScriptManager.cpp:248
std::shared_ptr< StatusEffectComponent > _status_effect_component
Definition: ScriptManager.hpp:109
std::shared_ptr< sol::state > lua_state()
Definition: ScriptManager.hpp:80
std::shared_ptr< NPCComponent > _npc_component
Definition: ScriptManager.hpp:103
ScriptManager()
Definition: ScriptManager.cpp:48
void prepare_lua_state(std::shared_ptr< sol::state > &lua)
std::vector< std::string > _script_files
Definition: ScriptManager.hpp:99
std::shared_ptr< sol::state > _lua_state
Definition: ScriptManager.hpp:100
Definition: Server.hpp:192
Definition: ReferenceListTest.cpp:114
Definition: Server.hpp:113
The TaskScheduler class provides the ability to schedule std::function's in the near future....
Definition: TaskScheduler.hpp:58
Definition: Element.hpp:7
Definition: Server.hpp:93