From d85fb648ace0cc901e481f2948ace6636fcbfbd8 Mon Sep 17 00:00:00 2001 From: SadlyWish <806891709@qq.com> Date: Tue, 27 Oct 2020 12:55:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6mirai=E5=88=86=E6=94=AF?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/dice/sinanya/dice/roll/Dx.java | 15 ++++++++++----- .../sinanya/exceptions/DxSuccessException.java | 4 ++-- .../dice/sinanya/exceptions/DxTimesException.java | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/dice/sinanya/dice/roll/Dx.java b/src/main/java/dice/sinanya/dice/roll/Dx.java index 6943b993..b6a8c59f 100644 --- a/src/main/java/dice/sinanya/dice/roll/Dx.java +++ b/src/main/java/dice/sinanya/dice/roll/Dx.java @@ -17,7 +17,7 @@ import static dice.sinanya.tools.makedata.RandomInt.random; import static dice.sinanya.tools.makedata.Sender.sender; public class Dx implements MakeNickToSender { - private final Pattern getParam = Pattern.compile("(\\d+)*[a]*(\\d+)*[+]*(\\d+)*"); + private final Pattern getParam = Pattern.compile("(\\d+)*[a]*(\\d+)*([+-])(\\d+)*"); private final EntityTypeMessages entityTypeMessages; public Dx(EntityTypeMessages entityTypeMessages) { @@ -26,20 +26,25 @@ public class Dx implements MakeNickToSender { public void dx() throws DxTimesException, DxSuccessException { String tag = TAG_DX; - String msg = entityTypeMessages.getMessage().trim().replaceFirst(tag.substring(0, tag.length() - 2), "").trim(); + String msg = entityTypeMessages.getMsgGet().getMsg().trim().replaceFirst(tag.substring(0, tag.length() - 2), "").trim(); int time = 1; int success = 10; int add = 0; int resultNum; + String addString = ""; ArrayList resultTmpStr; ArrayList resultStr = new ArrayList<>(); Matcher dxFind = getParam.matcher(msg); if (dxFind.find()) { time = getValue(dxFind.group(1), time); success = getValue(dxFind.group(2), success); - if (dxFind.groupCount() == 3) { - add = getValue(dxFind.group(3), add); + if (dxFind.groupCount() == 4) { + addString = dxFind.group(3) + dxFind.group(4); + add = getValue(dxFind.group(4), add); + if (addTag.equles("-")){ + add *= -1; + } } } if (success <= 1) { @@ -87,7 +92,7 @@ public class Dx implements MakeNickToSender { } String senderStr; if (add != 0) { - senderStr = StringUtils.join(resultStr, "\n+") + "\n+" + add + "\n=" + (resultNum + add); + senderStr = StringUtils.join(resultStr, "\n+") + "\n" + addString + "\n=" + (resultNum + add); } else { senderStr = StringUtils.join(resultStr, "\n+") + "\n=" + resultNum; } diff --git a/src/main/java/dice/sinanya/exceptions/DxSuccessException.java b/src/main/java/dice/sinanya/exceptions/DxSuccessException.java index 57bd2e9a..2fc7ae34 100644 --- a/src/main/java/dice/sinanya/exceptions/DxSuccessException.java +++ b/src/main/java/dice/sinanya/exceptions/DxSuccessException.java @@ -16,7 +16,7 @@ import static dice.sinanya.tools.makedata.Sender.sender; */ public class DxSuccessException extends Exception { public DxSuccessException(EntityTypeMessages entityTypeMessages) { - super("加骰必须大于1"); - sender(entityTypeMessages, "加骰必须大于1"); + super("暴击值(加骰阈值)必须大于1"); + sender(entityTypeMessages, "暴击值(加骰阈值)必须大于1"); } } diff --git a/src/main/java/dice/sinanya/exceptions/DxTimesException.java b/src/main/java/dice/sinanya/exceptions/DxTimesException.java index 93ae6148..8034efc6 100644 --- a/src/main/java/dice/sinanya/exceptions/DxTimesException.java +++ b/src/main/java/dice/sinanya/exceptions/DxTimesException.java @@ -15,7 +15,7 @@ import static dice.sinanya.tools.makedata.Sender.sender; */ public class DxTimesException extends Exception { public DxTimesException(EntityTypeMessages entityTypeMessages) { - super("次数必须大于等于1,且小于"); - sender(entityTypeMessages, "次数必须大于等于1,且小于"); + super("骰子数必须大于等于1,且小于50"); + sender(entityTypeMessages, "骰子数必须大于等于1,且小于50"); } } -- Gitee