Skip to content

Commit

Permalink
[Skill Caps] Further improvements (#4205)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius authored Mar 24, 2024
1 parent 823a595 commit cf7f0f4
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 77 deletions.
20 changes: 11 additions & 9 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ SET(common_sources
shared_tasks.cpp
shareddb.cpp
skills.cpp
skill_caps.cpp
spdat.cpp
strings.cpp
struct_strategy.cpp
Expand Down Expand Up @@ -492,7 +493,7 @@ SET(repositories
repositories/zone_repository.h
repositories/zone_points_repository.h

)
)

SET(common_headers
additive_lagged_fibonacci_engine.h
Expand Down Expand Up @@ -592,7 +593,7 @@ SET(common_headers
ptimer.h
queue.h
races.h
raid.h
raid.h
random.h
rdtsc.h
rulesys.h
Expand All @@ -606,6 +607,7 @@ SET(common_headers
shared_tasks.h
shareddb.h
skills.h
skill_caps.h
spdat.h
strings.h
struct_strategy.h
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -768,20 +770,20 @@ 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
util/directory.cpp
util/directory.h
util/uuid.cpp
util/uuid.h
)
)

INCLUDE_DIRECTORIES(Patches SocketLib StackWalker)

Expand All @@ -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)
21 changes: 0 additions & 21 deletions common/shareddb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16>(skill_id),
level
)
);

if (l.empty()) {
return 0;
}

const auto& e = l.front();

return e.cap;
}
2 changes: 0 additions & 2 deletions common/shareddb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
37 changes: 22 additions & 15 deletions zone/zone_skill_caps.cpp → common/skill_caps.cpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
#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<EQ::skills::SkillType>(e.skill_id) == skill_id
) {
) {
return e;
}
}

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<uint32>(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<EQ::skills::SkillType>(e.skill_id) == skill_id &&
e.level == current_level
) {
) {
return current_level;
}
}
Expand All @@ -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<EQ::skills::SkillType>(e.skill_id) >= EQ::skills::SkillCount
) {
) {
continue;
}

Expand All @@ -77,7 +84,7 @@ void Zone::LoadSkillCaps()
);
}

void Zone::ReloadSkillCaps()
void SkillCaps::ReloadSkillCaps()
{
ClearSkillCaps();
LoadSkillCaps();
Expand Down
26 changes: 26 additions & 0 deletions common/skill_caps.h
Original file line number Diff line number Diff line change
@@ -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<SkillCapsRepository::SkillCaps> m_skill_caps = {};
};

extern SkillCaps skill_caps;


#endif //CODE_SKILL_CAPS_H
2 changes: 1 addition & 1 deletion common/skills.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/

#include "skills.h"
#include "classes.h"

#include <string.h>


bool EQ::skills::IsTradeskill(SkillType skill)
{
switch (skill) {
Expand Down
1 change: 0 additions & 1 deletion common/skills.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <map>
#include <vector>


namespace EQ
{
namespace skills {
Expand Down
3 changes: 2 additions & 1 deletion world/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
#include <iomanip>
Expand Down Expand Up @@ -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;
}
}

Expand Down
5 changes: 4 additions & 1 deletion world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,6 +194,8 @@ int main(int argc, char **argv)
->SetExpansionContext()
->ReloadContentFlags();

skill_caps.SetContentDatabase(&content_db)->LoadSkillCaps();

std::unique_ptr<EQ::Net::ServertalkServer> server_connection;
server_connection = std::make_unique<EQ::Net::ServertalkServer>();

Expand Down
7 changes: 6 additions & 1 deletion world/zoneserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion zone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ SET(zone_sources
zone_event_scheduler.cpp
zone_npc_factions.cpp
zone_reload.cpp
zone_skill_caps.cpp
zoning.cpp
)

Expand Down
5 changes: 3 additions & 2 deletions zone/bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit cf7f0f4

Please sign in to comment.