forked from rpherbig/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common-travel.lic
126 lines (108 loc) · 4.13 KB
/
common-travel.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
# quiet
=begin
Documentation: https://elanthipedia.play.net/Lich_script_development#common-travel
=end
custom_require.call(%w[common common-arcana events drinfomon])
module DRCT
module_function
def walk_to(target_room, restart_on_fail = true)
Flags.add('closed-shop', 'The door is locked up tightly for the night', 'You smash your nose')
return false if target_room.nil?
room_num = target_room.to_i
return true if room_num == Room.current.id
DRC.fix_standing
if Room.current.id.nil?
echo "In an unknown room, manually attempting to navigate to #{room_num}"
rooms = Map.list.select { |room| room.description.include?(XMLData.room_description.strip) && room.title.include?(XMLData.room_title) }
if rooms.empty? || rooms.length > 1
echo 'failed to find a matching room'
return false
end
room = rooms.first
return true if room_num == room.id
if room.wayto[room_num.to_s]
move room.wayto[room_num.to_s]
return room_num == room.id
end
path = Map.findpath(room, Map[room_num])
move room.wayto[path.first.to_s]
return walk_to(room_num)
end
start_script('go2', [room_num.to_s], force: true)
timer = Time.now
prev_room = XMLData.room_description + XMLData.room_title
while Script.running?('go2')
if Flags['closed-shop']
Flags.reset('closed-shop')
kill_script('go2')
if /You / !~ DRC.bput('open door', 'It is locked', 'You ', 'What were')
return false
end
timer = Time.now
start_script 'go2', [room_num.to_s]
end
if (Time.now - timer) > 90
kill_script('go2')
pause 0.5 while Script.running?('go2')
timer = Time.now
break unless restart_on_fail
start_script('go2', [room_num.to_s])
end
if Script.running?('escort') || Script.running?('bescort') || (XMLData.room_description + XMLData.room_title) != prev_room || XMLData.room_description =~ /The terrain constantly changes as you travel along on your journey/
timer = Time.now
end
prev_room = XMLData.room_description + XMLData.room_title
pause 0.5
end
# Consider just returning this boolean and letting callers decide what to do on a failed move.
if room_num != Room.current.id && restart_on_fail
echo "Failed to navigate to room #{room_num}, attempting again"
walk_to room_num
end
room_num == Room.current.id
end
def retreat(ignored_npcs = [])
return if (DRRoom.npcs - ignored_npcs).empty?
DRC.retreat(ignored_npcs)
end
def find_empty_room(search_rooms, idle_room, predicate = nil, min_mana = 0, strict_mana = false)
check_mana = min_mana > 0
loop do
found_empty = false
search_rooms.each do |room_id|
walk_to(room_id)
pause 0.1 until room_id == Room.current.id
suitable_room = predicate ? predicate.call : (DRRoom.pcs - DRRoom.group_members).empty?
if suitable_room && check_mana && !DRStats.moon_mage?
found_empty = true
suitable_room = (DRCA.perc_mana >= min_mana)
end
return true if suitable_room
end
if found_empty && check_mana && !strict_mana
check_mana = false
echo '*** Empty rooms found, but not with the right mana. Going to use those anyway! ***'
next
end
(check_mana = min_mana > 0) && !check_mana
if idle_room
walk_to(idle_room)
echo '***Failed to find an empty room, pausing***'
pause 30
else
echo '***Failed to find an empty room, stopping the search***'
return false
end
end
end
def sort_destinations(target_list)
target_list = target_list.collect(&:to_i)
_previous, shortest_distances = Map.dijkstra(Room.current.id)
target_list.delete_if { |room_num| shortest_distances[room_num].nil? && room_num != Room.current.id }
target_list.sort { |a, b| shortest_distances[a] <=> shortest_distances[b] }
end
def find_sorted_empty_room(search_rooms, idle_room, predicate = nil)
sorted_rooms = sort_destinations(search_rooms)
find_empty_room(sorted_rooms, idle_room, predicate)
end
end