utility.rb
def convert_command_target(player, target, containers_only = false)
  case target
  when 'here', 'area', 'my surroundings'
    $areas[player.area]
  when 'me', 'myself', 'my bag'
    player
  else
    return $areas[player.area] if containers_only
    # Target type priority is
    # - Creature in the area
    # - Item in the player's surroundings
    # - Item in the player's current container
    # If still the target is not found, return nil
    if (creature = $areas[player.area].creatures.find { |x| x[1].is_called? target })
      creature[1]
    elsif (item = $areas[player.area].items.find { |x| $items[x[0]].is_called? target })
      $items[item[0]]
    elsif (item = player.items.find { |x| $items[x[0]].is_called? target})
      $items[item[0]]
    else
      nil
    end
  end
end
# Convert the command target into an actual object
Convert the command target into an actual object
Convert the command target into an actual object
def convert_command_target(player, target, containers_only = false)
  case target
  when 'here', 'area', 'my surroundings'
    $areas[player.area]
  when 'me', 'myself', 'my bag'
    player
  else
    return $areas[player.area] if containers_only
    if (creature = $areas[player.area].creatures.find { |x| x[1].is_called? target })
      creature[1]
    elsif (item = $areas[player.area].items.find { |x| $items[x[0]].is_called? target })
      $items[item[0]]
    elsif (item = player.items.find { |x| $items[x[0]].is_called? target})
      $items[item[0]]
    else
      nil
    end
  end
end
def convert_command_target ( player , target , containers_only = false ) case target when 'here' , 'area' , 'my surroundings' $areas [ player . area ] when 'me' , 'myself' , 'my bag' player else return $areas [ player . area ] if containers_only if ( creature = $areas [ player . area ] . creatures . find { | x | x [ 1 ] . is_called? target } ) creature [ 1 ] elsif ( item = $areas [ player . area ] . items . find { | x | $items [ x [ 0 ] ] . is_called? target } ) $items [ item [ 0 ] ] elsif ( item = player . items . find { | x | $items [ x [ 0 ] ] . is_called? target } ) $items [ item [ 0 ] ] else nil end end end
Convert the command target into an actual object
Convert the command target into an actual object
# Target type priority is # - Creature in the area # - Item in the player's surroundings # - Item in the player's current container # If still the target is not found, return nil
player
target
containers_only