Class: RubyWarrior::Abilities::Form

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_warrior/abilities/form.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

#descriptionObject



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

def description
  "Forms a golem in given direction taking half of invoker's health. The passed block is executed for each golem turn."
end

#perform(direction = :forward, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_warrior/abilities/form.rb', line 8

def perform(direction = :forward, &block)
  verify_direction(direction)
  if space(direction).empty?
    x, y = @unit.position.translate_offset(*offset(direction))
    health = (@unit.health/2.0).floor
    golem = @unit.base_golem
    golem.max_health = health
    golem.turn = block
    @unit.health -= health
    @unit.position.floor.add(golem, x, y, @unit.position.direction)
    @unit.say "forms a golem #{direction} and gives half of his health (#{health})"
  else
    @unit.say "fails to form golem because something is blocking the way."
  end
end