Class: FifthedSim::Damage

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

Defined Under Namespace

Classes: DefinitionProxy

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Damage

Returns a new instance of Damage.



27
28
29
# File 'lib/fifthed_sim/damage.rb', line 27

def initialize(hash)
  @hash = hash
end

Class Method Details

.define(&block) ⇒ Object



22
23
24
25
# File 'lib/fifthed_sim/damage.rb', line 22

def self.define(&block)
  h = DefinitionProxy.new(&block).attrs
  self.new(h)
end

Instance Method Details

#rawObject



50
51
52
# File 'lib/fifthed_sim/damage.rb', line 50

def raw
  @hash.values.inject{|s, k| s + k}
end

#to(enemy) ⇒ Object

Obtain a dice roll of how much damage we’re doing to a particular enemy



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fifthed_sim/damage.rb', line 33

def to(enemy)
  mapped = @hash.map do |k, v|
    if enemy.immune_to?(k)
      0.to_dice_expression
    elsif enemy.resistant_to?(k)
      (v / 2)
    else
      v
    end
  end
  if mapped.empty?
    0.to_dice_expression
  else
    mapped.inject{|memo, x| memo + x}
  end
end