mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 16:49:11 +00:00
Update all plugins to conform to Rubocop.
This commit is contained in:
@@ -4,6 +4,7 @@ require 'set'
|
||||
module DoorConstants
|
||||
|
||||
# TODO: GameObjectOrientation enumeration in Apollo's core?
|
||||
# The orientation of a door.
|
||||
module Orientation
|
||||
WEST = 0
|
||||
NORTH = 1
|
||||
@@ -15,29 +16,29 @@ module DoorConstants
|
||||
DOOR_SIZE = 1
|
||||
|
||||
# Door object ids that have a hinge on the left side.
|
||||
LEFT_HINGE_DOORS = Set.new [ 1516, 1536, 1533 ]
|
||||
LEFT_HINGE_DOORS = Set.new [1516, 1536, 1533]
|
||||
|
||||
# Door object ids that have a hinge on the right side.
|
||||
RIGHT_HINGE_DOORS = Set.new [ 1519, 1530, 4465, 4467, 3014, 3017, 3018, 3019 ]
|
||||
RIGHT_HINGE_DOORS = Set.new [1519, 1530, 4465, 4467, 3014, 3017, 3018, 3019]
|
||||
|
||||
# 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,
|
||||
Orientation::SOUTH => Orientation::EAST,
|
||||
Orientation::WEST => Orientation::SOUTH,
|
||||
Orientation::EAST => Orientation::NORTH
|
||||
},
|
||||
# Orientations for doors that have a hinge on the left side.
|
||||
left_side_hinge: {
|
||||
Orientation::NORTH => Orientation::WEST,
|
||||
Orientation::SOUTH => Orientation::EAST,
|
||||
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,
|
||||
Orientation::SOUTH => Orientation::WEST,
|
||||
Orientation::WEST => Orientation::NORTH,
|
||||
Orientation::EAST => Orientation::SOUTH
|
||||
}
|
||||
# Orientations for doors that have a hinge on the right side.
|
||||
right_side_hinge: {
|
||||
Orientation::NORTH => Orientation::EAST,
|
||||
Orientation::SOUTH => Orientation::WEST,
|
||||
Orientation::WEST => Orientation::NORTH,
|
||||
Orientation::EAST => Orientation::SOUTH
|
||||
}
|
||||
}
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
java_import 'org.apollo.game.action.DistancedAction'
|
||||
|
||||
# A distanced action which opens a door.
|
||||
@@ -13,20 +14,20 @@ class OpenDoorAction < DistancedAction
|
||||
|
||||
def executeAction
|
||||
mob.turn_to(@door.position)
|
||||
DoorUtil::toggle(@door)
|
||||
DoorUtil.toggle(@door)
|
||||
stop
|
||||
end
|
||||
|
||||
def equals(other)
|
||||
return (get_class == other.get_class && @door == other.door)
|
||||
get_class == other.get_class && @door == other.door
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# MessageListener for opening and closing doors.
|
||||
on :message, :first_object_action do |player, message|
|
||||
if DoorUtil::is_door?(message.id)
|
||||
door = DoorUtil::get_door_object(message.position, message.id)
|
||||
if DoorUtil.door?(message.id)
|
||||
door = DoorUtil.get_door_object(message.position, message.id)
|
||||
player.start_action(OpenDoorAction.new(player, door)) unless door.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,20 +15,18 @@ module DoorUtil
|
||||
# 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
|
||||
case door.orientation
|
||||
when Orientation::WEST
|
||||
return Position.new(position.x - 1, position.y, position.height)
|
||||
Position.new(position.x - 1, position.y, position.height)
|
||||
when Orientation::EAST
|
||||
return Position.new(position.x + 1, position.y, position.height)
|
||||
Position.new(position.x + 1, position.y, position.height)
|
||||
when Orientation::NORTH
|
||||
return Position.new(position.x, position.y + 1, position.height)
|
||||
Position.new(position.x, position.y + 1, position.height)
|
||||
when Orientation::SOUTH
|
||||
return Position.new(position.x, position.y - 1, position.height)
|
||||
Position.new(position.x, position.y - 1, position.height)
|
||||
else fail "Unsupported orientation #{door.orientation}."
|
||||
end
|
||||
|
||||
raise 'Invalid orientation for door!'
|
||||
end
|
||||
|
||||
# Translates the orientation of a door to a toggled position.
|
||||
@@ -42,13 +40,12 @@ module DoorUtil
|
||||
return ORIENTATIONS[:left_side_hinge][orientation]
|
||||
end
|
||||
|
||||
raise 'Given object was not registered as a door.'
|
||||
fail 'Given object was not registered as a door.'
|
||||
end
|
||||
|
||||
# Toggles the given door.
|
||||
def self.toggle(door)
|
||||
position = door.position
|
||||
region = $world.region_repository.from_position(position)
|
||||
region = $world.region_repository.from_position(door.position)
|
||||
region.remove_entity(door)
|
||||
|
||||
if TOGGLED_DOORS.include?(door)
|
||||
@@ -57,11 +54,13 @@ module DoorUtil
|
||||
original_region = $world.region_repository.from_position(original_door.position)
|
||||
original_region.add_entity(original_door)
|
||||
else
|
||||
toggled_position = translate_door_position(door)
|
||||
toggled_orientation = translate_door_orientation(door)
|
||||
toggled_door = DynamicGameObject.create_public($world, door.id, toggled_position, door.type, toggled_orientation)
|
||||
position = translate_door_position(door)
|
||||
orientation = translate_door_orientation(door)
|
||||
type = door.type
|
||||
|
||||
toggled_region = $world.region_repository.from_position(toggled_position)
|
||||
toggled_door = DynamicGameObject.create_public($world, door.id, position, type, orientation)
|
||||
|
||||
toggled_region = $world.region_repository.from_position(position)
|
||||
toggled_region.add_entity(toggled_door)
|
||||
|
||||
TOGGLED_DOORS[toggled_door] = door
|
||||
@@ -70,14 +69,15 @@ module DoorUtil
|
||||
|
||||
# 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::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT)
|
||||
game_objects.each { |game_object| return game_object if game_object.id == object_id }
|
||||
return nil
|
||||
region = $world.region_repository.from_position(position)
|
||||
objects = region.get_entities(position, EntityType::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT)
|
||||
objects.each { |game_object| return game_object if game_object.id == object_id }
|
||||
nil
|
||||
end
|
||||
|
||||
# Checks if the given game object id is a door.
|
||||
def self.is_door?(object_id)
|
||||
def self.door?(object_id)
|
||||
RIGHT_HINGE_DOORS.include?(object_id) || LEFT_HINGE_DOORS.include?(object_id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user