Module: Attack
- Defined in:
- lib/Olib/combat/attack.rb
Constant Summary collapse
- AS_DS_PATTERN =
AS: 491 vs DS: 195 with AvD: 25 d100 roll: 80 = 401
/AS: (?<as>.*) vs DS: (?<ds>.*) with AvD: (?<avd>.*) \+ d100 roll: (?<roll>.*) = (?<total>.*)$/
- CS_TD_PATTERN =
/CS: (?<cs>.*) \- TD: (?<td>.*) \+ CvA: (?<cva>.*) \+ d100: (?<roll>.*) == (?<total>.*)$/
Class Method Summary collapse
- .apply(creature, verb, qstrike: 0) ⇒ Object
- .build_command(verb, qstrike) ⇒ Object
- .parse_as_ds(line) ⇒ Object
- .parse_cs_td(line) ⇒ Object
- .parse_result(lines) ⇒ Object
Class Method Details
.apply(creature, verb, qstrike: 0) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/Olib/combat/attack.rb', line 19 def self.apply(creature, verb, qstrike: 0) begin return [:err, :dead] if creature.dead? waitrt? waitcastrt? return [:err, :dead] if creature.dead? code, lines = @matcher.capture(creature.to_h, build_command(verb, qstrike)) return parse_result(lines) unless lines.empty? return code rescue => exception return [:err, exception] end end |
.build_command(verb, qstrike) ⇒ Object
33 34 35 36 |
# File 'lib/Olib/combat/attack.rb', line 33 def self.build_command(verb, qstrike) return %[#{verb} \#{{id}}] if qstrike.eql?(0) return %[qstrike #{qstrike} #{verb} \#{{id}}] end |
.parse_as_ds(line) ⇒ Object
52 53 54 55 56 |
# File 'lib/Olib/combat/attack.rb', line 52 def self.parse_as_ds(line) resolution = OpenStruct.new line.match(AS_DS_PATTERN).to_h resolution[:likelihood] = (resolution.as + resolution.avd) - resolution.ds return resolution end |
.parse_cs_td(line) ⇒ Object
46 47 48 49 50 |
# File 'lib/Olib/combat/attack.rb', line 46 def self.parse_cs_td(line) resolution = OpenStruct.new line.match(CS_TD_PATTERN).to_h resolution[:likelihood] = (resolution.cs + resolution.cva) - resolution.td return resolution end |
.parse_result(lines) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/Olib/combat/attack.rb', line 38 def self.parse_result(lines) as_ds = lines.find {|line| line =~AS_DS_PATTERN} return [:ok, parse_as_ds(as_ds)] if as_ds cs_td = lines.find {|line| line =~CS_TD_PATTERN} return [:ok, parse_cs_td(cs_td)] if cs_td return [:err, :unknown] end |