-
Notifications
You must be signed in to change notification settings - Fork 178
/
afk.lic
121 lines (98 loc) · 3.82 KB
/
afk.lic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#afk
=end
custom_require.call(%w[common equipmanager])
no_pause_all
no_kill_all
def exit_game(message)
output = "#{message}\nCurrent room: #{Room.current.id}\nExiting at #{Time.now}"
echo output
send_slackbot_message(output)
pause 2
fput('exit')
end
def idle?(line)
return true if line =~ /you have been idle too long/i
if $_IDLETIMESTAMP_ && $_SCRIPTIDLETIMESTAMP_
return true if Time.now - $_IDLETIMESTAMP_ > 360 && Time.now - $_SCRIPTIDLETIMESTAMP_ > 360
end
false
end
echo 'Afk script started - pausing for 10 seconds or until health passes threshold'
pause 10
settings = get_settings
health_threshold = settings.health_threshold.to_i
depart_on_death = settings.depart_on_death
depart_type = settings.depart_type
justice_threshold = settings.afk_justice_threshold
warning_threshold = (100 + health_threshold) / 2
warned = false
equipment_manager = EquipmentManager.new
register_slackbot(settings.slack_username)
pause 1 while DRStats.health < [health_threshold + 20, 100].min || DRStats.spirit < [health_threshold + 20, 100].min
justice_message_count = 0
spell_check_count = 0
loop do
line = script.gets?
pause 0.05 unless line
fput(%w[tdp time age].sample) if idle?(line)
justice_message_count += 1 if line =~ /^"Burn .+! Burn .+!" .* giving you a wide berth/
justice_message_count += 1 if line =~ /authorities will try to bring you in for endangering the public/
if justice_message_count != spell_check_count
DRSpells.active_spells.each { |x, _y| fput("release #{get_data("spells")["spell_data"][x]["abbrev"]} spell") if get_data("spells")["spell_data"][x]["triggers_justice"] }
spell_check_count = justice_message_count
end
if justice_message_count > justice_threshold
exit_game("It looks like you've run into trouble with the law too many times")
end
if line =~ /For a current status of how many items you have, use LOOK PORTAL./
echo "Looks like you're in the junk yard. We'll log you out in 60 seconds unless you exit the junk yard. You can also ';kill afk' to stay in the game, just remember to restart it once you get out of the junk yard."
junk_timer = Time.now
while XMLData.room_title == '[[A Junk Yard]]'
pause 1
exit_game('Exiting from the Junk Yard') if Time.now - junk_timer > 60
end
end
if line =~ /^You should empty your hands first/
equipment_manager.empty_hands
stop_script('go2') if Script.running?('go2')
end
if line =~ /^You notice .* at your feet, and do not wish to leave it behind/ || line =~ /You find yourself unable to sneak with items at your feet/
DRCI.stow_hand('left') unless !DRC.right_hand || !DRC.left_hand
while DRC.bput('stow feet', /You pick up/, /Stow what/) =~ /You pick up/
end
stop_script('go2') if Script.running?('go2')
end
if XMLData.room_title.include?('Skeletal Claw') && Room.current.id == 9610
DRC.fix_standing
move('out')
end
if dead?
echo '*' * 30
echo 'Afk - detected death departing in 3 minutes'
echo '*' * 30
pause 60
echo '*' * 30
echo 'Afk - detected death departing in 2 minutes'
echo '*' * 30
pause 60
echo '*' * 30
echo 'Afk - detected death departing in 1 minute'
echo '*' * 30
pause 60
fput("depart #{depart_type}") if depart_on_death
exit_game('You died!')
end
if !warned && (DRStats.health < warning_threshold || DRStats.spirit < warning_threshold)
echo 'Afk - approaching low vitality/spirit threshold'
warned = true
end
if warned && DRStats.health > warning_threshold && DRStats.spirit > warning_threshold
warned = false
end
next unless DRStats.health < health_threshold || DRStats.spirit < health_threshold
fput('health')
echo 'Turning off avoids'
fput('avoid all')
exit_game('Detected low vitality/spirit health')
end