diff --git a/lib/bcdice/game_system/Warhammer.rb b/lib/bcdice/game_system/Warhammer.rb index 7dd9ee1ef..ddc485692 100644 --- a/lib/bcdice/game_system/Warhammer.rb +++ b/lib/bcdice/game_system/Warhammer.rb @@ -51,14 +51,23 @@ def eval_game_system_specific_command(command) return output_msg end - def check_1D100(total, _dice_total, cmp_op, target) - return '' if target == '?' - return '' unless cmp_op == :<= + def result_1d100(total, _dice_total, cmp_op, target) + return Result.nothing if target == '?' + return nil unless cmp_op == :<= if total <= target - " > 成功(成功度#{(target - total) / 10})" + Result.success("成功(成功度#{(target - total) / 10})") else - " > 失敗(失敗度#{(total - target) / 10})" + Result.failure("失敗(失敗度#{(total - target) / 10})") + end + end + + def result_1d100_text(total, dice_total, cmp_op, target) + result = result_1d100(total, dice_total, cmp_op, target)&.text + if result.nil? + "" + else + " > #{result}" end end @@ -322,7 +331,7 @@ def getAttackResult(string) total_n = @randomizer.roll_once(100) output = "(#{string}) > #{total_n}" - output += check_1D100(total_n, total_n, :<=, diff) + output += result_1d100_text(total_n, total_n, :<=, diff) pos_num = (total_n % 10) * 10 + (total_n / 10).to_i pos_num = 100 if total_n >= 100 diff --git a/test/data/Warhammer.toml b/test/data/Warhammer.toml index 06206af7c..c21f1b3c3 100644 --- a/test/data/Warhammer.toml +++ b/test/data/Warhammer.toml @@ -2,6 +2,7 @@ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 74 > 失敗(失敗度6)" +failure = true rands = [ { sides = 100, value = 74 }, ] @@ -10,6 +11,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 59 > 失敗(失敗度4)" +failure = true rands = [ { sides = 100, value = 59 }, ] @@ -18,6 +20,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 22 > 失敗(失敗度1)" +failure = true rands = [ { sides = 100, value = 22 }, ] @@ -26,6 +29,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 13 > 失敗(失敗度0)" +failure = true rands = [ { sides = 100, value = 13 }, ] @@ -34,6 +38,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 56 > 失敗(失敗度4)" +failure = true rands = [ { sides = 100, value = 56 }, ] @@ -42,6 +47,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 68 > 失敗(失敗度5)" +failure = true rands = [ { sides = 100, value = 68 }, ] @@ -50,6 +56,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 89 > 失敗(失敗度7)" +failure = true rands = [ { sides = 100, value = 89 }, ] @@ -58,6 +65,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 67 > 失敗(失敗度5)" +failure = true rands = [ { sides = 100, value = 67 }, ] @@ -66,6 +74,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 36 > 失敗(失敗度2)" +failure = true rands = [ { sides = 100, value = 36 }, ] @@ -74,6 +83,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=10" output = "(1D100<=10) > 76 > 失敗(失敗度6)" +failure = true rands = [ { sides = 100, value = 76 }, ] @@ -82,6 +92,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 97 > 失敗(失敗度0)" +failure = true rands = [ { sides = 100, value = 97 }, ] @@ -90,6 +101,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 31 > 成功(成功度5)" +success = true rands = [ { sides = 100, value = 31 }, ] @@ -98,6 +110,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 28 > 成功(成功度6)" +success = true rands = [ { sides = 100, value = 28 }, ] @@ -106,6 +119,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 99 > 失敗(失敗度0)" +failure = true rands = [ { sides = 100, value = 99 }, ] @@ -114,6 +128,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 66 > 成功(成功度2)" +success = true rands = [ { sides = 100, value = 66 }, ] @@ -122,6 +137,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 98 > 失敗(失敗度0)" +failure = true rands = [ { sides = 100, value = 98 }, ] @@ -130,6 +146,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 47 > 成功(成功度4)" +success = true rands = [ { sides = 100, value = 47 }, ] @@ -138,6 +155,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 67 > 成功(成功度2)" +success = true rands = [ { sides = 100, value = 67 }, ] @@ -146,6 +164,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 40 > 成功(成功度5)" +success = true rands = [ { sides = 100, value = 40 }, ] @@ -154,6 +173,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=90" output = "(1D100<=90) > 77 > 成功(成功度1)" +success = true rands = [ { sides = 100, value = 77 }, ] @@ -162,6 +182,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 83 > 失敗(失敗度3)" +failure = true rands = [ { sides = 100, value = 83 }, ] @@ -170,6 +191,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 4 > 成功(成功度4)" +success = true rands = [ { sides = 100, value = 4 }, ] @@ -178,6 +200,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 17 > 成功(成功度3)" +success = true rands = [ { sides = 100, value = 17 }, ] @@ -186,6 +209,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 27 > 成功(成功度2)" +success = true rands = [ { sides = 100, value = 27 }, ] @@ -194,6 +218,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 65 > 失敗(失敗度1)" +failure = true rands = [ { sides = 100, value = 65 }, ] @@ -202,6 +227,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 50 > 成功(成功度0)" +success = true rands = [ { sides = 100, value = 50 }, ] @@ -210,6 +236,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 37 > 成功(成功度1)" +success = true rands = [ { sides = 100, value = 37 }, ] @@ -218,6 +245,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 85 > 失敗(失敗度3)" +failure = true rands = [ { sides = 100, value = 85 }, ] @@ -226,6 +254,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 39 > 成功(成功度1)" +success = true rands = [ { sides = 100, value = 39 }, ] @@ -234,6 +263,7 @@ rands = [ game_system = "Warhammer" input = "1D100<=50" output = "(1D100<=50) > 43 > 成功(成功度0)" +success = true rands = [ { sides = 100, value = 43 }, ]