Housekeeping

This commit is contained in:
KeepBotting
2019-03-26 14:05:40 -04:00
parent a0c78ced90
commit 739c331860
135 changed files with 4 additions and 4 deletions
+61
View File
@@ -0,0 +1,61 @@
require 'java'
java_import 'org.apollo.game.message.impl.SetPlayerActionMessage'
java_import 'org.apollo.game.model.entity.Player'
# A right-click action for a Player.
class PlayerAction
attr_reader :slot, :primary, :name
def initialize(slot, primary, name)
index = [:first, :second, :third, :fourth, :fifth].find_index(slot)
fail "Unsupported action slot #{slot}." if index.nil?
@slot = index
@primary = primary
@name = name
end
end
ATTACK_ACTION = PlayerAction.new(:second, true, 'Attack')
CHALLENGE_ACTION = PlayerAction.new(:second, true, 'Challenge')
FOLLOW_ACTION = PlayerAction.new(:fourth, true, 'Follow')
TRADE_ACTION = PlayerAction.new(:fifth, true, 'Trade with')
# Shows multiple context menu action for the specified player
def show_actions(player, *actions)
fail 'Must specify at least one action.' 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)
player.send(SetPlayerActionMessage.new('null', action.slot, action.primary))
end
# Monkey-patch Player to provide action utility methods.
class Player
def actions
@actions ||= {}
end
def add_action(action)
actions[action.slot] = action.name
end
def action?(action)
actions[action.slot] == action.name
end
end
+6
View File
@@ -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,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>action.rb</script>
<script>login.rb</script>
</scripts>
<dependencies />
</plugin>