Skip to content

Commit

Permalink
Merge pull request #1419 from Deysh/BlackArts
Browse files Browse the repository at this point in the history
[blackarts] v1.0.1 bugfix troll's blood, gird command, and cauldron check
  • Loading branch information
mrhoribu authored Feb 20, 2024
2 parents b7cea79 + ad21a85 commit 31d681a
Showing 1 changed file with 133 additions and 27 deletions.
160 changes: 133 additions & 27 deletions scripts/BlackArts.lic
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,36 @@
contributors: Deysh, Tysong, Gob
game: Gemstone
tags: alchemy
version: 1.0.0
version: 1.1.0
Improvements:
Major_change.feature_addition.bugfix
v1.1.0 (2024-01-16)
- added help section
- added ;blackarts finish to stop script after current task is complete (use when script is running)
- bugfix for checking troll's blood
- bugfix for gird command if brawler
- bugfix for cauldron check if only buying elusive reagents
- bugfix for meditation regex
- bugfix: script was looping when user mastered a skill or reached max guild ranks
=end
=begin
v1.0.0 (2023-06-19)
- Initial creation
=end

require 'yaml'

begin
require 'terminal-table' unless defined?(Terminal::Table)
rescue LoadError
respond "You need to have the 'terminal-table' gem installed"
respond "Please install it with the following command: gem install terminal-table"
respond "Via your computer's local terminal/shell"
exit
end

# Recipes
module BlackArts
module Recipes
Expand Down Expand Up @@ -3852,6 +3873,36 @@ end
# Util
module BlackArts
module Util
def self.help
rows = []
rows << ["#{$lich_char}#{Script.current.name}", "Runs guild tasks based on UI settings"]
rows << [' ', ' ']
rows << ["#{$lich_char}#{Script.current.name} setup", "UI configuration tool"]
rows << ["#{$lich_char}#{Script.current.name} load", "Reloads settings from yaml file"]
rows << ["#{$lich_char}#{Script.current.name} list", "Lists settings from yaml file"]
rows << [' ', ' ']
rows << ["#{$lich_char}#{Script.current.name} check <recipe> x<amount>", "Checks if you have ingredients"]
rows << ["#{$lich_char}#{Script.current.name} make <recipe> x<amount>", "Makes a recipe a number of times"]
rows << ["#{$lich_char}#{Script.current.name} prepare <recipe> x<amount>", "Prepares any sub-recipes needed"]
rows << [' ', ' ']
rows << ["#{$lich_char}#{Script.current.name} guild", "Travels to the alchemy administrator"]
rows << ["#{$lich_char}#{Script.current.name} remove <alchemy|potions|trinkets>", "Trades task in"]
rows << [' ', ' ']
rows << ["#{$lich_char}#{Script.current.name} buy", "Buys consignment items"]
rows << ["#{$lich_char}#{Script.current.name} clean", "Attempts to organize/sell alchemy items"]
rows << ["#{$lich_char}#{Script.current.name} forage <herb to find> x<number>", "Forages herbs"]
rows << ["#{$lich_char}#{Script.current.name} suggest", "Lists potential recipes for current tasks"]
rows << [' ', ' ']
rows << ["#{$lich_char}#{Script.current.name} --debug=<on|off>", "Turns debug on/off for troubleshooting"]
rows << ["#{$lich_char}#{Script.current.name} finish", "Stops after the current task (script running)"]

table = Terminal::Table.new :title => "BlackArts Help", :rows => rows
table.align_column(1, :right)
respond
respond table
respond
end

def self.add_commas(num)
num.to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse
end
Expand Down Expand Up @@ -3935,7 +3986,7 @@ module BlackArts
end
end

if result =~ /You kneel down and begin to meditate/
if result =~ /You kneel down and begin to meditate|You begin to meditate/
waitfor 'You wake from your meditation', 'Your action interrupts your meditation'
end

Expand Down Expand Up @@ -4198,7 +4249,6 @@ module BlackArts
"Cysaegir",
"Icemule Trace",
"Kharam-Dzu",
"Kharam-Dzu",
"Mist Harbor",
"Moonshine Manor",
"Solhaven",
Expand Down Expand Up @@ -4539,6 +4589,28 @@ module BlackArts
}
end

def self.set_hooks
original_once = BlackArts.data.settings[:once_and_done]

finish = proc { |server_string|
if server_string =~ /^(?:<c>)?;bla(.*)finish(.*)/i
BlackArts.data.settings[:once_and_done] = true
Util.msg("info", " BlackArts will exit after the next task is completed")
elsif server_string =~ /Please rephrase that command/
nil
else
server_string
end
}

UpstreamHook.add('stop_alchemy', finish)

before_dying {
UpstreamHook.remove('stop_alchemy')
BlackArts.data.settings[:once_and_done] = original_once
}
end

