Class: PfrpgCore::Attack

Inherits:
Object
  • Object
show all
Includes:
Filterable
Defined in:
lib/pfrpg_core/attack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Filterable

#apply_filters

Constructor Details

#initialize(args) ⇒ Attack



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pfrpg_core/attack.rb', line 10

def initialize(args)
  @weapon_name    = args[:weapon_name]
  @range          = args[:range]
  @weight_class   = args[:weight_class]
  @damage         = args[:damage]
  @weapon_type    = args[:weapon_type]
  @critical_range = args[:critical_range]
  @critical_dmg   = args[:critical_dmg]
  @weapon_bonus   = args[:bonus] # bonus from weapon
  @strength_bonus = args[:strength_bonus]
  @bab            = args[:bab]
  @size           = args[:size]
  @filters        = args[:filters]
  @filter_str     = []
  @weapon         = args[:weapon]
  @macros         = args[:macros]
  @other_bonus    = 0 # things like weapon spec, training, etc
  apply_filters
end

Instance Attribute Details

#babObject

Returns the value of attribute bab.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def bab
  @bab
end

#base_bonusObject

Returns the value of attribute base_bonus.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def base_bonus
  @base_bonus
end

#critical_dmgObject

Returns the value of attribute critical_dmg.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def critical_dmg
  @critical_dmg
end

#critical_rangeObject

Returns the value of attribute critical_range.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def critical_range
  @critical_range
end

#damageObject

Returns the value of attribute damage.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def damage
  @damage
end

#filter_strObject

Returns the value of attribute filter_str.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def filter_str
  @filter_str
end

#macrosObject

Returns the value of attribute macros.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def macros
  @macros
end

#other_bonusObject

Returns the value of attribute other_bonus.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def other_bonus
  @other_bonus
end

#rangeObject

Returns the value of attribute range.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def range
  @range
end

#sizeObject

Returns the value of attribute size.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def size
  @size
end

#strength_bonusObject

Returns the value of attribute strength_bonus.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def strength_bonus
  @strength_bonus
end

#weaponObject

Returns the value of attribute weapon.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def weapon
  @weapon
end

#weapon_bonusObject

Returns the value of attribute weapon_bonus.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def weapon_bonus
  @weapon_bonus
end

#weapon_nameObject

Returns the value of attribute weapon_name.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def weapon_name
  @weapon_name
end

#weapon_typeObject

Returns the value of attribute weapon_type.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def weapon_type
  @weapon_type
end

#weight_classObject

Returns the value of attribute weight_class.



5
6
7
# File 'lib/pfrpg_core/attack.rb', line 5

def weight_class
  @weight_class
end

Instance Method Details

#as_json(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pfrpg_core/attack.rb', line 44

def as_json(options={})
  {
      :weapon_name  => @weapon_name,
      :range        => @range,
      :weight_class => @weight_class,
      :damage       => get_damage.to_s,
      :weapon_type  => @weapon_type,
      :critical_range => @critical_range,
      :critical_dmg => @critical_dmg,
      :weapon_bonus => @weapon_bonus,
      :strength_bonus   => @strength_bonus,
      :other_bonus  => @other_bonus,
      :attack_bonus => attack_bonus,
      :filters      => filter_str,
      :macros       => @macros.map { |m| m.as_json }
  }
end

#attack_bonusObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pfrpg_core/attack.rb', line 30

def attack_bonus
  attacks = []
  static_bonus = NullObject.maybe(weapon_bonus) +
      NullObject.maybe(other_bonus) +
      NullObject.maybe(strength_bonus)
  base = NullObject.maybe(bab)
  attacks << (static_bonus + base)
  while(base >= 6)
    base -= 5
    attacks << (static_bonus + base)
  end
  return attacks
end

#get_damageObject



62
63
64
# File 'lib/pfrpg_core/attack.rb', line 62

def get_damage
  size == 'MEDIUM' ? damage.dmg_m : damage.dmg_s
end