#!/usr/bin/ruby require "itemappearance.rb" class ElWandAppearance < ElItemAppearance def initialize(appearance) super(:wand, appearance) wands = [ # identity price directionality [:light, 100, :nodir], [:nothing, 100, :immediate], [:digging, 150, :ray], [:enlightenment, 150, :nodir], [:locking, 150, :immediate], [:magic_missile, 150, :ray], [:make_invisible, 150, :immediate], [:opening, 150, :immediate], [:probing, 150, :immediate], [:secret_door_detection, 150, :nodir], [:slow_monster, 150, :immediate], [:speed_monster, 150, :immediate], [:striking, 150, :immediate], [:undead_turning, 150, :immediate], [:cold, 175, :ray], [:fire, 175, :ray], [:lightning, 175, :ray], [:sleep, 175, :ray], [:cancellation, 200, :immediate], [:create_monster, 200, :nodir], [:polymorph, 200, :immediate], [:teleportation, 200, :immediate], [:death, 500, :ray], [:wishing, 500, :nodir] ] @possible_identities = {} wands.each {|wand| @possible_identities[wand[0]] = 0 } @price_of = {} wands.each {|wand| @price_of[wand[0]] = wand[1] } end def engrave_useful?() return false if @identity # How this works is we group each wand identity based on what it would # do in an engrave ID. For example, sleep and death would go into one # group, and invis, tele, canc would go into another. If we have # possible identities from two or more groups, then engrave-IDing would # be useful in the sense that it'd rule some possibilities out. engrave_groups = [ [:sleep, :death], [:make_invisible, :teleportation, :cancellation], [:cold], [:polymorph], [:speed_monster], [:slow_monster], [:striking], [:magic_missile], # We're excluding this group because we don't rule out if there's no # engrave messags, because the wand could possiblly be from a bones. # [:locking, :nothing, :opening, :probing, # :undead_turning, :secret_door_detection], [:light, :enlightenment, :create_monster, :digging, :fire, :lightning, :wishing] ] appearance_groups = 0 engrave_groups.each do |group| group.each do |identity| next unless @possible_identities.has_key?(identity) appearance_groups += 1 break # that is, next engrave group end end return appearance_groups > 1 end end for i in ["glass", "balsa", "crystal", "maple", "pine", "oak", "ebony", "marble", "tin", "brass", "copper", "silver", "platinum", "iridium", "zinc", "aluminum", "uranium", "iron", "steel", "hexagonal", "short", "runed", "long", "curved", "forked", "spiked", "jeweled"] ElWandAppearance.new(i) end if __FILE__ == $0 require "../utils/assert.rb" glass = ElWandAppearance.find("glass") glass.price_id_sell(250, false) glass.rule_out(:death) assert_eq("Price IDing.", glass.identity, :wishing) hexagonal = ElWandAppearance.find("hexagonal") assert_true("price_id_useful? initially true", hexagonal.price_id_useful?) hexagonal.price_id_buy(349, 6, true) assert_false("price_id_useful? becomes false after price ID", hexagonal.price_id_useful?) forked = ElWandAppearance.find("forked") forked.price_id_sell(75, false) assert_true("price_id_useful? even if two base price hits", forked.price_id_useful?) forked.price_id_sell(75, false) assert_true("price_id_useful? second two-hit test", forked.price_id_useful?) forked.price_id_sell(57, false) assert_false("price_id_useful? now false after we cleared that up two-hit test", forked.price_id_useful?) print "unit test succeeded\n" end