From 794bd49607022ad762e364ab682240a45ac0019b Mon Sep 17 00:00:00 2001 From: Ryley Kimmel Date: Sun, 1 Mar 2015 14:38:00 -0500 Subject: [PATCH] Basic implementation of player context menu action management. --- data/plugins/player-action/login.rb | 6 +++ data/plugins/player-action/player-action.rb | 59 +++++++++++++++++++++ data/plugins/player-action/plugin.xml | 15 ++++++ 3 files changed, 80 insertions(+) create mode 100644 data/plugins/player-action/login.rb create mode 100644 data/plugins/player-action/player-action.rb create mode 100644 data/plugins/player-action/plugin.xml diff --git a/data/plugins/player-action/login.rb b/data/plugins/player-action/login.rb new file mode 100644 index 00000000..ee2c78d3 --- /dev/null +++ b/data/plugins/player-action/login.rb @@ -0,0 +1,6 @@ +java_import 'org.apollo.game.model.entity.Player' + +on :login do |event, player| + show_action(player, TRADE_ACTION) + show_action(player, FOLLOW_ACTION) +end \ No newline at end of file diff --git a/data/plugins/player-action/player-action.rb b/data/plugins/player-action/player-action.rb new file mode 100644 index 00000000..46144a49 --- /dev/null +++ b/data/plugins/player-action/player-action.rb @@ -0,0 +1,59 @@ +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 + + def initialize(slot, primary, name) + index = [ :first, :second, :third, :fourth, :fifth ].find_index(slot) + raise "Unsupport action slot #{slot}." if index.nil? + + @slot = index + @primary = primary + @name = name + end + +end + +ATTACK_ACTION = PlayerAction.new(:third, true, 'Attack') +CHALLENGE_ACTION = PlayerAction.new(:third, true, 'Challenge') +TRADE_ACTION = PlayerAction.new(:fourth, true, 'Trade with') +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? + + actions.each do |action| + player.add_action(action) + player.send(SetPlayerActionMessage.new(action.name, action.slot, action.primary)) + end +end + +# Shows a single context menu action for the specified player +def show_action(player, action) + show_actions(player, action) +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)) +end + +class Player + + def actions + @actions ||= {} + end + + def add_action(action) + actions[action.slot] = action.name + end + + def has_action(action) + return actions[action.slot] == action.name + end + +end \ No newline at end of file diff --git a/data/plugins/player-action/plugin.xml b/data/plugins/player-action/plugin.xml new file mode 100644 index 00000000..82a7d15f --- /dev/null +++ b/data/plugins/player-action/plugin.xml @@ -0,0 +1,15 @@ + + + player-action + 1 + Player actions + Manages player right click actions + + Ryley + + + + + + + \ No newline at end of file