Class: FifthedSim::Actor::DefinitionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/fifthed_sim/actor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ DefinitionProxy

Returns a new instance of DefinitionProxy.



4
5
6
7
8
9
10
11
12
# File 'lib/fifthed_sim/actor.rb', line 4

def initialize(name, &block)
  @attrs = {
    name: name,
    attacks: {},
    spells: {},
    base_ac: 10
  }
  instance_eval(&block)
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



14
15
16
# File 'lib/fifthed_sim/actor.rb', line 14

def attrs
  @attrs
end

Instance Method Details

#attack(name, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/fifthed_sim/actor.rb', line 16

def attack(name, &block)
  if block_given? && name.is_a?(String)
    @attrs[:attacks][name] = Attack.define(name, &block)
  elsif name.is_a?(Attack)
    @attrs[:attacks][name.name] << name
  else
    raise ArgumentError, "must be an attack"
  end
end

#base_ac(num) ⇒ Object



46
47
48
# File 'lib/fifthed_sim/actor.rb', line 46

def base_ac(num)
  @attrs[:base_ac] = num
end

#spell(name, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/fifthed_sim/actor.rb', line 26

def spell(name, &block)
  if block_given? && name.is_a?(String)
    @attrs[:spells][name] = Spell.define(name, &block)
  elsif name.is_a?(Spell)
    @attrs[:spells][name.name] << name
  else
    raise ArgumentError, "must be a spell"
  end
end

#stats(n = nil, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/fifthed_sim/actor.rb', line 36

def stats(n = nil, &block)
  if n && n.is_a?(StatBlock)
    @attrs[:stats] = n
  elsif block
    @attrs[:stats] = StatBlock.define(&block)
  else
    raise ArgumentError, "Must be a statblock"
  end
end