diff --git a/src/Items.cc b/src/Items.cc index 9c1d36a7..c719bb55 100644 --- a/src/Items.cc +++ b/src/Items.cc @@ -200,6 +200,16 @@ void player_use_item(shared_ptr c, size_t item_index, shared_ptritem_stack_limits(c->version()); + auto report_item = player->remove_item(item.data.id, 1, stack_limits); + report_item.data1[2] = report_item.get_kill_count(); + player->add_item(report_item, stack_limits); + should_delete_item = false; + } else { // Use item combinations table from ItemPMT bool combo_applied = false; diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 6e97b083..540516f1 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -2374,16 +2374,15 @@ static asio::awaitable on_use_item(shared_ptr c, SubcommandMessage size_t index = p->inventory.find_item(cmd.item_id); string name; { - // Note: We do this weird scoping thing because player_use_item will - // likely delete the item, which will break the reference here. + // Note: We manually downscope item here because player_use_item will likely move or delete the item, which will + // break the reference, so we don't want to accidentally use it again after that. const auto& item = p->inventory.items[index].data; name = s->describe_item(c->version(), item); } player_use_item(c, index, l->rand_crypt); if (l->log.should_log(phosg::LogLevel::L_INFO)) { - l->log.info_f("Player {} used item {}:{:08X} ({})", - c->lobby_client_id, cmd.header.client_id, cmd.item_id, name); + l->log.info_f("Player {} used item {}:{:08X} ({})", c->lobby_client_id, cmd.header.client_id, cmd.item_id, name); c->print_inventory(); }