class Rules::AttackTurn
Attack turn. A new AttackTurn
object is created for each attack action
- The initializer receives the attacker and the defender sheets, from where it extracts the attacker weapon and defender armor used - The process_options method is the key help of this gem. The options from your rules system are coded into characters to be used in the prompt after a '-' - The resolve method resolves the attack action
Public Class Methods
new(attacker_sheet, defender_sheet)
click to toggle source
Extracts the attacker weapon and defender armor used Defines the globals to handle the options
# File data/rpg-prompt/rules_default.rb, line 126 def initialize(attacker_sheet, defender_sheet) @attacker_sheet = attacker_sheet @defender_sheet = defender_sheet @weapon = Weapon.new(@attacker_sheet) @armor = Armor.new(@defender_sheet) if @no_damage == nil @no_damage = false @modifier = 0 end end
Public Instance Methods
mod_roll(roll)
click to toggle source
helper method for resolve. It prompts the modifier
# File data/rpg-prompt/rules_default.rb, line 172 def mod_roll(roll) r = roll + @modifier Message.help(:attack_roll, {r: r, roll: roll, modifier: @modifier}) r end
process_options(options)
click to toggle source
Process the options matching a rule with a character to be typed in the prompt after a slash
# File data/rpg-prompt/rules_default.rb, line 139 def process_options(options) @no_damage = false @modifier = 0 distance = 0 options.each do |option| c = option[0] option[0] = ' ' case c when 'c' #check modifiers, no damage is done @no_damage = true when 'f' #flank attack @modifier += 1 when 'r' #attack from the rear @modifier += 2 when 'h' #higher ground @modifier += 1 when 's' #surprise @modifier += 2 when 'u' #attack while unsheathing @modifier -= -1 when 'd' #distance modifier distance += 1 end end if (distance > 0) && (distance < @weapon.weapon[:distance_mod].length) @modifier += @weapon.weapon[:distance_mod][distance][1] elsif (distance > 0) && (distance >= @weapon.weapon[:distance_mod].length) @no_damage = true end return @no_damage, @modifier end
resolve()
click to toggle source
Resolves the attack, with the modifier from process_options
# File data/rpg-prompt/rules_default.rb, line 179 def resolve # In these rules, attacks are resolved with d10 roll = Dice.prompt_roll(:d10) mod_roll = mod_roll(roll) # damage may be different for each weapon-armor combination damage = @weapon.damage_roll(@armor, mod_roll) # unless check option, reduce defender health points unless @no_damage then @defender_sheet.reduce_health(damage) end if damage > 0 Message.help(:hits_lose_hp, {full_name: @defender_sheet.full_name, damage: damage}) end end