#!/usr/bin/ruby require "itemappearance.rb" class ElPotionAppearance < ElItemAppearance def initialize(appearance) super(:potion, appearance) potions = [ # identity price [:water, 0], [:booze, 50], [:fruit_juice, 50], [:see_invisible, 50], [:sickness, 50], [:confusion, 100], [:extra_healing, 100], [:hallucination, 100], [:healing, 100], [:restore_ability, 100], [:sleeping, 100], [:blindness, 150], [:gain_energy, 150], [:invisibility, 150], [:monster_detection, 150], [:object_detection, 150], [:enlightenment, 200], [:full_healing, 200], [:levitation, 200], [:polymorph, 200], [:speed, 200], [:acid, 250], [:oil, 250], [:gain_ability, 300], [:gain_level, 300], [:polymorph, 300] ] @possible_identities = {} potions.each {|potion| @possible_identities[potion[0]] = 0 } @price_of = {} potions.each {|potion| @price_of[potion[0]] = potion[1] } end def nymph_drop() # call this for each potion each nymph drops to help ID !oOD return if @identity return unless @possible_identities.has_key?(:object_detection) @possible_identities[:object_detection] += 1 end end ElPotionAppearance.new("clear").identify_as(:water) for i in ["ruby", "pink", "orange", "yellow", "emerald", "dark green", "cyan", "sky blue", "brilliant blue", "magenta", "purple-red", "puce", "milky", "swirly", "bubbly", "smoky", "cloudy", "effervescent", "black", "golden", "brown", "fizzy", "dark", "white", "murky"] ElPotionAppearance.new(i) end if __FILE__ == $0 require "../utils/assert.rb" clear = ElPotionAppearance.find("clear") assert_eq("Lots of tests here...", clear.identity, :water) murky = ElPotionAppearance.find("murky") murky.rule_out(:extra_healing) assert_eq("Test rule_out", murky.identity, nil) smoky = ElPotionAppearance.find("smoky") smoky.rule_out_all_but(:gain_level) assert_eq("Test rule_out_all_but", smoky.identity, :gain_level) smoky = ElPotionAppearance.find("smoky") assert_eq("Test finding a second item of one appearance", smoky.identity, :gain_level) gain_level = ElPotionAppearance.find("gain level") assert_eq("Test finding a potion based on stringified identity", gain_level.appearance, "smoky") gain_level = ElPotionAppearance.find(:gain_level) assert_eq("Test finding a potion based on symbol identity", gain_level.appearance, "smoky") ruby = ElPotionAppearance.find("ruby") # price ID it as base 50 ruby.rule_out_all_but(:booze, :fruit_juice, :sickness, :see_invisible) assert_eq("Test multiple arguments in rule_out_all_but", ruby.possible_identities.size, 4) # deli won't buy it ruby.rule_out(:booze, :fruit_juice) assert_eq("Test multiple arguments in rule_out", ruby.possible_identities.size, 2) assert_true("Test multiple arguments in rule_out", ruby.possible_identities.include?(:sickness)) assert_true("Test multiple arguments in rule_out", ruby.possible_identities.include?(:see_invisible)) #quaff test! ruby.identify_as(:sickness) assert_eq("Test identify_as", ruby.identity, :sickness) golden = ElPotionAppearance.find("golden") assert_false("Test ruling out of an identified potion among other appearances", golden.possible_identities.include?(:sickness)) print "unit test succeeded\n" end