Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Skill Caps] Remove from shared memory and simplify #4069

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 42 additions & 45 deletions client_files/export/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "../../common/content/world_content_service.h"
#include "../../common/zone_store.h"
#include "../../common/path_manager.h"
#include "../../common/repositories/skill_caps_repository.h"
#include "../../common/file.h"

EQEmuLogSys LogSys;
WorldContentService content_service;
Expand Down Expand Up @@ -164,81 +166,76 @@ void ExportSpells(SharedDatabase *db)
fclose(f);
}

bool SkillUsable(SharedDatabase *db, int skill_id, int class_id)
bool SkillUsable(SharedDatabase* db, int skill_id, int class_id)
{

bool res = false;

std::string query = StringFormat(
"SELECT max(cap) FROM skill_caps WHERE class=%d AND skillID=%d",
class_id, skill_id
const auto& l = SkillCapsRepository::GetWhere(
*db,
fmt::format(
"`class_id` = {} AND `skill_id` = {} ORDER BY `cap` DESC LIMIT 1",
class_id,
skill_id
)
);
auto results = db->QueryDatabase(query);
if (!results.Success()) {
return false;
}

if (results.RowCount() == 0) {
return false;
}

auto row = results.begin();
if (row[0] && Strings::ToInt(row[0]) > 0) {
return true;
}

return false;
return !l.empty();
}

int GetSkill(SharedDatabase *db, int skill_id, int class_id, int level)
uint32 GetSkill(SharedDatabase* db, int skill_id, int class_id, int level)
{

std::string query = StringFormat(
"SELECT cap FROM skill_caps WHERE class=%d AND skillID=%d AND level=%d",
class_id, skill_id, level
const auto& l = SkillCapsRepository::GetWhere(
*db,
fmt::format(
"`class_id` = {} AND `skill_id` = {} AND `level` = {}",
class_id,
skill_id,
level
)
);
auto results = db->QueryDatabase(query);
if (!results.Success()) {
return 0;
}

if (results.RowCount() == 0) {
if (l.empty()) {
return 0;
}

auto row = results.begin();
return Strings::ToInt(row[0]);
auto e = l.front();

return e.cap;
}

void ExportSkillCaps(SharedDatabase *db)
void ExportSkillCaps(SharedDatabase* db)
{
LogInfo("Exporting Skill Caps");

std::string file = fmt::format("{}/export/SkillCaps.txt", path.GetServerPath());
FILE *f = fopen(file.c_str(), "w");
if (!f) {
std::ofstream file(fmt::format("{}/export/SkillCaps.txt", path.GetServerPath()));
if (!file || !file.is_open()) {
LogError("Unable to open export/SkillCaps.txt to write, skipping.");
return;
}

for (int cl = 1; cl <= 16; ++cl) {
for (int skill = 0; skill <= 77; ++skill) {
if (SkillUsable(db, skill, cl)) {
int previous_cap = 0;
for (int level = 1; level <= 100; ++level) {
int cap = GetSkill(db, skill, cl, level);
const uint8 skill_cap_max_level = (
RuleI(Character, SkillCapMaxLevel) > 0 ?
RuleI(Character, SkillCapMaxLevel) :
RuleI(Character, MaxLevel)
);

for (uint8 class_id = Class::Warrior; class_id <= Class::Berserker; class_id++) {
for (uint8 skill_id = EQ::skills::Skill1HBlunt; skill_id <= EQ::skills::Skill2HPiercing; skill_id++) {
if (SkillUsable(db, skill_id, class_id)) {
uint32 previous_cap = 0;
for (uint8 level = 1; level <= skill_cap_max_level; level++) {
uint32 cap = GetSkill(db, skill_id, class_id, level);
if (cap < previous_cap) {
cap = previous_cap;
}

fprintf(f, "%d^%d^%d^%d^0\n", cl, skill, level, cap);
file << fmt::format("{}^{}^{}^{}^0", class_id, skill_id, level, cap) << std::endl;

previous_cap = cap;
}
}
}
}

fclose(f);
file.close();
}

void ExportBaseData(SharedDatabase *db)
Expand Down
50 changes: 0 additions & 50 deletions common/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,56 +1150,6 @@ uint8 Database::GetRaceSkill(uint8 skillid, uint8 in_race)
return Strings::ToUnsignedInt(row[0]);
}

uint8 Database::GetSkillCap(uint8 skillid, uint8 in_race, uint8 in_class, uint16 in_level)
{
uint8 skill_level = 0, skill_formula = 0;
uint16 base_cap = 0, skill_cap = 0, skill_cap2 = 0, skill_cap3 = 0;


//Fetch the data from DB.
std::string query = StringFormat("SELECT level, formula, pre50cap, post50cap, post60cap from skillcaps where skill = %i && class = %i", skillid, in_class);
auto results = QueryDatabase(query);

if (results.Success() && results.RowsAffected() != 0)
{
auto row = results.begin();
skill_level = Strings::ToUnsignedInt(row[0]);
skill_formula = Strings::ToUnsignedInt(row[1]);
skill_cap = Strings::ToUnsignedInt(row[2]);
if (Strings::ToUnsignedInt(row[3]) > skill_cap)
skill_cap2 = (Strings::ToUnsignedInt(row[3])-skill_cap)/10; //Split the post-50 skill cap into difference between pre-50 cap and post-50 cap / 10 to determine amount of points per level.
skill_cap3 = Strings::ToUnsignedInt(row[4]);
}

int race_skill = GetRaceSkill(skillid,in_race);

if (race_skill > 0 && (race_skill > skill_cap || skill_cap == 0 || in_level < skill_level))
return race_skill;

if (skill_cap == 0) //Can't train this skill at all.
return 255; //Untrainable

if (in_level < skill_level)
return 254; //Untrained

//Determine pre-51 level-based cap
if (skill_formula > 0)
base_cap = in_level*skill_formula+skill_formula;
if (base_cap > skill_cap || skill_formula == 0)
base_cap = skill_cap;

//If post 50, add post 50 cap to base cap.
if (in_level > 50 && skill_cap2 > 0)
base_cap += skill_cap2*(in_level-50);

//No cap should ever go above its post50cap
if (skill_cap3 > 0 && base_cap > skill_cap3)
base_cap = skill_cap3;

//Base cap is now the max value at the person's level, return it!
return base_cap;
}

uint32 Database::GetCharacterInfo(std::string character_name, uint32 *account_id, uint32 *zone_id, uint32 *instance_id)
{
auto query = fmt::format(
Expand Down
1 change: 0 additions & 1 deletion common/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ class Database : public DBcore {
uint8 GetMinStatus(uint32 zone_id, uint32 instance_version);
uint8 GetRaceSkill(uint8 skillid, uint8 in_race);
uint8 GetServerType();
uint8 GetSkillCap(uint8 skillid, uint8 in_race, uint8 in_class, uint16 in_level);

void AddReport(std::string who, std::string against, std::string lines);
struct TimeOfDay_Struct LoadTime(time_t &realtime);
Expand Down
16 changes: 16 additions & 0 deletions common/database/database_update_manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5451,6 +5451,22 @@ DROP PRIMARY KEY,
ADD PRIMARY KEY (`group_id`, `character_id`, `bot_id`, `merc_id`) USING BTREE;
ALTER TABLE `group_id`
MODIFY COLUMN `character_id` int(11) UNSIGNED NOT NULL DEFAULT 0 AFTER `name`;
)"
},
ManifestEntry{
.version = 9268,
.description = "2024_03_23_skill_caps.sql",
.check = "SHOW COLUMNS FROM `skill_caps` LIKE 'skill_id'",
.condition = "empty",
.match = "",
.sql = R"(
ALTER TABLE `skill_caps`
CHANGE COLUMN `skillID` `skill_id` tinyint(3) UNSIGNED NOT NULL DEFAULT 0 FIRST,
CHANGE COLUMN `class` `class_id` tinyint(3) UNSIGNED NOT NULL DEFAULT 0 AFTER `skill_id`,
ADD COLUMN `id` int(3) UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`id`) USING BTREE,
ADD INDEX `level_skill_cap`(`skill_id`, `class_id`, `level`, `cap`);
)"
}
// -- template; copy/paste this when you need to create a new entry
Expand Down
Loading