Class: Core::Game::Magic

Inherits:
Object show all
Defined in:
lib/game/magic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char) ⇒ Magic

Returns a new instance of Magic.



8
9
10
11
# File 'lib/game/magic.rb', line 8

def initialize(char)
  @char = char
  @learned = []
end

Instance Attribute Details

#learnedObject (readonly)

Returns the value of attribute learned.



7
8
9
# File 'lib/game/magic.rb', line 7

def learned
  @learned
end

Instance Method Details

#cast(spell, caster, target = nil) ⇒ Object



21
22
23
24
25
# File 'lib/game/magic.rb', line 21

def cast(spell, caster, target=nil)
  if @learned.include?(spell) and @char.state == Core::Game::NORMAL
    spell.cast(caster, target)
  end
end

#cast_named(name, caster, target = nil) ⇒ Object



27
28
29
# File 'lib/game/magic.rb', line 27

def cast_named(name, caster, target=nil)
  cast(Core::Game.find_spell(name), caster, target)
end

#forget(spell) ⇒ Object



17
18
19
# File 'lib/game/magic.rb', line 17

def forget(spell)
  @learned.delete(spell)
end

#learn(spell) ⇒ Object



13
14
15
# File 'lib/game/magic.rb', line 13

def learn(spell)
  @learned.push(spell) if !@learned.include?(spell)
end