Skip to content

Commit

Permalink
Add a tiers hit field to dice result, add more comments to Difficulty…
Browse files Browse the repository at this point in the history
…Visitor.java, and clean up DiceRoller.java
  • Loading branch information
Alan19 committed May 16, 2019
1 parent dab8664 commit 60997ec
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 35 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'java'
apply plugin: 'maven'

group = 'main'
version = '5.2.2'
version = '5.2.3'

description = "A bot for the Facets tabletop RPG"

Expand Down Expand Up @@ -59,5 +59,4 @@ mainClassName = 'discord.TwoDee'

compileJava {
options.encoding = "UTF-8"
}

}
2 changes: 1 addition & 1 deletion resources/StartupLines.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TwoDee is here!
Need some help?
TwoDee is awake!
What will the part face today?
What will the party face today?
Are you ready to roll?
51 changes: 37 additions & 14 deletions src/main/java/dicerolling/DiceRoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import org.javacord.api.entity.message.MessageAuthor;
import org.javacord.api.entity.message.embed.EmbedBuilder;
import sheets.PPManager;
import statistics.resultvisitors.DifficultyVisitor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import java.util.*;

public class DiceRoller {

Expand Down Expand Up @@ -97,35 +95,60 @@ private EmbedBuilder buildResultEmbed(MessageAuthor author, ArrayList<Integer> d
.addField("Plot dice", replaceBrackets(pdResults.toString()), true)
.addField("Kept dice", replaceBrackets(keptResult.toString()), true)
.addField("Flat bonuses", Integer.toString(flatResult), true)
.addField("Total", String.valueOf(total), true);
.addField("Total", String.valueOf(total), true)
.addField("Tier Hit", tiersHit(total));
}

private String tiersHit(int total) {
DifficultyVisitor difficultyVisitor = new DifficultyVisitor();
if (total < 3) {
return "None";
}
StringBuilder output = new StringBuilder();
for (Map.Entry<Integer, String> diffEntry : difficultyVisitor.getDifficultyMap().entrySet()) {
if (difficultyVisitor.generateStageDifficulty(diffEntry.getKey() + 1) > total) {
output.append(diffEntry.getValue());
break;
}
}
if (total < 10) {
return String.valueOf(output);
}
for (Map.Entry<Integer, String> diffEntry : difficultyVisitor.getDifficultyMap().entrySet()) {
if (difficultyVisitor.generateStageExtraordinaryDifficulty(diffEntry.getKey() + 1) > total) {
output.append(", Extraordinary ").append(diffEntry.getValue());
break;
}
}
return String.valueOf(output);
}

//Bold 1s to show total doom generated. Runs doom increasing method afterwards.
private String formatResults(ArrayList<Integer> s) {
String resultString = "";
StringBuilder resultString = new StringBuilder();
if (s.size() > 1) {
for (int i = 0; i < s.size() - 1; i++) {
if (s.get(i) == 1) {
resultString += "**1**, ";
resultString.append("**1**, ");
} else {
resultString += s.get(i) + ", ";
resultString.append(s.get(i)).append(", ");
}
}
if (s.get(s.size() - 1) == 1) {
resultString += "**1**";
resultString.append("**1**");
} else {
resultString += s.get(s.size() - 1);
resultString.append(s.get(s.size() - 1));
}
} else if (s.size() == 1) {
if (s.get(0) == 1) {
resultString += "**1**";
resultString.append("**1**");
} else {
resultString += s.get(0);
resultString.append(s.get(0));
}
} else {
return "*none*";
}
return resultString;
return resultString.toString();
}

// Username is stored as <@!140973544891744256>
Expand Down Expand Up @@ -199,7 +222,7 @@ private void rollDie(ArrayList<Integer> keptResults, Random random, ArrayList<In

//Replaces brackets in the string. If the string is blank, returns "none" in italics
private String replaceBrackets(String s) {
String newStr = s.replaceAll("\\[", "").replaceAll("\\]", "");
String newStr = s.replaceAll("\\[", "").replaceAll("]", "");
if (newStr.equals("")) {
return "*none*";
}
Expand Down
44 changes: 27 additions & 17 deletions src/main/java/statistics/resultvisitors/DifficultyVisitor.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
package statistics.resultvisitors;

import statistics.DiceResult;
import logic.EmbedField;
import statistics.DiceResult;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* A class that visits the result to see which tiers of success was hit. Also used by DiceRoller to calculate the
* highest tier of success that was hit.
*/
public class DifficultyVisitor implements ResultVisitor {

private Map<Integer, String> difficultyMap = new HashMap<>();
private Map<Integer, Integer> hitSuccess = new HashMap<>();
private Map<Integer, Integer> hitExtraordinarySuccess = new HashMap<>();
private int totalCombinations = 0;

public DifficultyVisitor(){
difficultyMap.put(1, "Easy");
difficultyMap.put(2, "Average");
difficultyMap.put(3, "Hard");
difficultyMap.put(4, "Formidable");
difficultyMap.put(5, "Heroic");
difficultyMap.put(6, "Incredible");
difficultyMap.put(7, "Ridiculous");
difficultyMap.put(8, "Impossible");

for (int i = 1; i <= 8; i++){
hitSuccess.put(i, 0);
hitExtraordinarySuccess.put(i, 0);
}
}

/**
* Function to generate difficulty value based on difficulty level
*
* @param level The difficulty level. Must be greater than 0
* @return The difficulty that needs to be rolled to make that difficulty level
*/
private int generateStageDifficulty(int level){
public int generateStageDifficulty(int level) {
return 3 + (level - 1) * 4;
}

/**
* Function to generate difficulty extraordinary success value based on difficulty level
*
* @param level The difficulty level. Must be greater than 0
* @return The difficulty that needs to be rolled to make that difficulty level
*/
private int generateStageExtraordinaryDifficulty(int level){
public int generateStageExtraordinaryDifficulty(int level) {
return 10 + (level - 1) * 4;
}

public DifficultyVisitor(){
difficultyMap.put(1, "Easy");
difficultyMap.put(2, "Average");
difficultyMap.put(3, "Hard");
difficultyMap.put(4, "Formidable");
difficultyMap.put(5, "Heroic");
difficultyMap.put(6, "Incredible");
difficultyMap.put(7, "Ridiculous");
difficultyMap.put(8, "Impossible");

for (int i = 1; i <= 8; i++){
hitSuccess.put(i, 0);
hitExtraordinarySuccess.put(i, 0);
}
public Map<Integer, String> getDifficultyMap() {
return difficultyMap;
}

@Override
Expand Down

0 comments on commit 60997ec

Please sign in to comment.