From 328980628a5b8242ea5a2f6be92fc96a3c147f49 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 18 Nov 2025 17:28:48 -0800 Subject: [PATCH] fix $edit level --- src/ChatCommands.cc | 4 ++-- src/SaveFileFormats.cc | 6 ++++-- src/SaveFileFormats.hh | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index 69fb109f..f1e51804 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -922,7 +922,7 @@ ChatCommandDefinition cc_edit( p->disp.stats.experience = stoul(tokens.at(1)); } else if (tokens.at(0) == "level" && (cheats_allowed || !s->cheat_flags.edit_stats)) { p->disp.stats.level = stoul(tokens.at(1)) - 1; - p->recompute_stats(s->level_table(a.c->version())); + p->recompute_stats(s->level_table(a.c->version()), true); } else if (((tokens.at(0) == "material") || (tokens.at(0) == "mat")) && !is_v1_or_v2(a.c->version()) && (cheats_allowed || !s->cheat_flags.reset_materials)) { if (tokens.at(1) == "reset") { const auto& which = tokens.at(2); @@ -960,7 +960,7 @@ ChatCommandDefinition cc_edit( } else { throw precondition_failed("$C6Invalid subcommand"); } - p->recompute_stats(s->level_table(a.c->version())); + p->recompute_stats(s->level_table(a.c->version()), false); } else if (tokens.at(0) == "namecolor") { p->disp.visual.name_color = stoul(tokens.at(1), nullptr, 16); } else if (tokens.at(0) == "language" || tokens.at(0) == "lang") { diff --git a/src/SaveFileFormats.cc b/src/SaveFileFormats.cc index c4e64a71..67553ea0 100644 --- a/src/SaveFileFormats.cc +++ b/src/SaveFileFormats.cc @@ -1415,12 +1415,14 @@ void PSOBBCharacterFile::import_tethealla_material_usage(std::shared_ptrset_material_usage(MaterialType::LUCK, luck); } -void PSOBBCharacterFile::recompute_stats(std::shared_ptr level_table) { +void PSOBBCharacterFile::recompute_stats(std::shared_ptr level_table, bool reset_exp) { uint32_t level = this->disp.stats.level; uint32_t exp = this->disp.stats.experience; level_table->reset_to_base(this->disp.stats, this->disp.visual.char_class); level_table->advance_to_level(this->disp.stats, level, this->disp.visual.char_class); - this->disp.stats.experience = exp; + if (!reset_exp) { + this->disp.stats.experience = exp; + } this->disp.stats.char_stats.atp += (this->get_material_usage(MaterialType::POWER) * 2); this->disp.stats.char_stats.mst += (this->get_material_usage(MaterialType::MIND) * 2); diff --git a/src/SaveFileFormats.hh b/src/SaveFileFormats.hh index 9c127f2d..ca5482b6 100644 --- a/src/SaveFileFormats.hh +++ b/src/SaveFileFormats.hh @@ -920,7 +920,7 @@ struct PSOBBCharacterFile { void set_material_usage(MaterialType which, uint8_t usage); void clear_all_material_usage(); void import_tethealla_material_usage(std::shared_ptr level_table); - void recompute_stats(std::shared_ptr level_table); + void recompute_stats(std::shared_ptr level_table, bool reset_exp = false); } __packed_ws__(PSOBBCharacterFile, 0x2EA4); struct PSOCHARFile {