class OldSchool::Player

Represents a single player on OldSchool

Attributes

minigames[R]

@example Extract Minigame information from a Player

player = OldSchool::Player.new 'ruby'
player.minigames[:bh_hunter].score #=> 1_344
player.minigames[:bh_rogue].score #=> 900
player.minigames[:clue_all].rank #=> 10_333
player.minigames[:clue_elite].rank #=> 90_232
player.minigames #=> Hash of all Minigames

@see OldSchool::HiScores::MINIGAMES List of all possible Minigame Symbols @return [Hash<Symbol, OldSchool::HiScores::Minigame>] a Hash containing

all of the Player's minigame information as it stands on the HiScores
mode[R]

@return [Symbol] the mode of the Player

skills[R]

@example Extract Skill information from a Player

player = OldSchool::Player.new 'ruby'
player.skills[:overall].level #=> 1232
player.skills[:hunter] #=> OldSchool::HiScores::Skill
player.skills[:hunter].level #=> 72
player.skills[:hunter].experience #=> 780_000
player.skills[:hunter].rank #=> 131_232
player.skills #=> Hash of all Skills

@see OldSchool::HiScores::SKILLS List of all possible Skill Symbols

@return [Hash<Symbol, OldSchool::HiScores::Skill>] a Hash containing

all of the Player's skill information as it stands on the HiScores
username[R]

@return [String] the Player's username

Public Class Methods

new(username, mode = :default) click to toggle source

Creates a new Player object

Creates a new player object with the specified username

@example Create a new OldSchool Player

player = OldSchool::Player.new 'ruby'
player.mode #=> :default
player.username #=> "ruby"

@example Create a new Ironman Player

player = OldSchool::Player.new 'ruby', :ironman
player.mode #=> :ironman
player.username #=> "ruby"

@see OldSchool::HiScores::MODES List of all available game modes

@param username [String] the username of the Player @param mode [Symbol] the mode of the Player, such as

:default, :ironman, :ultimate, :hardcore, :deadman etc.
# File lib/oldschool/player.rb, line 66
def initialize(username, mode = :default)
  @username = username
  @mode = mode
  @csv = nil

  generate_hs_stats
end

Public Instance Methods

free?() click to toggle source

Determines if this Player is a F2P Player

This method dermines that a Player is F2P if they do not have any experience in their member's only skills.

@example For a player with no experience in a member's only skill

f2p = OldSchool::Player.new 'f2p'
f2p.free? #=> true

@example For a Player with experience in a member's only skill

member = OldSchool::Player.new 'member'
member.free? #=> false

@note This method is the inverse of member? @see member?

@return [true] if this Player has no experience in any member only skill @return [false] if this Player has experience in any member only skill

# File lib/oldschool/player.rb, line 120
def free?
  !member?
end
member?() click to toggle source

Determines if this Player was/is a member

This method determines that a Player is a member if they have any experience in any of their member's only skills. Some members, for example, do not have experience in any of their member's only skills.

@example For a Player with experience in a member's only skill

member = OldSchool::Player.new 'member'
member.member? #=> true

@example For a Player with no experience in a member's only skill

f2p_player = OldSchool::Player.new 'f2p guy'
f2p_player.member? #=> false

@note There is a certain level of inaccuracy using this

method, since this method determines a Player is a member
if they have experience in their member's only skills.

@return [true] if this Player has experience in any member only skill @return [false] if this Player has no experience in any member only skill

# File lib/oldschool/player.rb, line 95
def member?
  @skills.each do |_, skill|
    return true if skill.experience > 0 && skill.member?
  end
  false
end
nonmember?() click to toggle source

An alias for free? @see free?

# File lib/oldschool/player.rb, line 127
def nonmember?
  free?
end
nonskiller?() click to toggle source

Determines if this player is not a skiller

@example For a level 3 skiller

skiller = OldSchool::Player.new 'skiller'
skiller.nonskiller? #=> false

@example For a Player who has > 1 in any combat skill

main = OldSchool::Player.new 'main'
main.nonskiller? #=> true

@note This is the inverse of skiller? @see skiller?

@return [true] if the player is not classified as a skiller @return [false] if the player is classified as a skiller

# File lib/oldschool/player.rb, line 172
def nonskiller?
  !skiller?
end
skiller?() click to toggle source

Determines if this Player is a skiller

This method determines that a Player is a skiller by ensuring that the player has no combat-oriented skills over the level of 1 (with the exception of 10 hitpoints).

@example For a level 3 skiller

skiller = OldSchool::Player.new 'skiller'
skiller.skiller? #=> true

@example For a Player who has > 1 in any combat skill

main = OldSchool::Player.new 'main'
main.skiller? #=> false

@return [true] if the player is classified as a skiller @return [false] if the player is not classified as a skiller

# File lib/oldschool/player.rb, line 147
def skiller?
  skiller = true
  @skills.each do |_, skill|
    next if skill.symbol == :hitpoints && skill.level <= 10

    skiller = false if skill.combat? && skill.level > 1
  end
  skiller
end

Private Instance Methods

csv_data() click to toggle source
# File lib/oldschool/player.rb, line 182
def csv_data
  mode = HiScores::MODES[@mode]
  resource = HiScores::RESOURCE[:stats] + @username
  url = mode + resource

  @csv = CSV.parse(open_and_read(url)).map { |r| r.map(&:to_i) }
end
generate_hs_stats() click to toggle source
# File lib/oldschool/player.rb, line 190
def generate_hs_stats
  csv_data if @csv.nil?

  generate_skills
  generate_minigames
end
generate_minigames() click to toggle source
# File lib/oldschool/player.rb, line 210
def generate_minigames
  @minigames = {}
  minigames_arr = HiScores::MINIGAMES
  range = @skills.length..@skills.length + HiScores::MINIGAMES.length - 1

  range.each_with_index do |val, i|
    @minigames[HiScores::MINIGAMES[i]] = HiScores::Minigame.new(
      minigames_arr[i], @csv[val][0], @csv[val][1]
    )
  end
end
generate_skills() click to toggle source
# File lib/oldschool/player.rb, line 197
def generate_skills
  @skills = {}
  skills_arr = HiScores::SKILLS

  @csv.each_with_index do |row, i|
    break if i >= HiScores::SKILLS.length

    @skills[HiScores::SKILLS[i]] = HiScores::Skill.new(
      skills_arr[i], row[0], row[1], row[2]
    )
  end
end
open_and_read(url) click to toggle source
# File lib/oldschool/player.rb, line 178
def open_and_read(url)
  open(url, &:read)
end