#!/usr/bin/ruby require "aitask.rb" class TaskWandEngraveID < ElAITask def desire() # Just to be on the safe side, we don't want to engrave if any of the # following apply. The messages may differ, or it may just be # impossible (like trying to write in the dust with a wand when there's # already a burned engraving). return 0 if player.is_blind? || cur_tile.is_ice? || cur_tile.is_headstone? || cur_tile.is_altar? || (cur_tile.text && cur_tile.text_type != :dust) # If we have a wand to engrave ID, sure! return 1 if inventory.detect {|item| item.is_a == ElWand && item.engrave_useful? } return 0 end def execute() wand = inventory.detect {|item| item.is_a == ElWand && item.engrave_useful? } # Check to see if there's some text in the dirt. If not, write it. # The : command may take a turn if blind (I simply don't know) but we # wouldn't get this far if blind. response = send ":" if response !~ /Something is written here/ send "E- Elbereth\n" return end # Now we know there's some junk text on the dust. Let's engrave! response = send "E", wand.invletter wand.expend_charge() # This handles wands that ID as soon as you try to engrave with them. if response =~ /is a wand of (.*?)!/ case $1 when "fire" identity = :fire when "digging" identity = :digging when "lightning" identity = :lightning end wand.appearance.identify_as(identity) send "Elbereth\n" # Since we're using a charge up anyway.. return elsif response =~ /You may wish for an object\./ wand.appearance.identify_as(:wishing) make_wish() send "q" # Changed our minds, no engraving! return elsif response =~ /A lit field surrounds you!/ wand.appearance.identify_as(:light) send "q" # Changed our minds, no engraving! return elsif response =~ /You feel self-knowledgeable/ wand.appearance.identify_as(:enlightenment) enlighten() send "q" # Changed our minds, no engraving! return elsif response =~ /The engraving now reads:/ wand.appearance.identify_as(:polymorph) return elsif response =~ /The engraving on the floor vanishes!/ wand.appearance.rule_out_all_but(:make_invisible, :teleportation, :cancellation) send "\n" # No engrave message. return end response = send "y" # Yes, we want to add to the current engraving. # Wands that engrave when you touch the ground with them. if response =~ /You add to the writing in the dust with a wand of (.*?)\./ case $1 when "create monster" identity = :create_monster when "secret door detection" identity = :secret_door_detection end wand.appearance.identify_as(identity) send "\n" # No engrave message. return end # Wands that ID after being written with. response = send "Elbereth" # Engrave an E with the wand. if response =~ /The bugs on the \w+ stop moving!/ wand.appearance.rule_out_all_but(:sleep, :death) elsif response =~ /A few ice cubes drop from the wand\./ wand.appearance.identify_as(:cold) elsif response =~ /The bugs on the \w+ speed up!/ wand.appearance.identify_as(:speed_monster) elsif response =~ /The bugs on the \w+ slow down!// wand.appearance.identify_as(:slow_monster) elsif response =~ /The wand unsuccessfully fights your attempt to write!/ wand.appearance.identify_as(:striking) elsif response =~ /The \w+ is riddled by bullet holes!/ wand.appearance.identify_as(:magic_missile) # Comment by Clint on 10/7/2006 -- Everything in this class looks fantastic! Isn't this last rule_out_all_but assuming that the wand had charges though? We could have found an empty wand -- especially if it was from a bones pile. If so, this could certainly lead to a mis-ID. # Eidolos 10/7/2006 -- Perfectly right; let's not do any ruling out if there was no explicit message. I modified wandappearance.engrave_useful? to reflect that we won't be ruling out all but this group. Possible feature: if we know there are charges, then we _can_ make this ruling. But most methods that involve learning charges also involve learning identity. # else # wand.appearance.rule_out_all_but(:nothing, :undead_turning, :opening, :locking, :probing, :secret_door_detection) end end end if __FILE__ == $0 require "../utils/assert.rb" print "unit test succeeded\n" end