Fix bugs in the magic skill plugin.

This commit is contained in:
Major-
2014-03-09 09:42:06 +00:00
parent f9d982934c
commit 01a9631f32
7 changed files with 109 additions and 119 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ end
on :command, :tele, RIGHTS_ADMIN do |player, command| on :command, :tele, RIGHTS_ADMIN do |player, command|
args = command.arguments args = command.arguments
unless (2..3).include? args.length unless (2..3).include?(args.length)
player.send_message("Invalid syntax - ::tele [x] [y] [optional-z]") player.send_message("Invalid syntax - ::tele [x] [y] [optional-z]")
return return
end end
@@ -16,5 +16,5 @@ on :command, :tele, RIGHTS_ADMIN do |player, command|
y = args[1].to_i y = args[1].to_i
z = args.length == 3 ? args[2].to_i : player.position.height z = args.length == 3 ? args[2].to_i : player.position.height
player.teleport Position.new(x, y, z) player.teleport Position.new(x, y, z) if (0..4).include?(z)
end end
+22 -23
View File
@@ -5,67 +5,66 @@ java_import 'org.apollo.game.model.Graphic'
ALCHEMY_SPELLS = {} ALCHEMY_SPELLS = {}
LOW_ALC_ANIM = Animation.new(712) LOW_ALCH_ANIM = Animation.new(712)
LOW_ALC_GFX = Graphic.new(112, 0, 100) LOW_ALCH_GRAPHIC = Graphic.new(112, 0, 100)
LOW_ALC_MULTIPLIER = 0.4 LOW_ALCH_MULTIPLIER = 0.4
HIGH_ALC_ANIM = Animation.new(713) HIGH_ALCH_ANIM = Animation.new(713)
HIGH_ALC_GFX = Graphic.new(113, 0, 100) HIGH_ALCH_GRAPHIC = Graphic.new(113, 0, 100)
HIGH_ALC_MULTIPLIER = 0.6 HIGH_ALCH_MULTIPLIER = 0.6
ILLEGAL_ALC_ITEMS = [ 995, 6529, 6306, 6307, 6308, 6309, 6310 ] ILLEGAL_ALCH_ITEMS = [ 995, 6529, 6306, 6307, 6308, 6309, 6310 ]
class AlchemySpell < Spell class AlchemySpell < Spell
attr_reader :high, :animation, :graphic, :multiplier, :experience, :delay attr_reader :high, :animation, :graphic, :multiplier, :experience, :delay
def initialize(level, elements, high, animation, graphic, multiplier, experience, delay) def initialize(level, elements, high, animation, graphic, multiplier, experience, delay)
super level, elements, experience super(level, elements, experience)
@high = high @high = high
@animation = animation @animation = animation
@graphic = graphic @graphic = graphic
@multiplier = multiplier @multiplier = multiplier
@delay = delay @delay = delay
end end
end end
class AlchemyAction < ItemSpellAction class AlchemyAction < ItemSpellAction
def initialize(player, alchemy, slot, item) def initialize(player, alchemy, slot, item)
super player, alchemy, slot, item super(player, alchemy, slot, item)
end end
def illegal_item? def illegal_item?
return ILLEGAL_ALC_ITEMS.include? @item.id return ILLEGAL_ALCH_ITEMS.include?(@item.id)
end end
def execute_action def execute_action
player = character
if @pulses == 0 if @pulses == 0
player.play_animation(@spell.animation) mob.play_animation(@spell.animation)
player.play_graphic(@spell.graphic) mob.play_graphic(@spell.graphic)
player.send(DISPLAY_SPELLBOOK) mob.send(DISPLAY_SPELLBOOK)
inventory = player.inventory inventory = mob.inventory
gold = (item.definition.value * @spell.multiplier) gold = (item.definition.value * @spell.multiplier) + 1
inventory.remove(inventory.get(@slot).id, 1) inventory.remove(inventory.get(@slot).id, 1)
inventory.add(995, gold) inventory.add(995, gold)
player.skill_set.add_experience(MAGIC_ID, @spell.experience) mob.skill_set.add_experience(MAGIC_SKILL_ID, @spell.experience)
set_delay(@spell.delay) set_delay(@spell.delay)
elsif @pulses == 1 elsif @pulses == 1
player.stop_animation mob.stop_animation
player.stop_graphic mob.stop_graphic
stop stop
end end
end end
end end
def append_alchemy(button, level, elements, high, animation, graphic, multiplier, experience, delay) def append_alchemy(button, level, elements, high, animation, graphic, multiplier, experience, delay)
ALCHEMY_SPELLS[button] = AlchemySpell.new(level, elements, high, animation, graphic, multiplier, experience, delay) ALCHEMY_SPELLS[button] = AlchemySpell.new(level, elements, high, animation, graphic, multiplier, experience, delay)
end end
append_alchemy(1162, 21, { FIRE => 3, NATURE => 1 }, false, LOW_ALC_ANIM, LOW_ALC_GFX, 0.48, 31, 1) # Low level alchemy append_alchemy(1162, 21, { FIRE => 3, NATURE => 1 }, false, LOW_ALCH_ANIM, LOW_ALCH_GRAPHIC, 0.48, 31, 1) # Low level alchemy
append_alchemy(1178, 55, { FIRE => 5, NATURE => 1 }, true, HIGH_ALC_ANIM, HIGH_ALC_GFX, 0.72, 65, 4) # High level alchemy append_alchemy(1178, 55, { FIRE => 5, NATURE => 1 }, true, HIGH_ALCH_ANIM, HIGH_ALCH_GRAPHIC, 0.72, 65, 4) # High level alchemy
+12 -18
View File
@@ -8,16 +8,16 @@ CONVERT_SPELLS = {}
BONES_ID = 526 BONES_ID = 526
CONVERT_ANIM = Animation.new(722) CONVERT_ANIM = Animation.new(722)
CONVERT_GFX = Graphic.new(141, 0, 100) CONVERT_GRAPHIC = Graphic.new(141, 0, 100)
class ConvertSpell < Spell class ConvertSpell < Spell
attr_reader :reward attr_reader :reward
def initialize(level, elements, experience, reward) def initialize(level, elements, experience, reward)
super(level, elements, experience) super(level, elements, experience)
@reward = Item.new(reward) @reward = Item.new(reward)
end end
end end
class ConvertingAction < SpellAction class ConvertingAction < SpellAction
@@ -25,17 +25,15 @@ class ConvertingAction < SpellAction
def initialize(player, spell, slots) def initialize(player, spell, slots)
super(player, spell) super(player, spell)
@slots = slots @slots = slots
end end
def execute_action def execute_action
player = character
if @pulses == 0 if @pulses == 0
player.play_animation CONVERT_ANIM mob.play_animation(CONVERT_ANIM)
player.play_graphic CONVERT_GFX mob.play_graphic(CONVERT_GRAPHIC)
inventory = player.inventory inventory = mob.inventory
firing = (@slots.length * 2) < inventory.capacity firing = (@slots.length * 2) < inventory.capacity
inventory.stop_firing_events unless firing # In the case of many changes, wait with firing events inventory.stop_firing_events unless firing # In the case of many changes, wait with firing events
@@ -50,16 +48,15 @@ class ConvertingAction < SpellAction
inventory.force_refresh inventory.force_refresh
end end
player.skill_set.add_experience MAGIC_ID, @spell.experience mob.skill_set.add_experience(MAGIC_SKILL_ID, @spell.experience)
set_delay(2)
set_delay 2
elsif @pulses == 1 elsif @pulses == 1
player.stop_animation mob.stop_animation
player.stop_graphic mob.stop_graphic
stop stop
end end
end end
end end
def bone_slots(player) def bone_slots(player)
@@ -73,9 +70,7 @@ def bone_slots(player)
break unless counter <= size break unless counter <= size
item = items[slot] item = items[slot]
if item != nil and item.id == BONES_ID slots << slot if (item != nil and item.id == BONES_ID)
slots << slot
end
counter += 1 counter += 1
end end
@@ -84,8 +79,7 @@ def bone_slots(player)
end end
def append_convert(button, level, elements, experience, reward) def append_convert(button, level, elements, experience, reward)
convert = ConvertSpell.new(level, elements, experience, reward) CONVERT_SPELLS[button] = ConvertSpell.new(level, elements, experience, reward)
CONVERT_SPELLS[button] = convert
end end
append_convert 1159, 15, { EARTH => 2, WATER => 2, NATURE => 1 }, 25, 1963 # Bones to bananas append_convert 1159, 15, { EARTH => 2, WATER => 2, NATURE => 1 }, 25, 1963 # Bones to bananas
+1
View File
@@ -83,6 +83,7 @@ class Element
return false return false
end end
end end
AIR_RUNES = [ 556, 4695, 4696, 4697 ] AIR_RUNES = [ 556, 4695, 4696, 4697 ]
+10 -13
View File
@@ -25,13 +25,13 @@ class EnchantSpell < Spell
attr_reader :button, :animation, :graphic, :delay attr_reader :button, :animation, :graphic, :delay
def initialize(button, level, elements, animation, graphic, delay, experience) def initialize(button, level, elements, animation, graphic, delay, experience)
super level, elements, experience super(level, elements, experience)
@button = button @button = button
@animation = animation @animation = animation
@graphic = graphic @graphic = graphic
@delay = delay @delay = delay
end end
end end
class EnchantAction < ItemSpellAction class EnchantAction < ItemSpellAction
@@ -39,7 +39,6 @@ class EnchantAction < ItemSpellAction
def initialize(player, enchant, slot, item, reward) def initialize(player, enchant, slot, item, reward)
super(player, enchant, slot, item) super(player, enchant, slot, item)
@reward = Item.new(reward) @reward = Item.new(reward)
end end
@@ -48,20 +47,18 @@ class EnchantAction < ItemSpellAction
end end
def execute_action def execute_action
player = character
if @pulses == 0 if @pulses == 0
player.play_animation @spell.animation mob.play_animation(@spell.animation)
player.play_graphic @spell.graphic mob.play_graphic(@spell.graphic)
player.send DISPLAY_SPELLBOOK mob.send(DISPLAY_SPELLBOOK)
player.inventory.set @slot, @reward mob.inventory.set(@slot, @reward)
player.skill_set.add_experience MAGIC_ID, @spell.experience mob.skill_set.add_experience(MAGIC_SKILL_ID, @spell.experience)
set_delay @spell.delay set_delay(@spell.delay)
elsif @pulses == 1 elsif @pulses == 1
player.stop_animation mob.stop_animation
player.stop_graphic mob.stop_graphic
stop stop
end end
end end
+18 -17
View File
@@ -5,8 +5,7 @@ java_import 'org.apollo.game.event.impl.DisplayTabInterfaceEvent'
java_import 'org.apollo.game.model.EquipmentConstants' java_import 'org.apollo.game.model.EquipmentConstants'
java_import 'org.apollo.game.model.Skill' java_import 'org.apollo.game.model.Skill'
MAGIC_ID = Skill::MAGIC DISPLAY_SPELLBOOK = DisplayTabInterfaceEvent.new(6)
DISPLAY_SPELLBOOK = DisplayTabInterfaceEvent.new 6
class Spell class Spell
attr_reader :level, :elements, :experience attr_reader :level, :elements, :experience
@@ -16,6 +15,7 @@ class Spell
@elements = elements @elements = elements
@experience = experience @experience = experience
end end
end end
class SpellAction < Action class SpellAction < Action
@@ -45,8 +45,8 @@ class SpellAction < Action
def check_skill def check_skill
required = @spell.level required = @spell.level
if required > mob.skill_set.skill(MAGIC_ID).maximum_level if required > mob.skill_set.skill(MAGIC_SKILL_ID).maximum_level
mob.send_message "You need a Magic level of at least #{required} to cast this spell." mob.send_message("You need a Magic level of at least #{required} to cast this spell.")
return false return false
end end
@@ -58,7 +58,7 @@ class SpellAction < Action
elements.each do |element, amount| elements.each do |element, amount|
unless element.check_remove(mob, amount, false) unless element.check_remove(mob, amount, false)
mob.send_message "You do not have enough #{element.name}s to cast this spell." mob.send_message("You do not have enough #{element.name}s to cast this spell.")
return false return false
end end
end end
@@ -73,6 +73,7 @@ class SpellAction < Action
def equals(other) def equals(other)
return (get_class == other.get_class and @spell == other.spell) return (get_class == other.get_class and @spell == other.spell)
end end
end end
class ItemSpellAction < SpellAction class ItemSpellAction < SpellAction
@@ -80,7 +81,6 @@ class ItemSpellAction < SpellAction
def initialize(mob, spell, slot, item) def initialize(mob, spell, slot, item)
super(mob, spell) super(mob, spell)
@slot = slot @slot = slot
@item = item @item = item
end end
@@ -89,9 +89,9 @@ class ItemSpellAction < SpellAction
def execute def execute
if @pulses == 0 if @pulses == 0
if illegal_item? if illegal_item?
mob.send_message "You cannot use that spell on this item!" mob.send_message('You cannot use that spell on this item!')
stop stop
return next
end end
id = @item.id id = @item.id
@@ -100,9 +100,9 @@ class ItemSpellAction < SpellAction
@spell.elements.each do |element, amount| @spell.elements.each do |element, amount|
element.runes.each do |rune| element.runes.each do |rune|
if id == rune && !element.check_remove(mob, amount + 1, false) if id == rune && !element.check_remove(mob, amount + 1, false)
mob.send_message("You do not have enough " + element.name + "s to cast this spell.") mob.send_message("You do not have enough #{element.name}s to cast this spell.")
stop stop
return return false
end end
end end
end end
@@ -116,17 +116,18 @@ class ItemSpellAction < SpellAction
# Override this method if necessary # Override this method if necessary
return false return false
end end
end end
# MagicOnItemEvent handling # Intercepts the magic on item event.
on :event, :magic_on_item do |ctx, player, event| on :event, :magic_on_item do |ctx, player, event|
spell = event.spell_id spell = event.spell_id
alch = ALCHEMY_SPELLS[spell] alch = ALCHEMY_SPELLS[spell]
if alch != nil if alch != nil
slot = event.slot slot = event.slot
item = player.inventory.get slot item = player.inventory.get(slot)
player.start_action AlchemyAction.new(player, alch, slot, item) player.start_action(AlchemyAction.new(player, alch, slot, item))
ctx.break_handler_chain ctx.break_handler_chain
return return
end end
@@ -134,19 +135,19 @@ on :event, :magic_on_item do |ctx, player, event|
ench = ENCHANT_SPELLS[event.id] ench = ENCHANT_SPELLS[event.id]
if ench != nil and ench.button == spell if ench != nil and ench.button == spell
slot = event.slot slot = event.slot
item = player.inventory.get slot item = player.inventory.get(slot)
player.start_action EnchantAction.new(player, ench, slot, item, ENCHANT_ITEMS[item.id]) player.start_action(EnchantAction.new(player, ench, slot, item, ENCHANT_ITEMS[item.id]))
ctx.break_handler_chain ctx.break_handler_chain
end end
end end
# ButtonEvent handling # Intercepts the button event
on :event, :button do |ctx, player, event| on :event, :button do |ctx, player, event|
button = event.widget_id button = event.widget_id
tele = TELEPORT_SPELLS[button] tele = TELEPORT_SPELLS[button]
if tele != nil if tele != nil
player.start_action TeleportingAction.new(player, tele) player.start_action(TeleportingAction.new(player, tele))
ctx.break_handler_chain ctx.break_handler_chain
return return
end end
+17 -19
View File
@@ -10,11 +10,11 @@ TELEPORT_SPELLS = {}
MODERN_TELE_ANIM = Animation.new(714) MODERN_TELE_ANIM = Animation.new(714)
MODERN_TELE_END_ANIM = Animation.new(715) MODERN_TELE_END_ANIM = Animation.new(715)
MODERN_TELE_GFX = Graphic.new(308, 15, 100) MODERN_TELE_GRAPHIC = Graphic.new(308, 15, 100)
ANCIENT_TELE_END_GFX = Graphic.new(455) ANCIENT_TELE_END_GRAPHIC = Graphic.new(455)
ANCIENT_TELE_ANIM = Animation.new(1979) ANCIENT_TELE_ANIM = Animation.new(1979)
ANCIENT_TELE_GFX = Graphic.new(392) ANCIENT_TELE_GRAPHIC = Graphic.new(392)
class TeleportSpell < Spell class TeleportSpell < Spell
attr_reader :ancient, :destination, :experience, :name attr_reader :ancient, :destination, :experience, :name
@@ -25,6 +25,7 @@ class TeleportSpell < Spell
@destination = destination @destination = destination
@name = name @name = name
end end
end end
class TeleportingAction < SpellAction class TeleportingAction < SpellAction
@@ -38,37 +39,34 @@ class TeleportingAction < SpellAction
end end
def execute_modern def execute_modern
player = mob
if @pulses == 0 if @pulses == 0
player.play_animation(MODERN_TELE_ANIM) mob.play_animation(MODERN_TELE_ANIM)
elsif @pulses == 1 elsif @pulses == 1
player.play_graphic(MODERN_TELE_GFX) mob.play_graphic(MODERN_TELE_GRAPHIC)
delay = 1 delay = 1
elsif @pulses == 2 elsif @pulses == 2
player.stop_graphic mob.stop_graphic
player.play_animation(MODERN_TELE_END_ANIM) mob.play_animation(MODERN_TELE_END_ANIM)
mob.teleport(@spell.destination)
destination = @spell.destination mob.skill_set.add_experience(MAGIC_SKILL_ID, @spell.experience)
player.teleport(destination)
player.skill_set.add_experience(MAGIC_ID, @spell.experience)
stop stop
end end
end end
def execute_ancient def execute_ancient
player = mob
if @pulses == 0 if @pulses == 0
player.play_graphic(ANCIENT_TELE_GFX) mob.play_graphic(ANCIENT_TELE_GRAPHIC)
player.play_animation(ANCIENT_TELE_ANIM) mob.play_animation(ANCIENT_TELE_ANIM)
delay = 2 delay = 2
elsif @pulses == 1 elsif @pulses == 1
player.stop_graphic mob.stop_graphic
player.stop_animation mob.stop_animation
player.teleport(@spell.destination) mob.teleport(@spell.destination)
player.skill_set.add_experience(MAGIC_ID, @spell.experience) mob.skill_set.add_experience(MAGIC_SKILL_ID, @spell.experience)
stop stop
end end
end end
end end
def append_tele(ancient, button, level, elements, x, y, experience, name) def append_tele(ancient, button, level, elements, x, y, experience, name)