Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion foreach.lic
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
tags: utility
required: Lich >= 4.6.0.

version: 0.7 (2017-07.24)
version: 0.8 (2018-11.30)

changelog:
version 0.8 (2018-11.30)
* Add waitcastrt
* Add support for unique option.

version 0.7 (2017-07-24)
* Add waitmana, waithealth, waitspirit, and waitstamina commands.
* Change suggestions for GameObjAdd and GameObjAddMore to use xmlpatch instead.
Expand Down Expand Up @@ -147,6 +151,11 @@ module ForeachScript
@previous = nil unless defined?(@previous)
@previous_names = nil unless defined?(@previous_names)

# When true, only one of each item (by name) will be processed. For example, if there are 10 blue crystals
# ;foreach unique name=blue crystal;get item;
# will only get one of them.
@unique = false

def self.anon_hook(prefix = '')
now = Time.now
"Foreach::#{prefix}-#{now.tv_sec}.#{now.tv_usec}-#{Random.rand(10000)}"
Expand Down Expand Up @@ -537,6 +546,12 @@ module ForeachScript
resume_scripts
}

# If "unique" is present, remove it and set @unique to true.
if @script.vars[0] =~ /\bunique\b/
@unique = true
@script.vars[0].gsub!(/\bunique\b/, " ");
end

@script.vars[0] =~ /^\s*(.+?)\s*(?:([;\/|])\s*(.*?)\s*)?$/
filter = $1
separator = $2
Expand Down Expand Up @@ -745,6 +760,13 @@ module ForeachScript
next
end
items = items.find_all{|item| filter_proc.call(item)}

# If looking only for unique items, condense the results
# to just one of each item by name.
if @unique
items = items.uniq{|l| l.name}
end

unless items.length > 0
container_names.delete(container)
next
Expand Down Expand Up @@ -938,6 +960,9 @@ module ForeachScript
elsif command =~ /^waitrt$/i
before_next = nil
waitrt
elsif command =~ /^waitcastrt$/i
before_next = nil
waitcastrt
elsif command =~ /^waitfor (.*)$/i
script.want_downstream = true
script.want_downstream_xml = false
Expand Down