Files
apollo/data/plugins/combat/attack_requirements.rb
T
Gary Tierney 348e5cc8dc Build a framework for a maintainable combat plugin
* Uses a hierarchy of WeaponClasses -> Weapons for performing attacks,
  with WeaponClass having a set of styles and associated Attacks for
  those styles. Weapons and their classes are built with an easy to use
  and clean DSL.

* Adds a BonusContainer mixin, so that Equipment, Weapons, and
  WeaponClasses can all have their own set of bonuses which apply to the
  player.

* Allows attacks to be queued to the Mobs CombatState instance from
  external code, allowing e.g., NPCs or auto-cast to queue attacks to be
  executed.
2016-02-29 21:27:17 +00:00

57 lines
1.2 KiB
Ruby

java_import 'org.apollo.cache.def.ItemDefinition'
class AttackRequirementException < Exception
attr_reader :message
def initialize(message)
@message = message
end
end
class AttackRequirement
def validate!(player)
throw RuntimeError.new('validate! not implemented')
end
def apply(player)
throw RuntimeError.new('apply not implemented')
end
end
class SpecialEnergyRequirement < AttackRequirement
def initialize(amount)
@amount = amount
end
def validate!(player)
throw AttackRequirementException.new('Not enough special attack energy.') unless player.special_energy >= @amount
end
def apply(player)
player.special_energy = player.special_energy - @amount
end
end
class ItemRequirement < AttackRequirement
def initialize(item, amount)
@item = item
@amount = amount
end
def validate!(player)
throw AttackRequirementException.new(item_missing_message) unless player.inventory.get_amount(@item) >= @amount
end
def apply(player)
player.inventory.remove(@item, @amount)
end
private
def item_missing_message
definition = ItemDefinition.lookup(@item)
"You don't have enough #{lookup_item(@item).name}s"
end
end