Advertisement
intangibles

Untitled

May 18th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 63.85 KB | None | 0 0
  1. ##quiet
  2. ## vim: set ft=ruby:
  3. =begin
  4.  
  5.     SBounty by SpiffyJr (spiffyjr@gmail.com)
  6.  
  7.     Does all bounties except gem, escorts, and bandits. Gems should
  8.     be handled via your loot with stockpiling.
  9.  
  10.     Feel free to send donations or Gift's of Adventure.
  11.  
  12.      author: spiffyjr
  13.       email: theman@spiffyjr.me
  14.        name: SpiffyBounty
  15.        tags: bounty
  16.     version: 1.0
  17.  
  18. =end
  19.  
  20. $sbounty_debug = false
  21. $stop_bounty = "small green olive|herald|janissary|construct"
  22. stopbounty = false
  23.  
  24. Settings[:locations] = CharSettings[:locations]
  25.  
  26. CharSettings[:enable_cull]      = CharSettings[:enable_cull].nil? ? true : CharSettings[:enable_cull]
  27. CharSettings[:enable_dangerous] = CharSettings[:enable_dangerous].nil? ? true : CharSettings[:enable_dangerous]
  28. CharSettings[:enable_forage]    = CharSettings[:enable_forage].nil? ? true : CharSettings[:enable_forage]
  29. CharSettings[:enable_loot]      = CharSettings[:enable_loot].nil? ? true : CharSettings[:enable_loot]
  30. CharSettings[:enable_rescue]    = CharSettings[:enable_rescue].nil? ? true : CharSettings[:enable_rescue]
  31. CharSettings[:enable_search]    = CharSettings[:enable_search].nil? ? true : CharSettings[:enable_search]
  32. CharSettings[:enable_bandit]    = CharSettings[:enable_bandit].nil? ? false : CharSettings[:enable_bandit]
  33. CharSettings[:enable_skin]      = CharSettings[:enable_skin].nil? ? true : CharSettings[:enable_skin]
  34. CharSettings[:enable_expedite]  = CharSettings[:enable_expedite].nil? ? true : CharSettings[:enable_expedite]
  35.  
  36. CharSettings[:enable_hunt_complete] = CharSettings[:enable_hunt_complete].nil? ? true : CharSettings[:enable_hunt_complete]
  37.  
  38. CharSettings[:pre_search_commands]  ||= ['store all']
  39. CharSettings[:post_search_commands] ||= ['gird']
  40. CharSettings[:forage_retry_delay]   ||= 300
  41. CharSettings[:loot_script]          ||= 'sloot'
  42. CharSettings[:turn_in_percent]      ||= 95
  43.  
  44. CharSettings[:should_hunt_mind]    ||= 75
  45. CharSettings[:should_hunt_mana]    ||= 0
  46. CharSettings[:should_hunt_spirit]  ||= 7
  47. CharSettings[:hunt_pre_commands]   ||= ['gird']
  48. CharSettings[:should_rest_mind]    ||= 100
  49. CharSettings[:should_rest_mana]    ||= 0
  50. CharSettings[:should_rest_encum]   ||= 20
  51. CharSettings[:should_rest_wounded] ||= StringProc.new 'bleeding? || percenthealth <= 50 || ([Wounds.head, Scars.head].max >= 2) || ([Wounds.nsys, Scars.nsys].max >= 2) || ([Wounds.leftArm, Wounds.leftHand, Wounds.rightArm, Wounds.rightHand, Scars.leftArm, Scars.leftHand, Scars.rightArm, Scars.rightHand].max >= 3) || ( ([Wounds.leftArm, Wounds.leftHand, Scars.leftArm, Scars.leftHand].max >= 2) or ([Wounds.rightArm, Wounds.rightHand, Scars.leftArm, Scars.leftHand].max >= 2) )'
  52.  
  53. CharSettings[:rest_in_commands]    ||= ['go table, si']
  54. CharSettings[:rest_out_commands]   ||= ['stand', 'out']
  55. CharSettings[:rest_pre_commands]   ||= ['store all']
  56. CharSettings[:rest_scripts]        ||= ['useherbs --buy-missing=on', 'sloot sell', 'waggle']
  57. CharSettings[:rest_sleep_interval] ||= 30
  58.  
  59. CharSettings[:locations] ||= {}
  60.  
  61. $sbounty_rest        = false
  62. $current_bounty      = "none"
  63. $sbounty_rest_reason = nil
  64. in_rest_area         = false
  65. rest_reason          = nil
  66. hunt_reason          = nil
  67. can_do_bounty_cache  = nil
  68. expedite_left        = true
  69. last_forage_attempt  = 0
  70. last_forage_delay    = 300
  71.  
  72. if UserVars.lootsack.nil? or UserVars.lootsack.empty?
  73.     echo '** lootsack has not been set, set it with ;set change lootsack [container]'
  74.     exit
  75. end
  76.  
  77. if CharSettings[:enable_skin] and (UserVars.skinsack.nil? or UserVars.skinsack.empty?)
  78.     echo '** skinsack has not been set, set it with ;set change skinsack [container]'
  79.     exit
  80. end
  81.  
  82. #lootsack = GameObj.inv.find { |i| i.noun =~ /#{UserVars.lootsack}/ } or GameObj.inv.find { |i| i.name =~ /#{UserVars.lootsack}/ }
  83. #skinsack = GameObj.inv.find { |i| i.noun =~ /#{UserVars.skinsack}/ } or GameObj.inv.find { |i| i.name =~ /#{UserVars.lootsack}/ }
  84. lootsack = GameObj.inv.find { |i| i.name =~ /#{UserVars.lootsack}/ }
  85. skinsack = GameObj.inv.find { |i| i.name =~ /#{UserVars.skinsack}/ }
  86.  
  87. if lootsack.nil?
  88.     echo '** failed to find your lootsack, set it with ;set change lootsack [container]'
  89.     exit
  90. end
  91.  
  92. if CharSettings[:enable_skin] and skinsack.nil?
  93.     echo '** failed to find your skinsack, set it with ;set change skinsack [container]'
  94.     exit
  95. end
  96.  
  97. # You have been tasked to recover a peridot-inset pewter ring that an unfortunate citizen lost after being attacked by a storm giant in the Upper Trollfang near Wehnimer's Landing.  The heirloom can be identified by the initials MG engraved upon it.  Hunt down the creature and LOOT the item from its corpse.
  98.  
  99.  
  100. bounty_patterns = {
  101.     'none' => '^You are not currently assigned a task\.',
  102.  
  103.     # help
  104.     'help_bandit'    => 'It appears they have a bandit problem',
  105.     'help_creature'  => 'It appears they have a creature problem they\'d like you to solve\.',
  106.     'help_resident'  => 'It appears that a local resident urgently needs our help in some matter\.',
  107.     'help_heirloom'  => 'It appears they need your help in tracking down some kind of lost heirloom\.',
  108.     'help_gemdealer' => 'The local gem dealer, .*, has an order to fill and wants our help\.',
  109.     'help_herbalist' => 'local herbalist|local healer|local alchemist',
  110.     'help_furrier'   => 'The local furrier',
  111.  
  112.     # in progress
  113.     'task_bandit'    => '^You have been tasked to suppress bandit activity (?:in|on|near) (?:the )?(.*)\s(?:near|between|under|\.)',
  114.     'task_escort'    => '^You have made contact with the child',
  115.     'task_dangerous' => 'You have been tasked to hunt down and kill a particularly dangerous (.*) that has established a territory (?:in|on|near) (?:the )?(.*)(?:\s(?:near|between|under)|\.)\s+You can',
  116.     'task_provoked'  => 'You have been tasked to hunt down and kill a particularly dangerous (.*) that has established a territory (?:in|on|near) (?:the )?([\w\'\s-]+)(?:\s(?:in|on|near|\.).*)\s+ You have provoked',
  117.     'task_dealer'    => '^The(?: local)? gem dealer',
  118.     'task_forage'    => 'concoction that requires (?:a|an|some) (.*) found (?:in|on|near) (?:the )?(.*?)(?: near| between| under|\.).*These samples must be in pristine condition\.\s+You have been tasked to retrieve (\d+) samples\.',
  119.     'task_cull'      => 'You have been tasked to suppress (.*) activity (?:in|on) (?:the )?(.*)(?:\s(?:near|between|under)|\.)',
  120.     'task_search'    => 'unfortunate citizen lost after being attacked by (?:a|an) (.*) (?:in|on|near) (?:the )?(.*)\s(?:near|between|under|\.).*\.  SEARCH',
  121.     'task_heirloom'  => 'unfortunate citizen lost after being attacked by (?:a|an) (.*) (?:in|on|near) (?:the )?(.*)\s(?:near|between|under|\.).*LOOT',
  122.     'task_found'     => 'You have located the heirloom',
  123.     'task_skin'      => '^You have been tasked to retrieve (\d+|\w+)s? (.*) of at least .*\.  You can SKIN them off the corpse of (?:a|an) (.*) or ',
  124.     'task_rescue'    => 'A local divinist has had visions of the child fleeing from (?:a|an) (.*) (?:in|on) (?:the )?(\S+ ?(?:\S+)?)(?: near| between| under|\.)',
  125.  
  126.     # fail
  127.     'fail_child' => 'The child you were tasked to rescue is gone and your task is failed\.',
  128.  
  129.     # success
  130.     'success'          => '^You have succeeded',
  131.     'success_guard'    => '^You succeeded in your task and should report back to',
  132.     'success_heirloom' => '^You have located the heirloom and should bring it back .*\.$',
  133. }
  134.  
  135. setup = proc {
  136.     script_name = script.name
  137.  
  138.     action   = nil
  139.     window   = nil
  140.     notebook = nil
  141.  
  142.     locations = CharSettings[:locations].dup
  143.     location  = nil
  144.  
  145.     error = proc { |msg|
  146.         dlg = Gtk::Dialog.new(
  147.             'Error!',
  148.             window,
  149.             Gtk::Dialog::DESTROY_WITH_PARENT,
  150.             [ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_NONE ]
  151.         )
  152.         dlg.resize 200,100
  153.         dlg.signal_connect 'response' do dlg.destroy end
  154.         dlg.vbox.add(Gtk::Label.new(msg))
  155.         dlg.show_all
  156.     }
  157.  
  158.     widgets = {
  159.         :gui_widgets => {
  160.             # buttons
  161.             :close  => Gtk::Button.new('Close'),
  162.             :create => Gtk::Button.new('Create'),
  163.             :delete => Gtk::Button.new('Delete'),
  164.             :save   => Gtk::Button.new('Save & Close'),
  165.  
  166.             # combos
  167.             :locations => Gtk::ComboBox.new,
  168.  
  169.             # entries
  170.             :new_name => Gtk::Entry.new,
  171.         },
  172.  
  173.         :location_widgets => {
  174.             # check buttons
  175.             :enable_bounty_only      => Gtk::CheckButton.new('Only attack bouny critters'),
  176.             :enable_hunting_rotation => Gtk::CheckButton.new('In hunting rotation'),
  177.             :enable_search_only      => Gtk::CheckButton.new('Only search here (no hunting)'),
  178.  
  179.             #entries
  180.             :location   => Gtk::Entry.new,
  181.             :skins      => Gtk::Entry.new,
  182.             :targets    => Gtk::Entry.new,
  183.             :room       => Gtk::Entry.new,
  184.             :boundaries => Gtk::Entry.new,
  185.         },
  186.  
  187.         # check buttons
  188.         :enable_cull      => Gtk::CheckButton.new('Cull critters').set_active(CharSettings[:enable_cull]),
  189.         :enable_dangerous => Gtk::CheckButton.new('Dangerous critter').set_active(CharSettings[:enable_dangerous]),
  190.         :enable_forage    => Gtk::CheckButton.new('Forage herbs').set_active(CharSettings[:enable_forage]),
  191.         :enable_loot      => Gtk::CheckButton.new('Loot heirloom').set_active(CharSettings[:enable_loot]),
  192.         :enable_rescue    => Gtk::CheckButton.new('Rescue child').set_active(CharSettings[:enable_rescue]),
  193.         :enable_search    => Gtk::CheckButton.new('Search heirloom').set_active(CharSettings[:enable_search]),
  194.         :enable_bandit    => Gtk::CheckButton.new('Bandits').set_active(CharSettings[:enable_bandit]),
  195.         :enable_skin      => Gtk::CheckButton.new('Skin critters').set_active(CharSettings[:enable_skin]),
  196.         :enable_expedite  => Gtk::CheckButton.new('Expedite bounties').set_active(CharSettings[:enable_expedite]),
  197.  
  198.         :enable_hunt_complete => Gtk::CheckButton.new('Hunt until complete?').set_active(CharSettings[:enable_hunt_complete]),
  199.  
  200.         # entries
  201.         :pre_search_commands  => Gtk::Entry.new.set_text(CharSettings[:pre_search_commands].collect { |a| a.strip }.join(',')),
  202.         :post_search_commands => Gtk::Entry.new.set_text(CharSettings[:post_search_commands].collect { |a| a.strip }.join(',')),
  203.         :forage_retry_delay   => Gtk::Entry.new.set_text(CharSettings[:forage_retry_delay].to_s),
  204.         :loot_script          => Gtk::Entry.new.set_text(CharSettings[:loot_script].to_s),
  205.         :turn_in_percent      => Gtk::Entry.new.set_text(CharSettings[:turn_in_percent].to_s),
  206.  
  207.         :should_hunt_mind   => Gtk::Entry.new.set_text(CharSettings[:should_hunt_mind].to_s),
  208.         :should_hunt_mana   => Gtk::Entry.new.set_text(CharSettings[:should_hunt_mana].to_s),
  209.         :should_hunt_spirit => Gtk::Entry.new.set_text(CharSettings[:should_hunt_spirit].to_s),
  210.  
  211.         :hunt_pre_commands => Gtk::Entry.new.set_text(CharSettings[:hunt_pre_commands].collect { |a| a.strip }.join(',')),
  212.         :hunt_commands_a   => Gtk::Entry.new.set_text(CharSettings[:hunt_commands_a].collect { |a| a.strip }.join(',')),
  213.         :hunt_commands_b   => Gtk::Entry.new.set_text(CharSettings[:hunt_commands_b].collect { |a| a.strip }.join(',')),
  214.         :hunt_commands_c   => Gtk::Entry.new.set_text(CharSettings[:hunt_commands_c].collect { |a| a.strip }.join(',')),
  215.  
  216.         :should_rest_mana    => Gtk::Entry.new.set_text(CharSettings[:should_rest_mana].to_s),
  217.         :should_rest_mind    => Gtk::Entry.new.set_text(CharSettings[:should_rest_mind].to_s),
  218.         :should_rest_encum   => Gtk::Entry.new.set_text(CharSettings[:should_rest_encum].to_s),
  219.         :should_rest_wounded => Gtk::Entry.new.set_text(CharSettings[:should_rest_wounded]._dump),
  220.  
  221.         :rest_in_commands  => Gtk::Entry.new.set_text(CharSettings[:rest_in_commands].collect { |a| a.strip }.join(',')),
  222.         :rest_out_commands => Gtk::Entry.new.set_text(CharSettings[:rest_out_commands].collect { |a| a.strip }.join(',')),
  223.         :rest_pre_commands => Gtk::Entry.new.set_text(CharSettings[:rest_pre_commands].collect { |a| a.strip }.join(',')),
  224.         :rest_room         => Gtk::Entry.new.set_text(CharSettings[:rest_room]),
  225.         :rest_scripts      => Gtk::Entry.new.set_text(CharSettings[:rest_scripts].collect { |a| a.strip }.join(','))
  226.     }
  227.  
  228.     Gtk.queue {
  229.         update_disabled = proc {
  230.             widgets[:location_widgets].each { |key, widget|
  231.                 if location.nil?
  232.                     widget.set_sensitive(false)
  233.                 else
  234.                     widget.set_sensitive(true)
  235.                 end
  236.             }
  237.         }
  238.  
  239.         populate_locations = proc {
  240.             loop {
  241.                 break if not widgets[:gui_widgets][:locations].model.iter_first
  242.                 widgets[:gui_widgets][:locations].remove_text(0)
  243.             }
  244.  
  245.             locations.keys.sort.each { |text|
  246.                 widgets[:gui_widgets][:locations].append_text(text)
  247.             }
  248.         }
  249.  
  250.         save_location = proc {
  251.             widgets[:location_widgets].each { |key, widget|
  252.                 if widget.class == Gtk::CheckButton
  253.                     value = widget.active?
  254.                 elsif [:skins, :targets, :boundaries].include?(key)
  255.                     value = widget.text.strip.split(',').collect { |item| item.strip }
  256.                 else
  257.                     value = widget.text.strip
  258.                 end
  259.  
  260.                 locations[location][key] = value
  261.             }
  262.         }
  263.  
  264.         attach_signals = proc {
  265.             widgets[:gui_widgets][:close].signal_connect 'clicked' do action = :close end
  266.             widgets[:gui_widgets][:save].signal_connect 'clicked' do action = :save; save_location.call end
  267.  
  268.             widgets[:gui_widgets][:create].signal_connect 'clicked' do
  269.                 name = widgets[:gui_widgets][:new_name].text.strip
  270.  
  271.                 if name.nil? or name.empty? or name.length < 3
  272.                     error.call 'You need to enter a name!'
  273.                 elsif locations.keys.find { |n| n.downcase.strip == name.downcase.strip }
  274.                     error.call 'A location with that name already exists!'
  275.                 else
  276.                     locations[name] = {}
  277.  
  278.                     widgets[:gui_widgets][:new_name].set_text ""
  279.  
  280.                     populate_locations.call
  281.                     update_disabled.call
  282.                 end
  283.             end
  284.  
  285.             widgets[:gui_widgets][:delete].signal_connect 'clicked' do
  286.                 Gtk.queue {
  287.                     if widgets[:gui_widgets][:locations].active == -1
  288.                         error.call 'You do not have a location selected!'
  289.                     else
  290.                         locations.delete(widgets[:gui_widgets][:locations].active_text)
  291.                         widgets[:gui_widgets][:locations].remove_text(widgets[:gui_widgets][:locations].active)
  292.  
  293.                         widgets[:location_widgets].each { |key, widget|
  294.                             if widget.class == Gtk::CheckButton
  295.                                 widget.set_active(false)
  296.                             else
  297.                                 widget.set_text("")
  298.                             end
  299.                         }
  300.                     end
  301.                 }
  302.             end
  303.  
  304.             widgets[:gui_widgets][:locations].signal_connect 'changed' do
  305.                 Gtk.queue {
  306.                     save_location.call
  307.  
  308.                     location = widgets[:gui_widgets][:locations].active_text
  309.  
  310.                     if locations[location]
  311.                         widgets[:location_widgets].each { |key, widget|
  312.                             if widget.class == Gtk::CheckButton
  313.                                 widget.set_active(!!locations[location][key])
  314.                             elsif [:skins, :targets, :boundaries].include?(key)
  315.                                 widget.set_text(locations[location][key].join(','))
  316.                             else
  317.                                 widget.set_text(locations[location][key].strip)
  318.                             end
  319.                         }
  320.                     end
  321.  
  322.                     update_disabled.call
  323.                 }
  324.             end
  325.         }
  326.  
  327.         # main window
  328.         window = Gtk::Window.new
  329.         window.border_width = 5
  330.         window.keep_above = true
  331.         window.resizable = true
  332.         window.resize 500, 300
  333.         window.set_window_position Gtk::Window::POS_CENTER
  334.  
  335.         # main notebook (tabs)
  336.         notebook = Gtk::Notebook.new
  337.         notebook.show_border = true
  338.  
  339.         vbox_main = Gtk::VBox.new
  340.         vbox_main.pack_start notebook
  341.  
  342.         # sbounty options
  343.         vbox = Gtk::VBox.new
  344.  
  345.         frm = Gtk::Frame.new('Locations').set_border_width(3)
  346.         tbl = Gtk::Table.new(7, 4, true).set_border_width(3)
  347.  
  348.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('New name: ')), 0, 1, 0, 1
  349.         tbl.attach widgets[:gui_widgets][:new_name], 1, 3, 0, 1
  350.         tbl.attach widgets[:gui_widgets][:create], 3, 4, 0, 1
  351.  
  352.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Locations: ')), 0, 1, 1, 2
  353.         tbl.attach widgets[:gui_widgets][:locations], 1, 3, 1, 2
  354.         tbl.attach widgets[:gui_widgets][:delete], 3, 4, 1, 2
  355.  
  356.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Location: ')), 0, 1, 3, 4
  357.         tbl.attach widgets[:location_widgets][:location], 1, 2, 3, 4
  358.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Skins: ')), 2, 3, 3, 4
  359.         tbl.attach widgets[:location_widgets][:skins], 3, 4, 3, 4
  360.  
  361.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Targets: ')), 0, 1, 4, 5
  362.         tbl.attach widgets[:location_widgets][:targets], 1, 2, 4, 5
  363.  
  364.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Room #: ')), 0, 1, 5, 6
  365.         tbl.attach widgets[:location_widgets][:room], 1, 2, 5, 6
  366.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Boundaries: ')), 2, 3, 5, 6
  367.         tbl.attach widgets[:location_widgets][:boundaries], 3, 4, 5, 6
  368.  
  369.         tbl.attach widgets[:location_widgets][:enable_hunting_rotation], 0, 1, 6, 7
  370.         tbl.attach widgets[:location_widgets][:enable_bounty_only], 1, 2, 6, 7
  371.         tbl.attach widgets[:location_widgets][:enable_search_only], 2, 3, 6, 7
  372.  
  373.         frm.add(tbl)
  374.         vbox.pack_start(frm)
  375.  
  376.         frm = Gtk::Frame.new('Bounties').set_border_width(3)
  377.         tbl = Gtk::Table.new(5, 4, true).set_border_width(3)
  378.  
  379.         tbl.attach widgets[:enable_cull], 0, 1, 0, 1
  380.         tbl.attach widgets[:enable_dangerous], 1, 2, 0, 1
  381.         tbl.attach widgets[:enable_rescue], 2, 3, 0, 1
  382.         tbl.attach widgets[:enable_skin], 3, 4, 0, 1
  383.  
  384.         tbl.attach widgets[:enable_loot], 0, 1, 1, 2
  385.         tbl.attach widgets[:enable_search], 1, 2, 1, 2
  386.         tbl.attach widgets[:enable_forage], 2, 3, 1, 2
  387.         tbl.attach widgets[:enable_bandit], 3, 4, 1, 2
  388.  
  389.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('turn in when mind >= ')), 0, 1, 2, 3
  390.         tbl.attach widgets[:turn_in_percent], 1, 2, 2, 3
  391.         tbl.attach widgets[:enable_expedite], 2, 3, 2, 3
  392.         tbl.attach widgets[:enable_hunt_complete], 3, 4, 2, 3
  393.  
  394.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('pre-search commands: ')), 0, 1, 3, 4
  395.         tbl.attach widgets[:pre_search_commands], 1, 2, 3, 4
  396.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('post-search commands: ')), 2, 3, 3, 4
  397.         tbl.attach widgets[:post_search_commands], 3, 4, 3, 4
  398.  
  399.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('forage retry delay: ')), 0, 1, 4, 5
  400.         tbl.attach widgets[:forage_retry_delay], 1, 2, 4, 5
  401.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('loot script: ')), 2, 3, 4, 5
  402.         tbl.attach widgets[:loot_script], 3, 4, 4, 5
  403.  
  404.         frm.add(tbl)
  405.         vbox.pack_start(frm)
  406.  
  407.         notebook.append_page vbox, Gtk::Label.new('Locations / Options')
  408.  
  409.         # default options
  410.         vbox = Gtk::VBox.new
  411.  
  412.         frm = Gtk::Frame.new('Should Rest').set_border_width(3)
  413.         tbl = Gtk::Table.new(3, 4, true).set_border_width(3)
  414.  
  415.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('when mind % >= ')), 0, 1, 0, 1
  416.         tbl.attach widgets[:should_rest_mind], 1, 2, 0, 1
  417.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('or mana <= ')), 2, 3, 0, 1
  418.         tbl.attach widgets[:should_rest_mana], 3, 4, 0, 1
  419.  
  420.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('or encumbrance % >= ')), 0, 1, 1, 2
  421.         tbl.attach widgets[:should_rest_encum], 1, 2, 1, 2
  422.  
  423.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('or wounded eval: ')), 0, 1, 2, 3
  424.         tbl.attach widgets[:should_rest_wounded], 1, 4, 2, 3
  425.  
  426.         frm.add(tbl)
  427.         vbox.pack_start(frm)
  428.  
  429.         frm = Gtk::Frame.new('Resting').set_border_width(3)
  430.         tbl = Gtk::Table.new(2, 4, true).set_border_width(3)
  431.  
  432.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('room #: ')), 0, 1, 0, 1
  433.         tbl.attach widgets[:rest_room], 1, 2, 0, 1
  434.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('pre-rest commands: ')), 2, 3, 0, 1
  435.         tbl.attach widgets[:rest_pre_commands], 3, 4, 0, 1
  436.  
  437.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('enter commands: ')), 0, 1, 1, 2
  438.         tbl.attach widgets[:rest_in_commands], 1, 2, 1, 2
  439.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('exit commands: ')), 2, 3, 1, 2
  440.         tbl.attach widgets[:rest_out_commands], 3, 4, 1, 2
  441.  
  442.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('scripts: ')), 0, 1, 2, 3
  443.         tbl.attach widgets[:rest_scripts], 1, 4, 2, 3
  444.  
  445.         frm.add(tbl)
  446.         vbox.pack_start(frm)
  447.  
  448.         frm = Gtk::Frame.new('Should Hunt').set_border_width(3)
  449.         tbl = Gtk::Table.new(2, 4, true).set_border_width(3)
  450.  
  451.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('when mind % <= ')), 0, 1, 0, 1
  452.         tbl.attach widgets[:should_hunt_mind], 1, 2, 0, 1
  453.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('and mana >= ')), 2, 3, 0, 1
  454.         tbl.attach widgets[:should_hunt_mana], 3, 4, 0, 1
  455.  
  456.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('and spirit >= ')), 0, 1, 1, 2
  457.         tbl.attach widgets[:should_hunt_spirit], 1, 2, 1, 2
  458.  
  459.         frm.add(tbl)
  460.         vbox.pack_start(frm)
  461.  
  462.         frm = Gtk::Frame.new('Hunting').set_border_width(3)
  463.         tbl = Gtk::Table.new(2, 4, true).set_border_width(3)
  464.  
  465.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Pre-hunt commands: ')), 0, 1, 0, 1
  466.         tbl.attach widgets[:hunt_pre_commands], 1, 2, 0, 1
  467.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Commands (a): ')), 2, 3, 0, 1
  468.         tbl.attach widgets[:hunt_commands_a], 3, 4, 0, 1
  469.  
  470.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Commands (b): ')), 0, 1, 1, 2
  471.         tbl.attach widgets[:hunt_commands_b], 1, 2, 1, 2
  472.         tbl.attach Gtk::Alignment.new(1, 0, 0, 1).add(Gtk::Label.new('Commands (c): ')), 2, 3, 1, 2
  473.         tbl.attach widgets[:hunt_commands_c], 3, 4, 1, 2
  474.  
  475.         frm.add(tbl)
  476.         vbox.pack_start(frm)
  477.  
  478.         notebook.append_page vbox, Gtk::Label.new('Resting / Hunting')
  479.  
  480.         # main window widgets
  481.         vbox = Gtk::VBox.new
  482.         vbox.pack_start Gtk::Alignment.new(0, 1, 0, 0), false
  483.  
  484.         hbox = Gtk::HBox.new
  485.         hbox.add widgets[:gui_widgets][:save]
  486.         hbox.add widgets[:gui_widgets][:close]
  487.  
  488.         halign = Gtk::Alignment.new 1, 0, 0, 0
  489.         halign.add hbox
  490.  
  491.         vbox.pack_start halign
  492.         vbox_main.pack_start vbox
  493.  
  494.         # create the window
  495.         attach_signals.call
  496.         update_disabled.call
  497.         populate_locations.call
  498.  
  499.         window.add vbox_main
  500.         window.show_all
  501.     }
  502.  
  503.     before_dying { Gtk.queue { window.destroy unless window.nil? } }
  504.  
  505.     sleep 0.10 while action.nil?
  506.  
  507.     case action
  508.         when :save
  509.             CharSettings[:locations] = locations
  510.  
  511.             widgets.each { |key, widget|
  512.                 next if [:location_widgets, :gui_widgets].include?(key)
  513.  
  514.                 if widget.class == Gtk::CheckButton
  515.                     value = widget.active?
  516.                 elsif [:pre_search_commands, :post_search_commands, :hunt_pre_commands, :hunt_commands_a, :hunt_commands_b, :hunt_commands_c, :rest_in_commands, :rest_out_commands, :rest_pre_commands, :rest_scripts].include?(key)
  517.                     value = widget.text.strip.split(',').collect { |item| item.strip }
  518.                 elsif key == :should_rest_wounded
  519.                     value = StringProc.new widget.text.strip
  520.                 else
  521.                     value = widget.text.strip
  522.                 end
  523.  
  524.                 CharSettings[key] = value
  525.             }
  526.     end
  527. }
  528.  
  529. error = proc { |msg|
  530.     echo "** #{msg}"
  531.     exit
  532. }
  533.  
  534. print = proc { |msg|
  535.     echo "-- #{msg}"
  536. }
  537.  
  538. clean_skin = proc { |name|
  539.     name.strip.downcase.gsub(/s$/, '').gsub(/teeth/, 'tooth').gsub(/hooves?/, 'hoof')
  540. }
  541.  
  542. has_skins = proc {
  543.     if bounty? =~ /#{bounty_patterns['task_skin']}/
  544.         count = $1.to_i
  545.         skin  = $2.downcase
  546.  
  547.         skinsack.contents.find_all { |item| item.name =~ /#{clean_skin.call(skin)}/i }.size >= (count + 5)
  548.     else
  549.         false
  550.     end
  551. }
  552.  
  553. is_bounty = proc { |types|
  554.     result = []
  555.     types = [types] if types.class != Array
  556.  
  557.     types.each { |type| result.push(bounty_patterns[type]) if not bounty_patterns[type].nil? }
  558.  
  559.     !(bounty? =~ /#{result.join('|')}/).nil?
  560. }
  561.  
  562. get_bounty_location = proc {
  563.     location = target = nil
  564.  
  565.     # remove search only locations for hunting areas
  566.     locations = CharSettings[:locations].dup
  567.     if is_bounty.call ['task_skin', 'task_heirloom', 'task_dangerous', 'task_cull', 'task_rescue']
  568.         locations.delete_if { |name, data| data[:enable_search_only] }
  569.     end
  570.  
  571.     if bounty? =~ /#{bounty_patterns['task_skin']}/
  572.         # remember: don't swap the order or the global $ vars are lost!
  573.         target   = $3.strip.downcase
  574.         skin     = clean_skin.call($2)
  575.         location = locations.find { |name, data| $SBOUNTY_CLEAN_TARGETS.call(data[:targets]).find { |t| target =~ /#{t}/i } and data[:skins].find { |s| skin =~ /#{s.strip.downcase}/i }}
  576.     else
  577.         bounty_patterns.each { |key,value|
  578.             if bounty? =~ /#{value}/i
  579.                 target   = $1
  580.                 location = $2
  581.  
  582.                 break
  583.             end
  584.         }
  585.  
  586.         location = location.downcase.strip
  587.         location = locations.find { |name, data|
  588.             location =~ /#{data[:location].strip}/i and $SBOUNTY_CLEAN_TARGETS.call(data[:targets]).find {
  589.                 |t| target =~ /#{t}/i
  590.             }
  591.         }
  592.     end
  593.  
  594.     if location
  595.         name = location[0].dup
  596.         data = location[1].to_hash.dup
  597.  
  598.         if target
  599.             targets = data[:targets].dup
  600.             cleaned = $SBOUNTY_CLEAN_TARGETS.call(data[:targets])
  601.             index   = cleaned.index(cleaned.find { |t| target =~ /#{t}/i })
  602.             target  = targets[index]
  603.  
  604.             if is_bounty.call 'task_provoked' and target !~ /ancient|grizzled/i
  605.                 new_target = "(?:ancient|grizzled).*#{cleaned[index].split(' ').last}".downcase
  606.                 targets[target.index(target)] = new_target
  607.                 target = new_target
  608.             end
  609.         end
  610.  
  611.         if data[:enable_bounty_only]
  612.             targets = [ target ]
  613.         end
  614.  
  615.         data[:targets] = targets
  616.  
  617.         [name, data]
  618.     else
  619.         print.call 'could not find bounty location'
  620.         nil
  621.     end
  622. }
  623.  
  624. get_herb_rooms = proc { |location, herb|
  625.     rooms = Room.list.find_all { |room| room.location =~ /^(?:the)?\s*#{location.strip}/i and room.tags.find { |tag| tag =~ /#{herb}/i } }
  626.     rooms = rooms.collect { |r| r.id }
  627.  
  628.     previous, shortest_distances = Map.dijkstra(CharSettings[:rest_room])
  629.     rooms.delete_if { |room| shortest_distances[room].nil? or shortest_distances[room] > 60 }
  630. }
  631.  
  632. can_turn_in = proc {
  633.     echo "inside can_turn_in proc" if $sbounty_debug
  634.     echo "Current bounty: #{$current_bounty}" if $sbounty_debug
  635.     echo CharSettings[:turn_in_percent].to_i if $sbounty_debug
  636.     echo checkmind if $sbounty_debug
  637.     CharSettings[:turn_in_percent].nil?
  638.     is_bounty.call ['success', 'success_guard', 'success_heirloom'] and (CharSettings[:turn_in_percent].nil? or (percentmind >= CharSettings[:turn_in_percent].to_i and checkmind !~ /saturated/))
  639. }
  640.  
  641. can_do_bounty = proc {
  642.     echo "inside can_do_bounty" if $sbounty_debug
  643.     echo "is_bounty.call value: #{is_bounty.call}" if $sbounty_debug
  644.     #echo CharSettings[:enable_rescue] if $sbounty_debug
  645.     echo "Get_bounty_location.call value: #{get_bounty_location.call}" if $sbounty_debug
  646.     if not can_do_bounty_cache.nil?
  647.         ; # intentionally left blank
  648.     elsif is_bounty.call ['success', 'success_heirloom', 'success_guard']
  649.         can_do_bounty_cache = true
  650.     elsif is_bounty.call ['task_bandit'] and CharSettings[:enable_bandit]
  651.         can_do_bounty_cache = true
  652.     elsif ((is_bounty.call 'task_search' and CharSettings[:enable_search] and get_bounty_location.call) or (is_bounty.call 'task_heirloom' and CharSettings[:enable_loot] and get_bounty_location.call))
  653.         can_do_bounty_cache = true
  654.     elsif bounty? =~ /#{bounty_patterns['task_forage']}/ and CharSettings[:enable_forage] and not get_herb_rooms.call($2, $1).empty?
  655.         can_do_bounty_cache = true
  656.     elsif is_bounty.call 'task_skin' and CharSettings[:enable_skin] and get_bounty_location.call
  657.         can_do_bounty_cache = true
  658.     elsif is_bounty.call ['task_provoked', 'task_dangerous'] and CharSettings[:enable_dangerous] and get_bounty_location.call
  659.         can_do_bounty_cache = true
  660.     elsif is_bounty.call 'task_cull' and CharSettings[:enable_cull] and get_bounty_location.call
  661.         can_do_bounty_cache = true
  662.     elsif (is_bounty.call 'task_escort' and CharSettings[:enable_rescue]) or (is_bounty.call 'task_rescue' and CharSettings[:enable_rescue] and get_bounty_location.call)
  663.         can_do_bounty_cache = true
  664.     else
  665.         can_do_bounty_cache = false
  666.     end
  667.  
  668.     echo "can_do_bounty_cache return: #{can_do_bounty_cache}" if $sbounty_debug
  669.     can_do_bounty_cache
  670. }
  671.  
  672. should_hunt = proc {
  673.     echo "inside should_hunt" if $sbounty_debug
  674.     #exit
  675.     if (not can_do_bounty.call or is_bounty.call ['success', 'success_heirloom', 'success_guard'] or not CharSettings[:enable_hunt_complete]) and percentmind > CharSettings[:should_hunt_mind].to_i
  676.         hunt_reason = 'mind is full'
  677.         should_hunt_return = false
  678.         should_hunt_return = true if (can_do_bounty.call or is_bounty.call ['success', 'success_guard', 'success_heirloom']) and checkmind !~ /saturated/
  679.     elsif not checkmana(CharSettings[:should_hunt_mana].to_i)
  680.         hunt_reason = 'out of mana'
  681.         should_hunt_return = false
  682.     elsif not checkspirit(CharSettings[:should_hunt_spirit].to_i)
  683.         hunt_reason = 'low spirit'
  684.         should_hunt_return = false
  685.     else
  686.         should_hunt_return = true
  687.     end
  688.     echo "Should_hunt proc exiting." if $sbounty_debug
  689.     echo should_hunt_return if $sbounty_debug
  690.     should_hunt_return
  691. }
  692.  
  693. should_rest = proc {
  694.     echo "Inside should_rest proc" if $sbounty_debug
  695.     if CharSettings[:should_rest_wounded].call
  696.         rest_reason = 'wounded'
  697.         should_rest_return = true
  698.     elsif is_bounty.call 'task_forage' and can_do_bounty.call and Time.now.to_i < last_forage_attempt + last_forage_delay and percentmind >= CharSettings[:should_rest_mind].to_i
  699.         rest_reason = 'mind is full (waiting on foraging cooldown)'
  700.         should_rest_return = true
  701.     elsif ((not can_turn_in.call and is_bounty.call ['success', 'success_guard', 'success_heirloom']) or not can_do_bounty.call or not CharSettings[:enable_hunt_complete]) and percentmind >= CharSettings[:should_rest_mind].to_i
  702.         rest_reason = 'mind is full'
  703.         should_rest_return = true
  704.     elsif not checkmana(CharSettings[:should_rest_mana].to_i)
  705.         rest_reason = 'out of mana'
  706.         should_rest_return = true
  707.     elsif checkencumbrance(CharSettings[:should_rest_encum].to_i)
  708.         rest_reason = 'encumbered'
  709.         should_rest_return = true
  710.     #elsif is_bounty.call ['success', 'success_heirloom', 'success_guard'] and $current_bounty == "bandits"
  711.      #   rest_reason = 'Bandit task is done'
  712.       #  should_rest_turn = true
  713.     elsif $sbounty_rest
  714.         if $sbounty_rest_reason
  715.             rest_reason = $sbounty_rest_reason
  716.         else
  717.             rest_reason = '$sbounty_rest was set'
  718.         end
  719.  
  720.         $sbounty_rest        = false
  721.         $sbounty_rest_reason = nil
  722.  
  723.         should_rest_return = true
  724.     else
  725.         rest_reason = nil
  726.         should_rest_return = false
  727.     end
  728.     sleep 0.5
  729.     echo "Exiting should_rest with return value of: #{should_rest_return} and reason: #{rest_reason}" if $sbounty_debug
  730.     should_rest_return
  731. }
  732.  
  733. wander = proc { |boundaries|
  734.     room = Room.current
  735.     next_room_options = room.wayto.keys - boundaries
  736.     next_room_options.delete_if { |room_id| (room.timeto[room_id].class == Proc) and room.timeto[room_id].call.nil? }
  737.     next_room = next_room_options.find_all { |r| not $sbounty_wander_rooms.include?(r) }
  738.     if next_room.empty?
  739.         next_room = $sbounty_wander_rooms.find { |r| next_room_options.include?(r) }
  740.     else
  741.         next_room = next_room[rand(next_room.length)]
  742.     end
  743.     $sbounty_wander_rooms.delete(next_room)
  744.     $sbounty_wander_rooms.push(next_room)
  745.     way = room.wayto[next_room]
  746.     if way.class == String
  747.         move(way)
  748.     else
  749.         way.call
  750.     end
  751. }
  752.  
  753. go2 = proc { |room|
  754.     fput 'symbol of return' if Room.current.title.to_s =~ /Maaghara/
  755.     next if Room.current.id.to_s == room.to_s
  756.  
  757.     if checkarea =~ /table\]/i
  758.         fput 'stand' until standing?
  759.         move 'out'
  760.     end
  761.  
  762.     wait_while { running? 'go2' }
  763.     start_script('go2', [ room.to_s, '_disable_confirm_' ]);
  764.     wait_while { running? 'go2' }
  765. }
  766.  
  767. go2_nearest = proc { |list|
  768.     room = Room[CharSettings[:rest_room]].find_nearest(list)
  769.     if room.nil?
  770.         error.call "failed to find nearest room"
  771.     end
  772.  
  773.     go2.call(room)
  774. }
  775.  
  776. go2_nearest_tag = proc { |tag|
  777.     if checkarea =~ /table\]/i
  778.         fput 'stand' until standing?
  779.         fput 'out'
  780.     end
  781.  
  782.     town = Room[CharSettings[:rest_room]].find_nearest_by_tag('town')
  783.     room = Room[town].find_nearest_by_tag(tag)
  784.     if room.nil?
  785.         error.call "failed to find room by tag: #{tag}"
  786.     end
  787.  
  788.     go2.call(room)
  789. }
  790.  
  791. run_commands = proc { |commands|
  792.     next if commands.empty?
  793.  
  794.     if commands.class != Array
  795.         error.call "run_commands expects an input Array"
  796.     end
  797.  
  798.     commands.each { |command|
  799.         if command =~ /^script\s+(.*?)(\s|$)(.*)/i
  800.             script_name = $1
  801.             script_args = $3
  802.             if command =~ /\$/
  803.                 command_regex = /^script (\w+) (\S+)/.match(command)
  804.                 temp1 = eval("#{command_regex[2]}").to_s
  805.                 cmd_run_script(command_regex[1], temp1 )
  806.             else
  807.                 cmd_run_script(script_name, script_args )
  808.             end
  809.         else
  810.             fput(command)
  811.         end    
  812.     }
  813. }
  814.  
  815. run_scripts = proc { |scripts|
  816.     scripts.each { |script|
  817.         if script =~ /\$/
  818.             script_regex = /(\w+) (\S+)/.match(script)
  819.             args = eval("#{script_regex[2]}").to_s
  820.             script = script_regex[1]
  821.             cmd_run_script(script_regex[1], args )
  822.         else        
  823.             args   = script.split(' ')
  824.             script = args.shift
  825.             start_script(script, args, true)
  826.             wait_while { running? script }
  827.         end
  828.     }
  829. }
  830.  
  831.  
  832. def cmd_run_script( name, args )
  833.     if( args == nil || args =~ /^\s*$/ )
  834.         run_script( name, true )
  835.     else
  836.         args = args.split(/ /)
  837.         run_script( name, true, args )
  838.     end
  839. end
  840.  
  841.  
  842.     def run_script( name, pause_bigshot = false, args = [] )
  843.         if Script.running.find { |s| s.name.downcase == name.downcase }.paused or running? name
  844.             stop_script name
  845.             wait_while { running? name }
  846.         end
  847.  
  848.         start_script name, args
  849.         if pause_bigshot
  850.             wait_until { !running? name }
  851.         end
  852.     end
  853.  
  854.     def run_scripts( scripts, pause_bigshot = false )
  855.         scripts.each do |i|
  856.             tokens = i.split(/\s+/)
  857.             if( tokens.size > 1 )
  858.                 run_script( tokens[0], pause_bigshot, tokens[1..-1] )
  859.             else
  860.                 run_script( tokens[0], pause_bigshot )
  861.             end
  862.         end
  863.     end
  864.  
  865.  
  866. run_loot_script = proc {
  867.     wait_while { running? CharSettings[:loot_script] }
  868.     start_script(CharSettings[:loot_script], [], true)
  869.     wait_while { running? CharSettings[:loot_script] }
  870. }
  871.  
  872. hunt_prepare = proc {
  873.     run_commands.call(CharSettings[:hunt_pre_commands])
  874. }
  875.  
  876. rest_goto = proc {
  877.     if checkarea =~ /table\]/i
  878.         in_rest_area = true
  879.     end
  880.     next if in_rest_area
  881.  
  882.     if Spell[9825].known? && Map.current.image =~ /wl-graveyard/
  883.         start_script 'go2', [ '4141' ]
  884.         wait_while { running?('go2') }
  885.         fput "symbol of return"
  886.     end
  887.  
  888.     go2.call(CharSettings[:rest_room])
  889. }
  890.  
  891. rest_exit = proc {
  892.     if checkarea =~ /table\]/i
  893.         in_rest_area = true
  894.     end
  895.     next unless in_rest_area
  896.     if Room.current.id != CharSettings[:rest_room] and Room.current.path_to(CharSettings[:rest_room]).nil?
  897.         run_commands.call(CharSettings[:rest_out_commands])
  898.     end
  899.     in_rest_area = false
  900. }
  901.  
  902. rest_enter = proc {
  903.     if checkarea =~ /table\]/i
  904.         in_rest_area = true
  905.     end
  906.     next if in_rest_area
  907.     if Room.current.id != CharSettings[:rest_room] and Room.current.path_to(CharSettings[:rest_room]).nil?
  908.         run_commands.call(CharSettings[:rest_in_commands])
  909.     end
  910.     in_rest_area = true
  911. }
  912.  
  913. rest_run_scripts = proc {
  914.     rest_exit.call
  915.     run_scripts.call(CharSettings[:rest_scripts])
  916. }
  917.  
  918. reload_hunter = proc {
  919.     $SBOUNTY_HUNTER_SETUP.call(CharSettings.to_hash.dup, get_bounty_location.call)
  920.     $SBOUNTY_HUNTER_RELOAD.call
  921. }
  922.  
  923. start_hunter = proc { |location|
  924.     $SBOUNTY_HUNTER_SETUP.call(CharSettings.to_hash.dup, location)
  925.     start_script($SBOUNTY_HUNTER_NAME, [], false)
  926. }
  927.  
  928. finish_hunt = proc {
  929.     if running? $SBOUNTY_HUNTER_NAME
  930.         stop_script($SBOUNTY_HUNTER_NAME)
  931.         wait_while { running? $SBOUNTY_HUNTER_NAME }
  932.     end
  933.  
  934.     fput 'stance defensive' until checkstance('defensive') or checkstance('guarded')
  935.  
  936.     # pause to make sure looter isn't running
  937.     wait_while { running? CharSettings[:loot_script] }
  938.  
  939.     # run loot script in case the hunter wasn't able to clean up
  940.     if GameObj.npcs.find { |npc| npc.status =~ /dead/ } or is_bounty.call 'success_heirloom'
  941.         run_loot_script.call
  942.     end
  943. }
  944.  
  945. remove_bounty = proc {
  946.     next if (not CharSettings[:enable_expedite] and Spell['Next Bounty'].active? and stopbounty = false) or is_bounty.call 'none'
  947.  
  948.     rest_exit.call
  949.  
  950.     kill_script 'go2' if running? 'go2'
  951.  
  952.     go2_nearest_tag.call('advguild')
  953.  
  954.     print.call 'removing bounty, you have five seconds to kill me'
  955.     sleep 5.00
  956.  
  957.     npc = GameObj.npcs.find { |t| t.name =~ /taskmaster/i }
  958.     if npc.nil?
  959.         error.call 'failed to find taskmaster'
  960.     end
  961.  
  962.     ## A couple of bounties were being removed once they were completed.  Added error checking.
  963.     if can_turn_in.call == false
  964.     echo "is_bounty_call: #{is_bounty.call ['success', 'success_guard', 'success_heirloom']}" if $sbounty_debug
  965.     fput 'bounty'
  966.     sleep 1
  967.     res = dothistimeout "ask #{npc} about remove", 5, /^#{npc}.*?want to be removed|Trying to sneak/
  968.     if res =~ /Trying to sneak/
  969.         fput "ask #{npc} about bounty"
  970.     else
  971.         dothistimeout "ask #{npc} about remove", 5, /^#{npc}.*?have removed you/
  972.     end
  973.     else
  974.         # Double check to make sure bounty is not ready for completion.
  975.         echo "Error in bounty turn in. Please review!"
  976.         echo "is_bounty_call: #{is_bounty.call ['success', 'success_guard', 'success_heirloom']}"
  977.         fput 'bounty'
  978.         sleep 1
  979.         start_exec_script( <<-eos
  980.             kill_script 'sbounty' if running? 'sbounty';
  981.             kill_script 'bigshot' if running? 'bigshot';
  982.             kill_script 'go2' if running? 'go2';
  983.             sleep 2;
  984.             start_script 'sbounty';
  985.             eos
  986.         )
  987.         sleep 2
  988.     end
  989.     can_do_bounty_cache = nil
  990. }
  991.  
  992. expedite_bounty = proc {
  993.     print.call 'expediting bounty, you have five seconds to kill me'
  994.     sleep 5.00
  995.  
  996.     remove_bounty.call
  997.  
  998.     rest_exit.call
  999.     go2_nearest_tag.call('advguild')
  1000.  
  1001.     npc = GameObj.npcs.find { |t| t.name =~ /taskmaster/i }
  1002.     if npc.nil?
  1003.         error.call 'failed to find taskmaster'
  1004.     end
  1005.  
  1006.     res = dothistimeout "ask #{npc} about expedite", 5, /I'll expedite|You don't seem to have any expedited task reassignment|I still need to complete/
  1007.     if res =~ /expedited/
  1008.         expedite_left = false
  1009.     end
  1010.  
  1011.     can_do_bounty_cache = nil
  1012. }
  1013.  
  1014. get_bounty = proc {
  1015.     rest_exit.call
  1016.  
  1017.     go2_nearest_tag.call('advguild')
  1018.  
  1019.     npc = GameObj.npcs.find { |t| t.name =~ /taskmaster/i }
  1020.     res = dothistimeout "ask ##{npc.id} for bounty", 2, /(?:protective escort|creature problem|local gem dealer|local alchemist|local furrier|lost heirloom|local healer|local herbalist|local resident|bandit problem|I'm kind of busy right now)/
  1021.  
  1022.    if res.nil?
  1023.        error.call 'invalid response from taskmaster'
  1024.    elsif res =~ /Come back in about (\d+) minutes if you want another task./
  1025.        Spell['Next Bounty'].putup
  1026.        Spell['Next Bounty'].timeleft = $1.to_i
  1027.    elsif res =~ /Come back in about/
  1028.        Spell['Next Bounty'].putup
  1029.        Spell['Next Bounty'].timeleft = 5
  1030.    elsif res =~ /bandit/
  1031.        remove_bounty.call
  1032.    end
  1033.  
  1034.    can_do_bounty_cache = nil
  1035. }
  1036.  
  1037. talk_to_herbalist = proc {
  1038.    go2_nearest.call([ 3824, 1851, 10396, 640, 5722, 2406, 11002, 9505 ])
  1039.  
  1040.    if Room.current.id == 10396
  1041.        npc = 'maraene'
  1042.    else
  1043.        npc = GameObj.npcs.find { |t| t.name =~ /brother Barnstel|scarred Agarnil kris|healer|herbalist|merchant Kelph|famed baker Leaftoe|Akrash|old Mistress Lomara/i }
  1044.    end
  1045.  
  1046.    if is_bounty.call 'help_herbalist'
  1047.        res = dothistimeout "ask #{npc} about bounty", 5, /Yes, I do have a task for you/
  1048.        if res =~ /I've recently received an order for ([0-9]+) (.*?)\./
  1049.             print.call "received bounty from herbalist [#{$1} #{$2}]"
  1050.         end
  1051.     elsif bounty? =~ /#{bounty_patterns['task_forage']}/
  1052.         herb_name = $1.gsub(/s?$/,'')
  1053.         herbs     = lootsack.contents.find_all { |item| item.name =~ /#{herb_name}/ }
  1054.  
  1055.         if herbs.empty?
  1056.             error.call 'no herbs to turn in, why are you here?'
  1057.         end
  1058.  
  1059.         empty_hands
  1060.         herbs.each { |herb|
  1061.             fput "get ##{herb.id} from ##{lootsack.id}"
  1062.             result = dothistimeout "give ##{herb.id} to #{npc}", 3, /This looks perfect|That looks like it has been partially used up/
  1063.  
  1064.             if result !~ /perfect/
  1065.                 fput "drop ##{herb.id}"
  1066.             end
  1067.         }
  1068.         fill_hands
  1069.  
  1070.         if (checkleft == herb_name and GameObj.left.type =~ /herb/) or (checkright == herb_name and GameObj.right_hand.type =~ /herb/)
  1071.             fput 'drop ' + herb_name
  1072.         end
  1073.     else
  1074.         error.call 'why are you at the herbalist?'
  1075.     end
  1076.  
  1077.    
  1078.     if bounty? =~ /#{$stop_bounty}/
  1079.       stopbounty = true
  1080.       remove_bounty.call
  1081.       start_exec_script("sleep 2;start_script('sbounty')")
  1082.       exit
  1083.     end
  1084. }
  1085.  
  1086. talk_to_gemdealer = proc {
  1087.     go2_nearest_tag.call('gemshop')
  1088.  
  1089.     if Room.current.id == 10327
  1090.         npc = 'areacne'
  1091.     else
  1092.         npc = GameObj.npcs.find { |t| t.name =~ /dwarven clerk|gem dealer|jeweler|Zirconia/i }
  1093.     end
  1094.  
  1095.     res = dothistimeout "ask #{npc} about bounty", 5, /Yes, I do have a task for you/
  1096.     if res =~ /interested in purchasing an? (.*?)\. .* go round up ([0-9]+) of them/
  1097.         name  = $1
  1098.         count = $2.to_i
  1099.  
  1100.         print.call "-- received bounty from gem dealer [#{count} #{name}]"
  1101.     end
  1102. }
  1103.  
  1104. talk_to_furrier = proc {
  1105.     go2_nearest_tag.call('furrier')
  1106.  
  1107.     if Room.current.id == 10327
  1108.         npc 'areacne'
  1109.     else
  1110.         npc = GameObj.npcs.find { |t| t.name =~ /dwarven clerk|furrier/i }
  1111.     end
  1112.  
  1113.     res = dothistimeout "ask #{npc} about bounty", 5, /Yes, I do have a task for you/
  1114.     if res =~ /I've recently received an order for ([0-9]+) (.*?)\./
  1115.        print.call "received bounty from furrier [#{$1} #{$2}]"
  1116.    end
  1117. }
  1118.  
  1119. get_guard_npc = proc {
  1120.    if Room.current.id == 10915
  1121.        'purser'
  1122.    else
  1123.        GameObj.npcs.find { |npc| npc.name =~ /guard|sergeant|guardsman|purser/i }
  1124.    end
  1125. }
  1126.  
  1127. find_guard = proc {
  1128.    go2_nearest_tag.call('advguard')
  1129.    npc = get_guard_npc.call
  1130.  
  1131.    if npc.nil?
  1132.        go2_nearest_tag.call('advguard2')
  1133.        npc = get_guard_npc.call
  1134.    end
  1135.  
  1136.    if npc.nil?
  1137.        error.call "failed to locate guard"
  1138.    end
  1139.  
  1140.    npc
  1141. }
  1142.  
  1143. talk_to_guard = proc {
  1144.    npc = find_guard.call
  1145.  
  1146.    res = dothistimeout "ask #{npc} about bounty", 5, /Yes, we do have a task for you|Ah, so you have returned/
  1147.    if res.nil?
  1148.        print.call "unknown response from guard: #{res}"
  1149.    end
  1150. }
  1151.  
  1152. get_random_location = proc {
  1153.    keys = []
  1154.    CharSettings[:locations].each { |key, data|
  1155.        if data[:enable_hunting_rotation]
  1156.            keys.push(key)
  1157.        end
  1158.    }
  1159.    name = keys[rand(keys.size)]
  1160.  
  1161.    if name.nil?
  1162.        error.call 'failed to find a hunting area'
  1163.    end
  1164.  
  1165.    [ name, CharSettings[:locations][name] ]
  1166. }
  1167.  
  1168. task_escort = proc { |target|
  1169.    print.call "escorting child to #{target}"
  1170.  
  1171.    path  = []
  1172.    step2 = proc { |destination_room|
  1173.        unless path and (s = path.index(Room.current.id)) and (d = path.index(destination_room)) and (s < d)
  1174.            previous, shortest_distances = Map.dijkstra(Room.current.id, destination_room)
  1175.            unless previous[destination_room]
  1176.                echo "error: failed to find a path between your current room (#{Room.current.id}) and destination room (#{destination_room})"
  1177.                exit
  1178.            end
  1179.            path = [ destination_room ]
  1180.            path.push(previous[path[-1]]) until previous[path[-1]].nil?
  1181.            path.reverse!
  1182.            previous = shortest_distances = nil
  1183.        end
  1184.  
  1185.        way = Room.current.wayto[path[path.index(Room.current.id)+1].to_s]
  1186.  
  1187.        if way.class == String
  1188.            move way
  1189.        elsif way.class == Proc
  1190.            way.call
  1191.        end
  1192.    }
  1193.  
  1194.    waitrt?
  1195.    fput 'stance defensive' unless checkstance('guarded')
  1196.  
  1197.    destination = Room[CharSettings[:rest_room]].find_nearest_by_tag(target)
  1198.    while Room.current.id != destination and is_bounty.call 'task_escort'
  1199.        if GameObj.npcs.find { |n| n.name =~ /child/i }
  1200.            step2.call(destination)
  1201.        end
  1202.        sleep 0.25
  1203.    end
  1204.  
  1205.    if is_bounty.call 'fail_child'
  1206.        print.call 'failed to escort child or child was killed'
  1207.    elsif npc = get_guard_npc.call
  1208.        print.call 'waiting for child to arrive'
  1209.        wait_until { GameObj.npcs.find { |n| n.name =~ /child/ } }
  1210.  
  1211.        if Room.current.id == 10915
  1212.            fput "ask purser for bounty"
  1213.        else
  1214.            fput "ask ##{npc.id} for bounty"
  1215.        end
  1216.    elsif target == 'advguard'
  1217.        task_escort.call 'advguard2'
  1218.    else
  1219.        error.call 'failed to find guard for escort'
  1220.    end
  1221. }
  1222.  
  1223. task_search = proc {
  1224.    if bounty? !~ /#{bounty_patterns['task_search']}/
  1225.        error.call 'you are not on a search bounty'
  1226.    end
  1227.  
  1228.    print.call 'searching for heirloom'
  1229.  
  1230.    name, location = get_bounty_location.call
  1231.    song_of_peace  = false
  1232.    invalid_rooms  = []
  1233.    last_room      = nil
  1234.  
  1235.    hunt_prepare.call
  1236.    rest_exit.call
  1237.  
  1238.    go2.call location[:room]
  1239.  
  1240.    while is_bounty.call 'task_search' and not CharSettings[:should_rest_wounded].call
  1241.        if Spell[1011].known? and Spell[1011].affordable? and not song_of_peace
  1242.            Spell[1011].cast
  1243.            song_of_peace = true
  1244.        end
  1245.  
  1246.        wander.call location[:boundaries]
  1247.  
  1248.        fput 'stand' until standing?
  1249.        fput 'stance defensive' until checkstance 'defensive' or checkstance 'guarded'
  1250.  
  1251.        if (GameObj.npcs.empty? or GameObj.npcs.nil?) and Room.current.location =~ /#{location[:location].downcase.strip}/i and not invalid_rooms.include? Room.current.id and Room.current.id != last_room
  1252.            run_commands.call CharSettings[:pre_search_commands]
  1253.  
  1254.            fput 'kneel' until kneeling?
  1255.            res = dothistimeout 'search', 1, /You intently search the area|You put your head to the ground and peer intently/
  1256.            if res =~ /You intently search the area|You put your head to the ground and peer intently/
  1257.                last_room = Room.current.id
  1258.            else
  1259.                print.call 'invalid room, skipping in the future'
  1260.                invalid_rooms.push Room.current.id
  1261.            end
  1262.  
  1263.            waitrt?
  1264.  
  1265.            run_commands.call CharSettings[:post_search_commands]
  1266.  
  1267.            while not checkstance 'offensive' and (song_of_peace or GameObj.npcs.find_all { |npc| npc.status !~ /dead/ }.nil?)
  1268.                fput 'stance offensive'
  1269.            end
  1270.  
  1271.            fput 'stand' until standing?
  1272.  
  1273.            fput 'stance defensive' until checkstance 'defensive' or checkstance 'guarded'
  1274.  
  1275.            if is_bounty.call 'task_found'
  1276.                run_loot_script.call
  1277.                break
  1278.            end
  1279.        end
  1280.    end
  1281.  
  1282.    waitrt?
  1283.  
  1284.    if song_of_peace
  1285.        fput "stop 1011"
  1286.    end
  1287. }
  1288.  
  1289. task_bandits = proc {
  1290.    if bounty? !~ /#{bounty_patterns['task_bandit']}/
  1291.        error.call 'you are not on a bandits bounty'
  1292.    end
  1293.  
  1294.    $current_bounty = 'bandits'
  1295.    print.call 'culling bandits'
  1296.  
  1297.    my_ambush = false
  1298.    ambush_room_count = XMLData.room_count
  1299.  
  1300.    location = $1.strip.downcase
  1301.    rooms = Room.list.find_all { |r| r.location =~ /#{location}/i }.collect { |r| r.id }
  1302.    attack_script = 'ubermonk'
  1303.  
  1304.    while not CharSettings[:should_rest_wounded].call
  1305.        rooms.each { |room|
  1306.            waitrt?
  1307.            waitcastrt?
  1308.  
  1309.            print.call 'moving to room ' + room.to_s
  1310.  
  1311.            fput 'stance defensive' unless checkstance == 'defensive'
  1312.  
  1313.            go2.call(room)
  1314.            sleep 1
  1315.  
  1316.            while not should_rest.call or not can_turn_in.call
  1317.                npcs = GameObj.npcs.to_a.find_all { |npc| npc.type =~ /bandit/ and npc.status !~ /dead/ }
  1318.                dead = GameObj.npcs.to_a.find_all { |npc| npc.type =~ /bandit/ and npc.status =~ /dead/ }
  1319.  
  1320.                if npcs.empty?
  1321.                    break
  1322.                else
  1323.                    waitrt?
  1324.                    waitcastrt?
  1325.  
  1326.                    $bandits = false
  1327.                    #start_script(attack_script, npcs.collect { |n| n.id }, h={:quiet=>true})
  1328.                    start_script "#{attack_script}"
  1329.                    wait_while { running?(attack_script) }
  1330.                end
  1331.  
  1332.                sleep 0.1
  1333.                echo "Inside bandits attack loop" if $sbounty_debug
  1334.                echo "should_rest.call: #{should_rest.call} can_turn_in: #{can_turn_in.call}" if $sbounty_debug
  1335.            
  1336.            end
  1337.  
  1338.            echo "Outside bandits attack loop" if $sbounty_debug
  1339.            echo "should_rest.call: #{should_rest.call} can_turn_in: #{can_turn_in.call}" if $sbounty_debug
  1340.  
  1341.            break if should_rest.call or can_turn_in.call
  1342.        }
  1343.  
  1344.        sleep 0.1
  1345.    end
  1346. }
  1347.  
  1348. task_forage = proc {
  1349.    echo bounty?
  1350.    if bounty? !~ /#{bounty_patterns['task_forage']}/
  1351.        error.call 'you are not on a forage bounty'
  1352.    end
  1353.  
  1354.    print.call 'foraging for herbs'
  1355.  
  1356.    herb     = $1.downcase
  1357.    location = $2
  1358.    count    = $3.to_i
  1359.  
  1360.    if bounty? =~ /#{$stop_bounty}/
  1361.        stopbounty = true
  1362.        remove_bounty.call
  1363.        start_exec_script("sleep 2;start_script('sbounty')")
  1364.        exit
  1365.    end
  1366.  
  1367.    refresh_spells = proc {
  1368.        [506, 603, 9704].each { |spell|
  1369.            if Spell[spell].known? and not Spell[spell].active? and Spell[spell].affordable?
  1370.                waitrt?
  1371.                waitcastrt?
  1372.  
  1373.                Spell[spell].cast
  1374.            end
  1375.        }
  1376.  
  1377.        yierka          = Spell['AA: Yierka']
  1378.        yierka_cooldown = Spell['AA: Yierka Cooldown']
  1379.  
  1380.        if yierka.known? and yierka.affordable? and not yierka_cooldown.active?
  1381.            yierka.cast
  1382.        end
  1383.    }
  1384.  
  1385.    get_herb_count = proc {
  1386.        lootsack.contents.find_all { |item| item.name =~ /#{herb.gsub(/s?$/,'')}/i }.size
  1387.    }
  1388.  
  1389.    last_forage_attempt = Time.now.to_i
  1390.  
  1391.    if not get_herb_count.call >= count
  1392.        hunt_prepare.call
  1393.        rest_exit.call
  1394.  
  1395.        rooms = get_herb_rooms.call(location, herb)
  1396.  
  1397.        cur_room  = 0
  1398.        num_tries = 0
  1399.  
  1400.        song_of_peace = false
  1401.  
  1402.        while not get_herb_count.call >= count and not CharSettings[:should_rest_wounded].call and num_tries < 3
  1403.            go2.call(rooms[cur_room])
  1404.            cur_room = cur_room + 1
  1405.  
  1406.            if cur_room >= rooms.length
  1407.                cur_room  = 0
  1408.                num_tries = num_tries + 1
  1409.            end
  1410.  
  1411.            while not get_herb_count.call >= count and not CharSettings[:should_rest_wounded].call
  1412.                if Spell[1011].known? and Spell[1011].affordable? and not song_of_peace
  1413.                    Spell[1011].cast
  1414.                    song_of_peace = true
  1415.                end
  1416.  
  1417.                waitrt?
  1418.                fput 'stance defensive' unless checkstance == 'defensive'
  1419.  
  1420.                refresh_spells.call
  1421.  
  1422.                if not song_of_peace and not GameObj.npcs.find_all { |npc| npc.status !~ /dead|gone/ }.nil?
  1423.                    break
  1424.                end
  1425.  
  1426.                if not kneeling?
  1427.                    run_commands.call(CharSettings[:pre_search_commands])
  1428.                    fput "kneel" until kneeling?
  1429.  
  1430.                    if Spell[213].known? and Spell[213].affordable?
  1431.                        fput "incant 213"
  1432.                    end
  1433.  
  1434.                    if Spell[205].known? and Spell[205].affordable?
  1435.                        fput "incant 205"
  1436.                    end
  1437.                end
  1438.  
  1439.                res = dothistimeout "forage #{herb.gsub(/(?:(?:handful|bunch|sprig) of)\s+/, '') }", 1, /not even positive|it could be|it could even be found|and manage to find|Roundtime|In order to forage|foraging here recently/
  1440.  
  1441.                 if res =~ /it could be|it could even be found|not even positive/
  1442.                    rooms.delete(cur_room)
  1443.                     break
  1444.                 elsif res =~ /and manage to find/
  1445.                     if checkleft =~ /#{herb}/
  1446.                         fput "put #{checkleft} in ##{lootsack.id}"
  1447.                     else
  1448.                         fput "put #{checkright} in ##{lootsack.id}"
  1449.                     end
  1450.  
  1451.                     print.call "-- success, found #{get_herb_count.call} of #{count} #{herb}"
  1452.                 elsif res =~ /In order to forage/
  1453.                     fput "stow all"
  1454.                 elsif res =~ /foraging here recently/
  1455.                    rooms.delete(cur_room)
  1456.                     break
  1457.                 else
  1458.                     print.call "-- failure, found #{get_herb_count.call} of #{count} #{herb}"
  1459.                 end
  1460.            end
  1461.  
  1462.            # Sanity check, cleanup any remaining herbs
  1463.            if checkleft =~ /#{herb}/
  1464.                fput "put #{checkleft} in ##{lootsack.id}"
  1465.            elsif checkright =~ /#{herb}/
  1466.                fput "put #{checkright} in ##{lootsack.id}"
  1467.            end
  1468.  
  1469.            if not standing?
  1470.                run_commands.call(CharSettings[:post_search_commands])
  1471.  
  1472.                while not checkstance 'offensive' and (song_of_peace or GameObj.npcs.find_all { |npc| npc.status !~ /dead/ }.nil?)
  1473.                    fput 'stance offensive'
  1474.                end
  1475.  
  1476.                fput 'stance defensive' until checkstance 'defensive' or checkstance 'guarded'
  1477.  
  1478.                fput "stand" until standing?
  1479.            end
  1480.        end
  1481.    end
  1482.  
  1483.    if song_of_peace
  1484.        fput "stop 1011"
  1485.    end
  1486.  
  1487.    if get_herb_count.call >= count
  1488.        talk_to_herbalist.call
  1489.        last_forage_attempt = 0
  1490.    end
  1491. }
  1492.  
  1493. success_heirloom = proc {
  1494.    print.call 'turning in heirloom'
  1495.  
  1496.    npc = find_guard.call
  1497.  
  1498.    empty_hands
  1499.  
  1500.    close = false
  1501.    if lootsack.contents.nil?
  1502.        open_result = dothistimeout "open ##{lootsack.id}", 5, /^You open|^That is already open\.$/
  1503.        if open_result =~ /^You open/
  1504.            close = true
  1505.        else
  1506.            dothistimeout "look in ##{lootsack.id}", 5, /In .*? you see/
  1507.        end
  1508.    end
  1509.  
  1510.    found = false
  1511.    lootsack.contents.each { |item|
  1512.        res = dothistimeout "look ##{item.id}", 2, /^Engraved .* initials|^You see nothing unusual\.$|^The ring appears|^It takes you a moment|^It is difficult to see/
  1513.        if res =~ /^Engraved .* initials/
  1514.            fput "get ##{item.id}"
  1515.            fput "give ##{item.id} to #{npc}"
  1516.            found = true
  1517.  
  1518.            break
  1519.        end
  1520.    }
  1521.  
  1522.    fput "close ##{lootsack.id}" if close
  1523.  
  1524.    if not found
  1525.        error.call 'failed to find heirloom for guard'
  1526.    end
  1527.  
  1528.    fill_hands
  1529. }
  1530.  
  1531. turn_in = proc {
  1532.    rest_exit.call
  1533.  
  1534.    if is_bounty.call 'success_guard'
  1535.        talk_to_guard.call
  1536.    elsif is_bounty.call 'success_heirloom'
  1537.        success_heirloom.call
  1538.    end
  1539.  
  1540.    go2_nearest_tag.call('advguild')
  1541.  
  1542.    npc = GameObj.npcs.find { |t| t.name =~ /taskmaster/i }
  1543.    res = dothistimeout "ask #{npc} about bounty", 5, /^#{npc}.*?done with that assignment/
  1544.    10.times {
  1545.        if line = get? and line =~ /You have earned ([0-9]+) bounty points?, ([0-9]+) experience points, and ([0-9]+) silver\./
  1546.            print.call "finished task (#{$1} points, #{$2} exp, #{$3} silver)"
  1547.            break
  1548.            sleep 1
  1549.            sleep 76 if checkrt > 0
  1550.        end
  1551.  
  1552.        sleep 0.1
  1553.    }
  1554.  
  1555.    run_loot_script.call
  1556.  
  1557.    can_do_bounty_cache = nil
  1558. }
  1559.  
  1560. talk_to_npc = proc {
  1561.    if is_bounty.call ['help_creature', 'help_resident', 'help_heirloom', 'success_guard']
  1562.        talk_to_guard.call
  1563.    # separate bandits so we don't trigger them on accident while walking
  1564.     elsif is_bounty.call ['help_bandit'] and CharSettings[:enable_bandit]
  1565.         talk_to_guard.call
  1566.     elsif is_bounty.call 'help_furrier'
  1567.         talk_to_furrier.call
  1568.     elsif is_bounty.call 'help_herbalist'
  1569.         talk_to_herbalist.call
  1570.     elsif is_bounty.call 'help_gemdealer'
  1571.         talk_to_gemdealer.call
  1572.     end
  1573. }
  1574.  
  1575. help = proc {
  1576.     respond
  1577.     respond 'SpiffyBounty by SpiffyJr (theman@spiffyjr.me)'
  1578.     respond 'usage: ;sbounty [hunter=bigshot]'
  1579.     respond
  1580. }
  1581.  
  1582. hunter = 'sbounty-bigshot'
  1583.  
  1584. if script.vars[1] =~ /^setup$/i
  1585.     setup.call
  1586.     exit
  1587. elsif script.vars[1] =~ /^help$/i
  1588.     help.call
  1589.     exit
  1590. elsif script.vars[1] =~ /^forage$/i
  1591.     task_forage.call
  1592.     exit
  1593. elsif script.vars[1] =~ /^npc$/i
  1594.     talk_to_npc.call
  1595.     exit
  1596. elsif script.vars[1]
  1597.     hunter = "sbounty-#{script.vars[1]}"
  1598. end
  1599.  
  1600. task_accepted = false
  1601. resting       = false
  1602.  
  1603. start_script(hunter, nil, true)
  1604. wait_while { running? hunter }
  1605.  
  1606. if not defined? $SBOUNTY_HUNTER_SETUP
  1607.     error.call 'hunter setup was not defined'
  1608. elsif not defined? $SBOUNTY_HUNTER_NAME
  1609.     error.call 'hunter name was not defined'
  1610. elsif not defined? $SBOUNTY_HUNTER_RELOAD
  1611.     error.call 'hunter reload was not defined'
  1612. end
  1613.  
  1614. before_dying { kill_script $SBOUNTY_HUNTER_NAME if running? $SBOUNTY_HUNTER_NAME }
  1615.  
  1616. while true
  1617.     echo "start of total loop" if $sbounty_debug
  1618.     talk_to_npc.call
  1619.  
  1620.     if can_do_bounty.call and not CharSettings[:should_rest_wounded].call
  1621.         if is_bounty.call 'task_search'
  1622.             task_search.call
  1623.         elsif is_bounty.call 'task_forage' and Time.now.to_i >= last_forage_attempt + last_forage_delay
  1624.             task_forage.call
  1625.         end
  1626.     elsif Spell['Next Bounty'].active? and (expedite_left and not is_bounty.call 'none' and not can_do_bounty.call and CharSettings[:enable_expedite])
  1627.         expedite_bounty.call
  1628.         next
  1629.     end
  1630.  
  1631.     if is_bounty.call 'task_escort' and GameObj.npcs.find { |npc| npc.name =~ /child/ }
  1632.         task_escort.call 'advguard'
  1633.     elsif is_bounty.call 'task_fail'
  1634.         can_do_bounty_cache = nil
  1635.     elsif is_bounty.call 'success_heirloom'
  1636.         success_heirloom.call
  1637.     end
  1638.  
  1639.     exit if dead?
  1640.  
  1641.     if can_turn_in.call
  1642.         turn_in.call
  1643.         resting = false
  1644.     else
  1645.         echo "total loop: in hunting check" if $sbounty_debug
  1646.         echo "should_hunt_call: #{should_hunt.call} should_rest.call: #{should_rest.call}" if $sbounty_debug
  1647.         echo "can_do_bounty: #{can_do_bounty.call}" if $sbounty_debug
  1648.         if not can_do_bounty.call and not Spell['Next Bounty'].active?
  1649.             remove_bounty.call
  1650.             get_bounty.call
  1651.         elsif should_hunt.call and not should_rest.call and not has_skins.call
  1652.             resting  = false
  1653.             provoked = false
  1654.             success  = false
  1655.             bounty   = bounty?
  1656.  
  1657.             rest_exit.call
  1658.             hunt_prepare.call
  1659.  
  1660.             # default hunter location
  1661.             if can_do_bounty.call
  1662.                 # order is important here - bandits and regular culling look similar
  1663.                 if is_bounty.call ['task_bandit']
  1664.                     task_bandits.call
  1665.                 elsif is_bounty.call ['task_cull', 'task_dangerous', 'task_heirloom', 'task_rescue', 'task_skin']
  1666.                     start_hunter.call(get_bounty_location.call)
  1667.                 else
  1668.                     start_hunter.call(get_random_location.call)
  1669.                 end
  1670.             else
  1671.                 start_hunter.call(get_random_location.call)
  1672.             echo "Exiting can_do_bounty.call" if $sbounty_debug
  1673.             echo "Is_bounty.call value: #{is_bounty.call}" if $sbounty_debug
  1674.             end
  1675.  
  1676.             while not should_rest.call and running? $SBOUNTY_HUNTER_NAME
  1677.                 if bounty? =~ /#{bounty_patterns['task_provoked']}/ and not provoked
  1678.                     reload_hunter.call
  1679.                     provoked = true
  1680.                 elsif is_bounty.call 'task_escort'
  1681.                     break
  1682.                 elsif has_skins.call
  1683.                     break
  1684.                 elsif not success and (bounty? != bounty and (is_bounty.call [ 'success', 'success_heirloom' ] or (provoked and is_bounty.call 'success_guard')))
  1685.                     finish_hunt.call
  1686.                     start_hunter.call(get_random_location.call)
  1687.  
  1688.                     success = true
  1689.                 elsif can_turn_in.call
  1690.                     break
  1691.                 elsif not can_do_bounty.call and not Spell['Next Bounty'].active?
  1692.                     break
  1693.                 end
  1694.  
  1695.                 sleep 0.10
  1696.             end
  1697.             echo "Exiting while not should_rest.call and running? $SBOUNTY_HUNTER_NAME LOOP." if $sbounty_debug
  1698.  
  1699.             finish_hunt.call
  1700.         elsif not can_turn_in.call
  1701.             rest_goto.call
  1702.  
  1703.             if not resting or CharSettings[:should_rest_wounded].call
  1704.                 rest_run_scripts.call
  1705.                 rest_goto.call
  1706.  
  1707.                 sleep 1
  1708.             end
  1709.  
  1710.             rest_enter.call
  1711.  
  1712.             while not should_hunt.call or should_rest.call
  1713.                 echo "Inside rest loop." if $sbounty_debug
  1714.                 if can_turn_in.call
  1715.                     break
  1716.                 elsif CharSettings[:should_rest_wounded].call
  1717.                     break
  1718.                 elsif not can_do_bounty.call and not Spell['Next Bounty'].active?
  1719.                     break
  1720.                 elsif (can_do_bounty.call or is_bounty.call ['success', 'success_guard', 'success_heirloom']) and should_hunt.call
  1721.                     break
  1722.                 end
  1723.  
  1724.                 fput 'exp'
  1725.                 dothistimeout 'hide', 2, /^Roundtime/ if !hidden?
  1726.                 waitrt?
  1727.  
  1728.                 if rest_reason.nil?
  1729.                     rest_reason = hunt_reason
  1730.                 end
  1731.                 print.call "still resting because: #{rest_reason}"
  1732.  
  1733.                 sleep CharSettings[:rest_sleep_interval]
  1734.             end
  1735.  
  1736.             resting = true
  1737.             rest_exit.call
  1738.         end
  1739.     end
  1740.  
  1741.     sleep 0.10
  1742. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement