More Options for Potion-Effects

This commit is contained in:
Sn0wStorm 2014-09-03 01:05:53 +02:00
parent ebfbda884a
commit 30fa43633f
8 changed files with 327 additions and 58 deletions

View File

@ -61,21 +61,46 @@ version: '1.3'
# -- Recipes for Potions --
# name: Different names for bad/normal/good (Formatting codes possible: such as &6)
# ingredients: List of 'material or id,data/amount' (Item-ids instead of material are deprecated by bukkit and may not work in the future!)
# ingredients: List of 'material or id,data/amount'
# (Item-ids instead of material are deprecated by bukkit and may not work in the future!)
# A list of materials can be found here: http://jd.bukkit.org/beta/apidocs/org/bukkit/Material.html
# You can specify a data value, omitting it will ignore the data value of the added ingredient
# cookingtime: Time in real minutes ingredients have to boil
# distillruns: How often it has to be distilled for full alcohol (0=without distilling)
# wood: Wood of the barrel 0=any 1=Birch 2=Oak 3=Jungle 4=Spruce 5=Acacia 6=Dark Oak
# age: Time in Minecraft-days, the potion has to age in a barrel 0=no aging
# color: Color of the potion after distilling/aging. DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY
# color: Color of the potion after distilling/aging.
# Usable Colors: DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY
# difficulty: 1-10 accuracy needed to get good quality (1 = unaccurate/easy, 10 = very precise/hard)
# alcohol: Absolute amount of alcohol 0-100 in a perfect potion (will be added directly to the player, where 100 means fainting)
# effects: List of effect/duration Special potion-effect when drinking, duration in sek. Suffix name with 'X' to hide effect from label. Sample: POISONX/10
# (WEAKNESS, INCREASE_DAMAGE, SLOW and SPEED are always hidden.) Possible Effects: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html
# instant effects (such as HEAL) _must!_ have defined the level instead of the duration!
# effects: List of effect/level/duration Special potion-effect when drinking, duration in sek.
# Suffix name with 'X' to hide effect from label. Sample: 'POISONX/2/10' (WEAKNESS, INCREASE_DAMAGE, SLOW and SPEED are always hidden.)
# Possible Effects: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html
# Level or Duration ranges may be specified with a "-", ex. 'SPEED/1-2/30-40' = lvl 1 and 30 sec at worst and lvl 2 and 40 sec at best
# Ranges also work high-low, ex. 'POISON/3-1/20-5' for weaker effects at good quality.
# Highest possible Duration: 1638 sec. Instant Effects dont need any duration specified.
recipes:
# Example Recipe with every possible entry first:
0:
name: Bad Example/Example/Good Example
ingredients:
- SUGAR_CANE/5
- 264/1
- INK_SACK,3/20
- 5,1/8
cookingtime: 3
distillruns: 2
wood: 4
age: 11
color: DARK_RED
difficulty: 3
alcohol: 23
effects:
- FIRE_RESISTANCE/20
- HEAL/1
- WEAKNESS/2-3/50-60
- POISONX/1-0/20-0
1:
name: Skunky Wheatbeer/Wheatbeer/Fine Wheatbeer
ingredients:
@ -133,7 +158,7 @@ recipes:
difficulty: 4
alcohol: 12
effects:
- WATER_BREATHINGX/150
- WATER_BREATHINGX/1-2/150
6:
name: Bitter Rum/Spicy Rum/&6Golden Rum
ingredients:
@ -146,7 +171,8 @@ recipes:
difficulty: 6
alcohol: 30
effects:
- FIRE_RESISTANCE/100
- FIRE_RESISTANCE/1/20-100
- POISONX/1-0/30-0
7:
name: Lousy Vodka/Vodka/Russian Vodka
ingredients:
@ -170,7 +196,7 @@ recipes:
difficulty: 8
alcohol: 45
effects:
- POISON/20
- POISON/20-30
9:
name: Potato soup
ingredients:
@ -180,7 +206,18 @@ recipes:
color: PINK
difficulty: 1
effects:
- HEAL/1
- HEAL/0-1
10:
name: Stale Coffee/Coffee/Strong Coffee
ingredients:
- INK_SACK,3/6
- MILK_BUCKET/1
cookingtime: 2
color: BLACK
difficulty: 3
effects:
- REGENERATION/1/2-5
- SPEED/1-2/10-25
@ -194,6 +231,8 @@ cooked:
POTATO_ITEM: Potatomash
LONG_GRASS: Boiled herbs
RED_MUSHROOM: Mushroom brew
INK_SACK: Colored brew
MILK_BUCKET: Milky water

