diff options
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activity_processor.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb index 73f296d..5e6acaf 100644 --- a/app/lib/activity_processor.rb +++ b/app/lib/activity_processor.rb @@ -210,18 +210,30 @@ class ActivityProcessor base_accuracy_roll = roll(20) accuracy_roll = base_accuracy_roll + actor.accuracy(with_combat_style: true) evasion_roll = roll(20) + target.evasion(with_combat_style: true) - if accuracy_roll >= evasion_roll - dealt_damage = roll(4) + actor.power(with_combat_style: true) # TODO: Replace d4 with weapon damage + if accuracy_roll >= evasion_roll || base_accuracy_roll == 20 + + dealt_damage = {} + actor.damage_ranges.each do |data| + damage_roll = rand(data[:min]..data[:max]) + dealt_damage[data[:gid]] = damage_roll + end + if base_accuracy_roll == 20 combat_message.call("#{actor.name} landed a critical hit!") - dealt_damage = dealt_damage * 2 + dealt_damage.each do |gid, amount| + dealt_damage[gid] = amount * 2 + end end - blocked_damage = (accuracy_roll >= (roll(20) + target.block(with_combat_style: true))) ? 0 : target.block_value - blocked_damage = [blocked_damage, (dealt_damage - 1)].min - resolved_damage = dealt_damage - blocked_damage - actor == char ? mon_hp -= resolved_damage : char_hp -= resolved_damage - damage_text = "#{resolved_damage} damage." - damage_text += " (#{dealt_damage} - #{blocked_damage} blocked)" if blocked_damage > 0 + + resolved_damage = {} + dealt_damage.each do |gid, amount| + effective_resistance = [target.resistance(gid), amount].min + resolved_damage[gid] = amount - (effective_resistance * rand(0.5..1)).round + end + + total_damage = resolved_damage.values.sum + actor == char ? mon_hp -= total_damage : char_hp -= total_damage + damage_text = "#{total_damage} damage (#{resolved_damage.to_a.map { |gid, amount| "#{amount} #{gid}" }.join(", ")})" combat_message.call("#{actor.name} hit for #{damage_text}") elsif evasion_roll > accuracy_roll combat_message.call("#{target.name} evaded #{actor.name}'s attack.") |