#!/usr/bin/ruby require "aitask.rb" class TaskPriceID < ElAITask def desire() return 0 # if (not inshop) or (shk is angry) # if we're in a shop and have something to price ID, then yes, we # very much want to do it return 1 if inventory.detect {|item| item.price_id_useful? } return 0 end # price ID one item for simplicity.. this should eventually drop all # ID-useful items and price ID them all in one turn def execute() item = inventory.detect {|item| item.price_id_useful? } response = send "d1", item.invletter if response =~ /offers (\d+) gold pieces? for your .*?\. Sell it\? \[ynaq\]/ item.appearance.price_id_sell($1, false) # false == isTourist? elsif response =~ /offers only (\d+) gold pieces? for your .*?\. Sell it\? \[ynaq\]/ # exclude everything below $1 elsif response =~ /Will you accept (\d+) zorkmids? in credit for .*?\? \[ynaq\]/ # shk offers 90% credit (or thereabouts, with integer arithmetic) # perhaps we shouldn't attempt to price ID at all in this situation item.appearance.price_id_sell(($1*10/9).to_i, false) else # emit warning? end send "n" # pick up item from the floor end end if __FILE__ == $0 require "../utils/assert.rb" print "unit test succeeded\n" end