View File

@ -110,7 +110,7 @@
<repository>
<id>sacredlabyrinth-repo</id>
<url>http://repo.sacredlabyrinth.net:8081/artifactory/repo/</url>
<url>http://repo.sacredlabyrinth.net/artifactory/repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>

View File

@ -0,0 +1,120 @@
package com.dre.brewery;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType;
public class BEffect {
private PotionEffectType type;
private short minlvl;
private short maxlvl;
private short minduration;
private short maxduration;
private boolean hidden = false;
public BEffect(String effectString) {
String[] effectSplit = effectString.split("/");
String effect = effectSplit[0];
if (effect.equalsIgnoreCase("WEAKNESS") ||
effect.equalsIgnoreCase("INCREASE_DAMAGE") ||
effect.equalsIgnoreCase("SLOW") ||
effect.equalsIgnoreCase("SPEED") ||
effect.equalsIgnoreCase("REGENERATION")) {
// hide these effects as they put crap into lore
// Dont write Regeneration into Lore, its already there storing data!
hidden = true;
} else if (effect.endsWith("X")) {
hidden = true;
effect = effect.substring(0, effect.length() - 1);
}
type = PotionEffectType.getByName(effect);
if (type == null) {
P.p.errorLog("Effect: " + effect + " does not exist!");
return;
}
if (effectSplit.length == 3) {
String[] range = effectSplit[1].split("-");
if (type.isInstant()) {
setLvl(range);
} else {
setLvl(range);
range = effectSplit[2].split("-");
setDuration(range);
}
} else if (effectSplit.length == 2) {
String[] range = effectSplit[1].split("-");
if (type.isInstant()) {
setLvl(range);
} else {
setDuration(range);
maxlvl = 3;
minlvl = 1;
}
} else {
maxduration = 20;
minduration = 10;
maxlvl = 3;
minlvl = 1;
}
}
private void setLvl(String[] range) {
if (range.length == 1) {
maxlvl = (short) P.p.parseInt(range[0]);
minlvl = 1;
} else {
maxlvl = (short) P.p.parseInt(range[1]);
minlvl = (short) P.p.parseInt(range[0]);
}
}
private void setDuration(String[] range) {
if (range.length == 1) {
maxduration = (short) P.p.parseInt(range[0]);
minduration = (short) (maxduration / 8);
} else {
maxduration = (short) P.p.parseInt(range[1]);
minduration = (short) P.p.parseInt(range[0]);
}
}
public void apply(int quality, Player player) {
int duration = calcDuration(quality);
int lvl = calcLvl(quality);
if (lvl < 1 || (duration < 1 && !type.isInstant())) {
return;
}
duration *= 20;
duration /= type.getDurationModifier();
type.createEffect(duration, lvl - 1).apply(player);
}
public int calcDuration(float quality) {
return (int) Math.round(minduration + ((maxduration - minduration) * (quality / 10.0)));
}
public int calcLvl(float quality) {
return (int) Math.round(minlvl + ((maxlvl - minlvl) * (quality / 10.0)));
}
public void writeInto(PotionMeta meta, int quality) {
if ((calcDuration(quality) > 0 || type.isInstant()) && calcLvl(quality) > 0) {
meta.addCustomEffect(type.createEffect(0, 0), true);
} else {
meta.removeCustomEffect(type);
}
}
public boolean isValid() {
return type != null && minlvl >= 0 && maxlvl >= 0 && minduration >= 0 && maxduration >= 0;
}
public boolean isHidden() {
return hidden;
}
}

View File

@ -79,7 +79,7 @@ public class BIngredients {
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
P.p.debugLog("cooked potion has Quality: " + quality);
Brew brew = new Brew(uid, quality, cookRecipe, this);
Brew.addOrReplaceEffects(potionMeta, brew.getEffects());
Brew.addOrReplaceEffects(potionMeta, brew.getEffects(), brew.getQuality());
cookedName = cookRecipe.getName(quality);
potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));

