Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AnimaAnimus]Result対応 #436

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions lib/bcdice/game_system/AnimaAnimus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'bcdice/dice_table/table'
require 'bcdice/dice_table/range_table'
require 'bcdice/arithmetic_evaluator'
require 'bcdice/arithmetic'

module BCDice
module GameSystem
Expand Down Expand Up @@ -32,17 +32,19 @@ class AnimaAnimus < Base
MESSAGETEXT

def eval_game_system_specific_command(command)
case command
when /(\d+)AN<=(\d+([+\-]\d+)*)/i
return check_action(Regexp.last_match)
else
m = /(\d+)AN<=(\d+([+\-]\d+)*)/i.match(command)
if TABLES.key?(command)
return roll_tables(command, TABLES)
elsif m
return check_action(m)
else
return nil
end
end

def check_action(match_data)
dice_cnt = ArithmeticEvaluator.eval(match_data[1])
target = ArithmeticEvaluator.eval(match_data[2])
dice_cnt = Arithmetic.eval(match_data[1], RoundType::FLOOR)
target = Arithmetic.eval(match_data[2], RoundType::FLOOR)
debug("dice_cnt", dice_cnt)
debug("target", target)

Expand All @@ -52,7 +54,12 @@ def check_action(match_data)
has_critical = dice_arr.include?(1)
result = has_critical ? suc_cnt + 2 : suc_cnt

return "(#{dice_cnt}B10<=#{target}) > #{dice_str} > #{result > 0 ? '成功' : '失敗'}(達成値:#{result})#{has_critical ? ' (クリティカル発生)' : ''}"
Result.new.tap do |r|
r.text = "(#{dice_cnt}B10<=#{target}) > #{dice_str} > #{result > 0 ? '成功' : '失敗'}(達成値:#{result})#{has_critical ? ' (クリティカル発生)' : ''}"
r.critical = has_critical
r.success = result > 0
r.failure = !r.success?
end
end

