forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
safe-room.lic
194 lines (157 loc) · 4.59 KB
/
safe-room.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#safe-room
=end
custom_require.call(%w(common common-healing common-money common-travel drinfomon events))
class SafeRoom
include DRC
include DRCH
include DRCM
include DRCT
def initialize
arg_definitions = [
[
{ name: 'force', regex: /force/i, optional: true, description: 'Run healing logic even if there are no visible wounds' }
]
]
args = parse_args(arg_definitions)
settings = get_settings
@health_threshold = settings.saferoom_health_threshold
return unless args.force || need_healing?
if use_pc_empath?(settings.safe_room_id, settings.safe_room_empath)
ensure_copper_on_hand(settings.safe_room_tip_threshold || 0, settings.hometown)
tip(settings.safe_room_tip_threshold, settings.safe_room_tip_amount, settings.safe_room_empath)
elsif DRStats.empath?
walk_to(settings.safe_room)
wait_for_script_to_complete('healme')
elsif !DRStats.necromancer?
ensure_copper_on_hand(4_000, settings.hometown)
Flags.add('healthy', 'Dokt waves a large hand at you', 'Dokt gives you a quick glance', 'go have yourself a birthday party', 'you are well', 'have other patients', 'you look fine and healthy', 'A little rest and exercise')
Flags.add('moved', 'grabs you and drags you')
Flags.add('idle', 'you have been idle too long')
town_data = get_data('town')
hometown = town_data[settings.hometown]
wait_at_empath(hometown['npc_empath']['id'])
fix_standing
end
give_and_take(settings.safe_room_id, settings.safe_room_give, settings.safe_room_take)
end
def need_healing?
if bleeding? || checkpoison
echo "***STATUS*** Bleeding: #{bleeding?}, poison: #{checkpoison}"
return true
end
health_hash = check_health
unless health_hash.any?
echo '***STATUS*** No wounds, skipping healing'
return false
end
score = health_hash.map { |k, v| (k**2) * v.count }.reduce(:+)
echo "***STATUS*** Current health score is #{score}, threshold is #{@health_threshold}"
score > @health_threshold
end
def check_idle
return unless Flags['idle']
Flags.reset('idle')
fput('tdp')
end
def wait_for_healing
Flags.reset('healthy')
Flags.reset('moved')
until Flags['healthy'] || Flags['moved']
lie_down
pause 1
check_idle
end
wait_for_healing if Flags['moved']
end
def wait_at_empath(room_id)
walk_to room_id
unless Room.current.id == room_id
beep
beep
echo 'ERROR Navigating to safe room'
return
end
if DRRoom.pcs.empty? || DRRoom.pcs_prone.empty?
wait_for_healing
return
end
people_in_front = DRRoom.pcs - DRRoom.pcs_sitting
echo "people_in_front: #{people_in_front}" if UserVars.safe_room_debug
while bleeding?
lie_down
pause 10
end
fix_standing
counter = 0
while counter < 10
pause 1
if DRRoom.pcs_prone.empty? || (DRRoom.pcs_prone & people_in_front).empty?
counter += 1
else
counter = 0
end
check_idle
break if ((DRRoom.pcs - DRRoom.pcs_sitting) & people_in_front).empty?
end
wait_for_healing
end
def lie_down
bput('lie', 'You lie') if standing?
end
def use_pc_empath?(room_id, empath)
return false unless room_id
return false unless empath
walk_to room_id
return false unless DRRoom.pcs.include?(empath)
fput("whisper #{empath} heal")
fput("listen to #{empath}")
pause 45
!need_healing?
end
def give_and_take(room_id, give_items, take_items)
return unless room_id
return unless give_items || take_items
walk_to room_id
give(give_items)
take(take_items)
end
def tip(tip_threshold, tip_amount, empath)
return unless tip_threshold
return unless wealth > tip_threshold
return unless tip_amount
return unless empath
minimize_coins(tip_amount).each do |amount|
fput "give #{empath} #{amount}"
end
end
def give(items)
items.each do |item|
loop do
case bput("get my #{item}", 'You get', 'What were you referring')
when 'You get'
fput "drop #{item}"
else
break
end
end
end
end
def take(items)
items.each do |item|
break unless stow?(item)
end
end
def stow?(item)
DRRoom.room_objs.grep(/#{item}/).each do |_|
fput "stow #{item}"
pause 1
next unless [right_hand, left_hand].grep(/#{item}/i)
fput "drop #{item}"
pause 1
return false
end
true
end
end
SafeRoom.new