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
149150class SkillSystem {
150151public:
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+
212213private:
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