From 7d7dddeb4a87f4b2fa70f561554bdf0e7feba4c7 Mon Sep 17 00:00:00 2001 From: Eiriksgata <2353686862@qq.com> Date: Thu, 4 Aug 2022 15:51:17 +0800 Subject: [PATCH] Update create dnd5e interface impl handler --- .../eiriksgata/dice/operation/RollRole.java | 2 + .../dice/operation/impl/RollRoleImpl.java | 38 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/java/indi/eiriksgata/dice/operation/RollRole.java b/src/main/java/indi/eiriksgata/dice/operation/RollRole.java index 370cf63..87871a7 100644 --- a/src/main/java/indi/eiriksgata/dice/operation/RollRole.java +++ b/src/main/java/indi/eiriksgata/dice/operation/RollRole.java @@ -11,4 +11,6 @@ public interface RollRole { String createCocRole(int number); String createDndRole(int number); + + String createDnd5eRole(); } diff --git a/src/main/java/indi/eiriksgata/dice/operation/impl/RollRoleImpl.java b/src/main/java/indi/eiriksgata/dice/operation/impl/RollRoleImpl.java index 800c1ea..f01dfc9 100644 --- a/src/main/java/indi/eiriksgata/dice/operation/impl/RollRoleImpl.java +++ b/src/main/java/indi/eiriksgata/dice/operation/impl/RollRoleImpl.java @@ -3,6 +3,8 @@ import indi.eiriksgata.dice.operation.RollRole; import org.apache.commons.lang3.RandomUtils; +import java.util.Arrays; + /** * author: create by Keith * version: v1.0 @@ -44,13 +46,43 @@ public String createDndRole(int number) { StringBuilder role = new StringBuilder(); int attributeCount = 0; for (String attributeName : attributeText) { - int random = RandomUtils.nextInt(7, 18 + 1); - role.append(attributeName).append(":").append(random).append(" "); - attributeCount = attributeCount + random; + int[] tempDiceValue = new int[4]; + for (int j = 0; j < 4; j++) { + tempDiceValue[j] = RandomUtils.nextInt(1, 6 + 1); + } + Arrays.sort(tempDiceValue); + int attributeMax = tempDiceValue[1] + tempDiceValue[2] + tempDiceValue[3]; + role.append(attributeName).append(":").append(attributeMax).append(" "); + attributeCount = attributeCount + attributeMax; } result.append("\n").append(role).append("总计:").append(attributeCount); } return result.toString(); } + @Override + public String createDnd5eRole() { + int[] attributeValue = new int[6]; + int count = 0; + StringBuilder result = new StringBuilder(); + for (int i = 0; i < 6; i++) { + int[] tempDiceValue = new int[4]; + for (int j = 0; j < 4; j++) { + tempDiceValue[j] = RandomUtils.nextInt(1, 6 + 1); + } + result.append(Arrays.toString(tempDiceValue)).append("=>"); + Arrays.sort(tempDiceValue); + int attributeMax = tempDiceValue[1] + tempDiceValue[2] + tempDiceValue[3]; + count += attributeMax; + attributeValue[i] = attributeMax; + result.append(tempDiceValue[1]).append("+") + .append(tempDiceValue[2]).append("+") + .append(tempDiceValue[3]).append("+") + .append("=").append(attributeMax).append("\n"); + } + result.append("\n").append("最终数值为:").append(Arrays.toString(attributeValue)) + .append(",").append("合计:").append(count); + return result.toString(); + } + }