=Updated Roll Output
It pretty... er
This commit is contained in:
@@ -1,9 +1,13 @@
|
|||||||
package commands.general;
|
package commands.general;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import core.*;
|
import core.Command;
|
||||||
|
import core.LocStrings;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
|
import dataStructures.KittyEmbed;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
import dataStructures.KittyRole;
|
import dataStructures.KittyRole;
|
||||||
@@ -23,7 +27,15 @@ public class CommandRoll extends Command
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
res.send(rollDice(input.args));
|
KittyEmbed embed = new KittyEmbed();
|
||||||
|
embed.title = user.name +"'s roll!";
|
||||||
|
embed.descriptionText = rollDice(input.args);
|
||||||
|
Random numGen = new Random(user.name.hashCode());
|
||||||
|
float hue = numGen.nextFloat();
|
||||||
|
float sat = .7f;
|
||||||
|
float bright = .7f;
|
||||||
|
embed.color = Color.getHSBColor(hue, sat, bright);
|
||||||
|
res.send(embed);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@@ -35,6 +47,7 @@ public class CommandRoll extends Command
|
|||||||
{
|
{
|
||||||
Stack<Integer> values = new Stack<Integer>();
|
Stack<Integer> values = new Stack<Integer>();
|
||||||
Stack<Character> operators = new Stack<Character>();
|
Stack<Character> operators = new Stack<Character>();
|
||||||
|
String steps = "";
|
||||||
for(int i = 0; i < thing.length(); i ++)
|
for(int i = 0; i < thing.length(); i ++)
|
||||||
{
|
{
|
||||||
char current = thing.charAt(i);
|
char current = thing.charAt(i);
|
||||||
@@ -49,7 +62,7 @@ public class CommandRoll extends Command
|
|||||||
operators.add(current);
|
operators.add(current);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
calculate(values, operators);
|
steps += "\n" + calculate(values, operators);
|
||||||
operators.add(current);
|
operators.add(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +78,7 @@ public class CommandRoll extends Command
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
i --;
|
i --;
|
||||||
calculate(values, operators);
|
steps += "\n" + calculate(values, operators);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -73,7 +86,7 @@ public class CommandRoll extends Command
|
|||||||
if(operators.isEmpty() || operators.peek() == '(' || !hasPrecendence(operators.peek(), current))
|
if(operators.isEmpty() || operators.peek() == '(' || !hasPrecendence(operators.peek(), current))
|
||||||
operators.add(current);
|
operators.add(current);
|
||||||
else
|
else
|
||||||
calculate(values, operators);
|
steps += "\n" + calculate(values, operators);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case ' ':
|
case ' ':
|
||||||
@@ -114,19 +127,20 @@ public class CommandRoll extends Command
|
|||||||
|
|
||||||
while(operators.size() > 0)
|
while(operators.size() > 0)
|
||||||
{
|
{
|
||||||
calculate(values, operators);
|
steps += "\n" + calculate(values, operators);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "" + values.pop();
|
return "Roll```" + thing + "```" + "Steps```" + steps + "```" + "Final value ```" + values.pop() +"```";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculate(Stack<Integer> nums, Stack<Character> operators)
|
private String calculate(Stack<Integer> nums, Stack<Character> operators)
|
||||||
{
|
{
|
||||||
int second = nums.pop();
|
int second = nums.pop();
|
||||||
int first = nums.pop();
|
int first = nums.pop();
|
||||||
int value = 0;
|
int value = 0;
|
||||||
|
char op = operators.pop();
|
||||||
|
|
||||||
switch(operators.pop())
|
switch(op)
|
||||||
{
|
{
|
||||||
case '+':
|
case '+':
|
||||||
value = first + second;
|
value = first + second;
|
||||||
@@ -143,8 +157,8 @@ public class CommandRoll extends Command
|
|||||||
case 'd':
|
case 'd':
|
||||||
value = roll(first, second);
|
value = roll(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
nums.add(value);
|
nums.add(value);
|
||||||
|
return (first + "" + op + "" + second + "=" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int roll(int first, int second)
|
private int roll(int first, int second)
|
||||||
|
|||||||
Reference in New Issue
Block a user