Skip to content

Commit

Permalink
Spell books show up in the [R]ead menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman committed Jan 30, 2020
1 parent 1cef694 commit 25f127c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ class read_inventory_preset: public pickup_inventory_preset
}

bool is_shown( const item_location &loc ) const override {
return loc->is_book();
return loc->is_book() || loc->type->can_use( "learn_spell" );
}

std::string get_denial( const item_location &loc ) const override {
Expand All @@ -990,7 +990,8 @@ class read_inventory_preset: public pickup_inventory_preset
}

std::vector<std::string> denials;
if( u->get_book_reader( *loc, denials ) == nullptr && !denials.empty() ) {
if( u->get_book_reader( *loc, denials ) == nullptr && !denials.empty() &&
!loc->type->can_use( "learn_spell" ) ) {
return denials.front();
}
return pickup_inventory_preset::get_denial( loc );
Expand Down
13 changes: 9 additions & 4 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,12 +1171,17 @@ static void read()
{
avatar &u = g->u;
// Can read items from inventory or within one tile (including in vehicles)
auto loc = game_menus::inv::read( u );
item_location loc = game_menus::inv::read( u );

if( loc ) {
// calling obtain() invalidates the item pointer
// TODO: find a way to do this without an int index
u.read( u.i_at( loc.obtain( u ) ) );
if( loc->type->can_use( "learn_spell" ) ) {
item spell_book = *loc.get_item();
spell_book.get_use( "learn_spell" )->call( u, spell_book, spell_book.active, u.pos() );
} else {
// calling obtain() invalidates the item pointer
// TODO: find a way to do this without an int index
u.read( u.i_at( loc.obtain( u ) ) );
}
} else {
add_msg( _( "Never mind." ) );
}
Expand Down

0 comments on commit 25f127c

Please sign in to comment.