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

import AFF2e #135

Merged
merged 4 commits into from
Mar 14, 2020
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
124 changes: 124 additions & 0 deletions src/diceBot/AFF2e.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# -*- coding: utf-8 -*-

class AFF2e < DiceBot
# ダイスボットで使用するコマンドを配列で列挙する
setPrefixes(['FF.+', 'FR.+', 'FD.+'])

def gameName
'ADVANCED FIGHTING FANTASY 2nd Edition'
end

def gameType
'AFF2e'
end

def getHelpMessage
return <<MESSAGETEXT
対抗なしロール\tFF{目標値}+{補正}
対抗ロール\tFR{能力値}+{補正}
武器ロール\tFD[2,3,3,3,3,3,4]+{補正}
防具ロール\tFD[0,0,0,0,1+1,1+1,2+2]+{補正}
MESSAGETEXT
end

def explicit_sign(i)
format('%+d', i)
end

def eval_term(term)
value = 0
term.scan(/[+-]?\d+/) do |fact|
value += fact.to_i
end
value
end

def parentheses(str)
'(' + str + ')'
end

def successful_or_failed(total, diff)
case total
when 2
diff <= 1 ? '成功(大成功ではない)' : '大成功!'
when 12
diff >= 12 ? '失敗(大失敗ではない)' : '大失敗!'
else
total <= diff ? '成功' : '失敗'
end
end

def clamp(i, min, max)
if i < min
min
elsif i > max
max
else
i
end
end

def rollDiceCommand(command)
case command
when /\AFF/
# 対抗なしロール
# '成功' or '失敗' を出力する
#
md = Regexp.last_match
term = md.post_match

# 目標値
diff = eval_term(term)

dice_command = "2D6<=#{diff}"
total, dice_str = roll(2, 6)
expr = "#{total}[#{dice_str}]"
succ = successful_or_failed(total, diff)
sequence = [ parentheses(dice_command), expr, succ ]
when /\AFR/
# 対抗ロール
# 値を出力する
#
md = Regexp.last_match
term = md.post_match

# 補正値
corr = eval_term(term)

dice_command = "2D6#{explicit_sign corr}"
total, dice_str = roll(2, 6)
expr = "#{total}[#{dice_str}]#{explicit_sign corr}"
sequence = [ parentheses(dice_command), expr, total + corr ]
when /\AFD/
# 武器防具ロール
# ダメージを出力する
#
md = Regexp.last_match
term = md.post_match
md = /\A\[(.+)\]/.match(term)
unless md
return 'ダメージスロットは必須です。', false
end

term = md.post_match
damage_slots = md[1].split(',').map { |t| eval_term(t) }
if damage_slots.size != 7
return 'ダメージスロットの長さに誤りがあります。', false
end

# 補正値
corr = eval_term(term)

dice_command = "1D6#{explicit_sign corr}"
total, dice_str = roll(1, 6)
expr = "#{total}#{explicit_sign corr}"
slot_number = clamp(total + corr, 1, 7)
damage = damage_slots[slot_number - 1]
sequence = [ parentheses(dice_command), expr, total + corr, "#{damage}ダメージ" ]
end

result = sequence.join(' > ')
secret = false
return result, secret
end
end
101 changes: 101 additions & 0 deletions src/test/data/AFF2e.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
input:
FF8 ▼
output:
AFF2e : (2D6<=8) > 5[4,1] > 成功
rand:4/6,1/6
============================
input:
FF8 ▼
output:
AFF2e : (2D6<=8) > 10[4,6] > 失敗
rand:4/6,6/6
============================
input:
FF10-2 ▼
output:
AFF2e : (2D6<=8) > 5[4,1] > 成功
rand:4/6,1/6
============================
input:
FF10-2 ▼
output:
AFF2e : (2D6<=8) > 10[4,6] > 失敗
rand:4/6,6/6
============================
input:
FF10-2
output:
AFF2e : (2D6<=8) > 2[1,1] > 大成功!
rand:1/6,1/6
============================
input:
FF10-2
output:
AFF2e : (2D6<=8) > 12[6,6] > 大失敗!
rand:6/6,6/6
============================
input:
FF1
output:
AFF2e : (2D6<=1) > 2[1,1] > 成功(大成功ではない)
rand:1/6,1/6
============================
input:
FF12
output:
AFF2e : (2D6<=12) > 12[6,6] > 失敗(大失敗ではない)
rand:6/6,6/6
============================
input:
FR8 ▼
output:
AFF2e : (2D6+8) > 5[4,1]+8 > 13
rand:4/6,1/6
============================
input:
FR10-2 ▼
output:
AFF2e : (2D6+8) > 5[4,1]+8 > 13
rand:4/6,1/6
============================
input:
FD8 ▼
output:
AFF2e : ダメージスロットは必須です。
rand:
============================
input:
FD[0] ▼
output:
AFF2e : ダメージスロットの長さに誤りがあります。
rand:
============================
input:
FD[0,0,0,0,1,1,2] ▼
output:
AFF2e : (1D6+0) > 6+0 > 6 > 1ダメージ
rand:6/6
============================
input:
FD[0,0,0,0,1,1,2]+0 ▼
output:
AFF2e : (1D6+0) > 6+0 > 6 > 1ダメージ
rand:6/6
============================
input:
FD[0,0,0,0,1,1,2]+2 ▼
output:
AFF2e : (1D6+2) > 6+2 > 8 > 2ダメージ
rand:6/6
============================
input:
FD[0,0,0,0,1+1,1+1,2+2]+0 ▼
output:
AFF2e : (1D6+0) > 6+0 > 6 > 2ダメージ
rand:6/6
============================
input:
FD[0,0,0,0,1+1,1+1,2+2]+2 ▼
output:
AFF2e : (1D6+2) > 6+2 > 8 > 4ダメージ
rand:6/6