Skip to content

Commit

Permalink
Fixed bug where 'w'ield can pick up NPC items without triggering warn…
Browse files Browse the repository at this point in the history
…ing (CleverRaven#66807)

* fixed issue where wield menu can steal without prompting warning

* Update src/activity_actor.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/game.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fixed naming for clang-tidy

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
fyhannes and github-actions[bot] authored Jul 12, 2023
1 parent ffe5a45 commit 6ea6d11
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5534,13 +5534,21 @@ static bool check_stealing( Character &who, item &it )
Pickup::query_thief();
}
if( who.get_value( "THIEF_MODE" ) == "THIEF_HONEST" ) {
if( who.get_value( "THIEF_MODE_KEEP" ) != "YES" ) {
who.set_value( "THIEF_MODE", "THIEF_ASK" );
}
return false;
}
}

return true;
}

bool avatar_action::check_stealing( Character &who, item &weapon )
{
return ::check_stealing( who, weapon );
}

void wield_activity_actor::do_turn( player_activity &, Character &who )
{
if( who.moves > 0 ) {
Expand Down
3 changes: 3 additions & 0 deletions src/avatar_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void unload( avatar &you );
// Use item; also tries E,R,W 'a'
void use_item( avatar &you, item_location &loc, std::string const &method = {} );
void use_item( avatar &you );

/** Check if avatar is stealing a weapon. */
bool check_stealing( Character &who, item &weapon );
} // namespace avatar_action

#endif // CATA_SRC_AVATAR_ACTION_H
6 changes: 6 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9854,6 +9854,12 @@ void game::wield( item_location loc )
tripoint pos = loc.position();
const int obtain_cost = loc.obtain_cost( u );
int worn_index = INT_MIN;

// Need to account for case where we're trying to wield a weapon that belongs to someone else
if( !avatar_action::check_stealing( u, *loc.get_item() ) ) {
return;
}

if( u.is_worn( *loc.get_item() ) ) {
auto ret = u.can_takeoff( *loc.get_item() );
if( !ret.success() ) {
Expand Down

0 comments on commit 6ea6d11

Please sign in to comment.