Eardanw Modul hinzugefügt
This commit is contained in:
462
src/main/java/Earthdawn/dice.java
Normal file
462
src/main/java/Earthdawn/dice.java
Normal file
@ -0,0 +1,462 @@
|
|||||||
|
package Earthdawn;
|
||||||
|
|
||||||
|
import Shadowrun.db_connect;
|
||||||
|
import Shadowrun.help;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
public class dice extends ListenerAdapter {
|
||||||
|
|
||||||
|
private String prefixSr;
|
||||||
|
private String prefixIni;
|
||||||
|
|
||||||
|
|
||||||
|
private language langDe = new language("de");
|
||||||
|
private language langEn = new language("en");
|
||||||
|
|
||||||
|
private help helpDe = new help("de");
|
||||||
|
private help helpEn = new help("En");
|
||||||
|
|
||||||
|
private language activLang;
|
||||||
|
private help activHelp;
|
||||||
|
|
||||||
|
private db_connect db;
|
||||||
|
|
||||||
|
private Map<String, String> channelList = new HashMap<>();
|
||||||
|
|
||||||
|
private step dieRoll = new step();
|
||||||
|
|
||||||
|
|
||||||
|
public dice() {
|
||||||
|
this.prefixSr = "/ed";
|
||||||
|
this.prefixIni = "/ini";
|
||||||
|
|
||||||
|
|
||||||
|
helpDe.add("Alle Befehle können in einen Channel geschrieben werden oder per Direkt Nachricht gesender werden");
|
||||||
|
helpDe.add(this.prefixSr + "Zahl", "Würfelt Zahl x W6. Gewürfelte 5. und 6. Werden als Erfolge gezählt, 1. als Misserfolge.\n" +
|
||||||
|
"Erreicht oder übersteigt die Anzhal der 1. die hälfte der gewürfelten Würfel, zählt dies als ein Patzer. Gibt es mind. 1 Erfolg wird die Markierung der Ausgabe Gelb." +
|
||||||
|
"wird aber kein Erfolg gewürfelt zählt dies als Kritischer Patzer und die Markierung wird Rot **Wichtig: Vor- und Nachteile die Einfluss auf die Patzer Changse haben werden nicht berücksichtigt");
|
||||||
|
|
||||||
|
helpDe.add(this.prefixSr + "+ Zahl", "Gleich wie bei " + this.prefixSr + "Zahl. Mit dem Unterschied dass alle gewürfelten 6. ein zuzätlichen Würfel generien.");
|
||||||
|
|
||||||
|
helpDe.add(this.prefixSr + " Zahl_1 + Zahl_2", "Würfelt Zahl_2 x W6 und addiert Zahl_1 hinzu, um die Initative zu bestimmen");
|
||||||
|
|
||||||
|
helpDe.add(this.prefixIni + " Zahl_1 + Zahl_2", "Synonym für " + this.prefixSr + " Zahl_1 + Zahl_2");
|
||||||
|
|
||||||
|
|
||||||
|
this.db = new db_connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessageReceived(MessageReceivedEvent event) {
|
||||||
|
if ((!event.getMessage().getContentRaw().startsWith(this.prefixSr))
|
||||||
|
|| (event.getChannelType() != ChannelType.TEXT && event.getChannelType() != ChannelType.PRIVATE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!channelList.containsKey(event.getChannel().getId())) {
|
||||||
|
Map<String, String> Einstellungen = db.getChannelSettings(event.getChannel().getId());
|
||||||
|
channelList.put(event.getChannel().getId(), Einstellungen.get("lang").toString());
|
||||||
|
}
|
||||||
|
switch (channelList.get(event.getChannel().getId())) {
|
||||||
|
case "de":
|
||||||
|
activLang = langDe;
|
||||||
|
break;
|
||||||
|
case "en":
|
||||||
|
activLang = langEn;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
activLang = langDe;
|
||||||
|
|
||||||
|
}
|
||||||
|
User author = event.getAuthor();
|
||||||
|
if (!author.isBot() || true) {
|
||||||
|
if (event.getMessage().getContentRaw().startsWith(this.prefixSr))
|
||||||
|
this.srroll(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rolltest
|
||||||
|
*
|
||||||
|
* @param event JDA Event
|
||||||
|
*/
|
||||||
|
private void rollTest(MessageReceivedEvent event) {
|
||||||
|
|
||||||
|
EmbedBuilder test = new EmbedBuilder();
|
||||||
|
test.setTitle("Das ist ein Test");
|
||||||
|
test.setColor(Color.red);
|
||||||
|
test.setDescription("Text " + getAsMention(event));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int[] verteilung = new int[6];
|
||||||
|
int[] verteilung2 = new int[6];
|
||||||
|
int[] verteilung3 = new int[6];
|
||||||
|
int dice1, dice2, dice3;
|
||||||
|
|
||||||
|
try {
|
||||||
|
String[] MsgParts_exl_Mention = event.getMessage().getContentRaw().split(" ");
|
||||||
|
int rounds = Integer.parseInt(MsgParts_exl_Mention[1]);
|
||||||
|
if(rounds <= 0) {
|
||||||
|
event.getChannel().sendMessage("Nope").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(int i = 0; i < rounds; i++) {
|
||||||
|
dice1 = new Random().nextInt(6);
|
||||||
|
dice2 = new SecureRandom().nextInt(6);
|
||||||
|
//dice3 = new ThreadLocalRandom().current().nextInt(6);
|
||||||
|
dice3 = ThreadLocalRandom.current().nextInt(0, 6);
|
||||||
|
verteilung[dice1]++;
|
||||||
|
verteilung2[dice2]++;
|
||||||
|
verteilung3[dice3]++;
|
||||||
|
}
|
||||||
|
for(int i = 0; i < 6; i++) {
|
||||||
|
float pro = verteilung[i]*100f/rounds;
|
||||||
|
test.addField(Integer.toString(i+1), Integer.toString(verteilung[i]) + " - " + String.format("%.2f", pro) + "%", true);
|
||||||
|
}
|
||||||
|
test.addBlankField(false);
|
||||||
|
for(int i = 0; i < 6; i++) {
|
||||||
|
float pro = verteilung2[i]*100f/rounds;
|
||||||
|
test.addField(Integer.toString(i+1), Integer.toString(verteilung2[i]) + " - " + String.format("%.2f", pro) + "%", true);
|
||||||
|
}
|
||||||
|
test.addBlankField(false);
|
||||||
|
for(int i = 0; i < 6; i++) {
|
||||||
|
float pro = verteilung3[i]*100f/rounds;
|
||||||
|
test.addField(Integer.toString(i+1), Integer.toString(verteilung3[i]) + " - " + String.format("%.2f", pro) + "%", true);
|
||||||
|
}
|
||||||
|
event.getChannel().sendMessage(test.build()).queue();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
event.getChannel().sendMessage("Nope").queue();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("problem: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* rolltest
|
||||||
|
*
|
||||||
|
* @param event JDA Event
|
||||||
|
*/
|
||||||
|
private void srroll(MessageReceivedEvent event) {
|
||||||
|
|
||||||
|
EmbedBuilder outputBox = new EmbedBuilder();
|
||||||
|
|
||||||
|
int[] verteilung = new int[6];
|
||||||
|
int dice1;
|
||||||
|
int numberOfDice = 1;
|
||||||
|
int diceart = 6;
|
||||||
|
StringBuilder result = new StringBuilder("");
|
||||||
|
|
||||||
|
int hits = 0;
|
||||||
|
boolean glitches = false;
|
||||||
|
|
||||||
|
boolean karma = false;
|
||||||
|
boolean doppelkarma = false;
|
||||||
|
boolean weiheJunger = false;
|
||||||
|
boolean doppelweiheJunger = false;
|
||||||
|
boolean weiheAnheanger = false;
|
||||||
|
boolean doppelweiheAnheanger = false;
|
||||||
|
boolean weiheVorbild = false;
|
||||||
|
boolean doppelweiheVorbild = false;
|
||||||
|
|
||||||
|
int stufe = 0;
|
||||||
|
int modifier = 1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(event.getMessage().getContentRaw().matches(".*[ \\+jav].*")) { // es wurden andere zeichen als Zahlen gefunden
|
||||||
|
|
||||||
|
}
|
||||||
|
// Prüfen ob Karma wurf
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"+") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" +")) {
|
||||||
|
karma = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"++") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" ++")) {
|
||||||
|
doppelkarma = true;
|
||||||
|
}
|
||||||
|
// Prüfen ob weihepunkte wurf
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"j") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" j")) {
|
||||||
|
weiheJunger = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"jj") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" jj")) {
|
||||||
|
doppelweiheJunger = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"a") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" a")) {
|
||||||
|
weiheAnheanger = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"aa") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" aa")) {
|
||||||
|
doppelweiheAnheanger = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"v") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" v")) {
|
||||||
|
weiheVorbild = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"vv") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" vv")) {
|
||||||
|
doppelweiheVorbild = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// korrikiert Karama eingabe von /ed + zu /ed+
|
||||||
|
String ContentRaw = event.getMessage().getContentRaw();
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+" +")) {
|
||||||
|
ContentRaw = ContentRaw.replace(this.prefixSr+" +", this.prefixSr+"+ ").replace(" ", " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+" j")) {
|
||||||
|
ContentRaw = ContentRaw.replace(this.prefixSr+" j", this.prefixSr+"j ").replace(" ", " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+" a")) {
|
||||||
|
ContentRaw = ContentRaw.replace(this.prefixSr+" a", this.prefixSr+"a ").replace(" ", " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+" v")) {
|
||||||
|
ContentRaw = ContentRaw.replace(this.prefixSr+" v", this.prefixSr+"v ").replace(" ", " ");
|
||||||
|
}
|
||||||
|
String[] MsgParts = ContentRaw.split(" ", 2);
|
||||||
|
if(MsgParts.length < 2) { // Leerer Befehl
|
||||||
|
String message = activLang.emptyCommand;
|
||||||
|
message = message.replace("%command%", this.prefixIni);
|
||||||
|
event.getChannel().sendMessage(getAsMention(event) + message).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MsgParts[1].trim().matches(".*[^0-9].*")) { // es wurden andere zeichen als Zahlen gefunden
|
||||||
|
if(MsgParts[1].trim().toLowerCase().equals("de")) {
|
||||||
|
activLang = langDe;
|
||||||
|
channelList.put(event.getChannel().getId(), "de");
|
||||||
|
event.getChannel().sendMessage(getAsMention(event) + activLang.language).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if(MsgParts[1].trim().toLowerCase().equals("en")) {
|
||||||
|
activLang = langEn;
|
||||||
|
channelList.put(event.getChannel().getId(), "en");
|
||||||
|
event.getChannel().sendMessage(getAsMention(event) + activLang.language).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String[] iniParts = MsgParts[1].trim().toLowerCase().split("[\\+\\-]", 2);
|
||||||
|
messageInterpreter mI = new messageInterpreter(event, activLang);
|
||||||
|
rollStufe(Integer.parseInt(iniParts[0]));
|
||||||
|
if(iniParts.length > 1) { // Nachricht hat kein + Zeichen
|
||||||
|
|
||||||
|
rollStufe(Integer.parseInt(iniParts[0]));
|
||||||
|
if(MsgParts[1].trim().toLowerCase().matches("\\-")) // Prüft auf Negativen Modifizier wenn Ja
|
||||||
|
modifier = -1;
|
||||||
|
dieRoll.addModifier(Integer.parseInt(iniParts[1].trim())*modifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
rollStufe(Integer.parseInt(MsgParts[1].trim().toLowerCase()));
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
String message = activLang.error;
|
||||||
|
message = message.replace("%command%", MsgParts[1].trim());
|
||||||
|
event.getChannel().sendMessage(getAsMention(event) + message).queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(karma)
|
||||||
|
dieRoll.addKarma(1);
|
||||||
|
if(doppelkarma)
|
||||||
|
dieRoll.addKarma(1);
|
||||||
|
|
||||||
|
if(weiheAnheanger)
|
||||||
|
dieRoll.addWeiheA(1);
|
||||||
|
if(doppelweiheAnheanger)
|
||||||
|
dieRoll.addWeiheA(1);
|
||||||
|
|
||||||
|
if(weiheJunger)
|
||||||
|
dieRoll.addWeiheJ(1);
|
||||||
|
if(doppelweiheJunger)
|
||||||
|
dieRoll.addWeiheJ(1);
|
||||||
|
|
||||||
|
if(weiheVorbild)
|
||||||
|
dieRoll.addWeiheV(1);
|
||||||
|
if(doppelweiheVorbild)
|
||||||
|
dieRoll.addWeiheV(1);
|
||||||
|
|
||||||
|
dieRoll.roll();
|
||||||
|
|
||||||
|
if(dieRoll.isGlitches()) { // Patzer
|
||||||
|
outputBox.setColor(Color.red);
|
||||||
|
}
|
||||||
|
else { // Erfolg
|
||||||
|
outputBox.setColor(Color.green);
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = activLang.resultText;
|
||||||
|
message = "%rolls%: %hits%";
|
||||||
|
message = message.replace("%rolls%", dieRoll.getDiceStructur()).replace("%hits%", String.valueOf(dieRoll.getResultInt()));
|
||||||
|
|
||||||
|
outputBox.setTitle(getEffectiveName(event) + message);
|
||||||
|
outputBox.setDescription("(" + dieRoll.getResultStructur() + ")");
|
||||||
|
|
||||||
|
event.getChannel().sendMessage(outputBox.build()).queue();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
event.getChannel().sendMessage("Nope").queue();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("problem: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private String getEffectiveName(MessageReceivedEvent event) {
|
||||||
|
if(event.getMember() == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return event.getMember().getEffectiveName() + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAsMention(MessageReceivedEvent event) {
|
||||||
|
if(event.getMember() == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return event.getMember().getAsMention() + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rollStufe(int stufe) {
|
||||||
|
|
||||||
|
dieRoll.reset();
|
||||||
|
|
||||||
|
switch (stufe) {
|
||||||
|
case 1:
|
||||||
|
dieRoll.setW4(1).setModifier(-2);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
dieRoll.setW4(1).setModifier(-1);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
dieRoll.setW4(1);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
dieRoll.setW6(1);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
dieRoll.setW8(1);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
dieRoll.setW10(1);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
dieRoll.setW12(1);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
dieRoll.setW6(2);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
dieRoll.setW8(1).setW6(1);
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
dieRoll.setW8(2);
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
dieRoll.setW10(1).setW8(1);
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
dieRoll.setW10(2);
|
||||||
|
case 13:
|
||||||
|
dieRoll.setW12(1).setW10(1);
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
dieRoll.setW12(2);
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
dieRoll.setW12(1).setW6(2);
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
dieRoll.setW12(1).setW8(1).setW6(1);
|
||||||
|
break;
|
||||||
|
case 17:
|
||||||
|
dieRoll.setW12(1).setW8(2);
|
||||||
|
break;
|
||||||
|
case 18:
|
||||||
|
dieRoll.setW12(1).setW10(1).setW8(1);
|
||||||
|
break;
|
||||||
|
case 19:
|
||||||
|
dieRoll.setW20(1).setW6(2);
|
||||||
|
break;
|
||||||
|
case 20:
|
||||||
|
dieRoll.setW20(1).setW8(1).setW6(1);
|
||||||
|
break;
|
||||||
|
case 21:
|
||||||
|
dieRoll.setW20(1).setW8(2);
|
||||||
|
break;
|
||||||
|
case 22:
|
||||||
|
dieRoll.setW20(1).setW10(1).setW8(1);
|
||||||
|
break;
|
||||||
|
case 23:
|
||||||
|
dieRoll.setW20(1).setW10(2);
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
dieRoll.setW20(1).setW12(1).setW10(1);
|
||||||
|
break;
|
||||||
|
case 25:
|
||||||
|
dieRoll.setW20(1).setW12(2);
|
||||||
|
break;
|
||||||
|
case 26:
|
||||||
|
dieRoll.setW20(1).setW12(1).setW6(2);
|
||||||
|
break;
|
||||||
|
case 27:
|
||||||
|
dieRoll.setW20(1).setW12(1).setW8(1).setW6(1);
|
||||||
|
break;
|
||||||
|
case 28:
|
||||||
|
dieRoll.setW20(1).setW12(1).setW8(2);
|
||||||
|
break;
|
||||||
|
case 29:
|
||||||
|
dieRoll.setW20(1).setW12(1).setW10(1).setW8(1);
|
||||||
|
break;
|
||||||
|
case 30:
|
||||||
|
dieRoll.setW20(2).setW6(1);
|
||||||
|
break;
|
||||||
|
case 31:
|
||||||
|
dieRoll.setW20(2).setW8(1).setW6(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
diceList[30] = "2W20+2W6";
|
||||||
|
diceList[31] = "2W20+W8+W6";
|
||||||
|
diceList[32] = "2W20+2W8";
|
||||||
|
diceList[33] = "2W20+W10+W8";
|
||||||
|
diceList[34] = "2W20+2W10";
|
||||||
|
diceList[35] = "2W20+W12+W10";
|
||||||
|
diceList[36] = "2W20+2W12";
|
||||||
|
diceList[37] = "2W20+W12+2W6";
|
||||||
|
diceList[38] = "2W20+W12+W8+W6";
|
||||||
|
diceList[39] = "2W20+W12+2W8";
|
||||||
|
diceList[40] = "2W20+W12+W10+W8";
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
89
src/main/java/Earthdawn/language.java
Normal file
89
src/main/java/Earthdawn/language.java
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
package Earthdawn;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
|
public class language {
|
||||||
|
|
||||||
|
public String language = "Deutsch";
|
||||||
|
public String emptyCommand = " der %command% befehl benötigt einen Wert";
|
||||||
|
public String error = " Irgend was dummes ist passiert beim Verstehen von %command%";
|
||||||
|
public String error2 = " Irgend was dummes ist passiert beim Verstehen von %command%";
|
||||||
|
public String noNegativ = " es darf kein Negativen Wurf geben";
|
||||||
|
public String dice = "w";
|
||||||
|
public String resultText = " %numberOfDice%w%diceart% %EdgeDice%:\tErfolge: %hits%\tMisserfolge: %oneHits%";
|
||||||
|
public String basisresultText = " %numberOfDice%w%diceart%:";
|
||||||
|
|
||||||
|
public language() {
|
||||||
|
this.readConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param lang Srache
|
||||||
|
*/
|
||||||
|
public language(String lang) {
|
||||||
|
this.readConfig(lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readConfig() {
|
||||||
|
this.readConfig("de");
|
||||||
|
}
|
||||||
|
public void readConfig(String lang) {
|
||||||
|
FileInputStream input = null;
|
||||||
|
OutputStream output = null;
|
||||||
|
Properties config = new Properties();
|
||||||
|
try {
|
||||||
|
File f = new File("shadowrun.cfg");
|
||||||
|
if (f.isFile() && f.canRead()) {
|
||||||
|
|
||||||
|
input = new FileInputStream("shadowrun.cfg");
|
||||||
|
config.load(input);
|
||||||
|
if(config.containsKey(lang + ".language"))
|
||||||
|
this.language = config.getProperty(lang + ".language");
|
||||||
|
|
||||||
|
if(config.containsKey(lang + ".emptyCommand"))
|
||||||
|
this.emptyCommand = config.getProperty(lang + ".emptyCommand");
|
||||||
|
if(config.containsKey(lang + ".error"))
|
||||||
|
this.error = config.getProperty(lang + ".error");
|
||||||
|
if(config.containsKey(lang + ".error2"))
|
||||||
|
this.error2 = config.getProperty(lang + ".error2");
|
||||||
|
if(config.containsKey(lang + ".noNegativ"))
|
||||||
|
this.noNegativ = config.getProperty(lang + ".noNegativ");
|
||||||
|
if(config.containsKey(lang + ".dice"))
|
||||||
|
this.dice = config.getProperty(lang + ".dice");
|
||||||
|
if(config.containsKey(lang + ".resultText"))
|
||||||
|
this.resultText = config.getProperty(lang + ".resultText");
|
||||||
|
if(config.containsKey(lang + ".basisresultText"))
|
||||||
|
this.resultText = config.getProperty(lang + ".basisresultText");
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
output = new FileOutputStream("shadowrun.cfg");
|
||||||
|
config.setProperty(lang + ".language", this.language);
|
||||||
|
config.setProperty(lang + ".emptyCommand", this.emptyCommand);
|
||||||
|
config.setProperty(lang + ".error", this.error);
|
||||||
|
config.setProperty(lang + ".error2", this.error2);
|
||||||
|
config.setProperty(lang + ".noNegativ", this.noNegativ);
|
||||||
|
config.setProperty(lang + ".dice", this.dice);
|
||||||
|
config.setProperty(lang + ".resultText", this.resultText);
|
||||||
|
config.setProperty(lang + ".basisresultText", this.basisresultText);
|
||||||
|
config.store(output, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (input != null) {
|
||||||
|
try {
|
||||||
|
input.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
124
src/main/java/Earthdawn/messageInterpreter.java
Normal file
124
src/main/java/Earthdawn/messageInterpreter.java
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
package Earthdawn;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class messageInterpreter {
|
||||||
|
|
||||||
|
private Integer diceart = 6;
|
||||||
|
private Integer numberOfDice = 1;
|
||||||
|
private Integer typ = 0;
|
||||||
|
private Integer intResult = 0;
|
||||||
|
|
||||||
|
private language activLang;
|
||||||
|
private MessageReceivedEvent event;
|
||||||
|
boolean glitches = true;
|
||||||
|
|
||||||
|
public Integer getDiceart() {
|
||||||
|
return diceart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNumberOfDice() {
|
||||||
|
return numberOfDice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIntResult() {
|
||||||
|
return intResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isNum() {
|
||||||
|
if(typ == 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDice() {
|
||||||
|
if(typ == 2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param event JDA Event
|
||||||
|
* @param activLang Aktive Sprache
|
||||||
|
*/
|
||||||
|
public messageInterpreter(MessageReceivedEvent event, language activLang) {
|
||||||
|
this.event = event;
|
||||||
|
this.activLang = activLang;
|
||||||
|
}
|
||||||
|
private void reset() {
|
||||||
|
diceart = 6;
|
||||||
|
numberOfDice = 1;
|
||||||
|
typ = 0;
|
||||||
|
intResult = 0;
|
||||||
|
}
|
||||||
|
public void inputInterpreter(String Input) {
|
||||||
|
reset();
|
||||||
|
Scanner sc = new Scanner(Input.trim());
|
||||||
|
|
||||||
|
StringBuilder resultString = new StringBuilder("");
|
||||||
|
|
||||||
|
Integer PartValue = 0;
|
||||||
|
|
||||||
|
|
||||||
|
int dice1;
|
||||||
|
|
||||||
|
if(sc.hasNextInt()) { // ist eine Zahl
|
||||||
|
typ = 1;
|
||||||
|
intResult = Integer.parseInt(Input.trim());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String[] MalusParts= Input.trim().toLowerCase().replace(" ", "").split("\\-");
|
||||||
|
for (String MalusPart : MalusParts) {
|
||||||
|
String[] Parts = MalusPart.split("\\+");
|
||||||
|
for (String Part : Parts ) {
|
||||||
|
PartValue = 0;
|
||||||
|
sc = new Scanner(Part);
|
||||||
|
if(sc.hasNextInt()) {
|
||||||
|
PartValue += Integer.parseInt(Part);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (Part.matches("([0-9]*)[dw]([0-9].*)")) { // format besteh aus (Zahlen)d(Zahlen) oder (Zahlen)w(Zahlen)
|
||||||
|
String[] diceInterpreter = Part.split("[wd]");
|
||||||
|
try {
|
||||||
|
diceart = Integer.parseInt(diceInterpreter[1]);
|
||||||
|
numberOfDice = Integer.parseInt(diceInterpreter[0]);
|
||||||
|
for(int i = 0; i < numberOfDice; i++) {
|
||||||
|
dice1 = new Random().nextInt(diceart);
|
||||||
|
resultString.append(dice1+1);
|
||||||
|
resultString.append(" ");
|
||||||
|
PartValue += dice1+1;
|
||||||
|
if(dice1 > 0)
|
||||||
|
glitches = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
String message = activLang.error;
|
||||||
|
message = message.replace("%command%", Input.trim().toLowerCase());
|
||||||
|
typ = -1;
|
||||||
|
throw new IllegalArgumentException( message );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String message = activLang.error;
|
||||||
|
message = message.replace("%command%", Input.trim().toLowerCase());
|
||||||
|
typ = -1;
|
||||||
|
throw new IllegalArgumentException( message );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(intResult == 0)
|
||||||
|
intResult = PartValue;
|
||||||
|
else
|
||||||
|
intResult -= PartValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
292
src/main/java/Earthdawn/step.java
Normal file
292
src/main/java/Earthdawn/step.java
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
package Earthdawn;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class step {
|
||||||
|
|
||||||
|
private int w4;
|
||||||
|
private int w6;
|
||||||
|
private int w8;
|
||||||
|
private int w10;
|
||||||
|
private int w12;
|
||||||
|
private int w20;
|
||||||
|
private int karma;
|
||||||
|
private int weiheA;
|
||||||
|
private int weiheJ;
|
||||||
|
private int weiheV;
|
||||||
|
|
||||||
|
private boolean glitches = true;
|
||||||
|
private String diceStructur = "";
|
||||||
|
private String diceResult = "";
|
||||||
|
private int resultInt = 0;
|
||||||
|
|
||||||
|
private int modifier = 0;
|
||||||
|
|
||||||
|
StringBuilder resultStructur = new StringBuilder("");
|
||||||
|
|
||||||
|
|
||||||
|
public int getW4() {
|
||||||
|
return w4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step setW4(int w4) {
|
||||||
|
this.w4 = w4;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getW6() {
|
||||||
|
return w6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step setW6(int w6) {
|
||||||
|
this.w6 = w6;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getW8() {
|
||||||
|
return w8;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step setW8(int w8) {
|
||||||
|
this.w8 = w8;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getW10() {
|
||||||
|
return w10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step setW10(int w10) {
|
||||||
|
this.w10 = w10;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getW12() {
|
||||||
|
return w12;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step setW12(int w12) {
|
||||||
|
this.w12 = w12;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getW20() {
|
||||||
|
return w20;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step setW20(int w20) {
|
||||||
|
this.w20 = w20;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addW4(int w4) {
|
||||||
|
this.w4 += w4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addW6(int w6) {
|
||||||
|
this.w6 += w6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addW8(int w8) {
|
||||||
|
this.w8 += w8;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addW10(int w10) {
|
||||||
|
this.w10 += w10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addW12(int w12) {
|
||||||
|
this.w12 += w12;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addW20(int w20) {
|
||||||
|
this.w20 += w20;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getModifier() {
|
||||||
|
return modifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getKarma() {
|
||||||
|
return karma;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step setKarma(int karma) {
|
||||||
|
this.karma = karma;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step addKarma(int karma) {
|
||||||
|
this.karma += karma;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step addWeiheJ(int weiheJ) {
|
||||||
|
this.weiheJ += weiheJ;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step addWeiheA(int weiheA) {
|
||||||
|
this.weiheA += weiheA;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public step addWeiheV(int weiheV) {
|
||||||
|
this.weiheV += weiheV;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step setModifier(int modifier) {
|
||||||
|
this.modifier = modifier;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public step addModifier(int modifier) {
|
||||||
|
this.modifier += modifier;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGlitches() {
|
||||||
|
return glitches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDiceStructur() {
|
||||||
|
return diceStructur;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDiceResult() {
|
||||||
|
return diceResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResultInt() {
|
||||||
|
return resultInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getResultStructur() {
|
||||||
|
return resultStructur.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public step reset() {
|
||||||
|
w4 = 0;
|
||||||
|
w6 = 0;
|
||||||
|
w8 = 0;
|
||||||
|
w10 = 0;
|
||||||
|
w12 = 0;
|
||||||
|
w20 = 0;
|
||||||
|
karma = 0;
|
||||||
|
weiheJ = 0;
|
||||||
|
weiheA = 0;
|
||||||
|
weiheV = 0;
|
||||||
|
|
||||||
|
modifier = 0;
|
||||||
|
|
||||||
|
glitches = true;
|
||||||
|
diceStructur = "";
|
||||||
|
diceResult = "";
|
||||||
|
resultInt = 0;
|
||||||
|
resultStructur = new StringBuilder("");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void roll() {
|
||||||
|
|
||||||
|
StringBuilder resultConstruction = new StringBuilder("");
|
||||||
|
|
||||||
|
if(w4 > 0) {
|
||||||
|
rollDice(w4, 4);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append("+");
|
||||||
|
resultConstruction.append(w4).append("w4");
|
||||||
|
}
|
||||||
|
if(w6 > 0) {
|
||||||
|
rollDice(w6, 6);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append("+");
|
||||||
|
resultConstruction.append(w6).append("w6");
|
||||||
|
}
|
||||||
|
if(w8 > 0) {
|
||||||
|
rollDice(w8, 8);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append("+");
|
||||||
|
resultConstruction.append(w8).append("w8");
|
||||||
|
}
|
||||||
|
if(w10 > 0) {
|
||||||
|
rollDice(w10, 10);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append("+");
|
||||||
|
resultConstruction.append(w10).append("w10");
|
||||||
|
}
|
||||||
|
if(w12 > 0) {
|
||||||
|
rollDice(w12, 12);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append("+");
|
||||||
|
resultConstruction.append(w12).append("w12");
|
||||||
|
}
|
||||||
|
if(w20 > 0) {
|
||||||
|
rollDice(w20, 20);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append(" + ");
|
||||||
|
resultConstruction.append(w20).append("w20");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(karma > 0) {
|
||||||
|
rollDice(karma, 6);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append(" + ");
|
||||||
|
resultConstruction.append(karma).append("w6");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(weiheJ > 0) {
|
||||||
|
rollDice(weiheJ, 4);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append(" + ");
|
||||||
|
resultConstruction.append(weiheJ).append("w4");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(weiheA > 0) {
|
||||||
|
rollDice(weiheA, 6);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append(" + ");
|
||||||
|
resultConstruction.append(weiheA).append("w6");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(weiheV > 0) {
|
||||||
|
rollDice(weiheV, 8);
|
||||||
|
if(resultConstruction.length() > 0)
|
||||||
|
resultConstruction.append(" + ");
|
||||||
|
resultConstruction.append(weiheV).append("w8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(modifier != 0) {
|
||||||
|
resultInt += modifier;
|
||||||
|
if(modifier > 0)
|
||||||
|
resultConstruction.append(" + ");
|
||||||
|
|
||||||
|
|
||||||
|
resultConstruction.append(modifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
diceStructur = resultConstruction.toString();
|
||||||
|
|
||||||
|
if(resultInt <= 0)
|
||||||
|
resultInt = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rollDice(int numberOfDice, int diceart) {
|
||||||
|
int dice;
|
||||||
|
for(int i = 0; i < numberOfDice; i++) {
|
||||||
|
dice = new Random().nextInt(diceart);
|
||||||
|
if(resultStructur.length() > 0) {
|
||||||
|
resultStructur.append(" ");
|
||||||
|
}
|
||||||
|
resultStructur.append(dice+1);
|
||||||
|
resultStructur.append("/");
|
||||||
|
resultStructur.append(diceart);
|
||||||
|
resultInt += dice+1;
|
||||||
|
if(dice+1 == diceart)
|
||||||
|
i--;
|
||||||
|
if(dice > 0)
|
||||||
|
glitches = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user