TABLES = {
Expand Down
26 changes: 26 additions & 0 deletions test/data/AnimaAnimus.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
game_system = "AnimaAnimus"
input = "3AN<=3"
output = "(3B10<=3) > 2,3,4 > 成功(達成値:2)"
success = true
rands = [
{ sides = 10, value = 2 },
{ sides = 10, value = 3 },
Expand All @@ -12,6 +13,7 @@ rands = [
game_system = "AnimaAnimus"
input = "3AN<=3+1"
output = "(3B10<=4) > 2,3,4 > 成功(達成値:3)"
success = true
rands = [
{ sides = 10, value = 2 },
{ sides = 10, value = 3 },
Expand All @@ -22,6 +24,7 @@ rands = [
game_system = "AnimaAnimus"
input = "3AN<=1-2"
output = "(3B10<=-1) > 2,3,4 > 失敗(達成値:0)"
failure = true
rands = [
{ sides = 10, value = 2 },
{ sides = 10, value = 3 },
Expand All @@ -32,6 +35,8 @@ rands = [
game_system = "AnimaAnimus"
input = "3AN<=1-2"
output = "(3B10<=-1) > 2,3,1 > 成功(達成値:2) (クリティカル発生)"
success = true
critical = true
rands = [
{ sides = 10, value = 2 },
{ sides = 10, value = 3 },
Expand All @@ -42,6 +47,7 @@ rands = [
game_system = "AnimaAnimus"
input = "(3+1)AN<=3-1"
output = "(4B10<=2) > 2,3,4,4 > 成功(達成値:1)"
success = true
rands = [
{ sides = 10, value = 2 },
{ sides = 10, value = 3 },
Expand All @@ -53,6 +59,8 @@ rands = [
game_system = "AnimaAnimus"
input = "3AN<=3"
output = "(3B10<=3) > 1,2,5 > 成功(達成値:4) (クリティカル発生)"
success = true
critical = true
rands = [
{ sides = 10, value = 1 },
{ sides = 10, value = 2 },
Expand All @@ -63,6 +71,8 @@ rands = [
game_system = "AnimaAnimus"
input = "3AN<=3"
output = "(3B10<=3) > 9,1,1 > 成功(達成値:4) (クリティカル発生)"
success = true
critical = true
rands = [
{ sides = 10, value = 9 },
{ sides = 10, value = 1 },
Expand All @@ -73,6 +83,7 @@ rands = [
game_system = "AnimaAnimus"
input = "3AN<=3"
output = "(3B10<=3) > 7,6,5 > 失敗(達成値:0)"
failure = true
rands = [
{ sides = 10, value = 7 },
{ sides = 10, value = 6 },
Expand All @@ -83,6 +94,7 @@ rands = [
game_system = "AnimaAnimus"
input = "5AN<=7"
output = "(5B10<=7) > 4,4,9,6,7 > 成功(達成値:4)"
success = true
rands = [
{ sides = 10, value = 4 },
{ sides = 10, value = 4 },
Expand All @@ -95,6 +107,8 @@ rands = [
game_system = "AnimaAnimus"
input = "5AN<=7"
output = "(5B10<=7) > 4,4,9,1,7 > 成功(達成値:6) (クリティカル発生)"
success = true
critical = true
rands = [
{ sides = 10, value = 4 },
{ sides = 10, value = 4 },
Expand All @@ -107,6 +121,8 @@ rands = [
game_system = "AnimaAnimus"
input = "5AN<=7"
output = "(5B10<=7) > 4,1,9,1,7 > 成功(達成値:6) (クリティカル発生)"
success = true
critical = true
rands = [
{ sides = 10, value = 4 },
{ sides = 10, value = 1 },
Expand All @@ -119,6 +135,7 @@ rands = [
game_system = "AnimaAnimus"
input = "5AN<=7"
output = "(5B10<=7) > 10,8,9,9,8 > 失敗(達成値:0)"
failure = true
rands = [
{ sides = 10, value = 10 },
{ sides = 10, value = 8 },
Expand All @@ -131,6 +148,7 @@ rands = [
game_system = "AnimaAnimus"
input = "(5+1)AN<=7"
output = "(6B10<=7) > 7,3,10,9,10,3 > 成功(達成値:3)"
success = true
rands = [
{ sides = 10, value = 7 },
{ sides = 10, value = 3 },
Expand All @@ -144,6 +162,8 @@ rands = [
game_system = "AnimaAnimus"
input = "(5+1)AN<=7"
output = "(6B10<=7) > 9,2,1,7,8,2 > 成功(達成値:6) (クリティカル発生)"
success = true
critical = true
rands = [
{ sides = 10, value = 9 },
{ sides = 10, value = 2 },
Expand All @@ -157,6 +177,7 @@ rands = [
game_system = "AnimaAnimus"
input = "3an<=3"
output = "(3B10<=3) > 2,3,4 > 成功(達成値:2)"
success = true
rands = [
{ sides = 10, value = 2 },
{ sides = 10, value = 3 },
Expand All @@ -167,6 +188,7 @@ rands = [
game_system = "AnimaAnimus"
input = "3An<=3"
output = "(3B10<=3) > 2,3,4 > 成功(達成値:2)"
success = true
rands = [
{ sides = 10, value = 2 },
{ sides = 10, value = 3 },
Expand All @@ -177,6 +199,7 @@ rands = [
game_system = "AnimaAnimus"
input = "3aN<=3"
output = "(3B10<=3) > 2,3,4 > 成功(達成値:2)"
success = true
rands = [
{ sides = 10, value = 2 },
{ sides = 10, value = 3 },
Expand All @@ -187,6 +210,7 @@ rands = [
game_system = "AnimaAnimus"
input = "S3AN<=3"
output = "(3B10<=3) > 2,3,4 > 成功(達成値:2)"
success = true
secret = true
rands = [
{ sides = 10, value = 2 },
Expand All @@ -198,6 +222,8 @@ rands = [
game_system = "AnimaAnimus"
input = "S(5+1)AN<=7"
output = "(6B10<=7) > 9,2,1,7,8,2 > 成功(達成値:6) (クリティカル発生)"
success = true
critical = true
secret = true
rands = [
{ sides = 10, value = 9 },
Expand Down