summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-05-26 19:26:00 -0400
committerDavid Gay <david@davidgay.org>2021-05-26 19:26:00 -0400
commit9b2acceda7e36946f9bb15ff8d1a93f9c45a964f (patch)
tree67ebf8f7fcefb4a1811074c9eec519d865c70391 /app/controllers
parent0b9b45d573cc4f836ba7a99de77e9da18e768f10 (diff)
Combat styles
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/characters_controller.rb15
-rw-r--r--app/controllers/game_controller.rb8
2 files changed, 19 insertions, 4 deletions
diff --git a/app/controllers/characters_controller.rb b/app/controllers/characters_controller.rb
index d851ad5..77e1a94 100644
--- a/app/controllers/characters_controller.rb
+++ b/app/controllers/characters_controller.rb
@@ -21,6 +21,21 @@ class CharactersController < ApplicationController
end
end
+ def set_combat_styles
+ @character = Character.find(params[:character_id])
+ unless @character == current_char
+ flash[:alert] = "You can't set the combat styles of another character."
+ redirect_to character_path(@character) and return
+ end
+ if @character.update(offensive_style: params[:offensive_style],
+ defensive_style: params[:defensive_style])
+ flash[:notice] = "Changed combat styles to #{@character.offensive_style} and #{@character.defensive_style}."
+ else
+ flash[:alert] = "Failed to set combat styles."
+ end
+ redirect_to character_path(@character)
+ end
+
private
def character_params
params.require(:character).permit(:name)
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb
index 32ddd12..922301a 100644
--- a/app/controllers/game_controller.rb
+++ b/app/controllers/game_controller.rb
@@ -149,15 +149,15 @@ class GameController < ApplicationController
end
turn_order.cycle do |actor, target|
base_accuracy_roll = roll(20)
- accuracy_roll = base_accuracy_roll + actor.accuracy
- evasion_roll = roll(20) + target.evasion
+ 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 # TODO: Replace d4 with weapon damage
+ dealt_damage = roll(4) + actor.power(with_combat_style: true) # 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
- blocked_damage = (accuracy_roll >= (roll(20) + target.block)) ? 0 : target.block_value
+ blocked_damage = (accuracy_roll >= (roll(20) + target.block(with_combat_style: true))) ? 0 : target.block_value
resolved_damage = dealt_damage - blocked_damage
actor == char ? mon_hp -= resolved_damage : char_hp -= resolved_damage
damage_text = "#{resolved_damage} damage."