class Gemwarrior::WareHawker

Constants

PLAYER_COMMAND_INVALID
PLAYER_ITEMS_ADDITIONAL
PLAYER_ROX_INSUFFICIENT
PRICE_IRON_HELMET

CONSTANTS

PRICE_MACE
PRICE_SPEAR

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/gemwarrior/entities/people/ware_hawker.rb, line 19
def initialize
  super

  self.name         = 'ware_hawker'
  self.name_display = 'Ware Hawker'
  self.description  = 'A literal anthropomorphic hawk has set up shop behind a crudely-made table. Some wares are scattered atop its surface, seemingly within anyone\'s grasp, but the hawk\'s piercing eyes seem to belie this observation.'
end

Public Instance Methods

use(world) click to toggle source
# File lib/gemwarrior/entities/people/ware_hawker.rb, line 27
def use(world)
  if !self.used
    puts 'You greet the hawk, mentioning that you are interested in the objects presented.'
    STDIN.getc
    puts 'The hawk speaks in a beautiful, yet commanding, tone:'
  end

  hawk_shop(world)
end

Private Instance Methods

hawk_shop(world) click to toggle source
# File lib/gemwarrior/entities/people/ware_hawker.rb, line 39
def hawk_shop(world)
  player_rox_remaining = world.player.rox
  amount_spent = 0
  items_purchased = []

  iron_helmet = IronHelmet.new
  mace = Mace.new
  spear = Spear.new

  speak('I hope you have rox, human. My time affords business transactions, not idle chit chat. What do you want?')
  STDIN.getc

  puts 'A feathered arm quickly moves across the table in an arc suggesting to you that a choice is to be made. Each object has a price tag underneath it, painstakingly written in ink.'
  puts

  puts 'Hawk Shop'.colorize(:cyan)
  puts '---------'
  puts "(1) #{'Iron Helmet'.colorize(:yellow)} - #{PRICE_IRON_HELMET} rox"
  puts "    #{iron_helmet.description}"
  puts "    Defense: +#{iron_helmet.defense} (current: #{world.player.defense})"
  puts "(2) #{'Mace'.colorize(:yellow)}        - #{PRICE_MACE} rox"
  puts "    #{mace.description}"
  puts "    Attack: +#{mace.atk_lo}-#{mace.atk_hi} (current: #{world.player.atk_lo}-#{world.player.atk_hi})"
  puts "(3) #{'Spear'.colorize(:yellow)}       - #{PRICE_SPEAR} rox"
  puts "    #{spear.description}"
  puts "    Attack: +#{spear.atk_lo}-#{spear.atk_hi} (current: #{world.player.atk_lo}-#{world.player.atk_hi})"
  puts
  speak('Choose. Now.')

  loop do
    puts  " 1 - Iron Helmet (#{PRICE_IRON_HELMET})"
    puts  " 2 - Mace        (#{PRICE_MACE})"
    puts  " 3 - Spear       (#{PRICE_SPEAR})"
    print ' x - leave'
    if items_purchased.length > 0
      print ", and buy items\n"
    else
      print "\n"
    end
    puts
    print 'REMAINING ROX: '
    Animation.run(phrase: player_rox_remaining.to_s, oneline: true)
    print "\n"
    display_shopping_cart(items_purchased)
    print '[HAWK]> '

    choice = gets.chomp.downcase

    case choice
    when '1'
      if player_rox_remaining >= PRICE_IRON_HELMET
        player_rox_remaining -= PRICE_IRON_HELMET
        items_purchased.push(IronHelmet.new)
        amount_spent += PRICE_IRON_HELMET

        speak('The iron helmet? I see.')
        speak(PLAYER_ITEMS_ADDITIONAL)
        next
      else
        speak(PLAYER_ROX_INSUFFICIENT)
        next
      end
    when '2'
      if player_rox_remaining >= PRICE_MACE
        player_rox_remaining -= PRICE_MACE
        items_purchased.push(Mace.new)
        amount_spent += PRICE_MACE

        speak('Yes, fine. Buy a mace.')
        speak(PLAYER_ITEMS_ADDITIONAL)
        next
      else
        speak(PLAYER_ROX_INSUFFICIENT)
        next
      end
    when '3'
      if player_rox_remaining >= PRICE_SPEAR
        player_rox_remaining -= PRICE_SPEAR
        items_purchased.push(Spear.new)
        amount_spent += PRICE_SPEAR

        speak('Hmm. Very well, then. If the spear is what you wish.')
        speak(PLAYER_ITEMS_ADDITIONAL)
        next
      else
        speak(PLAYER_ROX_INSUFFICIENT)
        next
      end
    when 'x'
      return_type = { type: nil, data: nil }
      if items_purchased.length > 0
        display_shopping_cart(items_purchased)
        speak('Are you certain you wish to buy these things? (y/n)')
        print '[HAWK]> '
        answer = gets.chomp.downcase

        case answer
        when 'y', 'yes'
          world.player.rox -= amount_spent
          speak('Take them.')
          return_type = { type: 'purchase', data: items_purchased }
        end
      end
      speak('Our business is complete then.')
      return return_type
    else
      speak(PLAYER_COMMAND_INVALID)
      next
    end
  end
end