-
Notifications
You must be signed in to change notification settings - Fork 8
/
wander.lic
172 lines (164 loc) · 5.77 KB
/
wander.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
=begin
This script replaces walk.lic
Moves around randomly in any direction defined in the map database, trying not to backtrack.
Stops in a room only if:
there is a live, targetable npc in the room
there are no characters in the room that aren't in your group
there is no disk in the room that belongs to someone not in your group
Use ;wander add or ;wander del to set up boundaries and keep you in your hunting area.
Use ;wander <npc1> <npc2> to stop only for specific npcs.
use ;wander to stop only for targetable npcs.
tillmen@lichproject.org
=end
# fixme: add room titles to ;wander list
CharSettings['boundary'] ||= Array.new
CharSettings['untargetable'] ||= Array.new
CharSettings['targetable'] ||= Array.new
$wander_rooms ||= Array.new
wander = proc {
room = Room.current
next_room_options = room.wayto.keys - CharSettings['boundary']
next_room_options.delete_if { |room_id| (room.timeto[room_id].class == Proc) and room.timeto[room_id].call.nil? }
next_room = next_room_options.find_all { |r| not $wander_rooms.include?(r) }
if next_room.empty?
next_room = $wander_rooms.find { |r| next_room_options.include?(r) }
else
next_room = next_room[rand(next_room.length)]
end
$wander_rooms.delete(next_room)
$wander_rooms.push(next_room)
way = room.wayto[next_room]
wait_while { ($loot_grab_list.length.to_i > 0) or $loot_working }
if way.class == String
move(way)
else
way.call
end
}
if script.vars[1] =~ /help/i
respond
respond ';wander add adds the current room to the boundary list'
respond ';wander add <room id> adds the given room id to the boundary list'
respond ';wander del deletes the current room to the boundary list'
respond ';wander del <room id> deletes the given room id to the boundary list'
respond ';wander clear clears the boundary list and npc info'
respond ';wander list shows saved boundaries and npc info'
respond ';wander <npc1> <npc2> wanders around, stopping only for the given npcs'
respond ';wander wanders around, stopping only for targetable npcs'
respond
elsif script.vars[1] =~ /^add$|^set$/i
if script.vars[2] and script.vars[2] =~ /^[0-9]+$/
CharSettings['boundary'].push(script.vars[2])
echo "room #{script.vars[2]} has been added to the boundary list"
elsif room = Room.current
CharSettings['boundary'].push(room.id.to_s)
echo "this room (#{room.id}) has been added to the boundary list"
else
echo 'current room is uknown'
end
elsif script.vars[1] =~ /^del(?:ete)?$|^rem(?:ove)?$/i
if script.vars[2] and script.vars[2] =~ /^[0-9]+$/
if CharSettings['boundary'].delete(script.vars[2])
echo "room #{script.vars[2]} has been removed from the boundary list"
else
echo "room #{script.vars[2]} was not found in the boundary list"
end
elsif room = Room.current
if CharSettings['boundary'].delete(room.id.to_s)
echo "this room (#{room.id}) has been removed from the boundary list"
else
echo "this room (#{room.id}) was not found in the boundary list"
end
else
echo 'current room is uknown'
end
elsif script.vars[1] =~ /^list$/i
respond
if CharSettings['boundary'].empty?
respond ' boundaries: none'
else
respond " boundaries: #{CharSettings['boundary'].join(', ')}"
end
respond
if CharSettings['targetable'].empty?
respond ' targetable npcs: none'
else
respond " targetable npcs: #{CharSettings['targetable'].join(', ')}"
end
respond
if CharSettings['untargetable'].empty?
respond 'untargetable npcs: none'
else
respond "untargetable npcs: #{CharSettings['untargetable'].join(', ')}"
end
respond
elsif script.vars[1] =~ /^clear$/i
CharSettings['boundary'] = Array.new
CharSettings['untargetable'] = Array.new
CharSettings['targetable'] = Array.new
respond 'done'
elsif script.vars.empty?
loop {
group = checkpcs.to_a
wander.call
sleep 0.3
#
# keep moving if there are people besides your group in the room
#
next unless (checkpcs.to_a - group).empty?
#
# keep moving if there's a disk that doesn't belong to your group
#
next if GameObj.loot.find { |obj| (obj.noun == 'disk') and (obj.name !~ /#{group.join('|')}/) }
#
# keep moving if there's no decent npcs in the room
#
start_npcs = npcs = GameObj.npcs
npcs.delete_if { |npc| (npc.status == 'dead') or CharSettings['untargetable'].include?(npc.name) }
next if npcs.nil? or npcs.empty?
#
# stop if there's an npc that's known to be targetable
#
break if npcs.find { |npc| CharSettings['targetable'].include?(npc.name) }
sleep 0.1
#
# check to see if there's an npc in the room that's targetable
#
clear
target_result = dothistimeout 'target random', 5, /^Could not find a valid target\.$|^You are now targeting/
if target_result =~ /^You are now targeting \w+ (.*)\.$/
target = $1
CharSettings['targetable'].push(target) unless CharSettings['targetable'].include?(target)
break
elsif target_result == 'Could not find a valid target.'
if GameObj.npcs == start_npcs
npcs.each { |npc| CharSettings['untargetable'].push(npc.name) unless CharSettings['untargetable'].include?(npc.name) }
end
next
end
break
}
else
group = checkpcs.to_a
loop {
wander.call
# sleep 0.1
#
# remove names from the group list if they didn't follow you
#
group = group & checkpcs.to_a
#
# keep moving if there are people besides your group in the room
#
next unless (checkpcs.to_a - group).empty?
#
# keep moving if there's a disk that doesn't belong to your group
#
next if GameObj.loot.find { |obj| (obj.noun == 'disk') and (obj.name !~ /#{group.join('|')}/) }
#
# stop if a given npc is in the room
#
break if GameObj.npcs.any? { |npc| (npc.status != 'dead') and npc.name =~ /#{script.vars[1..-1].join('|')}/ }
break if GameObj.pcs.any? { |pc| pc.noun =~ /#{script.vars[1..-1].join('|')}/i }
}
end