Class: RubyWarrior::Abilities::Detonate

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_warrior/abilities/detonate.rb

Instance Method Summary collapse

Methods inherited from Base

#damage, #initialize, #offset, #pass_turn, #space, #unit, #verify_direction

Constructor Details

This class inherits a constructor from RubyWarrior::Abilities::Base

Instance Method Details

#bomb(direction, x, y, damage_amount) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_warrior/abilities/detonate.rb', line 19

def bomb(direction, x, y, damage_amount)
  if @unit.position
    receiver = space(direction, x, y).unit
    if receiver
      if receiver.abilities[:explode!]
        receiver.say "caught in bomb's flames which detonates ticking explosive"
        receiver.abilities[:explode!].perform
      else
        damage(receiver, damage_amount)
      end
    end
  end
end

#descriptionObject



4
5
6
# File 'lib/ruby_warrior/abilities/detonate.rb', line 4

def description
  "Detonate a bomb in a given direction (forward by default) which damages that space and surrounding 4 spaces (including yourself)."
end

#perform(direction = :forward) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby_warrior/abilities/detonate.rb', line 8

def perform(direction = :forward)
  verify_direction(direction)
  if @unit.position
    @unit.say "detonates a bomb #{direction} launching a deadly explosion."
    bomb(direction, 1, 0, 8)
    [[1, 1], [1, -1], [2, 0], [0, 0]].each do |x, y|
      bomb(direction, x, y, 4)
    end
  end
end