mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 00:38:46 +00:00
Add regexp support to name_lookup#find_entities
This commit is contained in:
@@ -35,11 +35,16 @@ end
|
|||||||
# Finds entities with the specified type (e.g. npc) and name, returning possible ids as an array.
|
# Finds entities with the specified type (e.g. npc) and name, returning possible ids as an array.
|
||||||
def find_entities(type, name, limit = 5)
|
def find_entities(type, name, limit = 5)
|
||||||
ids = []
|
ids = []
|
||||||
name.downcase!
|
|
||||||
|
|
||||||
Kernel.const_get("#{type.capitalize}Definition").definitions.each do |definition|
|
Kernel.const_get("#{type.capitalize}Definition").definitions.each do |definition|
|
||||||
break if (ids.length == limit)
|
break if (ids.length == limit)
|
||||||
ids << definition.id.to_i if definition.name.to_s.downcase == name
|
if name.is_a? Regexp
|
||||||
|
ids << definition.id.to_i if definition.name.to_s.downcase =~ name
|
||||||
|
elsif name.is_a? Symbol
|
||||||
|
ids << definition.id.to_i if definition.name.to_s.downcase == name.to_s.downcase.gsub(/_/, ' ')
|
||||||
|
else
|
||||||
|
ids << definition.id.to_i if definition.name.to_s.downcase == name.downcase
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ids
|
ids
|
||||||
|
|||||||
Reference in New Issue
Block a user