From 26d1def1c6c8aa4daa462f8a721cf33baac136e2 Mon Sep 17 00:00:00 2001 From: Ryley Kimmel Date: Tue, 3 Mar 2015 21:12:32 -0500 Subject: [PATCH] Fix, format and rebase wilderness and player-action plugins. --- data/plugins/areas/wilderness.rb | 33 +++++++++++---------- data/plugins/player-action/player-action.rb | 6 ++-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/data/plugins/areas/wilderness.rb b/data/plugins/areas/wilderness.rb index 746c5e4f..5e97dc0f 100644 --- a/data/plugins/areas/wilderness.rb +++ b/data/plugins/areas/wilderness.rb @@ -1,35 +1,35 @@ require 'java' java_import 'org.apollo.game.model.entity.Player' -java_import 'org.apollo.game.message.impl.OpenOverlayMessage' java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' +java_import 'org.apollo.game.message.impl.OpenOverlayMessage' +# Constants constants related to the wilderness +module WildernessConstants -private + # The wilderness level overlay interface id + OVERLAY_INTERFACE_ID = 197 -MIN_X = 2945 -MIN_Y = 3522 -MAX_X = 3390 -MAX_Y = 3972 + # The wilderness level string id + LEVEL_STRING_ID = 199 -OVERLAY_INTERFACE_ID = 197 -LEVEL_STRING_ID = 199 +end declare_attribute(:wilderness_level, 0, :transient) # Determines the wilderness level for the specified player's position def wilderness_level(player) - return (player.position.y - (MIN_Y - 1) / 8).ceil + return ((player.position.y - 3520) / 8).ceil end area_action :wilderness_level do on_entry do |player| player.wilderness_level = wilderness_level(player) - player.interface_set.open_overlay(OVERLAY_INTERFACE_ID) - player.send(SetWidgetTextMessage.new(LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) - show_action(ATTACK_ACTION) + player.interface_set.open_overlay(WildernessConstants::OVERLAY_INTERFACE_ID) + player.send(SetWidgetTextMessage.new(WildernessConstants::LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) + show_action(player, ATTACK_ACTION) end while_in do |player| @@ -37,16 +37,17 @@ area_action :wilderness_level do updated = wilderness_level(player) if (current != updated) player.wilderness_level = updated - player.send(SetWidgetTextMessage.new(LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) + player.send(SetWidgetTextMessage.new(WildernessConstants::LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) end end on_exit do |player| player.wilderness_level = 0 - player.interface_set.close() # TODO: Will this cause issues with other potentially open interfaces? - hide_action(ATTACK_ACTION) + player.interface_set.close() + player.send(OpenOverlayMessage.new(-1)) + hide_action(player, ATTACK_ACTION) end end -area :name => :wilderness, :coordinates => [ MIN_X, MIN_Y, MAX_X, MAX_Y, 0 ], :actions => :wilderness_level \ No newline at end of file +area :name => :wilderness, :coordinates => [ 2945, 3522, 3390, 3972, 0 ], :actions => :wilderness_level \ No newline at end of file diff --git a/data/plugins/player-action/player-action.rb b/data/plugins/player-action/player-action.rb index 46144a49..edd914e4 100644 --- a/data/plugins/player-action/player-action.rb +++ b/data/plugins/player-action/player-action.rb @@ -3,6 +3,8 @@ require 'java' java_import 'org.apollo.game.message.impl.SetPlayerActionMessage' java_import 'org.apollo.game.model.entity.Player' + + class PlayerAction attr_reader :slot, :primary, :name @@ -24,7 +26,7 @@ FOLLOW_ACTION = PlayerAction.new(:fifth, true, 'Follow') # Shows multiple context menu action for the specified player def show_actions(player, *actions) - raise 'Must specify at least one action to show' if actions.nil? + raise 'Must specify at least one action' if actions.nil? actions.each do |action| player.add_action(action) @@ -39,7 +41,7 @@ end # Hides a context menu action for the specified player def hide_action(player, action) - show_action(player, PlayerAction.new('null', action.slot, action.primary)) + show_action(player, PlayerAction.new(action.slot, action.primary, 'null')) end class Player