mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-11 21:57:40 +00:00
Added bonusAttribute function, which works the same as the command.
This commit is contained in:
1 parent
e9a4471cd2
commit
98d2d943ae
1 file changed
+217
@@ -9,6 +9,7 @@ import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.ScriptItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T>{
|
||||
public T player;
|
||||
@@ -75,6 +76,215 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T>{
|
||||
"\nstr, dex, con, wil, mnd, spi\nstrength, dexterity, constitution, willpower, mind, spirit",new Object[0]);
|
||||
}
|
||||
|
||||
private double applyOperator(String method, double n1, double n2) {
|
||||
if (method.equals("+")) {
|
||||
n1 += n2;
|
||||
} else if (method.equals("-")) {
|
||||
n1 -= n2;
|
||||
} else if (method.equals("*")) {
|
||||
n1 *= n2;
|
||||
} else if (method.equals("/")) {
|
||||
n1 /= n2;
|
||||
} else if (method.equals("%")) {
|
||||
n1 %= n2;
|
||||
}
|
||||
|
||||
return n1;
|
||||
}
|
||||
|
||||
public String bonusAttribute(String action, String stat, String bonusID, String operation, double attributeValue, boolean endOfTheList) {
|
||||
String[] actions = new String[]{"add", "addto", "set", "get", "remove", "clear"};
|
||||
String[] operations = new String[]{"+", "-", "*", "/", "%"};
|
||||
|
||||
boolean valid = false;
|
||||
for(String s : actions){
|
||||
if(s.equals(action.toLowerCase())){
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
throw new CustomNPCsException("Action can be: add/addTo/set/get/remove/clear", new Object[0]);
|
||||
}
|
||||
|
||||
valid = false;
|
||||
for(String s : operations){
|
||||
if(s.equals(operation)){
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
throw new CustomNPCsException("Operation can be: + - * / %", new Object[0]);
|
||||
}
|
||||
|
||||
stat = stat.toLowerCase().trim();
|
||||
switch (stat) {
|
||||
case "strength":
|
||||
stat = "str";
|
||||
case "dexterity":
|
||||
stat = "dex";
|
||||
case "constitution":
|
||||
stat = "con";
|
||||
case "willpower":
|
||||
stat = "wil";
|
||||
case "mind":
|
||||
stat = "mnd";
|
||||
case "spirit":
|
||||
stat = "spi";
|
||||
}
|
||||
if(!(stat.equals("str") || stat.equals("dex") || stat.equals("con") || stat.equals("wil") || stat.equals("mnd") || stat.equals("spi")))
|
||||
throw new CustomNPCsException("Invalid stat name: " + stat + "\nValid stat names are:" +
|
||||
"\nstr, dex, con, wil, mnd, spi\nstrength, dexterity, constitution, willpower, mind, spirit",new Object[0]);
|
||||
|
||||
String bonusValueString = operation + attributeValue;
|
||||
String bonus = player.getEntityData().getCompoundTag("PlayerPersisted").getString("jrmcAttrBonus"+stat);
|
||||
String bonuses[] = bonus.split("\\|");
|
||||
String[][] bonusValues = new String[bonuses.length][2];
|
||||
if (bonuses.length > 0 && bonuses[0].length() > 0) {
|
||||
for(int i = 0; i < bonuses.length; ++i) {
|
||||
String[] bonusValue = bonuses[i].split("\\;");
|
||||
bonusValues[i][0] = bonusValue[0];
|
||||
bonusValues[i][1] = bonusValue[1];
|
||||
}
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case "get":
|
||||
if(player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcAttrBonus"+stat)) {
|
||||
for (String[] s : bonusValues) {
|
||||
if (s[0].equals(bonusID))
|
||||
return s[1];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
case "clear":
|
||||
if(player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcAttrBonus"+stat))
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").setString("jrmcAttrBonus"+stat, "");
|
||||
break;
|
||||
case "remove":
|
||||
String newBonusString = "";
|
||||
for (int i = 0; i < bonusValues.length; i++) {
|
||||
if (!bonusValues[i][0].equals(bonusID))
|
||||
newBonusString += (i != 0 ? "|" : "") + bonusValues[i][0] + ";" + bonusValues[i][1];
|
||||
}
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").setString("jrmcAttrBonus"+stat, newBonusString);
|
||||
break;
|
||||
case "add":
|
||||
boolean nbtFail = false;
|
||||
|
||||
for (int id = 0; id < bonuses.length; ++id) {
|
||||
String[] bonusValue = bonuses[id].split("\\;");
|
||||
bonusValues[id][0] = bonusValue[0];
|
||||
if (bonusValues[id][0].equals(bonusID)) {
|
||||
nbtFail = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!nbtFail) {
|
||||
if (endOfTheList) {
|
||||
if (bonus.length() == 0) {
|
||||
bonus = bonusID + ";" + bonusValueString;
|
||||
} else {
|
||||
bonus = bonus + "|" + bonusID + ";" + bonusValueString;
|
||||
}
|
||||
} else {
|
||||
if (bonus.length() == 0) {
|
||||
bonus = bonusID + ";" + bonusValueString;
|
||||
} else {
|
||||
bonus = bonusID + ";" + bonusValueString + "|" + bonus;
|
||||
}
|
||||
}
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").setString("jrmcAttrBonus"+stat, bonus);
|
||||
}
|
||||
break;
|
||||
case "set": {
|
||||
String noNBTText;
|
||||
int startIndex = -1;
|
||||
boolean number = false;
|
||||
boolean run = false;
|
||||
|
||||
try {
|
||||
startIndex = Integer.parseInt(bonusID);
|
||||
number = true;
|
||||
} catch (Exception var34) {
|
||||
number = false;
|
||||
}
|
||||
|
||||
for (startIndex = 0; startIndex < bonuses.length; ++startIndex) {
|
||||
String[] bonusValue = bonuses[startIndex].split("\\;");
|
||||
bonusValues[startIndex][0] = bonusValue[0];
|
||||
if (number && startIndex == startIndex || !number && bonusValues[startIndex][0].equals(bonusID)) {
|
||||
noNBTText = bonusValues[startIndex][0] + ";" + bonusValueString;
|
||||
bonuses[startIndex] = "";
|
||||
run = true;
|
||||
bonuses[startIndex] = noNBTText;
|
||||
bonusValue = bonuses[startIndex].split("\\;");
|
||||
bonusValues[startIndex][0] = bonusValue[0];
|
||||
bonusValues[startIndex][1] = bonusValue[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (run) {
|
||||
String startString = "";
|
||||
|
||||
for (int i = 0; i < bonuses.length; ++i) {
|
||||
if (bonuses[i] != null && bonuses[i].length() > 0) {
|
||||
startString = startString + bonuses[i] + (bonuses.length - 1 == i ? "" : "|");
|
||||
}
|
||||
}
|
||||
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").setString("jrmcAttrBonus"+stat, startString);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "addto": {
|
||||
boolean number;
|
||||
boolean run = false;
|
||||
int id = -1;
|
||||
try {
|
||||
id = Integer.parseInt(bonusID);
|
||||
number = true;
|
||||
} catch (Exception var35) {
|
||||
number = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < bonuses.length; ++i) {
|
||||
String[] bonusValue = bonuses[i].split("\\;");
|
||||
bonusValues[i][0] = bonusValue[0];
|
||||
if (number && i == id || !number && bonusValues[i][0].equals(bonusID)) {
|
||||
if (!bonusValues[i][1].contains("nbt_") && !bonusValues[i][1].contains("NBT_") && !bonusValueString.contains("nbt_") && !bonusValueString.contains("NBT_")) {
|
||||
double value = Double.parseDouble(bonusValues[i][1].substring(1));
|
||||
double resultValue = applyOperator(operation, value, attributeValue);
|
||||
String result = bonusValues[i][1].substring(0, 1) + resultValue;
|
||||
String data = bonusValues[i][0] + ";" + result;
|
||||
bonuses[i] = data;
|
||||
bonusValue = bonuses[i].split("\\;");
|
||||
bonusValues[i][0] = bonusValue[0];
|
||||
bonusValues[i][1] = bonusValue[1];
|
||||
run = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (run) {
|
||||
String startString = "";
|
||||
|
||||
for (int i = 0; i < bonuses.length; ++i) {
|
||||
if (bonuses[i] != null && bonuses[i].length() > 0) {
|
||||
startString = startString + bonuses[i] + (bonuses.length - 1 == i ? "" : "|");
|
||||
}
|
||||
}
|
||||
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").setString("jrmcAttrBonus"+stat, startString);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setRelease(byte release){
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").setByte("jrmcRelease",release);
|
||||
}
|
||||
@@ -200,6 +410,13 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T>{
|
||||
return player.getEntityData().getCompoundTag("PlayerPersisted").getString("jrmcSSlts");
|
||||
}
|
||||
|
||||
public void setJRMCSE(String statusEffects){
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").setString("jrmcStatusEff",statusEffects);
|
||||
}
|
||||
public String getJRMCSE(){
|
||||
return player.getEntityData().getCompoundTag("PlayerPersisted").getString("jrmcStatusEff");
|
||||
}
|
||||
|
||||
public byte getDBCClass(){
|
||||
return player.getEntityData().getCompoundTag("PlayerPersisted").getByte("jrmcClass");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user