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

Fate Core System #499

Merged
merged 2 commits into from
Oct 16, 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
1 change: 1 addition & 0 deletions lib/bcdice/game_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
require "bcdice/game_system/Emoklore"
require "bcdice/game_system/EndBreaker"
require "bcdice/game_system/EtrianOdysseySRS"
require "bcdice/game_system/FateCoreSystem"
require "bcdice/game_system/Fiasco"
require "bcdice/game_system/Fiasco_Korean"
require "bcdice/game_system/FilledWith"
Expand Down
117 changes: 117 additions & 0 deletions lib/bcdice/game_system/FateCoreSystem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# frozen_string_literal: true

module BCDice
module GameSystem
class FateCoreSystem < Base
# ゲームシステムの識別子
ID = 'FateCoreSystem'

# ゲームシステム名
NAME = 'Fate Core System'

# ゲームシステム名の読みがな
SORT_KEY = 'ふえいとこあしすてむ'

# ダイスボットの使い方
HELP_MESSAGE = <<~MESSAGETEXT
■ ファッジダイスによる判定 (xDF+y>=t)
ファッジダイスをx個ダイスロールし、結果を判定します。
x: ダイス数
y: 修正値(省略可)
t: 目標値値(省略可)
例)4DF, 4DF>=3, 4DF+1>=3
MESSAGETEXT

register_prefix('\d+DF')

def eval_game_system_specific_command(command)
roll_df(command)
end

private

def roll_df(command)
parser = Command::Parser.new("DF", round_type: @round_type)
.enable_prefix_number()
.restrict_cmp_op_to(:>=, nil)

parsed = parser.parse(command)
unless parsed
return nil
end

dice_list = roll_fate_dice(parsed.prefix_number)
total = dice_list.sum() + parsed.modify_number

fate_dice_list = dice_list.map do |i|
if i.zero?
"[ ]"
elsif i.positive?
"[+]"
else
"[-]"
end
end

result = outcome(total, parsed.target_number)
sequence = [
"(#{parsed})",
"#{fate_dice_list.join()}#{Format.modifier(parsed.modify_number)}",
result_ladder(total),
result.text,
]

result.text = sequence.compact.join(" > ")
return result
end

def roll_fate_dice(times)
@randomizer.roll_barabara(times, 3).map { |i| i - 2 }
end

def result_ladder(total)
ladder =
case total.clamp(-2, 8)
when 8
"Legendary"
when 7
"Epic"
when 6
"Fantastic"
when 5
"Superb"
when 4
"Great"
when 3
"Good"
when 2
"Fair"
when 1
"Average"
when 0
"Mediocre"
when -1
"Poor"
else
"Terrible"
end

return "#{ladder}(#{format('%+d', total)})"
end

def outcome(total, target)
if target.nil?
Result.new
elsif total == target
Result.success("Tie")
elsif total >= target + 3
Result.critical("Succeed with Style")
elsif total >= target
Result.success("Succeed")
else
Result.failure("Fail")
end
end
end
end
end
219 changes: 219 additions & 0 deletions test/data/FateCoreSystem.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [-][ ][-][-] > Terrible(-3)"
rands = [
{ sides = 3, value = 1 },
{ sides = 3, value = 2 },
{ sides = 3, value = 1 },
{ sides = 3, value = 1 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [-][ ][-][ ] > Terrible(-2)"
rands = [
{ sides = 3, value = 1 },
{ sides = 3, value = 2 },
{ sides = 3, value = 1 },
{ sides = 3, value = 2 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [ ][ ][-][ ] > Poor(-1)"
rands = [
{ sides = 3, value = 2 },
{ sides = 3, value = 2 },
{ sides = 3, value = 1 },
{ sides = 3, value = 2 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [ ][ ][ ][ ] > Mediocre(+0)"
rands = [
{ sides = 3, value = 2 },
{ sides = 3, value = 2 },
{ sides = 3, value = 2 },
{ sides = 3, value = 2 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [+][ ][ ][ ] > Average(+1)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 2 },
{ sides = 3, value = 2 },
{ sides = 3, value = 2 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [+][+][ ][ ] > Fair(+2)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 2 },
{ sides = 3, value = 2 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [+][+][+][ ] > Good(+3)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 2 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [+][+][+][+] > Great(+4)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "5DF"
output = "(5DF) > [+][+][+][+][+] > Superb(+5)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "5DF+1"
output = "(5DF+1) > [+][+][+][+][+]+1 > Fantastic(+6)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "5DF+2"
output = "(5DF+2) > [+][+][+][+][+]+2 > Epic(+7)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "5DF+3"
output = "(5DF+3) > [+][+][+][+][+]+3 > Legendary(+8)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "5DF+4"
output = "(5DF+4) > [+][+][+][+][+]+4 > Legendary(+9)"
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF"
output = "(4DF) > [ ][-][ ][+] > Mediocre(+0)"
rands = [
{ sides = 3, value = 2 },
{ sides = 3, value = 1 },
{ sides = 3, value = 2 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF>=3"
output = "(4DF>=3) > [+][+][+][+] > Great(+4) > Succeed"
success = true
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF+1>=3"
output = "(4DF+1>=3) > [+][+][+][+]+1 > Superb(+5) > Succeed"
success = true
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF+2>=3"
output = "(4DF+2>=3) > [+][+][+][+]+2 > Fantastic(+6) > Succeed with Style"
success = true
critical = true
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF+1>=3"
output = "(4DF+1>=3) > [+][+][+][-]+1 > Good(+3) > Tie"
success = true
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 3 },
{ sides = 3, value = 1 },
]

[[ test ]]
game_system = "FateCoreSystem"
input = "4DF+1>=3"
output = "(4DF+1>=3) > [+][ ][+][-]+1 > Fair(+2) > Fail"
failure = true
rands = [
{ sides = 3, value = 3 },
{ sides = 3, value = 2 },
{ sides = 3, value = 3 },
{ sides = 3, value = 1 },
]