Skip to content

Commit 3d8b0b2

Browse files
add missed SkillSystem implementations
1 parent 86502b6 commit 3d8b0b2

7 files changed

Lines changed: 404 additions & 447 deletions

File tree

CMakeLists.txt

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ else()
1818
message(STATUS "ASIO found via find_package")
1919
endif()
2020

21+
# Add GLM include directory
2122
set(GLM_DIR "${CMAKE_SOURCE_DIR}/thirdparty/glm")
2223
set(GLM_INCLUDE_DIRS "${GLM_DIR}")
24+
include_directories(${glm_INCLUDE_DIRS})
2325

2426
find_package(nlohmann_json 3.2.0 QUIET)
2527
if(NOT nlohmann_json_FOUND)
@@ -64,8 +66,7 @@ if(NOT UUID_LIBRARY)
6466
message(FATAL_ERROR "libuuid not found - install libuuid-dev or equivalent")
6567
endif()
6668

67-
# Add GLM include directory
68-
include_directories(${glm_INCLUDE_DIRS})
69+
find_library(CRYPT_LIB crypt)
6970

7071
# Config system
7172
set(CONFIG_SOURCES
@@ -102,38 +103,36 @@ set(NETWORK_SOURCES
102103
src/network/WebSocketProtocol.cpp
103104
)
104105

105-
# Core logic system
106-
set(LOGIC_CORE_SOURCES
107-
src/game/LootItem.cpp
108-
src/game/LootTable.cpp
109-
src/game/LootTableManager.cpp
110-
src/game/MobSystem.cpp
111-
src/game/LogicCore.cpp
112-
src/game/LogicWorld.cpp
113-
src/game/LogicEntity.cpp
114-
src/game/GameLogic.cpp
115-
src/game/EntityManager.cpp
116-
src/game/Player.cpp
117-
src/game/PlayerManager.cpp
118-
src/game/QuestManager.cpp
119-
src/game/NPCEntity.cpp
120-
)
121-
122106
# Loot system source files
123107
set(LOOT_SOURCES
124108
src/game/LootItem.cpp
125109
src/game/InventorySystem.cpp
126110
src/game/LootTable.cpp
111+
src/game/LootTableManager.cpp
127112
)
128113

129114
# 3D world system
130115
set(WORLD_SOURCES
131116
src/game/WorldChunk.cpp
132117
src/game/WorldGenerator.cpp
118+
src/game/NPCEntity.cpp
133119
src/game/NPCSystem.cpp
134120
src/game/MobSystem.cpp
135121
src/game/GameEntity.cpp
136122
src/game/CollisionSystem.cpp
123+
src/game/LogicWorld.cpp
124+
)
125+
126+
# Core logic system
127+
set(LOGIC_CORE_SOURCES
128+
src/game/LogicCore.cpp
129+
src/game/LogicEntity.cpp
130+
src/game/GameLogic.cpp
131+
src/game/EntityManager.cpp
132+
src/game/SkillSystem.cpp
133+
src/game/Player.cpp
134+
src/game/PlayerManager.cpp
135+
src/game/QuestManager.cpp
137136
)
138137

139138
# Database system
@@ -145,10 +144,9 @@ set(DATABASE_SOURCES
145144
if(USE_CITUS)
146145
message(STATUS "Building with Citus support")
147146
list(APPEND DATABASE_SOURCES src/database/CitusClient.cpp)
148-
add_definitions(-DUSE_CITUS=1)
149147
else()
150148
message(STATUS "Building without Citus (PostgreSQL only)")
151-
add_definitions(-DUSE_CITUS=0)
149+
# No definition added here – Citus code is completely excluded
152150
endif()
153151

154152
# Include directories
@@ -175,6 +173,11 @@ add_executable(gameserver
175173
${DATABASE_SOURCES}
176174
)
177175

176+
# Add target-specific preprocessor definitions
177+
if(USE_CITUS)
178+
target_compile_definitions(gameserver PRIVATE USE_CITUS=1)
179+
endif()
180+
178181
# Link libraries
179182
target_link_libraries(gameserver PRIVATE
180183
${OPENGL_LIBRARIES}
@@ -189,6 +192,7 @@ target_link_libraries(gameserver PRIVATE
189192
fmt::fmt
190193
spdlog::spdlog
191194
${UUID_LIBRARY}
195+
${CRYPT_LIB}
192196
)
193197

194198
# Compiler flags

include/game/NPCEntity.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ class NPCEntity : public GameEntity {
403403
NPCLootTable loot_table_;
404404
NPCDialogue dialogue_;
405405

406+
glm::vec3 move_target_;
407+
bool has_move_target_ = false;
408+
float move_speed_multiplier_ = 1.0f;
409+
406410
// Targeting
407411
uint64_t target_id_ = 0;
408412
std::vector<uint64_t> hate_list_; // Ordered by hate/damage dealt
@@ -411,8 +415,6 @@ class NPCEntity : public GameEntity {
411415
// AI state tracking
412416
float state_timer_ = 0.0f;
413417
float idle_timer_ = 0.0f;
414-
float patrol_index_ = 0.0f;
415-
bool patrol_direction_ = true; // true = forward, false = backward
416418

417419
// Combat tracking
418420
float attack_cooldown_ = 0.0f;
@@ -421,6 +423,8 @@ class NPCEntity : public GameEntity {
421423
float summon_cooldown_ = 0.0f;
422424

423425
// Patrol and movement
426+
float patrol_index_ = 0.0f;
427+
bool patrol_direction_ = true; // true = forward, false = backward
424428
float patrol_wait_timer_ = 0.0f;
425429
bool waiting_at_patrol_point_ = false;
426430
glm::vec3 spawn_position_;

include/game/SkillSystem.hpp

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string>
1313
#include <set>
1414

15+
#include <glm/glm.hpp>
1516
#include <nlohmann/json.hpp>
1617

1718
#include "logging/Logger.hpp"
@@ -67,7 +68,7 @@ struct SkillRequirement {
6768
std::string required_attribute;
6869
std::string required_item;
6970
std::string required_quest;
70-
71+
7172
nlohmann::json Serialize() const;
7273
void Deserialize(const nlohmann::json& data);
7374
};
@@ -81,7 +82,7 @@ struct SkillEffect {
8182
std::string stat_modified;
8283
float modifier = 0.0f;
8384
std::vector<std::string> additional_effects;
84-
85+
8586
nlohmann::json Serialize() const;
8687
void Deserialize(const nlohmann::json& data);
8788
};
@@ -93,33 +94,33 @@ struct SkillData {
9394
SkillType type = SkillType::ACTIVE;
9495
SkillTarget target = SkillTarget::SINGLE_TARGET;
9596
SkillResource resource = SkillResource::MANA;
96-
97+
9798
float resource_cost = 0.0f;
9899
float cooldown = 0.0f;
99100
float cast_time = 0.0f;
100101
float range = 0.0f;
101102
float area_radius = 0.0f;
102103
float duration = 0.0f;
103-
104+
104105
int max_level = 1;
105106
int required_level = 1;
106107
std::vector<SkillRequirement> requirements;
107108
std::vector<SkillEffect> effects;
108-
109+
109110
std::string icon_path;
110111
std::string animation_name;
111112
std::string sound_effect;
112113
std::string visual_effect;
113-
114+
114115
bool is_toggleable = false;
115116
bool is_channeled = false;
116117
bool is_interruptible = true;
117118
bool can_crit = false;
118119
bool scales_with_level = true;
119-
120+
120121
float level_scaling_factor = 1.0f;
121122
std::string scaling_attribute;
122-
123+
123124
nlohmann::json Serialize() const;
124125
void Deserialize(const nlohmann::json& data);
125126
};
@@ -132,112 +133,106 @@ struct PlayerSkill {
132133
bool unlocked = false;
133134
bool equipped = false;
134135
int slot = -1;
135-
136+
136137
// Cooldown tracking
137138
float current_cooldown = 0.0f;
138139
std::chrono::steady_clock::time_point last_used_time;
139-
140+
140141
// For toggleable/channeled skills
141142
bool is_active = false;
142143
bool is_channeling = false;
143144
float channel_time_remaining = 0.0f;
144-
145+
145146
nlohmann::json Serialize() const;
146147
void Deserialize(const nlohmann::json& data);
147148
};
148149

149150
class SkillSystem {
150151
public:
151152
static SkillSystem& GetInstance();
152-
153+
153154
// Skill data management
154155
bool LoadSkillData(const std::string& file_path);
155156
bool SaveSkillData(const std::string& file_path);
156157
const SkillData* GetSkillData(const std::string& skill_id) const;
157158
std::vector<std::string> GetSkillsByType(SkillType type) const;
158159
std::vector<std::string> GetSkillsByClass(PlayerClass player_class) const;
159-
160+
160161
// Player skill management
161162
bool LearnSkill(uint64_t player_id, const std::string& skill_id, int level = 1);
162163
bool ForgetSkill(uint64_t player_id, const std::string& skill_id);
163164
bool UpgradeSkill(uint64_t player_id, const std::string& skill_id);
164165
bool SetSkillLevel(uint64_t player_id, const std::string& skill_id, int level);
165166
bool EquipSkill(uint64_t player_id, const std::string& skill_id, int slot);
166167
bool UnequipSkill(uint64_t player_id, const std::string& skill_id);
167-
168+
168169
// Skill usage and cooldowns
169170
bool CanUseSkill(uint64_t player_id, const std::string& skill_id) const;
170171
bool UseSkill(uint64_t player_id, const std::string& skill_id, uint64_t target_id = 0, const glm::vec3& target_position = glm::vec3(0.0f));
171172
bool InterruptSkill(uint64_t player_id, const std::string& skill_id);
172173
bool ToggleSkill(uint64_t player_id, const std::string& skill_id);
173-
174+
174175
// Query methods
175176
int GetSkillLevel(uint64_t player_id, const std::string& skill_id) const;
176177
bool HasSkill(uint64_t player_id, const std::string& skill_id) const;
177178
bool IsSkillEquipped(uint64_t player_id, const std::string& skill_id) const;
178179
float GetSkillCooldownRemaining(uint64_t player_id, const std::string& skill_id) const;
179180
std::vector<PlayerSkill> GetPlayerSkills(uint64_t player_id) const;
180181
std::vector<PlayerSkill> GetEquippedSkills(uint64_t player_id) const;
181-
182+
182183
// Skill effects and calculations
183184
float CalculateSkillValue(uint64_t player_id, const std::string& skill_id, const std::string& effect_type) const;
184185
float CalculateResourceCost(uint64_t player_id, const std::string& skill_id) const;
185186
float CalculateCooldown(uint64_t player_id, const std::string& skill_id) const;
186-
187+
187188
// Update methods
188189
void UpdatePlayerCooldowns(uint64_t player_id, float delta_time);
189190
void UpdateActiveSkills(uint64_t player_id, float delta_time);
190191
void UpdateChanneledSkills(uint64_t player_id, float delta_time);
191-
192+
192193
// Skill requirements checking
193194
bool MeetsSkillRequirements(uint64_t player_id, const std::string& skill_id) const;
194195
std::vector<std::string> GetMissingRequirements(uint64_t player_id, const std::string& skill_id) const;
195-
196+
196197
// Skill trees and specializations
197198
bool UnlockSkillTree(uint64_t player_id, const std::string& tree_id);
198199
bool IsSkillTreeUnlocked(uint64_t player_id, const std::string& tree_id) const;
199200
std::vector<std::string> GetUnlockedSkillTrees(uint64_t player_id) const;
200-
201+
201202
// Serialization
202203
bool LoadPlayerSkills(uint64_t player_id);
203204
bool SavePlayerSkills(uint64_t player_id);
204205
nlohmann::json SerializePlayerSkills(uint64_t player_id) const;
205206
bool DeserializePlayerSkills(uint64_t player_id, const nlohmann::json& data);
206-
207+
207208
// Skill effects application (called by UseSkill)
208209
void ApplySkillEffects(uint64_t caster_id, uint64_t target_id, const std::string& skill_id);
209210
void ApplyAreaEffect(uint64_t caster_id, const glm::vec3& center, float radius, const std::string& skill_id);
210211
void ApplyConeEffect(uint64_t caster_id, const glm::vec3& direction, float angle, float range, const std::string& skill_id);
211-
212+
212213
private:
213214
SkillSystem();
214215
~SkillSystem() = default;
215-
216+
216217
struct PlayerSkillData {
217218
std::unordered_map<std::string, PlayerSkill> skills;
218219
std::unordered_map<std::string, bool> unlocked_trees;
219220
std::unordered_map<int, std::string> equipped_slots; // slot -> skill_id
220221
float global_cooldown = 0.0f;
221222
bool is_global_cooldown_active = false;
222-
223+
223224
// Active/channeled skills tracking
224225
std::set<std::string> active_skills;
225226
std::set<std::string> channeling_skills;
226-
227+
227228
nlohmann::json Serialize() const;
228229
void Deserialize(const nlohmann::json& data);
229230
};
230-
231+
231232
mutable std::mutex mutex_;
232233
std::unordered_map<uint64_t, PlayerSkillData> player_skills_;
233234
std::unordered_map<std::string, SkillData> skill_database_;
234-
235-
#ifdef USE_CITUS
236-
CitusClient& db_client_;
237-
#else
238-
std::unique_ptr<PostgreSQLBackend> db_backend_;
239-
#endif
240-
235+
241236
// Helper methods
242237
bool ValidateSkillSlot(int slot) const;
243238
bool HasSkillPoint(uint64_t player_id) const;
@@ -246,26 +241,26 @@ class SkillSystem {
246241
void StartGlobalCooldown(uint64_t player_id, float duration);
247242
void UpdateGlobalCooldown(uint64_t player_id, float delta_time);
248243
bool IsGlobalCooldownActive(uint64_t player_id) const;
249-
244+
250245
// Effect application helpers
251246
void ApplyDamageEffect(uint64_t caster_id, uint64_t target_id, const SkillEffect& effect);
252247
void ApplyHealingEffect(uint64_t caster_id, uint64_t target_id, const SkillEffect& effect);
253248
void ApplyBuffEffect(uint64_t caster_id, uint64_t target_id, const SkillEffect& effect);
254249
void ApplySummonEffect(uint64_t caster_id, const SkillEffect& effect, const glm::vec3& position);
255250
void ApplyTeleportEffect(uint64_t caster_id, const glm::vec3& target_position);
256-
257-
// Database operations
251+
252+
// Database operations – always implemented using DbManager
258253
bool LoadSkillDataFromDatabase();
259254
bool SaveSkillDataToDatabase();
260255
bool LoadPlayerSkillsFromDatabase(uint64_t player_id);
261256
bool SavePlayerSkillsToDatabase(uint64_t player_id);
262-
257+
263258
// Constants
264259
static constexpr int MAX_SKILL_LEVEL = 100;
265260
static constexpr int MAX_EQUIPPED_SKILLS = 12;
266261
static constexpr int SKILL_POINTS_PER_LEVEL = 1;
267262
static constexpr float GLOBAL_COOLDOWN_DURATION = 1.5f;
268-
263+
269264
// Callbacks for skill effects (can be overridden by game-specific logic)
270265
std::function<void(uint64_t, uint64_t, const std::string&)> on_skill_used_;
271266
std::function<void(uint64_t, const std::string&, float)> on_skill_cooldown_start_;

0 commit comments

Comments
 (0)