Add the new utils plugin, change entity spawning and the lookup command plugins to use it.

This commit is contained in:
Major-
2014-08-09 06:45:53 +01:00
parent e08a737933
commit 587901c630
8 changed files with 157 additions and 28 deletions
+1 -26
View File
@@ -41,17 +41,7 @@ end
# Returns an npc with the id and position specified by the hash.
def get_npc(hash)
id = hash.delete(:id)
if id == nil
name = hash.delete(:name).to_s.gsub('_', ' ')
if name.include?(' ')
id = name[name.rindex(' ') + 1, name.length - 1].to_i
end
id = locate_entity('npc', name, 1).first if id == nil || id == 0
end
raise "The npc called #{name} could not be identified." if id == nil
id = hash.delete(:id) || lookup_npc(hash.delete(:name))
z = hash.delete(:z)
position = Position.new(hash.delete(:x), hash.delete(:y), z == nil ? 0 : z)
@@ -111,21 +101,6 @@ def direction_to_position(direction, position)
end
end
# Locates an entity with the specified type (e.g. npc) and name, returning possible ids as an array.
def locate_entity(type, name, limit=5)
ids = []
name.downcase!
Kernel.const_get("#{type.capitalize}Definition").definitions.each do |definition|
break if ids.length == limit
ids << definition.id.to_i if definition.name.to_s.downcase == name
end
return ids
end
# An action that spawns an npc temporarily, before executing an action.
class TemporaryNpcAction < Action
attr_reader :executions, :combative
+3 -1
View File
@@ -10,5 +10,7 @@
<scripts>
<script>npc-spawn.rb</script>
</scripts>
<dependencies />
<dependencies>
<dependency>util</dependency>
</dependencies>
</plugin>