From 52644695a3742288a56fdc0266af8502c729b97a Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 26 Jun 2024 19:37:32 -0700 Subject: [PATCH] fix grind limit overdraft --- src/Items.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Items.cc b/src/Items.cc index 35a0293e..3b07859c 100644 --- a/src/Items.cc +++ b/src/Items.cc @@ -39,14 +39,12 @@ void player_use_item(shared_ptr c, size_t item_index, shared_ptrinventory.items[player->inventory.find_equipped_item(EquipSlot::WEAPON)]; // Only enforce grind limits on BB, since the server doesn't have direct // control over players' inventories on other versions - if (is_v4) { - auto item_parameter_table = s->item_parameter_table(c->version()); - auto weapon_def = item_parameter_table->get_weapon(weapon.data.data1[1], weapon.data.data1[2]); - if (weapon.data.data1[3] >= weapon_def.max_grind) { - throw runtime_error("weapon already at maximum grind"); - } + auto item_parameter_table = s->item_parameter_table(c->version()); + auto weapon_def = item_parameter_table->get_weapon(weapon.data.data1[1], weapon.data.data1[2]); + if (is_v4 && (weapon.data.data1[3] >= weapon_def.max_grind)) { + throw runtime_error("weapon already at maximum grind"); } - weapon.data.data1[3] += (item.data.data1[2] + 1); + weapon.data.data1[3] = min(weapon.data.data1[3] + item.data.data1[2] + 1, weapon_def.max_grind); } else if ((primary_identifier & 0xFFFF0000) == 0x030B0000) { // Material auto p = c->character();