mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Move some classes into the new org.apollo.game.model.entity package, and update plugins and classes that reference these.
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.Entity'
|
||||
java_import 'org.apollo.game.model.entity.Entity'
|
||||
|
||||
# Maps attribute names (i.e. symbols) to attribute definitions.
|
||||
ATTRIBUTE_DEFINITIONS = {}
|
||||
|
||||
class Entity
|
||||
|
||||
# The map of strings to attributes.
|
||||
def attributes
|
||||
@attributes ||= {}
|
||||
end
|
||||
|
||||
# Overridies method_missing
|
||||
def method_missing(symbol, *args)
|
||||
@@ -20,11 +15,13 @@ class Entity
|
||||
raise "Error - expected argument count of 1, received #{args.length}" unless args.length == 1
|
||||
|
||||
name = name[0...-1].strip # Drop the equals and preceeding whitespace
|
||||
attributes[name] = args[0]
|
||||
attributes[name] = args[0].is_a?(Symbol) ? args[0].to_s : args[0]
|
||||
elsif ATTRIBUTE_DEFINITIONS[name] == nil
|
||||
super(symbol, *args)
|
||||
else
|
||||
return attributes[name] || ATTRIBUTE_DEFINITIONS[name].default
|
||||
if attributes[name] == nil then return ATTRIBUTE_DEFINITIONS[name].default end
|
||||
|
||||
return ATTRIBUTE_DEFINITIONS[name].type == :symbol ? attributes[name].to_sym : attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,7 +33,7 @@ end
|
||||
|
||||
# An attribute belonging to an entity.
|
||||
class AttributeDefinition
|
||||
attr_reader :default, :persistence
|
||||
attr_reader :default, :type, :persistence
|
||||
|
||||
def initialize(default, persistence=:transient)
|
||||
@default = default
|
||||
|
||||
@@ -3,10 +3,10 @@ require 'java'
|
||||
java_import 'org.apollo.game.action.Action'
|
||||
java_import 'org.apollo.game.model.Animation'
|
||||
java_import 'org.apollo.game.model.Graphic'
|
||||
java_import 'org.apollo.game.model.Npc'
|
||||
java_import 'org.apollo.game.model.Position'
|
||||
java_import 'org.apollo.game.model.World'
|
||||
java_import 'org.apollo.game.model.def.NpcDefinition'
|
||||
java_import 'org.apollo.game.model.entity.Npc'
|
||||
|
||||
# Information about npc spawning
|
||||
#
|
||||
@@ -61,16 +61,12 @@ end
|
||||
# Applies a decoded hash (one aquired using parse_hash) to the specified npc.
|
||||
def apply_decoded_hash(npc, hash)
|
||||
hash.each do |key, value|
|
||||
if key == :face
|
||||
npc.turn_to(value)
|
||||
elsif key == :boundary
|
||||
npc.boundary = value
|
||||
elsif key == :spawn_animation
|
||||
npc.play_animation(Animation.new(value))
|
||||
elsif key == :spawn_graphic
|
||||
npc.play_graphic(Graphic.new(value))
|
||||
else
|
||||
raise "Unrecognised key #{key} - value #{value}."
|
||||
case key
|
||||
when :face then npc.turn_to(value)
|
||||
when :boundary then npc.boundary = value
|
||||
when :spawn_animation then npc.play_animation(Animation.new(value))
|
||||
when :spawn_graphic then npc.play_graphic(Graphic.new(value))
|
||||
else raise "Unrecognised key #{key} - value #{value}."
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -78,23 +74,20 @@ end
|
||||
# Parses the remaining key-value pairs in the hash.
|
||||
def decode_hash(position, hash)
|
||||
decoded = {}
|
||||
hash.each do |key, value|
|
||||
if key == :face
|
||||
facing_position = direction_to_position(value, position)
|
||||
decoded[:face] = facing_position
|
||||
elsif key == :bounds
|
||||
decoded[:boundary] = value
|
||||
elsif key == :delta_bounds
|
||||
dx, dy, x, y, z = value[0], value[1], position.x, position.y, position.height
|
||||
raise 'Delta values cannot be < 0.' if dx < 0 || dy < 0
|
||||
hash.each do |key, value|
|
||||
case key
|
||||
when :face
|
||||
facing_position = direction_to_position(value, position)
|
||||
decoded[:face] = facing_position
|
||||
when :delta_bounds
|
||||
dx, dy, x, y, z = value[0], value[1], position.x, position.y, position.height
|
||||
raise 'Delta values cannot be less than 0.' if dx < 0 || dy < 0
|
||||
|
||||
decoded[:boundary] = [ Position.new(x + dx, y, z), Position.new(x, y + dy, z), Position.new(x - dx, y, z), Position.new(x, y - dy, z) ]
|
||||
elsif key == :spawn_animation
|
||||
decoded[:spawn_animation] = Animation.new(value)
|
||||
elsif key == :spawn_graphic
|
||||
decoded[:spawn_graphic] = Graphic.new(value)
|
||||
else
|
||||
raise "Unrecognised key #{key} - value #{value}."
|
||||
decoded[:boundary] = [ Position.new(x + dx, y, z), Position.new(x, y + dy, z), Position.new(x - dx, y, z), Position.new(x, y - dy, z) ]
|
||||
when :bounds then decoded[:boundary] = value
|
||||
when :spawn_animation then decoded[:spawn_animation] = Animation.new(value)
|
||||
when :spawn_graphic then decoded[:spawn_graphic] = Graphic.new(value)
|
||||
else raise "Unrecognised key #{key} - value #{value}."
|
||||
end
|
||||
end
|
||||
return decoded
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>npc-spawn.rb</script>
|
||||
<script>item-spawn.rb</script>
|
||||
</scripts>
|
||||
<dependencies />
|
||||
</plugin>
|
||||
Reference in New Issue
Block a user