Skip to content

Commit

Permalink
Fix dice result and .sc error
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksgata committed Jun 21, 2022
1 parent 6dbc6e6 commit 85247cc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@

<includes>
<include>messages/**</include>
<include>default-text.json</include>
<include>dice-config.properties</include>
<include>rulebook.coc.properties</include>
<include>rulebook-dnd.properties</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,19 @@ public String rollRandom(String text, Long id, RollRandomCallback callback) {
formula.append(")");
text = text.replaceFirst(temp, String.valueOf(formula));
} else {
System.out.println(text);
text = text.replaceFirst(temp, String.valueOf(randomData[0]));
System.out.println(text);
}
}
}

String result = new Expression(text).value().val.toString();
callback.getFormulaResult(result, text);
return CustomText.getText("coc7.roll", inputFormula, text, result);

if (!text.contains("+")) {
return CustomText.getText("coc7.roll1", inputFormula, result);
}
return CustomText.getText("coc7.roll1", inputFormula + "=" + text, result);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String sanCheck(String text, String attribute, SanCheckCallback callback)
AtomicInteger surplus = new AtomicInteger();
String resultText = new RollBasicsImpl().rollRandom(formula[0], 0L, (value, calculationProcess) -> {
try {
surplus.set(Integer.parseInt(value));
surplus.set(sanNumber - Integer.parseInt(value));
} catch (NumberFormatException e) {
surplus.set(-1);
return;
Expand Down Expand Up @@ -71,23 +71,23 @@ public String sanCheck(String text, String attribute, SanCheckCallback callback)
int surplus = sanNumber - Integer.parseInt(formulaResult);
String resultAttribute = attribute.replaceFirst(sanAttribute, "san" + surplus);
callback.getResultData(resultAttribute, random, sanNumber, calProcess, surplus);
return CustomText.getText("coc7.sc.big-fail", text, random, sanNumber, calProcess, surplus);

return CustomText.getText("coc7.sc.big-fail", text, random, sanNumber, formulaResult, surplus);

} else {
//理智判定默认百面骰
AtomicInteger surplus = new AtomicInteger();
String resultText = new RollBasicsImpl().rollRandom(formula[1], 0L, (value, calculationProcess) -> {
try {
surplus.set(Integer.parseInt(value));
surplus.set(sanNumber - Integer.parseInt(value));
} catch (NumberFormatException e) {
surplus.set(-1);
return;
}

String resultAttribute = attribute.replaceFirst(sanAttribute, "san" + surplus);
callback.getResultData(resultAttribute, random, sanNumber, calculationProcess, surplus.get());

});

if (surplus.get() == -1) {
return "不能处理除整数以外的数值";
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/custom-text.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"custom-text.version": "1.0.2",
"custom-text.version": "1.0.3",
"dice.base.parameter.error": "指令中的参数不正确。",
"dice.pool.parameter.format.error": "参数格式不正确",
"dice.pool.parameter.range.error": "参数必须要 大于0 & 小于300",
Expand Down Expand Up @@ -33,7 +33,7 @@
"coc7.attribute.big-success": "{3}属性检测[{0}]:{1}/{2} 大成功!",
"coc7.attribute.fail": "{3}属性检测[{0}]:{1}/{2} 失败!",
"coc7.attribute.big-fail": "{3}属性检测[{0}]:{1}/{2} 大失败!",
"coc7.roll": "{0}={1}={2}",
"coc7.roll1": "{0}={1}",
"coc7.sc.success": "San check:{0}={1}/{2} 成功! 减少{3} 剩余 {4}",
"coc7.sc.fail": "San check:{0}={1}/{2} 失败! 减少{3} 剩余 {4}",
"coc7.sc.big-fail": "San check:{0}={1}/{2}大失败! 减少{3} 剩余 {4}",
Expand All @@ -46,9 +46,9 @@
"dr5e.rule.lib.result.list.tail": "\n最多显示20条数据。如果需要查询更多信息,请前往网站查询:https://eiriksgata.github.io/rulateday-dnd5e-wiki/#/",
"dr5e.rule.lib.result.list.not.found": "查询不到结果,欢迎联系QQ:2353686862提供更多的数据",
"dr5e.role.create.size.max": "参数范围需要在1-20内",
"instructions.help.result": "插件名称:Rulateda v0.1.0 by Eiriksgata\n反馈联系Github:https://github.com/Eiriksgata/mirai-rulateday-dice\n所有指令:.help指令\nDND5eWiki:https://keith404.gitee.io/rulateday-dnd5e-wiki/#/",
"instructions.all.result": "骰子常用指令列表:\n.st 属性设置\n.ra|.rc 属性检测\n.rb 奖励骰|.rp惩罚骰\n.cr coc7规则书查询\n.dr dnd5e信息查询\n.ti 随机获取发疯情况\n.li 发疯后总结\n.sc 理智检测\n.rh 暗骰\n.set 设置默认骰\n.coc 随机coc7角色属性\n.dnd 随机dnd5e角色属性\n.r 随机数生成\n.rd 默认骰数值生成\n.ww 骰池功能\n.kkp 随机图片速览(测试)\n.atk 先攻指令系列,详情请看文档\n.botoff | .boton 启用骰子开关\n更多的指令详情请查看:https://keith404.gitee.io/mirai-rulateday-dice/#/instruction\n备用文档:https://gitee.com/Keith404/mirai-rulateday-dice/blob/master/docs/instruction.md",
"api.request.error": "请求云端服务器接口失败。请联系相关开发人员",
"instructions.help.result1": "插件名称:Rulateda v0.4.x by Eiriksgata\n反馈联系Github:https://github.com/Eiriksgata/mirai-rulateday-dice\n所有指令:.help指令\nDND5eWiki:https://keith404.gitee.io/rulateday-dnd5e-wiki/#/\n",
"instructions.all.result1": "骰子常用指令列表:\n.st 属性设置\n.ra|.rc 属性检测\n.rb 奖励骰|.rp惩罚骰\n.cr coc7规则书查询\n.dr dnd5e信息查询\n.ti 随机获取发疯情况\n.li 发疯后总结\n.sc 理智检测\n.rh 暗骰\n.set 设置默认骰\n.coc 随机coc7角色属性\n.dnd 随机dnd5e角色属性\n.r 随机数生成\n.rd 默认骰数值生成\n.ww 骰池功能\n.kkp 随机图片速览(测试)\n.atk 先攻指令系列,详情请看文档\n.botoff | .boton 启用骰子开关\n更多的指令详情请查看:https://eiriksgata.github.io/mirai-rulateday-dice/#/instruction\n备用文档:https://note.youdao.com/s/PZ3tqThT",
"api.request.error": "请求云端服务器接口失败。请联系相关开发人员QQ2353686862",
"cards.type.not.found": "当前存储库没有卡组类型,可以通过指令.cardsAdd进行添加。",
"cards.type.list.title": "当前存储库下有以下卡组类型:",
"cards.add.parameter.format.error": "参数类型不正确,正确格式应该是[卡组名称 卡组数据]例如:麻将 白板,红中,发字,东风,南风",
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/default-text.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"custom-text.version": "1.0.2",
"custom-text.version": "1.0.3",
"dice.base.parameter.error": "指令中的参数不正确。",
"dice.pool.parameter.format.error": "参数格式不正确",
"dice.pool.parameter.range.error": "参数必须要 大于0 & 小于300",
Expand Down Expand Up @@ -33,7 +33,7 @@
"coc7.attribute.big-success": "{3}属性检测[{0}]:{1}/{2} 大成功!",
"coc7.attribute.fail": "{3}属性检测[{0}]:{1}/{2} 失败!",
"coc7.attribute.big-fail": "{3}属性检测[{0}]:{1}/{2} 大失败!",
"coc7.roll": "{0}={1}={2}",
"coc7.roll1": "{0}={1}",
"coc7.sc.success": "San check:{0}={1}/{2} 成功! 减少{3} 剩余 {4}",
"coc7.sc.fail": "San check:{0}={1}/{2} 失败! 减少{3} 剩余 {4}",
"coc7.sc.big-fail": "San check:{0}={1}/{2}大失败! 减少{3} 剩余 {4}",
Expand All @@ -46,9 +46,9 @@
"dr5e.rule.lib.result.list.tail": "\n最多显示20条数据。如果需要查询更多信息,请前往网站查询:https://eiriksgata.github.io/rulateday-dnd5e-wiki/#/",
"dr5e.rule.lib.result.list.not.found": "查询不到结果,欢迎联系QQ:2353686862提供更多的数据",
"dr5e.role.create.size.max": "参数范围需要在1-20内",
"instructions.help.result": "插件名称:Rulateda v0.1.0 by Eiriksgata\n反馈联系Github:https://github.com/Eiriksgata/mirai-rulateday-dice\n所有指令:.help指令\nDND5eWiki:https://keith404.gitee.io/rulateday-dnd5e-wiki/#/",
"instructions.all.result": "骰子常用指令列表:\n.st 属性设置\n.ra|.rc 属性检测\n.rb 奖励骰|.rp惩罚骰\n.cr coc7规则书查询\n.dr dnd5e信息查询\n.ti 随机获取发疯情况\n.li 发疯后总结\n.sc 理智检测\n.rh 暗骰\n.set 设置默认骰\n.coc 随机coc7角色属性\n.dnd 随机dnd5e角色属性\n.r 随机数生成\n.rd 默认骰数值生成\n.ww 骰池功能\n.kkp 随机图片速览(测试)\n.atk 先攻指令系列,详情请看文档\n.botoff | .boton 启用骰子开关\n更多的指令详情请查看:https://keith404.gitee.io/mirai-rulateday-dice/#/instruction\n备用文档:https://gitee.com/Keith404/mirai-rulateday-dice/blob/master/docs/instruction.md",
"api.request.error": "请求云端服务器接口失败。请联系相关开发人员",
"instructions.help.result1": "插件名称:Rulateda v0.4.x by Eiriksgata\n反馈联系Github:https://github.com/Eiriksgata/mirai-rulateday-dice\n所有指令:.help指令\nDND5eWiki:https://keith404.gitee.io/rulateday-dnd5e-wiki/#/\n",
"instructions.all.result1": "骰子常用指令列表:\n.st 属性设置\n.ra|.rc 属性检测\n.rb 奖励骰|.rp惩罚骰\n.cr coc7规则书查询\n.dr dnd5e信息查询\n.ti 随机获取发疯情况\n.li 发疯后总结\n.sc 理智检测\n.rh 暗骰\n.set 设置默认骰\n.coc 随机coc7角色属性\n.dnd 随机dnd5e角色属性\n.r 随机数生成\n.rd 默认骰数值生成\n.ww 骰池功能\n.kkp 随机图片速览(测试)\n.atk 先攻指令系列,详情请看文档\n.botoff | .boton 启用骰子开关\n更多的指令详情请查看:https://eiriksgata.github.io/mirai-rulateday-dice/#/instruction\n备用文档:https://note.youdao.com/s/PZ3tqThT",
"api.request.error": "请求云端服务器接口失败。请联系相关开发人员QQ2353686862",
"cards.type.not.found": "当前存储库没有卡组类型,可以通过指令.cardsAdd进行添加。",
"cards.type.list.title": "当前存储库下有以下卡组类型:",
"cards.add.parameter.format.error": "参数类型不正确,正确格式应该是[卡组名称 卡组数据]例如:麻将 白板,红中,发字,东风,南风",
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/DiceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import indi.eiriksgata.dice.callback.SanCheckCallback;
import indi.eiriksgata.dice.exception.DiceInstructException;
import indi.eiriksgata.dice.operation.RollBasics;
import indi.eiriksgata.dice.operation.impl.AttributeCheckImpl;
import indi.eiriksgata.dice.operation.impl.RollBasicsImpl;
import indi.eiriksgata.dice.operation.impl.RollBonusImpl;
Expand Down Expand Up @@ -98,5 +100,15 @@ void randomUtilsNextInt() {
}
}

@Test
void sanCheckTest() {
String result = new RollBasicsImpl().sanCheck("1d5+2d3+5/1d100", "san50", new SanCheckCallback() {
@Override
public void getResultData(String attribute, int random, int sanValue, String calculationProcess, int surplus) {
System.out.println(attribute + "," + random + "," + sanValue + "," + calculationProcess + "," + surplus);
}
});
System.out.println(result);
}

}

0 comments on commit 85247cc

Please sign in to comment.