mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Basic implementation of player context menu action management.
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<plugin>
|
||||
<id>player-action</id>
|
||||
<version>1</version>
|
||||
<name>Player actions</name>
|
||||
<description>Manages player right click actions</description>
|
||||
<authors>
|
||||
<author>Ryley</author>
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>player-action.rb</script>
|
||||
<script>login.rb</script>
|
||||
</scripts>
|
||||
<dependencies />
|
||||
</plugin>
|
||||
Reference in New Issue
Block a user