Skip to content

Commit

Permalink
Merge pull request #485 from bcdice/PersonaO
Browse files Browse the repository at this point in the history
ペルソナTRPG-O
  • Loading branch information
ysakasin authored Jul 28, 2021
2 parents b1286d9 + 8316c73 commit d330926
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/bcdice/game_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
require "bcdice/game_system/Pathfinder"
require "bcdice/game_system/Peekaboo"
require "bcdice/game_system/Pendragon"
require "bcdice/game_system/PersonaO"
require "bcdice/game_system/PhantasmAdventure"
require "bcdice/game_system/Postman"
require "bcdice/game_system/PulpCthulhu"
Expand Down
86 changes: 86 additions & 0 deletions lib/bcdice/game_system/PersonaO.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# frozen_string_literal: true

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

# ゲームシステム名
NAME = 'ペルソナTRPG-O'

# ゲームシステム名の読みがな
SORT_KEY = 'へるそなTRPGO'

# ダイスボットの使い方
HELP_MESSAGE = <<~INFO_MESSAGE_TEXT
・基本判定
 PTx@y x:目標値、y:クリティカル値(省略時は5)
 例)PT60 PT90@10
・ダメージ計算
 nPD+(x+y*2)%(z-a)-b n:ダイス個数、x:スキル固定値、y:ボーナス、z:バフ倍率、a:耐性、b:敵防御力
 nPD+(x+y*2)までがスキルによる素のダメージ、zおよびaは計算式を入れてよい。
 
 例)ソニックパンチ、力B2点、
   タルカジャがかかっており、打撃耐性あり、
   目標の物理防御力は2点
   
   2PD+(20+2*2)%(100+50-50)-2
INFO_MESSAGE_TEXT

register_prefix(
'PT',
'\d+PD'
)

def eval_game_system_specific_command(command)
roll_attack(command) || roll_damage(command)
end

private

def roll_attack(command)
m = /^PT(-?\d+)?(@(-?\d+))?$/i.match(command)
unless m
return nil
end

success_rate = m[1].to_i
critical_border = m[3]&.to_i || 5

dice_value = @randomizer.roll_once(100)
result =
if dice_value <= critical_border
Result.critical("クリティカル")
elsif dice_value <= success_rate
Result.success("成功")
else
Result.failure("失敗")
end

result.text = "D100<=#{success_rate}@#{critical_border}#{dice_value}#{result.text}"
return result
end

def roll_damage(command)
m = /^(\d+)PD\+(-?\d+)%(-?\d+)-(\d+)$/i.match(command)
unless m
return nil
end

dice = m[1].to_i
kotei = m[2].to_i
hosei = m[3].to_i
bougyo = m[4].to_i

dice_list = @randomizer.roll_barabara(dice, 10)
dice_sum = dice_list.sum

dmg = dice_sum + (hosei * kotei / 100.0).to_i - bougyo

return "#{dice}D10+#{kotei}#{hosei}%-#{bougyo} > [#{dice_list.join(',')}]+#{kotei}#{hosei}%-#{bougyo}#{dmg} ダメージ!"
end
end
end
end
118 changes: 118 additions & 0 deletions test/data/PersonaO.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
[[ test ]]
game_system = "PersonaO"
input = "PT50"
output = "D100<=50@5 > 50 > 成功"
success = true
rands = [
{ sides = 100, value = 50 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT50"
output = "D100<=50@5 > 51 > 失敗"
failure = true
rands = [
{ sides = 100, value = 51 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT50"
output = "D100<=50@5 > 95 > 失敗"
failure = true
rands = [
{ sides = 100, value = 95 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT100"
output = "D100<=100@5 > 96 > 成功"
success = true
rands = [
{ sides = 100, value = 96 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT100"
output = "D100<=100@5 > 98 > 成功"
success = true
rands = [
{ sides = 100, value = 98 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT50"
output = "D100<=50@5 > 11 > 成功"
success = true
rands = [
{ sides = 100, value = 11 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT50"
output = "D100<=50@5 > 11 > 成功"
success = true
rands = [
{ sides = 100, value = 11 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT50@11"
output = "D100<=50@11 > 11 > クリティカル"
critical = true
success = true
rands = [
{ sides = 100, value = 11 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT50@11"
output = "D100<=50@11 > 12 > 成功"
success = true
rands = [
{ sides = 100, value = 12 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT90@(5+50)"
output = "D100<=90@55 > 57 > 成功"
success = true
rands = [
{ sides = 100, value = 57 },
]

[[ test ]]
game_system = "PersonaO"
input = "PT90@(5+50)"
output = "D100<=90@55 > 12 > クリティカル"
critical = true
success = true
rands = [
{ sides = 100, value = 12 },
]

[[ test ]]
game_system = "PersonaO"
input = "2PD+(20+2*2)%(100+50-50)-2"
output = "2D10+24*100%-2 > [8,5]+24*100%-2 > 35 ダメージ!"
rands = [
{ sides = 10, value = 8 },
{ sides = 10, value = 5 }
]

[[ test ]]
game_system = "PersonaO"
input = "2PD+(20+2*2)%(100+50)-2"
output = "2D10+24*150%-2 > [8,5]+24*150%-2 > 47 ダメージ!"
rands = [
{ sides = 10, value = 8 },
{ sides = 10, value = 5 }
]

0 comments on commit d330926

Please sign in to comment.