Class: FifthedSim::Actor

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

Defined Under Namespace

Classes: DefinitionProxy

Constant Summary collapse

ASSIGNABLE_ATTRS =
[:base_ac, 
:name, 
:attacks, 
:spells]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Actor

Returns a new instance of Actor.



60
61
62
63
# File 'lib/fifthed_sim/actor.rb', line 60

def initialize(attrs)
  attrs.to_a.keep_if{ |(k, v)| ASSIGNABLE_ATTRS.include?(v) }
    .each { |(k, v)| self.instance_variable_set("@#{k}", v) }
end

Instance Attribute Details

#attacksObject (readonly)

Returns the value of attribute attacks.



75
76
77
# File 'lib/fifthed_sim/actor.rb', line 75

def attacks
  @attacks
end

#base_acObject (readonly)

Returns the value of attribute base_ac.



75
76
77
# File 'lib/fifthed_sim/actor.rb', line 75

def base_ac
  @base_ac
end

#nameObject (readonly)

Returns the value of attribute name.



75
76
77
# File 'lib/fifthed_sim/actor.rb', line 75

def name
  @name
end

#spellsObject (readonly)

Returns the value of attribute spells.



75
76
77
# File 'lib/fifthed_sim/actor.rb', line 75

def spells
  @spells
end

Class Method Details

.define(name, &block) ⇒ Object



51
52
53
54
# File 'lib/fifthed_sim/actor.rb', line 51

def self.define(name, &block)
  d = DefinitionProxy.new(name, &block)
  return self.new(d.attrs)
end

Instance Method Details

#acObject

TODO: Implement armor



71
72
73
# File 'lib/fifthed_sim/actor.rb', line 71

def ac
  base_ac
end

#random_attackObject



65
66
67
# File 'lib/fifthed_sim/actor.rb', line 65

def random_attack
  @attacks.keys.sample
end