View File

@ -1,5 +1,6 @@
package com.dre.brewery;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
@ -462,20 +463,10 @@ public class BPlayer {
}
public static void addBrewEffects(Brew brew, Player player) {
Map<String, Integer> effects = brew.getEffects();
ArrayList<BEffect> effects = brew.getEffects();
if (effects != null) {
for (Map.Entry<String, Integer> entry : effects.entrySet()) {
PotionEffectType type = PotionEffectType.getByName(entry.getKey().replace("X", ""));
if (type != null) {
int duration = (entry.getValue() * brew.getQuality()) / 8;
if (type.isInstant()) {
type.createEffect(0, duration - 1).apply(player);
} else {
int amplifier = brew.getQuality() / 4;
duration /= type.getDurationModifier();
type.createEffect(duration * 20, amplifier).apply(player);
}
}
for (BEffect effect : effects) {
effect.apply(brew.getQuality(), player);
}
}
}

View File

@ -2,8 +2,6 @@ package com.dre.brewery;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.Material;
@ -22,7 +20,7 @@ public class BRecipe {
private String color;// color of the destilled/finished potion
private int difficulty;// difficulty to brew the potion, how exact the instruction has to be followed
private int alcohol;// Alcohol in perfect potion
private Map<String, Integer> effects = new HashMap<String, Integer>(); // Special Effect, Duration
private ArrayList<BEffect> effects = new ArrayList<BEffect>(); // Special Effects when drinking
public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
String nameList = configSectionRecipes.getString(recipeId + ".name");
@ -80,20 +78,11 @@ public class BRecipe {
List<String> effectStringList = configSectionRecipes.getStringList(recipeId + ".effects");
if (effectStringList != null) {
for (String effectString : effectStringList) {
String[] effectSplit = effectString.split("/");
String effect = effectSplit[0];
if (effect.equalsIgnoreCase("WEAKNESS") ||
effect.equalsIgnoreCase("INCREASE_DAMAGE") ||
effect.equalsIgnoreCase("SLOW") ||
effect.equalsIgnoreCase("SPEED") ||
effect.equalsIgnoreCase("REGENERATION")) {
// hide these effects as they put crap into lore
effect = effect + "X";
}
if (effectSplit.length > 1) {
effects.put(effect, P.p.parseInt(effectSplit[1]));
BEffect effect = new BEffect(effectString);
if (effect.isValid()) {
effects.add(effect);
} else {
effects.put(effect, 20);
P.p.errorLog("Error adding Effect to Recipe: " + getName(5));
}
}
}
@ -148,11 +137,16 @@ public class BRecipe {
return true;
}
for (ItemStack ingredient : ingredients) {
boolean matches = false;
for (ItemStack used : list) {
if (!ingredientsMatch(used, ingredient)) {
return true;
if (ingredientsMatch(used, ingredient)) {
matches = true;
break;
}
}
if (!matches) {
return true;
}
}
return false;
}
@ -201,7 +195,7 @@ public class BRecipe {
potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
brew.convertLore(potionMeta, false);
Brew.addOrReplaceEffects(potionMeta, effects);
Brew.addOrReplaceEffects(potionMeta, effects, quality);
potion.setItemMeta(potionMeta);
return potion;
@ -282,7 +276,7 @@ public class BRecipe {
return alcohol;
}
public Map<String, Integer> getEffects() {
public ArrayList<BEffect> getEffects() {
return effects;
}

View File

@ -242,7 +242,7 @@ public class Brew {
}
// return special effect
public Map<String, Integer> getEffects() {
public ArrayList<BEffect> getEffects() {
if (currentRecipe != null && quality > 0) {
return currentRecipe.getEffects();
}
@ -303,11 +303,12 @@ public class Brew {
currentRecipe = recipe;
quality = calcQuality();
addOrReplaceEffects(potionMeta, getEffects());
addOrReplaceEffects(potionMeta, getEffects(), quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
} else {
quality = 0;
removeEffects(potionMeta);
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_DistillUndefined")));
slotItem.setDurability(PotionColor.GREY.getColorId(canDistill()));
}
@ -347,11 +348,12 @@ public class Brew {
currentRecipe = recipe;
quality = calcQuality();
addOrReplaceEffects(potionMeta, getEffects());
addOrReplaceEffects(potionMeta, getEffects(), quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
} else {
quality = 0;
removeEffects(potionMeta);
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_BadPotion")));
item.setDurability(PotionColor.GREY.getColorId(canDistill()));
}
@ -520,14 +522,23 @@ public class Brew {
}
// Adds the Effect names to the Items description
public static void addOrReplaceEffects(PotionMeta meta, Map<String, Integer> effects) {
public static void addOrReplaceEffects(PotionMeta meta, ArrayList<BEffect> effects, int quality) {
if (effects != null) {
for (Map.Entry<String, Integer> entry : effects.entrySet()) {
if (!entry.getKey().endsWith("X")) {
PotionEffectType type = PotionEffectType.getByName(entry.getKey());
if (type != null) {
meta.addCustomEffect(type.createEffect(0, 0), true);
}
for (BEffect effect : effects) {
if (!effect.isHidden()) {
effect.writeInto(meta, quality);
}
}
}
}
// Removes all effects except regeneration which stores data
public static void removeEffects(PotionMeta meta) {
if (meta.hasCustomEffects()) {
for (PotionEffect effect : meta.getCustomEffects()) {
PotionEffectType type = effect.getType();
if (!type.equals(PotionEffectType.REGENERATION)) {
meta.removeCustomEffect(type);
}
}
}

View File

@ -391,7 +391,7 @@ public class ConfigUpdater {
// Add the new Wood Types to the Description
int index = indexOfStart("# wood:");
if (index != -1) {
setLine(index, "# wood: Wood of the barrel 0=any 1=Birch 2=Oak 3=Jungle 4=Spruce 5=Acacia 6=Dark Oak");
setLine(index, "# wood: Holz des Fasses 0=alle Holzsorten 1=Birke 2=Eiche 3=Jungel 4=Fichte 5=Akazie 6=Schwarzeiche");
}
// Add the Example to the Cooked Section
@ -401,8 +401,9 @@ public class ConfigUpdater {
}
// Add new ingredients description
String replacedLine = "# ingredients: Auflistung von 'Material oder ID,Data/Anzahl' (Item-ids anstatt Material werden von Bukkit nicht mehr unterstützt und funktionieren möglicherweise in Zukunft nicht mehr!)";
String replacedLine = "# ingredients: Auflistung von 'Material oder ID,Data/Anzahl'";
String[] lines = new String[] {
"# (Item-ids anstatt Material werden von Bukkit nicht mehr unterstützt und funktionieren möglicherweise in Zukunft nicht mehr!)",
"# Eine Liste von allen Materialien kann hier gefunden werden: http://jd.bukkit.org/beta/apidocs/org/bukkit/Material.html",
"# Es kann ein Data-Wert angegeben werden, weglassen ignoriert diesen beim hinzufügen einer Zutat"
};
@ -424,6 +425,62 @@ public class ConfigUpdater {
}
}
// Split the Color explanation into two lines
replacedLine = "# color: Farbe des Getränks nach destillieren/reifen.";
lines = new String[] {
"# Benutzbare Farben: DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY"
};
index = indexOfStart("# color:");
if (index != -1) {
setLine(index, replacedLine);
addLines(index + 1, lines);
} else {
index = indexOfStart("# age:");
if (index != -1) {
addLines(index + 1, lines);
addLines(index + 1, replacedLine);
}
}
// Add all the new info to the effects description
replacedLine = "# effects: Auflistung Effekt/Level/Dauer Besonderere Trank-Effekte beim Trinken, Dauer in sek.";
lines = new String[] {
"# Ein 'X' an den Namen anhängen, um ihn zu verbergen. Bsp: 'POISONX/2/10' (WEAKNESS, INCREASE_DAMAGE, SLOW und SPEED sind immer verborgen.)",
"# Mögliche Effekte: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html",
"# Minimale und Maximale Level/Dauer können durch \"-\" festgelegt werden, Bsp: 'SPEED/1-2/30-40' = Level 1 und 30 sek minimal, Level 2 und 40 sek maximal",
"# Diese Bereiche funktionieren auch umgekehrt, Bsp: 'POISON/3-1/20-5' für abschwächende Effekte bei guter Qualität",
"# Längste mögliche Effektdauer: 1638 sek. Es muss keine Dauer für Effekte mit sofortiger Wirkung angegeben werden."
};
index = indexOfStart("# effects:");
if (index != -1) {
setLine(index, replacedLine);
addLines(index + 1, lines);
} else {
index = indexOfStart("# alcohol:");
if (index != -1) {
addLines(index + 1, lines);
addLines(index + 1, replacedLine);
} else {
index = indexOfStart("# -- Rezepte für Getränke --");
if (index != -1) {
addLines(index + 2, lines);
addLines(index + 2, "", replacedLine);
}
}
}
if (index != -1) {
index = indexOfStart("# (WEAKNESS, INCREASE_DAMAGE, SLOW und SPEED sind immer verborgen.) Mögliche Effekte:");
if (index != -1) {
config.remove(index);
}
}
index = indexOfStart("# Bei Effekten mit sofortiger Wirkung ");
if (index != -1) {
config.remove(index);
}
}
// Update en from 1.2 to 1.3
@ -433,7 +490,7 @@ public class ConfigUpdater {
// Add the new Wood Types to the Description
int index = indexOfStart("# wood:");
if (index != -1) {
setLine(index, "# wood: Holz des Fasses 0=alle Holzsorten 1=Birke 2=Eiche 3=Jungel 4=Fichte 5=Akazie 6=Schwarzeiche");
setLine(index, "# wood: Wood of the barrel 0=any 1=Birch 2=Oak 3=Jungle 4=Spruce 5=Acacia 6=Dark Oak");
}
// Add the Example to the Cooked Section
@ -443,8 +500,9 @@ public class ConfigUpdater {
}
// Add new ingredients description
String replacedLine = "# ingredients: List of 'material or id,data/amount' (Item-ids instead of material are deprecated by bukkit and may not work in the future!)";
String replacedLine = "# ingredients: List of 'material or id,data/amount'";
String[] lines = new String[] {
"# (Item-ids instead of material are deprecated by bukkit and may not work in the future!)",
"# A list of materials can be found here: http://jd.bukkit.org/beta/apidocs/org/bukkit/Material.html",
"# You can specify a data value, omitting it will ignore the data value of the added ingredient"
};
@ -466,6 +524,62 @@ public class ConfigUpdater {
}
}
// Split the Color explanation into two lines
replacedLine = "# color: Color of the potion after distilling/aging.";
lines = new String[] {
"# Usable Colors: DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY"
};
index = indexOfStart("# color:");
if (index != -1) {
setLine(index, replacedLine);
addLines(index + 1, lines);
} else {
index = indexOfStart("# age:");
if (index != -1) {
addLines(index + 1, lines);
addLines(index + 1, replacedLine);
}
}
// Add all the new info to the effects description
replacedLine = "# effects: List of effect/level/duration Special potion-effect when drinking, duration in sek.";
lines = new String[] {
"# Suffix name with 'X' to hide effect from label. Sample: 'POISONX/2/10' (WEAKNESS, INCREASE_DAMAGE, SLOW and SPEED are always hidden.)",
"# Possible Effects: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html",
"# Level or Duration ranges may be specified with a \"-\", ex. 'SPEED/1-2/30-40' = lvl 1 and 30 sec at worst and lvl 2 and 40 sec at best",
"# Ranges also work high-low, ex. 'POISON/3-1/20-5' for weaker effects at good quality.",
"# Highest possible Duration: 1638 sec. Instant Effects dont need any duration specified."
};
index = indexOfStart("# effects:");
if (index != -1) {
setLine(index, replacedLine);
addLines(index + 1, lines);
} else {
index = indexOfStart("# alcohol:");
if (index != -1) {
addLines(index + 1, lines);
addLines(index + 1, replacedLine);
} else {
index = indexOfStart("# -- Recipes for Potions --");
if (index != -1) {
addLines(index + 2, lines);
addLines(index + 2, "", replacedLine);
}
}
}
if (index != -1) {
index = indexOfStart("# (WEAKNESS, INCREASE_DAMAGE, SLOW and SPEED are always hidden.) Possible Effects:");
if (index != -1) {
config.remove(index);
}
}
index = indexOfStart("# instant effects ");
if (index != -1) {
config.remove(index);
}
}
}