Skip to content

Commit

Permalink
Update create dnd5e interface impl handler
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksgata committed Aug 4, 2022
1 parent 4b1869a commit 7d7ddde
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/indi/eiriksgata/dice/operation/RollRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface RollRole {
String createCocRole(int number);

String createDndRole(int number);

String createDnd5eRole();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}


}

0 comments on commit 7d7ddde

Please sign in to comment.