Created
October 28, 2018 20:18
-
-
Save sandersch/41ea3e28389bd2081893743bb43cf6d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imbed_info_for = proc do |spell_num| | |
item, info = UserVars.imbeds.find do |(imbed_name, imbed_info)| | |
imbed_info[:spell] == spell_num | |
end | |
info.merge(item_name: item) | |
end | |
find_magicsack = proc do | |
GameObj[UserVars.magicsack] or raise "Couldn't find magic sack" | |
end | |
find_imbed_in_inventory = proc do |imbed_name| | |
GameObj.inv.find { |item| item.name == imbed_name } | |
end | |
find_imbed_in_magicsack = proc do |imbed_name| | |
magicsack = find_magicsack.call | |
fput "look in ##{magicsack.id}" if magicsack.contents.none? | |
magicsack.contents.find do |item| | |
item.name == imbed_name | |
end | |
end | |
find_imbed_gameobj = proc do |spell_num| | |
imbed_name = imbed_info_for[spell_num].fetch(:item_name) | |
find_imbed_in_inventory.call(imbed_name) || find_imbed_in_magicsack.call(imbed_name) | |
end | |
imbed_has_charges_of = proc do |spell_num| | |
imbed_info = imbed_info_for[spell_num] | |
if imbed_info.nil? | |
echo "ERROR: couldn't find #{spell_num} item in imbed list" | |
false | |
elsif !find_imbed_gameobj[spell_num] | |
echo "ERROR: couldn't find #{spell_num} item in magic sack" | |
false | |
elsif imbed_info[:use_last_charge] | |
imbed_info[:charges] > 0 | |
else | |
imbed_info[:charges] > 1 | |
end | |
end | |
magicsack = find_magicsack.call | |
if !magicsack.contents | |
fput "look in ##{magicsack.id}" | |
30.times do | |
break if magicsack.contents | |
sleep 0.1 | |
end | |
end | |
#spells_to_activate = [1701,1712].tap do |spells| | |
#spells << 1711 if ["Empath"].include? Char.prof | |
## Kind of a hack: | |
## Refresh common imbeds not managed by this script if in check mode | |
#if variable[1] == "check" | |
#spells << 117 unless Spell[117].known? | |
#end | |
#end.map(&:to_i).reject(&:zero?) | |
#CharSettings['spells_to_activate'] = spells_to_activate | |
CharSettings['spells_to_activate'] ||= [] | |
spells_to_activate = CharSettings['spells_to_activate'].map(&:to_i).uniq | |
echo spells_to_activate.inspect | |
missing_imbeds = spells_to_activate.reject { |spell_num| imbed_has_charges_of[spell_num] } | |
if script.vars[1] == "add" | |
script.vars.shift | |
if script.vars[1] =~ /^\d+/ | |
spell_num = script.vars[1].to_i | |
CharSettings['spells_to_activate'] << spell_num | |
CharSettings['spells_to_activate'].sort!.uniq! | |
CharSettings.save | |
respond | |
respond "Added #{spell_num} to list: #{CharSettings['spells_to_activate'].join(", ")}" | |
respond | |
exit | |
else | |
echo "ERROR: didn't recognize #{script.vars[1].inspect} as a spell number" | |
exit | |
end | |
elsif script.vars[1] =~ /del|rem/ | |
script.vars.shift | |
if script.vars[1] =~ /^\d+/ | |
spell_num = script.vars[1].to_i | |
CharSettings['spells_to_activate'].delete(spell_num) | |
CharSettings.save | |
respond | |
respond "Removed #{spell_num} from list: #{CharSettings['spells_to_activate'].join(", ")}" | |
respond | |
exit | |
else | |
echo "ERROR: didn't recognize #{script.vars[1].inspect} as a spell number" | |
exit | |
end | |
elsif script.vars[1] == "list" | |
respond | |
respond "Spell list: #{CharSettings['spells_to_activate'].join(", ")}" | |
respond | |
exit | |
elsif variable[1] =~ /check|restock/ | |
missing_spells = UserVars.imbeds.reject do |imbed_name, imbed_info| | |
imbed_has_charges_of[imbed_info[:spell]] | |
end.map do |imbed_name, imbed_info| | |
imbed_info[:spell] | |
end | |
if missing_spells.any? | |
respond | |
respond "Missing the follow imbeds:" | |
respond | |
respond "| Spell | Imbed Description |" | |
respond "|-------|--------------------------------------------------|" | |
missing_spells.each do |spell_num| | |
respond "| %5s | %-48s |" % [spell_num, imbed_info_for[spell_num][:item_name]] | |
end | |
respond | |
if variable[1] =~ /restock/ | |
starting_spot = Room.current.id | |
missing_spells.each do |spell_num| | |
echo "INFO: need to get item: #{spell_num}" | |
if obj = find_imbed_gameobj[spell_num] | |
fput "get ##{obj.id}" | |
fput "put ##{obj.id} in my #{Vars.lootsack}" | |
end | |
item_name = imbed_info_for[spell_num][:item_name] | |
echo item_name.inspect | |
start_script "grabfromlocker", [item_name, "--no-return"] | |
wait_while { running? "grabfromlocker" } | |
if find_imbed_gameobj[spell_num] | |
start_script "setimbed", ["\"#{item_name}\"", "40"] | |
wait_while { running? "setimbed" } | |
else | |
echo "WARNING: doesn't seem like we could find a #{item_name} with #{spell_num}" | |
#exit | |
end | |
end | |
Script.run("go2", starting_spot) | |
echo "INFO: imbeds refreshed" | |
end | |
else | |
echo "INFO: all imbeds available" | |
start_script "useimbed", ["list"] | |
end | |
exit | |
else | |
missing_imbeds.each do |spell_num| | |
echo "INFO: unable to activate #{spell_num}" | |
end | |
end | |
loop do | |
(spells_to_activate - missing_imbeds).each do |spell_num| | |
unless Spell[spell_num].active? | |
echo "INFO: activating #{spell_num} item" | |
start_script "useimbed", [spell_num] | |
wait_while { running? "useimbed" } | |
end | |
end | |
sleep 10 | |
end | |
#echo "1711 item is out of charges!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment