diff --git a/lib/aethyr/core/actions/commands/close.rb b/lib/aethyr/core/actions/commands/close.rb new file mode 100644 index 0000000000000000000000000000000000000000..ec14e2f750cc52ff6e92400110380e06aa6e71f3 --- /dev/null +++ b/lib/aethyr/core/actions/commands/close.rb @@ -0,0 +1,30 @@ +require "aethyr/core/actions/command_action" + +module Aethyr + module Core + module Actions + module Close + class CloseCommand < Aethyr::Extend::CommandAction + def initialize(actor, **data) + super(actor, **data) + end + + def action() + event = @data + room = $manager.get_object(@player.container) + object = expand_direction(event[:object]) + object = @player.search_inv(object) || $manager.find(object, room) + + if object.nil? + @player.output("Close what?") + elsif not object.can? :open + @player.output("You cannot close #{object.name}.") + else + object.close(event) + end + end + end + end + end + end +end diff --git a/lib/aethyr/core/input_handlers/close.rb b/lib/aethyr/core/input_handlers/close.rb index 26030578e13dec2ff7d27aa6ebd0987ab3aa436f..535a34efee513b81d2ac75afb7a4a0f88e3b1788 100644 --- a/lib/aethyr/core/input_handlers/close.rb +++ b/lib/aethyr/core/input_handlers/close.rb @@ -3,6 +3,7 @@ require "aethyr/core/input_handlers/command_handler" require "aethyr/core/util/direction" require "aethyr/core/help/help_entry" require "aethyr/core/actions/command_action" +require "aethyr/core/actions/commands/close" module Aethyr module Core @@ -50,34 +51,8 @@ EOF end end end - Aethyr::Extend::HandlerRegistry.register_handler(CloseHandler) end end - - module Actions - module Close - class CloseCommand < Aethyr::Core::Actions::CommandAction - def initialize(actor, **data) - super(actor, **data) - end - - def action() - event = @data - room = $manager.get_object(@player.container) - object = expand_direction(event[:object]) - object = @player.search_inv(object) || $manager.find(object, room) - - if object.nil? - @player.output("Close what?") - elsif not object.can? :open - @player.output("You cannot close #{object.name}.") - else - object.close(event) - end - end - end - end - end end end