Class: ItemLibrary::HealingPotion
- Defined in:
- lib/natural_20/item_library/healing_potion.rb
Instance Attribute Summary
Attributes inherited from BaseItem
Instance Method Summary collapse
- #build_map(action) ⇒ Object
- #consumable? ⇒ Boolean
-
#initialize(name, properties) ⇒ HealingPotion
constructor
A new instance of HealingPotion.
- #resolve(entity, battle) ⇒ Object
- #use!(entity, result) ⇒ Object
Methods inherited from BaseItem
Constructor Details
#initialize(name, properties) ⇒ HealingPotion
Returns a new instance of HealingPotion.
26 27 28 29 |
# File 'lib/natural_20/item_library/healing_potion.rb', line 26 def initialize(name, properties) @name = name @properties = properties end |
Instance Method Details
#build_map(action) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/natural_20/item_library/healing_potion.rb', line 4 def build_map(action) OpenStruct.new({ param: [ { type: :select_target, num: 1, range: 5, target_types: %i[allies self] } ], next: lambda { |target| action.target = target OpenStruct.new({ param: nil, next: lambda { action } }) } }) end |
#consumable? ⇒ Boolean
31 32 33 |
# File 'lib/natural_20/item_library/healing_potion.rb', line 31 def consumable? @properties[:consumable] end |
#resolve(entity, battle) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/natural_20/item_library/healing_potion.rb', line 37 def resolve(entity, battle) hp_regain_roll = Natural20::DieRoll.roll(@properties[:hp_regained], description: t('dice_roll.healing_potion'), entity: entity, battle: battle) { hp_gain_roll: hp_regain_roll } end |
#use!(entity, result) ⇒ Object
47 48 49 |
# File 'lib/natural_20/item_library/healing_potion.rb', line 47 def use!(entity, result) entity.heal!(result[:hp_gain_roll].result) end |