mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add support for combat related UI
* Allows switching between different combat styles, and updates the combat tabs styles for every equipped weapon. If a weapon with a special attack is equipped, the special bar for that interface will be shown. * Adds a scheduled task which periodically restores special energy to the player and updates their special bar.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
java_import 'org.apollo.game.model.inter.InterfaceConstants'
|
||||
java_import 'org.apollo.game.model.entity.EquipmentConstants'
|
||||
java_import 'org.apollo.game.message.impl.SetWidgetTextMessage'
|
||||
java_import 'org.apollo.game.message.impl.SetInterfaceConfigMessage'
|
||||
java_import 'org.apollo.game.message.impl.ConfigMessage'
|
||||
java_import 'org.apollo.game.model.inv.SynchronizationInventoryListener'
|
||||
|
||||
|
||||
on :message, :item_option do |player, message|
|
||||
update_combat_tab(player) if message.option == 2 and message.interface_id == SynchronizationInventoryListener::INVENTORY_ID
|
||||
end
|
||||
|
||||
on :login do |event|
|
||||
update_combat_tab(event.player)
|
||||
end
|
||||
|
||||
on :message, :item_action do |player, message|
|
||||
update_combat_tab(player) if message.interface_id == SynchronizationInventoryListener::EQUIPMENT_ID and message.slot == EquipmentConstants::WEAPON
|
||||
end
|
||||
|
||||
|
||||
on :message, :button do |player, msg|
|
||||
weapon = EquipmentUtil.equipped_weapon player
|
||||
weapon_class = weapon.weapon_class
|
||||
weapon_class_widget = weapon_class.widget
|
||||
|
||||
next unless weapon_class_widget == msg.interface_id
|
||||
|
||||
if weapon_class.special_bar? and msg.button == weapon_class.special_bar_button
|
||||
player.using_special = !player.using_special
|
||||
update_special_bar(player)
|
||||
else
|
||||
player.combat_style = msg.button
|
||||
end
|
||||
|
||||
update_combat_style player
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_combat_tab(player)
|
||||
weapon = EquipmentUtil.equipped_weapon player
|
||||
weapon_name = weapon.name
|
||||
weapon_class = weapon.weapon_class
|
||||
weapon_class_widget = weapon_class.widget
|
||||
|
||||
attack_style_interface_layer = InterfaceConstants::UserInterface::ATTACK_STYLE.layer
|
||||
|
||||
player.interface_set.send_user_interface(attack_style_interface_layer, weapon_class_widget)
|
||||
player.send SetWidgetTextMessage.new(weapon_class_widget, 0, weapon_name)
|
||||
|
||||
if weapon_class.special_bar?
|
||||
player.send SetInterfaceConfigMessage.new(weapon_class_widget, weapon_class.special_bar_config, !weapon.special_attack?)
|
||||
end
|
||||
|
||||
update_combat_style player
|
||||
end
|
||||
|
||||
def update_combat_style(player)
|
||||
weapon = EquipmentUtil.equipped_weapon player
|
||||
weapon_class = weapon.weapon_class
|
||||
|
||||
# Update the combat style in case we had an invalid style selected,
|
||||
# and therefore reverted to the first combat style
|
||||
selected_style = weapon_class.style_at(player.combat_style)
|
||||
|
||||
player.combat_style = weapon_class.button selected_style
|
||||
player.send ConfigMessage.new(43, weapon_class.config(selected_style))
|
||||
end
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
java_import 'org.apollo.game.message.impl.ConfigMessage'
|
||||
|
||||
def update_special_bar(player)
|
||||
player.send(ConfigMessage.new(300, player.special_energy * 10)) # special energy
|
||||
player.send(ConfigMessage.new(301, player.using_special ? 1 : 0)) # special enabled
|
||||
end
|
||||
|
||||
on :login do |event|
|
||||
player = event.player
|
||||
|
||||
update_special_bar player
|
||||
|
||||
schedule 25 do |task|
|
||||
unless player.is_active
|
||||
task.stop
|
||||
next
|
||||
end
|
||||
|
||||
player.special_energy = [player.special_energy + 5, 100].min
|
||||
update_special_bar player
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user