Fixed Distilling

This commit is contained in:
Sn0wStorm 2013-07-03 18:06:13 +02:00
parent 6e2df99c14
commit c99da614c7
5 changed files with 61 additions and 27 deletions

View File

@ -57,7 +57,7 @@ public class BIngredients {
if (cookRecipe != null) {
// Potion is best with cooking only, can still be destilled, etc.
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe)) / 2.0);
int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
P.p.log("cooked potion has Quality: " + quality);
new Brew(uid, quality, cookRecipe, new BIngredients(ingredients, cookedTime));
@ -118,7 +118,7 @@ public class BIngredients {
// best recipe for current state of potion, STILL not always returns the
// correct one...
public BRecipe getBestRecipe(byte wood, float time) {
public BRecipe getBestRecipe(byte wood, float time, boolean distilled) {
float quality = 0;
int ingredientQuality = 0;
int cookingQuality = 0;
@ -127,7 +127,7 @@ public class BIngredients {
BRecipe bestRecipe = null;
for (BRecipe recipe : recipes) {
ingredientQuality = getIngredientQuality(recipe);
cookingQuality = getCookingQuality(recipe);
cookingQuality = getCookingQuality(recipe, distilled);
if (ingredientQuality > -1) {
P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) + " age Quality: "
@ -160,7 +160,7 @@ public class BIngredients {
// returns recipe that is cooking only and matches the ingredients and
// cooking time
public BRecipe getCookRecipe() {
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, false);
// Check if best recipe is cooking only
if (bestRecipe != null) {
@ -174,7 +174,7 @@ public class BIngredients {
// returns the currently best matching recipe for distilling for the
// ingredients and cooking time
public BRecipe getdistillRecipe() {
BRecipe bestRecipe = getBestRecipe((byte) 0, 0);
BRecipe bestRecipe = getBestRecipe((byte) 0, 0, true);
// Check if best recipe needs to be destilled
if (bestRecipe != null) {
@ -187,8 +187,8 @@ public class BIngredients {
// returns currently best matching recipe for ingredients, cooking- and
// ageingtime
public BRecipe getAgeRecipe(byte wood, float time) {
BRecipe bestRecipe = getBestRecipe(wood, time);
public BRecipe getAgeRecipe(byte wood, float time, boolean distilled) {
BRecipe bestRecipe = getBestRecipe(wood, time, distilled);
if (bestRecipe != null) {
if (bestRecipe.needsToAge()) {
@ -240,7 +240,10 @@ public class BIngredients {
}
// returns the quality regarding the cooking-time conditioning given Recipe
public int getCookingQuality(BRecipe recipe) {
public int getCookingQuality(BRecipe recipe, boolean distilled) {
if (!recipe.needsDistilling() == distilled) {
return 0;
}
int quality = 10 - (int) Math.round(((float) Math.abs(cookedTime - recipe.getCookingTime()) / recipe.allowedTimeDiff(recipe.getCookingTime())) * 10.0);
if (quality > 0) {

View File

@ -79,6 +79,7 @@ public class Barrel {
if (inventory.getViewers().isEmpty()) {
// if inventory contains potions
if (inventory.contains(373)) {
long loadTime = System.nanoTime();
for (ItemStack item : inventory.getContents()) {
if (item != null) {
if (item.getTypeId() == 373) {
@ -88,6 +89,9 @@ public class Barrel {
}
}
}
loadTime = System.nanoTime() - loadTime;
float ftime = (float) (loadTime / 1000000.0);
P.p.log("opening Barrel with potions (" + ftime + "ms)");
}
}
}

View File

@ -112,8 +112,11 @@ public class Brew {
if (currentRecipe != null) {
int alc = currentRecipe.getAlcohol();
alc *= ((float) quality / 10.0);
if (distillRuns > 1) {
alc *= (float) distillRuns / 2.0;
if (currentRecipe.needsDistilling()) {
// distillable Potions should have full alc after 6 distills
float factor = 1.4F / (distillRuns + 1);
factor += 0.8;
alc /= factor;
}
return alc;
}
@ -121,12 +124,12 @@ public class Brew {
}
// calculating quality
public int calcQuality(BRecipe recipe, byte wood) {
public int calcQuality(BRecipe recipe, byte wood, boolean distilled) {
// calculate quality from all of the factors
float quality = (
ingredients.getIngredientQuality(recipe) +
ingredients.getCookingQuality(recipe) +
ingredients.getCookingQuality(recipe, distilled) +
ingredients.getWoodQuality(recipe, wood) +
ingredients.getAgeQuality(recipe, ageTime));
@ -138,6 +141,17 @@ public class Brew {
return quality;
}
public boolean canDistill() {
if (distillRuns >= 6) {
return false;
} else {
if (currentRecipe != null) {
return currentRecipe.needsDistilling();
}
}
return true;
}
// return special effect
public String getEffect() {
if (currentRecipe != null) {
@ -156,10 +170,10 @@ public class Brew {
// Distilling section ---------------
// distill all custom potions in the brewer
public static void distillAll(BrewerInventory inv, Integer[] contents) {
public static void distillAll(BrewerInventory inv, Boolean[] contents) {
int slot = 0;
while (slot < 3) {
if (contents[slot] == 1) {
if (contents[slot]) {
distillSlot(inv, slot);
}
slot++;
@ -174,8 +188,7 @@ public class Brew {
BRecipe recipe = brew.ingredients.getdistillRecipe();
if (recipe != null) {
brew.quality = brew.calcQuality(recipe, (byte) 0);
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality);
brew.quality = brew.calcQuality(recipe, (byte) 0, true);
brew.distillRuns += 1;
// distillRuns will have an effect on the amount of alcohol, not the quality
if (brew.distillRuns > 1) {
@ -184,6 +197,7 @@ public class Brew {
potionMeta.setLore(lore);
}
brew.currentRecipe = recipe;
P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality + ", alc: " + brew.calcAlcohol());
potionMeta.setDisplayName(recipe.getName(brew.quality));
@ -195,7 +209,7 @@ public class Brew {
}
} else {
potionMeta.setDisplayName("Undefinierbares Destillat");
slotItem.setDurability(PotionColor.GREY.getColorId(true));
slotItem.setDurability(PotionColor.GREY.getColorId(brew.distillRuns <= 5));
}
slotItem.setItemMeta(potionMeta);
@ -210,11 +224,11 @@ public class Brew {
brew.ageTime += time;
// if younger than half a day, it shouldnt get aged form
if (brew.ageTime > 0.5) {
BRecipe recipe = brew.ingredients.getAgeRecipe(wood, brew.ageTime);
BRecipe recipe = brew.ingredients.getAgeRecipe(wood, brew.ageTime, brew.distillRuns > 0);
if (recipe != null) {
if (!recipe.needsDistilling() || brew.distillRuns > 0) {
//if (!recipe.needsDistilling() || brew.distillRuns > 0) {
brew.quality = brew.calcQuality(recipe, wood);
brew.quality = brew.calcQuality(recipe, wood, brew.distillRuns > 0);
brew.currentRecipe = recipe;
P.p.log("Final " + recipe.getName(5) + " has Quality: " + brew.quality);
@ -249,7 +263,7 @@ public class Brew {
potionMeta.setDisplayName(recipe.getName(brew.quality));
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
item.setItemMeta(potionMeta);
}
//}
}
}
}

View File

@ -335,7 +335,8 @@ public class P extends JavaPlugin {
@Override
public void run() {
p.log("Update");
long time = System.nanoTime();
for (BCauldron cauldron : BCauldron.bcauldrons) {
cauldron.onUpdate();// runs every min to update cooking time
}
@ -344,8 +345,16 @@ public class P extends JavaPlugin {
if (lastSave >= autosave) {
saveData();// save all data
time = System.nanoTime() - time;
float ftime = (float) (time / 1000000.0);
p.log("Update and saving (" + ftime + "ms)");
} else {
lastSave++;
time = System.nanoTime() - time;
float ftime = (float) (time / 1000000.0);
p.log("Update (" + ftime + "ms)");
}
}

View File

@ -18,21 +18,25 @@ public class InventoryListener implements Listener {
BrewerInventory inv = event.getContents();
ItemStack item;
boolean custom = false;
Integer[] contents = new Integer[3];
Boolean[] contents = new Boolean[3];
while (slot < 3) {
item = inv.getItem(slot);
contents[slot] = 0;
contents[slot] = false;
if (item != null) {
if (item.getType() == Material.POTION) {
if (item.hasItemMeta()) {
if (Brew.potions.containsKey(Brew.getUID(item))) {
int uid = Brew.getUID(item);
if (Brew.potions.containsKey(uid)) {
// has custom potion in "slot"
contents[slot] = 1;
if (Brew.get(uid).canDistill()) {
// is further distillable
contents[slot] = true;
custom = true;
}
}
}
}
}
slot++;
}
if (custom) {