def self.set_needed_reagents
ingredient_list = Array.new
check_proc = proc { |recipe|
Expand Down Expand Up @@ -4575,14 +4647,14 @@ module BlackArts
else
UserVars.needed_reagents = "^#{ingredient_list.join('$|^')}$"
end
# Util.msg("debug", "Util.set_needed_reagents: ingredient_list - #{ingredient_list}")
# Util.msg("info", "Util.set_needed_reagents: ingredient_list - #{ingredient_list}")
end

def self.set_variables(check_equipment = true, just_basic = false)
is_error = false

# Sort the skills
BlackArts.data.settings[:skill_types] = BlackArts.data.settings[:skill_types].sort
BlackArts.data.settings[:skill_types].sort!

# Set guild groups for travel
BlackArts.data.start_town = Room[Room.current.find_nearest_by_tag("town")].id
Expand All @@ -4591,7 +4663,7 @@ module BlackArts
BlackArts.data.east_guilds.delete_if { |id| !BlackArts.data.cities.include?(id) || (id == 3668 && UserVars.mapdb_fwi_trinket.nil?) }

# Set Home Guild
if BlackArts.data.settings[:home_guild] == 'Closest' || BlackArts.data.settings[:home_guild].nil?
if BlackArts.data.settings[:home_guild] == 'Closest' || BlackArts.data.settings[:home_guild].nil? || BlackArts.data.settings[:home_guild].empty?
BlackArts.data.current_admin = Room.current.find_nearest_by_tag("#{Char.prof.downcase} alchemy administrator")
else
guild_town = Map.list.find { |room| room.location.to_s =~ /#{BlackArts.data.settings[:home_guild]}/ }
Expand Down Expand Up @@ -4697,7 +4769,7 @@ module BlackArts
return if BlackArts.data.settings[:no_bank]
ending_silver = Util.silver_check

return if ending_silver.zero?
return if ending_silver.zero? && currency == 'silver'

Util.travel('bank')
fput("deposit #{currency}")
Expand All @@ -4716,8 +4788,6 @@ module BlackArts
def self.suggestion
guild_status = Guild.gld

# guild_status = {"guild"=>{:standing=>"member", :guild_master=>false, :checkin=>80, :vouchers=>69, :total_ranks=>159}, "alchemy"=>{:rank=>54, :task=>"visit the cauldron workshop and practice making solutions with your boil ability", :reps=>9}, "potions"=>{:rank=>54, :task=>"no task", :reps=>0}, "trinkets"=>{:rank=>54, :task=>"no task", :reps=>0}}

all_recipes = Guild.gld_suggestions(guild_status)

output = "\n"
Expand Down Expand Up @@ -4927,7 +4997,7 @@ module BlackArts
Util.go2(room_id)
else
fput 'stance defensive' unless stance =~ /defensive|guarded/
Util.get_res('gird', BlackArts.data.get_regex)
Util.get_res('gird', BlackArts.data.get_regex) unless Skills.brawling >= (Char.level / 1.5)
Util.go2(room_id)
Util.get_res('store right', BlackArts.data.put_regex) if checkright
Util.get_res('store left', BlackArts.data.put_regex) if checkleft
Expand Down Expand Up @@ -6689,7 +6759,7 @@ module BlackArts
tracker[:recipe_count][recipe[:product]] = tracker[:recipe_count][recipe[:product]].to_i + 1
recipe[:steps].each { |step| tracker[:finish_steps].push(step) unless step =~ /^buy|^forage|^kill/ }
else
recipe[:steps].each { |step| tracker[:prepare_steps].push(step) unless step =~ /^buy|^forage|^kill/ }
recipe[:steps].each { |step| tracker[:prepare_steps].push(step) unless step =~ /^buy|^forage|^kill|check blood/ }
end
recipe[:steps].each { |step| tracker[:steps].push(step) unless step =~ /^buy|^forage|^kill/ }
if recipe[:product] =~ /^(?:s'|t')?ayanad crystal$/
Expand All @@ -6703,7 +6773,7 @@ module BlackArts

def self.gld_suggestions(guild_status)
if guild_status.values.any? { |hash| hash[:recipes].nil? }
for type in guild_status.keys
guild_status.each_key do |type|
if guild_status[type][:task] =~ /(?:with your|that involve) (.*?)(?: ability| mana|ing spells|ing|ing mana|ing spirit)?$/
required_step = $1
if guild_status[type][:task] =~ /cauldron workshop/
Expand Down Expand Up @@ -6779,8 +6849,9 @@ module BlackArts
task['guild'][:checkin] = amount.to_i
elsif line =~ /have (.*?) task trading vouchers/i
task['guild'][:vouchers] = $1.to_i
elsif line =~ /You currently have (.*?) rank/
elsif line =~ /You currently have (.*?) ranks? out of a possible (.*?) for your training/
task['guild'][:total_ranks] = $1.to_i
task['guild'][:max_ranks] = $2.to_i
end
}
BlackArts.data.ranks = task["alchemy"][:rank].to_i
Expand Down Expand Up @@ -6866,6 +6937,15 @@ module BlackArts
def self.get_work(item)
Util.travel(BlackArts.data.current_admin)

guild_status = Guild.gld

if guild_status['guild'][:max_ranks] == guild_status['guild'][:total_ranks]
respond
Util.msg("yellow", " Your total ranks equal your max guild ranks. You need to level up more to continue. Exiting...")
respond
exit
end

lines = Util.get_command("ask ##{GameObj.npcs.find { |npc| npc.name =~ /training/i }.id} to train #{item}", /You ask|Who are you trying to ask/i)

# Exit if Run one task and quit
Expand All @@ -6877,6 +6957,11 @@ module BlackArts
exit
end

if lines.any?(/but you're a Master.*?already/)
BlackArts.data.settings[:skill_types].reject! { |skill| skill == item }
item = nil
end

if lines.any? { |l| l =~ /It seems that your general alchemy skills are not quite up to snuff/ }
respond
Util.msg("info", " Seems you need to train more general alchemy before continuing with #{item}. Exiting...")
Expand Down Expand Up @@ -6904,6 +6989,10 @@ module BlackArts
exit
end

['alchemy', 'potions', 'trinkets'].each do |type|
BlackArts.data.settings[:skill_types].reject! { |skill| skill == type } if guild_status[type][:rank] == 63
end

if guild_status['guild'][:vouchers] == 0 && BlackArts.data.settings[:use_vouchers]
# Do we have voucher packs?
voucher_pack = BlackArts.data.sacks["default"].contents.find { |i| i.name == 'Elanthian Guilds voucher pack' }
Expand All @@ -6916,6 +7005,10 @@ module BlackArts

if skill.nil?
skill = BlackArts.data.settings[:skill_types].map { |type| [type, guild_status.dig(type, :rank).to_i] }.min_by { |_type, rank| rank }[0]
if skill.nil?
Util.msg("yellow", " No skills available for training. Please check UI")
exit
end
end

Guild.activity(guild_status, skill)
Expand Down Expand Up @@ -7152,10 +7245,10 @@ module BlackArts
end
end

def self.buy_elusive
def self.buy_elusive(buy_only = false)
return unless BlackArts.data.settings[:buy_reagents]

Guild.get_cauldron
Guild.get_cauldron unless buy_only

unless UserVars.needed_reagents.nil? or UserVars.needed_reagents.empty?
Util.travel('town')
Expand Down Expand Up @@ -8484,12 +8577,17 @@ module BlackArts
end
end

if Script.current.vars.any? { |var| var =~ /help/ }
BlackArts::Util.help
exit
end

if Char.prof !~ /cleric|empath|sorcerer|wizard/i
BlackArts::Util.msg("orange", " This script will not work for the #{Char.prof} class. Exiting...")
# exit
exit
end

if script.vars.any? { |var| var =~ /^--debug=(on|off|true|false|yes|no)$/i }
if Script.current.vars.any? { |var| var =~ /^--debug=(on|off|true|false|yes|no)$/i }
fix_option = { 'on' => true, 'true' => true, 'yes' => true, 'off' => false, 'false' => false, 'no' => false }
BlackArts.load(BlackArts.load_profile()) unless BlackArts.data
BlackArts::Setup.update_setting(:debug, fix_option[$1])
Expand Down Expand Up @@ -8520,8 +8618,9 @@ BlackArts::Util.track_room
BlackArts.data.mortar_check = true

# Default to running guild tasks
if script.vars[1].nil?
if Script.current.vars[1].nil?
BlackArts::Util.set_variables
BlackArts::Util.set_hooks

current_settings = UserVars.op
before_dying {
Expand All @@ -8533,15 +8632,19 @@ if script.vars[1].nil?
end

case Script.current.vars[1].downcase
when 'help'
# Fixme
# BlackArts.help
when 'buy'
return_room = Room.current.id
BlackArts::Util.set_variables(false)
BlackArts::Actions.buy_elusive
BlackArts::Util.silver_deposit
BlackArts::Util.travel(return_room)
if (Time.now - BlackArts.data.last_alchemy_buy) > 600
return_room = Room.current.id
BlackArts::Util.set_variables(false)
BlackArts::Actions.buy_elusive(true)
BlackArts::Util.silver_deposit('all')
BlackArts::Util.travel(return_room)
else
total_seconds = 600 - (Time.now - BlackArts.data.last_alchemy_buy)
minutes = (total_seconds / 60).to_i
seconds = (total_seconds % 60).to_i
BlackArts::Util.msg("yellow", " Last buy was less than 10 minutes ago. Next buy in #{minutes} minutes and #{seconds} seconds")
end
when /clean/
return_room = Room.current.id
BlackArts::Util.set_variables(false)
Expand All @@ -8551,7 +8654,6 @@ when /clean/
when 'forage'
BlackArts::Util.set_variables(false)
BlackArts::Util.only_forage(Script.current.vars)

when /^(check|make|prepare)$/i
BlackArts::Util.set_variables
BlackArts::Util.prep_create(Script.current.vars)
Expand Down Expand Up @@ -8581,4 +8683,8 @@ when 'suggest'
BlackArts::Util.suggestion
when 'test'
BlackArts::Util.test
when 'finish'
BlackArts::Util.msg "yellow", ' This command only works while the script is running'
else
BlackArts::Util.help
end

0 comments on commit 31d681a

Please sign in to comment.