From e2e6448cf600e4a867e602e04382989141e2dac9 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 14 Aug 2013 20:08:55 +0200 Subject: [PATCH] Multiple Effects per Potion --- config.yml | 19 +++++++++----- src/com/dre/brewery/BCauldron.java | 3 ++- src/com/dre/brewery/BIngredients.java | 8 +++--- src/com/dre/brewery/BPlayer.java | 17 +++++++----- src/com/dre/brewery/BRecipe.java | 27 +++++++++---------- src/com/dre/brewery/Brew.java | 15 +++++------ src/com/dre/brewery/P.java | 38 ++++++++++++++++++++++++++- 7 files changed, 85 insertions(+), 42 deletions(-) diff --git a/config.yml b/config.yml index 025c18b..b65b9a8 100644 --- a/config.yml +++ b/config.yml @@ -49,7 +49,7 @@ autosave: 3 # color: Farbe des Getränks nach destillieren/reifen. DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY # difficulty: 1-10 Genauigkeit der Einhaltung der Vorgaben (1 = ungenau/einfach 10 = sehr genau/schwer) # alcohol: Alkoholgehalt 0-100 in absoluter Menge bei perfektem Getränk (wird dem Spieler hinzugefügt, bei 100 = tot) -# effect: Effekt/Dauer Besonderer Trank-Effekt beim Trinken, Dauer in sek. Siehe: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html +# effect: Auflistung Effekt/Dauer Besonderere Trank-Effekte beim Trinken, Dauer in sek. Siehe: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html recipes: 1: @@ -108,7 +108,8 @@ recipes: COLOR: ORANGE difficulty: 4 alcohol: 12 - effect: WATER_BREATHING/150 + effects: + - WATER_BREATHING/150 6: name: Bitterer Rum/Würziger Rum/Goldener Rum ingredients: @@ -120,7 +121,10 @@ recipes: color: DARK_RED difficulty: 6 alcohol: 30 - effect: FIRE_RESISTANCE/100 + effects: + - FIRE_RESISTANCE/100 + - WEAKNESS/30 + - POISON/20 7: name: Abgeranzter Vodka/Vodka/Russischer Vodka ingredients: @@ -131,7 +135,8 @@ recipes: color: BRIGHT_GREY difficulty: 4 alcohol: 20 - effect: WEAKNESS/15 + effects: + - WEAKNESS/15 8: name: minderwertiger Absinth/Absinth/Starker Absinth ingredients: @@ -141,7 +146,8 @@ recipes: color: GREEN difficulty: 8 alcohol: 45 - effect: POISON/10 + effects: + - POISON/10 9: name: Kartoffelsuppe ingredients: @@ -150,7 +156,8 @@ recipes: cookingtime: 3 color: PINK difficulty: 1 - effect: HEAL + effects: + - HEAL diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index 317ed41..03c3b4c 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -125,7 +125,8 @@ public class BCauldron { } } - //unloads cauldrons that are in a unloading world + // unloads cauldrons that are in a unloading world + // as they were written to file just before, this is safe to do public static void onUnload(String name) { for (BCauldron bcauldron : bcauldrons) { if (bcauldron.block.getWorld().getName().equals(name)) { diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index 9e5c4bb..b46a774 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -130,12 +130,12 @@ public class BIngredients { cookingQuality = getCookingQuality(recipe, distilled); if (ingredientQuality > -1) { - P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) + " age Quality: " - + getAgeQuality(recipe, time) + " for " + recipe.getName(5)); if (recipe.needsToAge()) { // needs riping in barrel ageQuality = getAgeQuality(recipe, time); woodQuality = getWoodQuality(recipe, wood); + P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) + + " age Quality: " + getAgeQuality(recipe, time) + " for " + recipe.getName(5)); // is this recipe better than the previous best? if ((((float) ingredientQuality + cookingQuality + woodQuality + ageQuality) / 4) > quality) { @@ -143,6 +143,7 @@ public class BIngredients { bestRecipe = recipe; } } else { + P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " for " + recipe.getName(5)); // calculate quality without age and barrel if ((((float) ingredientQuality + cookingQuality) / 2) > quality) { quality = ((float) ingredientQuality + cookingQuality) / 2; @@ -230,9 +231,6 @@ public class BIngredients { // calculate the quality quality -= (((float) Math.abs(count - recipe.amountOf(ingredient)) / recipe.allowedCountDiff(recipe.amountOf(ingredient))) * 10.0); } - /* - * if(quality != 0){ quality /= ingredients.size(); } - */ if (quality >= 0) { return Math.round(quality); } diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index b22ae85..5b7b62f 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -353,12 +353,17 @@ public class BPlayer { } public static void addBrewEffects(Brew brew, Player player) { - if (brew.getEffect() != null) { - int duration = (brew.getEffectDur() / 8) * brew.getQuality() * 20; - int amplifier = brew.getQuality() / 3; + Map effects = brew.getEffects(); + if (effects != null) { + for (Map.Entry entry : effects.entrySet()) { + PotionEffectType type = PotionEffectType.getByName(entry.getKey()); + if (type != null) { + int duration = (entry.getValue() / 8) * brew.getQuality() * 20; + int amplifier = brew.getQuality() / 3; - PotionEffectType type = PotionEffectType.getByName(brew.getEffect()); - type.createEffect(duration, amplifier).apply(player); + type.createEffect(duration, amplifier).apply(player); + } + } } } @@ -404,7 +409,7 @@ public class BPlayer { } } } else if (bplayer.drunkeness <= (-1) * bplayer.offlineDrunk) { - players.remove(name); + iter.remove(); } } } diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index d115272..a7a4378 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -18,8 +18,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 String effect;// Special Effect - private int effectDur;// Duration of the special effect + private Map effects = new HashMap(); // Special Effect, Duration public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) { String[] name = configSectionRecipes.getString(recipeId + ".name").split("/"); @@ -43,12 +42,16 @@ public class BRecipe { this.difficulty = configSectionRecipes.getInt(recipeId + ".difficulty"); this.alcohol = configSectionRecipes.getInt(recipeId + ".alcohol"); - String effectString = configSectionRecipes.getString(recipeId + ".effect"); - if (effectString != null) { - String[] effectSplit = effectString.split("/"); - this.effect = effectSplit[0]; - if (effectSplit.length > 1) { - this.effectDur = P.p.parseInt(effectSplit[1]); + List effectStringList = configSectionRecipes.getStringList(recipeId + ".effects"); + if (effectStringList != null) { + for (String effectString : effectStringList) { + String[] effectSplit = effectString.split("/"); + P.p.log("effekt: " + effectSplit[0]); + if (effectSplit.length > 1) { + effects.put(effectSplit[0], P.p.parseInt(effectSplit[1])); + } else { + effects.put(effectSplit[0], 20); + } } } } @@ -189,12 +192,8 @@ public class BRecipe { return alcohol; } - public String getEffect() { - return effect; - } - - public int getEffectDur() { - return effectDur; + public Map getEffects() { + return effects; } } \ No newline at end of file diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 3eba269..39e8a4a 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -153,20 +153,13 @@ public class Brew { } // return special effect - public String getEffect() { + public Map getEffects() { if (currentRecipe != null) { - return currentRecipe.getEffect(); + return currentRecipe.getEffects(); } return null; } - public int getEffectDur() { - if (currentRecipe != null) { - return currentRecipe.getEffectDur(); - } - return 0; - } - // Distilling section --------------- // distill all custom potions in the brewer @@ -269,6 +262,10 @@ public class Brew { } } + public PotionMeta addQualityLore(PotionMeta meta, String prefix, String lore) { + return null; + } + // Saves all data public static void save(ConfigurationSection config) { for (int uid : potions.keySet()) { diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index bbad5de..c023ebe 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -319,6 +319,7 @@ public class P extends JavaPlugin { // save all Data public void saveData() { + long time = System.nanoTime(); File datafile = new File(p.getDataFolder(), "data.yml"); FileConfiguration oldData = YamlConfiguration.loadConfiguration(datafile); @@ -334,25 +335,56 @@ public class P extends JavaPlugin { FileConfiguration configFile = new YamlConfiguration(); + time = System.nanoTime() - time; + float ftime = (float) (time / 1000000.0); + p.log("Creating a savefile (" + ftime + "ms)"); + time = System.nanoTime(); + if (!Brew.potions.isEmpty()) { Brew.save(configFile.createSection("Brew")); } + + time = System.nanoTime() - time; + ftime = (float) (time / 1000000.0); + p.log("Saving Brew (" + ftime + "ms)"); + time = System.nanoTime(); + if (!BCauldron.bcauldrons.isEmpty() || oldData.contains("BCauldron")) { BCauldron.save(configFile.createSection("BCauldron"), oldData.getConfigurationSection("BCauldron")); } + time = System.nanoTime() - time; + ftime = (float) (time / 1000000.0); + p.log("Saving BCauldrons (" + ftime + "ms)"); + time = System.nanoTime(); + if (!Barrel.barrels.isEmpty() || oldData.contains("Barrel")) { Barrel.save(configFile.createSection("Barrel"), oldData.getConfigurationSection("Barrel")); } + time = System.nanoTime() - time; + ftime = (float) (time / 1000000.0); + p.log("Saving Barrels (" + ftime + "ms)"); + time = System.nanoTime(); + if (!BPlayer.players.isEmpty()) { BPlayer.save(configFile.createSection("Player")); } + time = System.nanoTime() - time; + ftime = (float) (time / 1000000.0); + p.log("Saving players (" + ftime + "ms)"); + time = System.nanoTime(); + if (!Wakeup.wakeups.isEmpty() || oldData.contains("Wakeup")) { Wakeup.save(configFile.createSection("Wakeup"), oldData.getConfigurationSection("Wakeup")); } + time = System.nanoTime() - time; + ftime = (float) (time / 1000000.0); + p.log("Saving Wakeups (" + ftime + "ms)"); + time = System.nanoTime(); + try { configFile.save(datafile); } catch (IOException e) { @@ -360,6 +392,10 @@ public class P extends JavaPlugin { } lastSave = 1; + + time = System.nanoTime() - time; + ftime = (float) (time / 1000000.0); + p.log("Writing Data to File (" + ftime + "ms)"); } @@ -420,7 +456,7 @@ public class P extends JavaPlugin { } public String white() { - return ChatColor.WHITE + ""; + return ChatColor.WHITE.toString(); }