Add half-done grouped region frame stuff so Ryley can take a look. This is in master because I'm an idiot.

This commit is contained in:
Major-
2015-03-22 11:07:24 +00:00
parent 30045a6f10
commit 7cf31a2888
62 changed files with 1818 additions and 576 deletions
+10 -5
View File
@@ -1,6 +1,8 @@
java_import 'org.apollo.game.model.Direction'
require 'set'
# Contains door-related constants.
module DoorConstants
# TODO: GameObjectOrientation enumeration in Apollo's core?
module Orientation
WEST = 0
@@ -9,17 +11,18 @@ module DoorConstants
SOUTH = 3
end
# The object size of a door.
# The size of a door object.
DOOR_SIZE = 1
# Door object ids that have a hinge on the left side.
LEFT_SIDE_HINGE_DOOR_IDS = [1516, 1536, 1533]
LEFT_HINGE_DOORS = Set.new [ 1516, 1536, 1533 ]
# Door object ids that have a hinge on the right side.
RIGHT_SIDE_HINGE_DOOR_IDS = [1519, 1530, 4465, 4467, 3014, 3017, 3018, 3019]
RIGHT_HINGE_DOORS = Set.new [ 1519, 1530, 4465, 4467, 3014, 3017, 3018, 3019 ]
# A map of orientations that a door will translate to when opened.
# The hash of orientations that a door will translate to when opened.
ORIENTATIONS = {
# Orientations for doors that have a hinge on the left side.
:left_side_hinge => {
Orientation::NORTH => Orientation::WEST,
@@ -27,6 +30,7 @@ module DoorConstants
Orientation::WEST => Orientation::SOUTH,
Orientation::EAST => Orientation::NORTH
},
# Orientations for doors that have a hinge on the right side.
:right_side_hinge => {
Orientation::NORTH => Orientation::EAST,
@@ -35,4 +39,5 @@ module DoorConstants
Orientation::EAST => Orientation::SOUTH
}
}
end
+10 -8
View File
@@ -4,28 +4,30 @@ java_import 'org.apollo.game.action.DistancedAction'
class OpenDoorAction < DistancedAction
include DoorConstants
attr_reader :door_object
attr_reader :door
def initialize(mob, door_object)
super(0, true, mob, door_object.position, DOOR_SIZE)
@door_object = door_object
def initialize(mob, door)
super(0, true, mob, door.position, DOOR_SIZE)
@door = door
end
def executeAction
mob.turn_to @door_object.position
DoorUtil::toggle(@door_object, mob)
mob.turn_to(@door.position)
DoorUtil::toggle(@door, mob)
stop
end
def equals(other)
return (get_class == other.get_class && @door_object == other.door_object)
end
end
# Message handler for opening and closing doors.
on :message, :first_object_action do |ctx, player, message|
if DoorUtil::is_door?(message.id)
door_object = DoorUtil::get_door_object(message.position, message.id)
player.start_action(OpenDoorAction.new(player, door_object)) unless door_object.nil?
puts "Player: #{player.position}, door: #{message.position}"
door = DoorUtil::get_door_object(message.position, message.id)
player.start_action(OpenDoorAction.new(player, door)) unless door.nil?
end
end
+24 -40
View File
@@ -1,20 +1,22 @@
java_import 'org.apollo.game.model.entity.GameObject'
java_import 'org.apollo.game.model.entity.Entity'
java_import 'org.apollo.game.model.Position'
java_import 'org.apollo.game.message.impl.PositionMessage'
java_import 'org.apollo.game.message.impl.RemoveObjectMessage'
java_import 'org.apollo.game.message.impl.SendObjectMessage'
require 'java'
java_import 'org.apollo.game.model.Position'
java_import 'org.apollo.game.model.area.Region'
java_import 'org.apollo.game.model.entity.Entity'
java_import 'org.apollo.game.model.entity.obj.DynamicGameObject'
# Contains door-related utility methods.
module DoorUtil
include DoorConstants
# A hash containing currently toggled door objects mapped to the original door objects.
TOGGLED_DOOR_REPOSITORY = {}
TOGGLED_DOORS = {}
# Translates a door's position in the direction of its orientation.
def self.translate_door_position(door)
position = door.position
orientation = door.orientation
case orientation
when Orientation::WEST
return Position.new(position.x - 1, position.y, position.height)
@@ -25,6 +27,7 @@ module DoorUtil
when Orientation::SOUTH
return Position.new(position.x, position.y - 1, position.height)
end
raise 'Invalid orientation for door!'
end
@@ -32,68 +35,49 @@ module DoorUtil
def self.translate_door_orientation(door)
object_id = door.id
orientation = door.orientation
if RIGHT_SIDE_HINGE_DOOR_IDS.include?(object_id)
if RIGHT_HINGE_DOORS.include?(object_id)
return ORIENTATIONS[:right_side_hinge][orientation]
elsif LEFT_SIDE_HINGE_DOOR_IDS.include?(object_id)
elsif LEFT_HINGE_DOORS.include?(object_id)
return ORIENTATIONS[:left_side_hinge][orientation]
end
raise 'Given object was not registered as a door!'
end
# Replaces a door object for a given player.
# TODO: This is temporary.
def self.replace_door(player, original, new)
player.send PositionMessage.new(player.last_known_region, original.position)
player.send RemoveObjectMessage.new(original)
player.send PositionMessage.new(player.last_known_region, new.position)
player.send SendObjectMessage.new(new)
raise 'Given object was not registered as a door.'
end
# Toggles the given door.
def self.toggle(door, player)
# First, we remove the door we're toggling (or un-toggling) from the game world.
position = door.position
region = $world.region_repository.from_position(position)
region.remove_entity door
region.remove_entity(door)
# Have we toggled this door already?
if TOGGLED_DOOR_REPOSITORY.include?(door)
# If we have, we get our original door. This also deletes the entry from our repository.
original_door = TOGGLED_DOOR_REPOSITORY.delete(door)
if TOGGLED_DOORS.include?(door)
original_door = TOGGLED_DOORS.delete(door)
# Now we add our new door to the game world.
original_region = $world.region_repository.from_position(original_door.position)
original_region.add_entity original_door
# TODO: This and the 'player' parameter are temporary. We still need to synchronize objects for local players.
replace_door player, door, original_door
original_region.add_entity(original_door)
else
# If not, we get the translated orientation and position for this door, and create a new game object.
toggled_position = translate_door_position(door)
toggled_orientation = translate_door_orientation(door)
toggled_door = GameObject.new(door.id, toggled_position, door.type, toggled_orientation)
toggled_door = DynamicGameObject.createPublic(door.id, toggled_position, door.type, toggled_orientation)
# Now we add our new door to the game world.
toggled_region = $world.region_repository.from_position(toggled_position)
toggled_region.add_entity toggled_door
toggled_region.add_entity(toggled_door)
# Insert our toggled door in the repository.
TOGGLED_DOOR_REPOSITORY[toggled_door] = door
# TODO: This and the 'player' parameter are temporary. We still need to synchronize objects for local players.
replace_door player, door, toggled_door
TOGGLED_DOORS[toggled_door] = door
end
end
# Gets the door object at the given position, if it exists.
def self.get_door_object(position, object_id)
game_objects = $world.region_repository.from_position(position).get_entities(position, EntityType::GAME_OBJECT)
game_objects = $world.region_repository.from_position(position).get_entities(position, EntityType::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT)
game_objects.each { |game_object| return game_object if game_object.id == object_id }
return nil
end
# Checks if the given game object id is a door.
def self.is_door?(object_id)
RIGHT_SIDE_HINGE_DOOR_IDS.include?(object_id) || LEFT_SIDE_HINGE_DOOR_IDS.include?(object_id)
RIGHT_HINGE_DOORS.include?(object_id) || LEFT_HINGE_DOORS.include?(object_id)
end
end