summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/game_controller.rb55
1 files changed, 24 insertions, 31 deletions
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb
index c63fbc5..0e6e37b 100644
--- a/app/controllers/game_controller.rb
+++ b/app/controllers/game_controller.rb
@@ -27,6 +27,7 @@ class GameController < ApplicationController
if table_roll >= score
activity = Activity.find_by_gid(table_entry[:gid])
monster = Monster.find_by_gid(table_entry[:gid])
+ @results.push({ type: type, monster: monster })
resolve_combat_with(monster)
end
end
@@ -106,60 +107,52 @@ class GameController < ApplicationController
char_hp = current_char.max_hp
mon_hp = mon.max_hp
combat_message = ->(msg) { @results.push({ type: "message", body: "[#{char_hp}/#{char.max_hp}] #{msg}" }) }
- combat_message.call("You encountered a #{mon.name}.")
char_initiative = roll(10) + char.speed
mon_initative = roll(10) + mon.speed
if char_initiative > mon_initative
- turn_order = [char, mon]
+ turn_order = [[char, mon], [mon, char]]
elsif mon_initative > char_initiative
- turn_order = [mon, char]
+ turn_order = [[mon, char], [char, mon]]
else
- turn_order = [char, mon].shuffle
+ turn_order = [[char, mon], [mon, char]].shuffle
end
- turn_order.cycle do |actor|
- case actor
- when char
- accuracy_roll = roll(20) + char.accuracy
- evasion_roll = roll(20) + mon.evasion
- if accuracy_roll >= evasion_roll
- dealt_damage = roll(4) + char.power # TODO: Replace d4 with weapon damage
- if accuracy_roll >= (evasion_roll + 10)
- combat_message.call("You landed a critical hit!")
- dealt_damage = dealt_damage * 2
- end
- blocked_damage = (accuracy_roll >= (roll(20) + mon.block)) ? 0 : mon.block_value
- resolved_damage = dealt_damage - blocked_damage
- mon_hp -= resolved_damage
- combat_message.call("You hit for #{resolved_damage} (#{dealt_damage} - #{blocked_damage} blocked)")
- elsif evasion_roll > accuracy_roll
- combat_message.call("The #{mon.name} evaded your attack.")
+ turn_order.cycle do |actor, target|
+ base_accuracy_roll = roll(20)
+ accuracy_roll = base_accuracy_roll + actor.accuracy
+ evasion_roll = roll(20) + target.evasion
+ if accuracy_roll >= evasion_roll
+ dealt_damage = roll(4) + actor.power # TODO: Replace d4 with weapon damage
+ if base_accuracy_roll == 20
+ combat_message.call("#{actor.name} landed a critical hit!")
+ dealt_damage = dealt_damage * 2
end
- when mon
- combat_message.call("Monsters don't get turns yet.")
- else
- raise "Invalid combatant (class is #{actor.class})"
+ blocked_damage = (accuracy_roll >= (roll(20) + mon.block)) ? 0 : mon.block_value
+ resolved_damage = dealt_damage - blocked_damage
+ actor == char ? mon_hp -= resolved_damage : char_hp -= resolved_damage
+ combat_message.call("#{actor.name} hit for #{resolved_damage} (#{dealt_damage} - #{blocked_damage} blocked)")
+ elsif evasion_roll > accuracy_roll
+ combat_message.call("#{target.name} evaded #{actor.name}'s attack.")
end
if char_hp < 1 || mon_hp < 1
if char_hp < 1
- combat_message.call("You were defeated! You retreat, wounded.")
- char.increment(:wounds)
+ @results.push({ type: "message", body: "You were defeated! You retreat, wounded." })
+ char.wounds += 1
+ char.save!
else
- combat_message.call("You defeated the #{mon.name}.")
+ @results.push({ type: "message", body: "You slew the #{mon.name}." })
mon.whatnot[:awards]&.each do |award_data|
case award_data[:type]
when "xp"
skill = Skill.find_by_gid(award_data[:skill])
amount = award_data[:base]
char.add_skill_xp(skill, amount)
- combat_message.call("You gained #{amount} #{skill.name} XP.")
+ @results.push({ type: "xp", skill: skill, xp: amount })
else
raise "Invalid award type string (#{award_data[:type]})"
end
end
end
break
- else
- combat_message.call("-" * 20)
end
end
end