Skip to content

Commit

Permalink
Merge pull request #6744 from MahtraDR/common_tune_instruments
Browse files Browse the repository at this point in the history
[scripts][common] Add ability to tune tunable instruments
  • Loading branch information
MahtraDR authored Dec 20, 2023
2 parents 643c88c + 173e564 commit a74a12f
Showing 1 changed file with 74 additions and 7 deletions.
81 changes: 74 additions & 7 deletions common.lic
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ module DRC
g
end

def play_song?(settings, song_list, worn = true, skip_clean = false, climbing = false)
def play_song?(settings, song_list, worn = true, skip_clean = false, climbing = false, skip_tuning = false)
instrument = worn ? settings.worn_instrument : settings.instrument

if UserVars.instrument.nil?
Expand All @@ -658,28 +658,35 @@ module DRC
play_command = play_command + " on my #{instrument}"
end
fput('release ecry') if DRSpells.active_spells["Eillie's Cry"].to_i > 0
result = bput(play_command, 'too damaged to play', 'dirtiness may affect your performance', 'slightest hint of difficulty', 'fumble slightly', /Your .+ is submerged in the water/, 'You begin a', 'You struggle to begin', 'You\'re already playing a song', 'You effortlessly begin', 'You begin some', 'You cannot play', 'Play on what instrument', 'Are you sure that\'s the right instrument', 'now isn\'t the best time to be playing', 'Perhaps you should find somewhere drier before trying to play', 'You should stop practicing', /^You really need to drain/)
result = bput(play_command, 'too damaged to play', 'dirtiness may affect your performance', 'slightest hint of difficulty', 'fumble slightly', /Your .+ is submerged in the water/, 'You begin a', 'You struggle to begin', 'You\'re already playing a song', 'You effortlessly begin', 'You begin some', 'You cannot play', 'Play on what instrument', 'Are you sure that\'s the right instrument', 'now isn\'t the best time to be playing', 'Perhaps you should find somewhere drier before trying to play', 'You should stop practicing', /^You really need to drain/, /Your .* tuning is off, and may hinder your performance/)
case result
when 'Play on what instrument', 'Are you sure that\'s the right instrument'
snapshot = "#{right_hand}#{left_hand}"
fput("get #{instrument}")
return false if snapshot == "#{right_hand}#{left_hand}"

fput("wear #{instrument}") if worn
play_song?(settings, song_list, worn, skip_clean, climbing)
play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning)
when 'now isn\'t the best time to be playing', 'Perhaps you should find somewhere drier before trying to play', 'You should stop practicing'
false
when 'You\'re already playing a song'
fput('stop play')
play_song?(settings, song_list, worn, skip_clean, climbing)
play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning)
when 'You cannot play'
wait_for_script_to_complete('safe-room')
when /Your .* tuning is off, and may hinder your performance/
DRC.message("Instrument out of tune. Attempting to tune it.")
return true if DRSkill.getrank('Performance') < 20
return true if skip_tuning
return true unless DRC.tune_instrument(settings)

play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning)
when 'dirtiness may affect your performance', /^You really need to drain/
return true if DRSkill.getrank('Performance') < 20
return true if skip_clean
return true unless clean_instrument(settings, worn)

play_song?(settings, song_list, worn, skip_clean, climbing)
play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning)
when 'slightest hint of difficulty', 'fumble slightly'
true
when 'You begin a', 'You effortlessly begin', 'You begin some'
Expand All @@ -690,7 +697,7 @@ module DRC
stop_playing
UserVars.climbing_song = song_list[UserVars.climbing_song] || song_list.first.first if climbing
UserVars.song = song_list[UserVars.song] || song_list.first.first unless climbing
play_song?(settings, song_list, worn, skip_clean, climbing)
play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning)
when 'You struggle to begin'
return true if song_to_play == song_list.first.first
# Ignore difficulty messages if we have an offset
Expand All @@ -699,7 +706,7 @@ module DRC
stop_playing
UserVars.climbing_song = song_list.first.first if climbing
UserVars.song = song_list.first.first unless climbing
play_song?(settings, song_list, worn, skip_clean, climbing)
play_song?(settings, song_list, worn, skip_clean, climbing, skip_tuning)
else
false
end
Expand Down Expand Up @@ -763,6 +770,66 @@ module DRC
true
end

def tune_instrument(settings)
instrument = settings.worn_instrument || settings.instrument

unless instrument
DRC.message("Neither worn_instrument, nor instrument set. Doing nothing.")
return false
end

DRC.stop_playing

unless (DRC.left_hand.nil? && DRC.right_hand.nil?) || DRCI.in_hands?(instrument)
DRC.message("Need two free hands. Not tuning now.")
return false
end

if settings.worn_instrument
unless DRCI.remove_item?(instrument) || DRCI.in_hands?(instrument)
DRC.message("Could not remove #{instrument}. Not trying to tune.")
DRC.beep
return false
end
else
unless DRCI.get_item?(instrument) || DRCI.in_hands?(instrument)
DRC.message("Could not get #{instrument}. Not trying to tune.")
DRC.beep
return false
end
end
DRC.do_tune(instrument)
waitrt?
pause 1
DRCI.wear_item?(instrument) if settings.worn_instrument
true
end

def do_tune(instrument, tuning = "")
unless instrument && DRCI.in_hands?(instrument)
DRC.message("No instrument found in hands. Not trying to tune.")
DRC.beep
return false
end

case DRC.bput("tune my #{instrument} #{tuning}",
/^You should be sitting up/,
/After a moment, you .* flat/,
/After a moment, you .* sharp/,
/After a moment, you .* perfect tune/)
when /After a moment, you .* perfect tune/
DRC.message("Instrument tuned.")
return true
when /After a moment, you .* flat/
DRC.do_tune(instrument, "sharp")
when /After a moment, you .* sharp/
DRC.do_tune(instrument, "flat")
when /^You should be sitting up/
DRC.fix_standing
DRC.do_tune(instrument)
end
end

def pause_all
return false unless $pause_all_lock.try_lock

Expand Down

0 comments on commit a74a12f

Please sign in to comment.