-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathcapture-critter.lic
More file actions
117 lines (95 loc) · 3.33 KB
/
Copy pathcapture-critter.lic
File metadata and controls
117 lines (95 loc) · 3.33 KB
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
=begin
Runs critter-capture festival events.
Event room lists, critter names and junk items come from base-capture.yaml;
a custom event can be supplied via capture_critter_settings in your yaml.
Pass the event name as the sole argument.
=end
class CaptureCritter
def initialize
@settings = get_settings
@capture_settings = @settings.capture_critter_settings
@debug = @capture_settings["debug"]
event_data = get_data('capture')
# Load custom event if one is specified
if @capture_settings["custom"]["room_list"].size > 0
event_data = OpenStruct.new(
event_data.to_h.merge(
'custom' => @capture_settings["custom"]
)
)
end
arg_definitions = [[{ name: 'event', regex: /\w+/, optional: false, description: "Name of event (#{event_data.to_h.keys.join(", ")})" }]]
args = parse_args(arg_definitions)
# Each capture event may have different "game over" messages. They seem similar, but this may not capture all of them.
Flags.add("critter-done", '^(?:TWEET:\s+)?[PW]hew! +All of the')
# Set the target event
@event_info = event_data[args.event]
unless @event_info
valid_events = event_data.to_h.keys.join("\n ")
echo "'#{args.event}' is not a valid event name. See base-capture.yaml for valid event names:\n\n #{valid_events}\n\n"
exit
end
@critter_regexp = /\b(#{Regexp.union(@event_info["critter_names"]).source})\z/i
run
end
def critter?(obj_name)
echo "critter?(#{obj_name})" if @debug
@critter_regexp.match(obj_name)
end
def handle_item(item)
echo "handle_item(#{item})" if @debug
if @capture_settings['junk'].include?(item)
echo "#{item} is junk" if @debug
DRCI.dispose_trash(item, @settings.worn_trashcan, @settings.worn_trashcan_verb)
else
echo "#{item} is not junk" if @debug
DRCI.put_away_item?(item, @capture_settings['reward_container'])
end
end
def capture_and_return(critter_match)
echo "capture_and_return" if @debug
critter = critter_match[1]
DRC.fix_standing
fput("get #{critter}")
pause 0.5
waitrt?
held_item = DRC.right_hand || DRC.left_hand
# This junk check is mainly necessary for Hollows Eve, where we might "get shark" but end up with some discarded sharkskin
return if @capture_settings['junk'].include?(held_item) && handle_item(held_item)
return unless DRCI.in_hand?(held_item)
DRCT.walk_to(@event_info["return_room"])
fput("put my #{held_item} on #{@event_info["return_surface"]}")
pause 1
waitrt?
handle_item(DRC.right_hand || DRC.left_hand)
end
def run
echo "run" if @debug
loop do
# 1. Search rooms until we find a critter
found = false
@event_info["room_list"].each do |room|
DRCT.walk_to(room)
if DRRoom.room_objs.any? { |obj| critter?(obj) }
found = true
break
end
end
# 2. If no critters in any room, wait or exit
unless found
exit if Flags['critter-done']
DRC.message 'Waiting on more critters.'
pause 15
next
end
# 3. Capture all critters in the current room
while (match = DRRoom.room_objs.map { |obj| critter?(obj) }.compact.first)
capture_and_return(match)
end
end
end
end
before_dying do
Flags.delete('critter-done')
end
CaptureCritter.new