From cf7f0f4321b4a8d84feb710d59c2e4708e3d9ae7 Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Sun, 24 Mar 2024 12:04:26 -0500 Subject: [PATCH] [Skill Caps] Further improvements (#4205) --- common/CMakeLists.txt | 20 +++++----- common/shareddb.cpp | 21 ----------- common/shareddb.h | 2 - .../skill_caps.cpp | 37 +++++++++++-------- common/skill_caps.h | 26 +++++++++++++ common/skills.cpp | 2 +- common/skills.h | 1 - world/client.cpp | 3 +- world/main.cpp | 5 ++- world/zoneserver.cpp | 7 +++- zone/CMakeLists.txt | 1 - zone/bot.cpp | 5 ++- zone/client.cpp | 9 +++-- zone/main.cpp | 4 ++ zone/merc.cpp | 9 +++-- zone/npc.cpp | 5 ++- zone/worldserver.cpp | 3 +- zone/zone.cpp | 2 - zone/zone.h | 9 ----- 19 files changed, 94 insertions(+), 77 deletions(-) rename zone/zone_skill_caps.cpp => common/skill_caps.cpp (65%) create mode 100644 common/skill_caps.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a7ff137283..e297d6031f 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -83,6 +83,7 @@ SET(common_sources shared_tasks.cpp shareddb.cpp skills.cpp + skill_caps.cpp spdat.cpp strings.cpp struct_strategy.cpp @@ -492,7 +493,7 @@ SET(repositories repositories/zone_repository.h repositories/zone_points_repository.h - ) +) SET(common_headers additive_lagged_fibonacci_engine.h @@ -592,7 +593,7 @@ SET(common_headers ptimer.h queue.h races.h - raid.h + raid.h random.h rdtsc.h rulesys.h @@ -606,6 +607,7 @@ SET(common_headers shared_tasks.h shareddb.h skills.h + skill_caps.h spdat.h strings.h struct_strategy.h @@ -681,13 +683,13 @@ SOURCE_GROUP(Event FILES event/event_loop.h event/timer.h event/task.h - ) +) SOURCE_GROUP(Json FILES json/json.h json/jsoncpp.cpp json/json-forwards.h - ) +) SOURCE_GROUP(Net FILES net/console_server.cpp @@ -724,7 +726,7 @@ SOURCE_GROUP(Net FILES net/websocket_server.h net/websocket_server_connection.cpp net/websocket_server_connection.h - ) +) SOURCE_GROUP(Patches FILES patches/patches.h @@ -768,12 +770,12 @@ SOURCE_GROUP(Patches FILES patches/titanium_limits.cpp patches/uf.cpp patches/uf_limits.cpp - ) +) SOURCE_GROUP(StackWalker FILES StackWalker/StackWalker.h StackWalker/StackWalker.cpp - ) +) SOURCE_GROUP(Util FILES util/memory_stream.h @@ -781,7 +783,7 @@ SOURCE_GROUP(Util FILES util/directory.h util/uuid.cpp util/uuid.h - ) +) INCLUDE_DIRECTORIES(Patches SocketLib StackWalker) @@ -794,6 +796,6 @@ ENDIF (UNIX) IF (WIN32 AND EQEMU_BUILD_PCH) TARGET_PRECOMPILE_HEADERS(common PRIVATE pch/pch.h) -ENDIF() +ENDIF () SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 0bba4b5a16..a368357b23 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -1914,24 +1914,3 @@ void SharedDatabase::SetSharedSpellsCount(uint32 shared_spells_count) { SharedDatabase::m_shared_spells_count = shared_spells_count; } - -uint16 SharedDatabase::GetSkillCap(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level) -{ - const auto& l = SkillCapsRepository::GetWhere( - *this, - fmt::format( - "`class_id` = {} AND `skill_id` = {} AND `level` = {} LIMIT 1", - class_id, - static_cast(skill_id), - level - ) - ); - - if (l.empty()) { - return 0; - } - - const auto& e = l.front(); - - return e.cap; -} diff --git a/common/shareddb.h b/common/shareddb.h index 36aec680f9..c4b322e948 100644 --- a/common/shareddb.h +++ b/common/shareddb.h @@ -160,8 +160,6 @@ class SharedDatabase : public Database { uint32 GetSharedItemsCount() { return m_shared_items_count; } uint32 GetItemsCount(); - uint16 GetSkillCap(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level); - /** * spells */ diff --git a/zone/zone_skill_caps.cpp b/common/skill_caps.cpp similarity index 65% rename from zone/zone_skill_caps.cpp rename to common/skill_caps.cpp index b09de16496..dee19773e3 100644 --- a/zone/zone_skill_caps.cpp +++ b/common/skill_caps.cpp @@ -1,17 +1,24 @@ -#include "zone.h" +#include "skill_caps.h" -SkillCapsRepository::SkillCaps Zone::GetSkillCap(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level) +SkillCaps *SkillCaps::SetContentDatabase(Database *db) +{ + m_content_database = db; + + return this; +} + +SkillCapsRepository::SkillCaps SkillCaps::GetSkillCap(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level) { if (!IsPlayerClass(class_id)) { return SkillCapsRepository::NewEntity(); } - for (const auto& e : m_skill_caps) { + for (const auto &e: m_skill_caps) { if ( e.class_id == class_id && e.level == level && static_cast(e.skill_id) == skill_id - ) { + ) { return e; } } @@ -19,31 +26,31 @@ SkillCapsRepository::SkillCaps Zone::GetSkillCap(uint8 class_id, EQ::skills::Ski return SkillCapsRepository::NewEntity(); } -uint8 Zone::GetTrainLevel(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level) +uint8 SkillCaps::GetTrainLevel(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level) { if ( !IsPlayerClass(class_id) || class_id > Class::PLAYER_CLASS_COUNT || static_cast(skill_id) > (EQ::skills::HIGHEST_SKILL + 1) - ) { + ) { return 0; } const uint8 skill_cap_max_level = ( RuleI(Character, SkillCapMaxLevel) > 0 ? - RuleI(Character, SkillCapMaxLevel) : - RuleI(Character, MaxLevel) + RuleI(Character, SkillCapMaxLevel) : + RuleI(Character, MaxLevel) ); const uint8 max_level = level > skill_cap_max_level ? level : skill_cap_max_level; - for (const auto& e : m_skill_caps) { + for (const auto &e: m_skill_caps) { for (uint8 current_level = 1; current_level <= max_level; current_level++) { if ( e.class_id == class_id && static_cast(e.skill_id) == skill_id && e.level == current_level - ) { + ) { return current_level; } } @@ -52,18 +59,18 @@ uint8 Zone::GetTrainLevel(uint8 class_id, EQ::skills::SkillType skill_id, uint8 return 0; } -void Zone::LoadSkillCaps() +void SkillCaps::LoadSkillCaps() { - const auto& l = SkillCapsRepository::All(content_db); + const auto &l = SkillCapsRepository::All(*m_content_database); m_skill_caps.reserve(l.size()); - for (const auto& e : l) { + for (const auto &e: l) { if ( e.level < 1 || !IsPlayerClass(e.class_id) || static_cast(e.skill_id) >= EQ::skills::SkillCount - ) { + ) { continue; } @@ -77,7 +84,7 @@ void Zone::LoadSkillCaps() ); } -void Zone::ReloadSkillCaps() +void SkillCaps::ReloadSkillCaps() { ClearSkillCaps(); LoadSkillCaps(); diff --git a/common/skill_caps.h b/common/skill_caps.h new file mode 100644 index 0000000000..1e424d4660 --- /dev/null +++ b/common/skill_caps.h @@ -0,0 +1,26 @@ +#ifndef CODE_SKILL_CAPS_H +#define CODE_SKILL_CAPS_H + +#include "repositories/skill_caps_repository.h" +#include "types.h" +#include "classes.h" +#include "skills.h" + +class SkillCaps { +public: + inline void ClearSkillCaps() { m_skill_caps.clear(); } + SkillCapsRepository::SkillCaps GetSkillCap(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level); + uint8 GetTrainLevel(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level); + void LoadSkillCaps(); + void ReloadSkillCaps(); + + SkillCaps *SetContentDatabase(Database *db); +private: + Database *m_content_database{}; + std::vector m_skill_caps = {}; +}; + +extern SkillCaps skill_caps; + + +#endif //CODE_SKILL_CAPS_H diff --git a/common/skills.cpp b/common/skills.cpp index 41dabcd696..223a65cf85 100644 --- a/common/skills.cpp +++ b/common/skills.cpp @@ -18,10 +18,10 @@ */ #include "skills.h" +#include "classes.h" #include - bool EQ::skills::IsTradeskill(SkillType skill) { switch (skill) { diff --git a/common/skills.h b/common/skills.h index f19f9f700f..e9b280d535 100644 --- a/common/skills.h +++ b/common/skills.h @@ -26,7 +26,6 @@ #include #include - namespace EQ { namespace skills { diff --git a/world/client.cpp b/world/client.cpp index 975f3c9e29..08f96db3c9 100644 --- a/world/client.cpp +++ b/world/client.cpp @@ -55,6 +55,7 @@ #include "../common/content/world_content_service.h" #include "../common/repositories/group_id_repository.h" #include "../common/repositories/character_data_repository.h" +#include "../common/skill_caps.h" #include #include @@ -2133,7 +2134,7 @@ void Client::SetClassStartingSkills(PlayerProfile_Struct *pp) i == EQ::skills::SkillAlcoholTolerance || i == EQ::skills::SkillBindWound) continue; - pp->skills[i] = content_db.GetSkillCap(pp->class_, (EQ::skills::SkillType)i, 1); + pp->skills[i] = skill_caps.GetSkillCap(pp->class_, (EQ::skills::SkillType)i, 1).cap; } } diff --git a/world/main.cpp b/world/main.cpp index a2a9081282..1ba5bbfa6a 100644 --- a/world/main.cpp +++ b/world/main.cpp @@ -86,8 +86,9 @@ #include "world_boot.h" #include "../common/path_manager.h" #include "../common/events/player_event_logs.h" +#include "../common/skill_caps.h" - +SkillCaps skill_caps; ZoneStore zone_store; ClientList client_list; GroupLFPList LFPGroupList; @@ -193,6 +194,8 @@ int main(int argc, char **argv) ->SetExpansionContext() ->ReloadContentFlags(); + skill_caps.SetContentDatabase(&content_db)->LoadSkillCaps(); + std::unique_ptr server_connection; server_connection = std::make_unique(); diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index 1450dd7e51..ce8b0fcc17 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -49,6 +49,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "../common/patches/patches.h" #include "../zone/data_bucket.h" #include "../common/repositories/guild_tributes_repository.h" +#include "../common/skill_caps.h" extern ClientList client_list; extern GroupLFPList LFPGroupList; @@ -1411,7 +1412,6 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { case ServerOP_ReloadNPCEmotes: case ServerOP_ReloadObjects: case ServerOP_ReloadPerlExportSettings: - case ServerOP_ReloadSkillCaps: case ServerOP_ReloadStaticZoneData: case ServerOP_ReloadTitles: case ServerOP_ReloadTraps: @@ -1437,6 +1437,11 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { zoneserver_list.SendPacket(pack); break; } + case ServerOP_ReloadSkillCaps: { + zoneserver_list.SendPacket(pack); + skill_caps.ReloadSkillCaps(); + break; + } case ServerOP_ReloadRules: { zoneserver_list.SendPacket(pack); RuleManager::Instance()->LoadRules(&database, "default", true); diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index a8a1fc8c39..662c35e0f5 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -166,7 +166,6 @@ SET(zone_sources zone_event_scheduler.cpp zone_npc_factions.cpp zone_reload.cpp - zone_skill_caps.cpp zoning.cpp ) diff --git a/zone/bot.cpp b/zone/bot.cpp index 334e6b275a..0e0156a5c8 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -27,6 +27,7 @@ #include "../common/repositories/bot_starting_items_repository.h" #include "../common/data_verification.h" #include "../common/repositories/criteria/content_filter_criteria.h" +#include "../common/skill_caps.h" // This constructor is used during the bot create command Bot::Bot(NPCType *npcTypeData, Client* botOwner) : NPC(npcTypeData, nullptr, glm::vec4(), Ground, false), rest_timer(1), ping_timer(1) { @@ -1171,7 +1172,7 @@ uint16 Bot::GetPrimarySkillValue() { } uint16 Bot::MaxSkill(EQ::skills::SkillType skillid, uint16 class_, uint16 level) const { - return(content_db.GetSkillCap(class_, skillid, level)); + return skill_caps.GetSkillCap(class_, skillid, level).cap; } uint32 Bot::GetTotalATK() { @@ -6758,7 +6759,7 @@ void Bot::CalcBotStats(bool showtext) { SetLevel(GetBotOwner()->GetLevel()); for (int sindex = 0; sindex <= EQ::skills::HIGHEST_SKILL; ++sindex) { - skills[sindex] = content_db.GetSkillCap(GetClass(), (EQ::skills::SkillType)sindex, GetLevel()); + skills[sindex] = skill_caps.GetSkillCap(GetClass(), (EQ::skills::SkillType)sindex, GetLevel()).cap; } taunt_timer.Start(1000); diff --git a/zone/client.cpp b/zone/client.cpp index 7dcace56d4..9f7744ef8c 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -73,6 +73,7 @@ extern volatile bool RunLoops; #include "../common/events/player_event_logs.h" #include "dialogue_window.h" #include "../common/zone_store.h" +#include "../common/skill_caps.h" extern QueryServ* QServ; @@ -2771,7 +2772,7 @@ bool Client::CanHaveSkill(EQ::skills::SkillType skill_id) const skill_id = EQ::skills::Skill2HPiercing; } - return zone->GetSkillCap(GetClass(), skill_id, RuleI(Character, MaxLevel)).cap > 0; + return skill_caps.GetSkillCap(GetClass(), skill_id, RuleI(Character, MaxLevel)).cap > 0; } uint16 Client::MaxSkill(EQ::skills::SkillType skill_id, uint8 class_id, uint8 level) const @@ -2784,7 +2785,7 @@ uint16 Client::MaxSkill(EQ::skills::SkillType skill_id, uint8 class_id, uint8 le skill_id = EQ::skills::Skill2HPiercing; } - return(content_db.GetSkillCap(class_id, skill_id, level)); + return skill_caps.GetSkillCap(class_id, skill_id, level).cap; } uint8 Client::SkillTrainLevel(EQ::skills::SkillType skill_id, uint8 class_id) @@ -2797,7 +2798,7 @@ uint8 Client::SkillTrainLevel(EQ::skills::SkillType skill_id, uint8 class_id) skill_id = EQ::skills::Skill2HPiercing; } - return zone->GetTrainLevel(class_id, skill_id, RuleI(Character, MaxLevel)); + return skill_caps.GetTrainLevel(class_id, skill_id, RuleI(Character, MaxLevel)); } uint16 Client::GetMaxSkillAfterSpecializationRules(EQ::skills::SkillType skillid, uint16 maxSkill) @@ -11795,7 +11796,7 @@ void Client::MaxSkills() auto current_skill_value = ( EQ::skills::IsSpecializedSkill(s.first) ? MAX_SPECIALIZED_SKILL : - content_db.GetSkillCap(GetClass(), s.first, GetLevel()) + skill_caps.GetSkillCap(GetClass(), s.first, GetLevel()).cap ); if (GetSkill(s.first) < current_skill_value) { diff --git a/zone/main.cpp b/zone/main.cpp index e8e841f471..7c87427dab 100644 --- a/zone/main.cpp +++ b/zone/main.cpp @@ -86,6 +86,7 @@ extern volatile bool is_zone_loaded; #include "../common/events/player_event_logs.h" #include "../common/path_manager.h" #include "../common/database/database_update.h" +#include "../common/skill_caps.h" #include "zone_event_scheduler.h" #include "zone_cli.h" @@ -108,6 +109,7 @@ WorldContentService content_service; PathManager path; PlayerEventLogs player_event_logs; DatabaseUpdate database_update; +SkillCaps skill_caps; const SPDat_Spell_Struct* spells; int32 SPDAT_RECORDS = -1; @@ -307,6 +309,8 @@ int main(int argc, char **argv) player_event_logs.SetDatabase(&database)->Init(); + skill_caps.SetContentDatabase(&content_db)->LoadSkillCaps(); + const auto c = EQEmuConfig::get(); if (c->auto_database_updates) { if (database_update.SetDatabase(&database)->HasPendingUpdates()) { diff --git a/zone/merc.cpp b/zone/merc.cpp index 93b3002d10..76862645ad 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -8,6 +8,7 @@ #include "zone.h" #include "string_ids.h" +#include "../common/skill_caps.h" extern volatile bool is_zone_loaded; @@ -65,7 +66,7 @@ Merc::Merc(const NPCType* d, float x, float y, float z, float heading) int r; for (r = 0; r <= EQ::skills::HIGHEST_SKILL; r++) { - skills[r] = content_db.GetSkillCap(GetClass(), (EQ::skills::SkillType)r, GetLevel()); + skills[r] = skill_caps.GetSkillCap(GetClass(), (EQ::skills::SkillType)r, GetLevel()).cap; } size = d->size; @@ -770,16 +771,16 @@ void Merc::CalcRestState() { } bool Merc::HasSkill(EQ::skills::SkillType skill_id) const { - return((GetSkill(skill_id) > 0) && CanHaveSkill(skill_id)); + return ((GetSkill(skill_id) > 0) && CanHaveSkill(skill_id)); } bool Merc::CanHaveSkill(EQ::skills::SkillType skill_id) const { - return(content_db.GetSkillCap(GetClass(), skill_id, RuleI(Character, MaxLevel)) > 0); + return skill_caps.GetSkillCap(GetClass(), skill_id, RuleI(Character, MaxLevel)).cap > 0; //if you don't have it by max level, then odds are you never will? } uint16 Merc::MaxSkill(EQ::skills::SkillType skillid, uint16 class_, uint16 level) const { - return(content_db.GetSkillCap(class_, skillid, level)); + return skill_caps.GetSkillCap(class_, skillid, level).cap; } void Merc::FillSpawnStruct(NewSpawn_Struct* ns, Mob* ForWho) { diff --git a/zone/npc.cpp b/zone/npc.cpp index 70516656ff..36ef03e37d 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -48,6 +48,7 @@ #include "npc_scale_manager.h" #include "bot.h" +#include "../common/skill_caps.h" #include #include @@ -363,7 +364,7 @@ NPC::NPC(const NPCType *npc_type_data, Spawn2 *in_respawn, const glm::vec4 &posi //give NPCs skill values... int r; for (r = 0; r <= EQ::skills::HIGHEST_SKILL; r++) { - skills[r] = content_db.GetSkillCap(GetClass(), (EQ::skills::SkillType)r, moblevel); + skills[r] = skill_caps.GetSkillCap(GetClass(), (EQ::skills::SkillType)r, moblevel).cap; } // some overrides -- really we need to be able to set skills for mobs in the DB // There are some known low level SHM/BST pets that do not follow this, which supports @@ -3437,7 +3438,7 @@ void NPC::RecalculateSkills() { int r; for (r = 0; r <= EQ::skills::HIGHEST_SKILL; r++) { - skills[r] = content_db.GetSkillCap(GetClass(), (EQ::skills::SkillType)r, level); + skills[r] = skill_caps.GetSkillCap(GetClass(), (EQ::skills::SkillType)r, level).cap; } // some overrides -- really we need to be able to set skills for mobs in the DB diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index 49f260b062..4adcd80f4f 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -59,6 +59,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "../common/events/player_event_logs.h" #include "../common/repositories/guild_tributes_repository.h" #include "../common/patches/patches.h" +#include "../common/skill_caps.h" extern EntityList entity_list; extern Zone* zone; @@ -2101,7 +2102,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { if (zone && zone->IsLoaded()) { zone->SendReloadMessage("Skill Caps"); - zone->ReloadSkillCaps(); + skill_caps.ReloadSkillCaps(); } break; diff --git a/zone/zone.cpp b/zone/zone.cpp index b031506512..cc2a55a704 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -1185,8 +1185,6 @@ bool Zone::Init(bool is_static) { LoadBaseData(); - LoadSkillCaps(); - //Load merchant data LoadMerchants(); diff --git a/zone/zone.h b/zone/zone.h index 0cbd050e1c..544cf8a1a7 100755 --- a/zone/zone.h +++ b/zone/zone.h @@ -453,12 +453,6 @@ class Zone { void LoadBaseData(); void ReloadBaseData(); - // Skill Caps - inline void ClearSkillCaps() { m_skill_caps.clear(); } - SkillCapsRepository::SkillCaps GetSkillCap(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level); - uint8 GetTrainLevel(uint8 class_id, EQ::skills::SkillType skill_id, uint8 level); - void LoadSkillCaps(); - void ReloadSkillCaps(); private: bool allow_mercs; @@ -523,9 +517,6 @@ class Zone { // Base Data std::vector m_base_data = { }; - - // Skill Caps - std::vector m_skill_caps = { }; }; #endif