mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-05 09:00:18 +01:00
Added basic drunkenness
This commit is contained in:
parent
a7db7ff833
commit
2894985e71
@ -9,7 +9,6 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
|
||||||
import com.dre.brewery.P;
|
|
||||||
import com.dre.brewery.BRecipe;
|
import com.dre.brewery.BRecipe;
|
||||||
import com.dre.brewery.Brew;
|
import com.dre.brewery.Brew;
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ public class BIngredients {
|
|||||||
//Potion is best with cooking only, can still be destilled, etc.
|
//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)) / 2.0);
|
||||||
P.p.log("cooked potion has Quality: "+quality);
|
P.p.log("cooked potion has Quality: "+quality);
|
||||||
new Brew(uid,quality,new BIngredients(ingredients,cookedTime));
|
new Brew(uid,quality,cookRecipe.getAlcohol(),new BIngredients(ingredients,cookedTime));
|
||||||
|
|
||||||
cookedName = cookRecipe.getName(quality);
|
cookedName = cookRecipe.getName(quality);
|
||||||
potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));
|
potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));
|
||||||
|
109
src/com/dre/brewery/BPlayer.java
Normal file
109
src/com/dre/brewery/BPlayer.java
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package com.dre.brewery;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import com.dre.brewery.Brew;
|
||||||
|
|
||||||
|
public class BPlayer {
|
||||||
|
public static Map<Player,BPlayer> players=new HashMap<Player,BPlayer>();
|
||||||
|
|
||||||
|
private int quality = 0;// = quality of drunkeness * drunkeness
|
||||||
|
private int drunkeness = 0;// = amount of drunkeness
|
||||||
|
private Vector push = new Vector(0,0,0);
|
||||||
|
private int time = 20;
|
||||||
|
|
||||||
|
public BPlayer(){
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static BPlayer get(Player player){
|
||||||
|
if(!players.isEmpty()){
|
||||||
|
if(players.containsKey(player)){
|
||||||
|
return players.get(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public void remove(BPlayer player){
|
||||||
|
players.remove(player);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//returns true if drinking was successful
|
||||||
|
public static boolean drink(PotionMeta meta,Player player){
|
||||||
|
Brew brew = Brew.get(meta);
|
||||||
|
if(brew != null){
|
||||||
|
BPlayer bPlayer = get(player);
|
||||||
|
if(bPlayer == null){
|
||||||
|
bPlayer = new BPlayer();
|
||||||
|
players.put(player,bPlayer);
|
||||||
|
}
|
||||||
|
bPlayer.drunkeness += brew.getAlcohol();
|
||||||
|
bPlayer.quality += brew.getQuality() * brew.getAlcohol();
|
||||||
|
P.p.msg(player,"Du bist nun "+bPlayer.drunkeness+"% betrunken, mit einer Qualität von "+bPlayer.getQuality());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//push the player around if he moves
|
||||||
|
public static void playerMove(PlayerMoveEvent event){
|
||||||
|
BPlayer bPlayer = get(event.getPlayer());
|
||||||
|
if(bPlayer != null){
|
||||||
|
bPlayer.move(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//player is drunk
|
||||||
|
public void move(PlayerMoveEvent event){
|
||||||
|
//has player more alc than 10
|
||||||
|
if(drunkeness >= 10){
|
||||||
|
if(drunkeness <= 100){
|
||||||
|
if(time > 1){
|
||||||
|
time--;
|
||||||
|
} else {
|
||||||
|
//Is he moving
|
||||||
|
if(event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ()){
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Entity entity = (Entity) player;
|
||||||
|
//not in midair
|
||||||
|
if(entity.isOnGround()){
|
||||||
|
time--;
|
||||||
|
if(time == 0){
|
||||||
|
//push him only to the side? or any direction like now
|
||||||
|
push.setX(Math.random() - 0.5);
|
||||||
|
push.setZ(Math.random() - 0.5);
|
||||||
|
player.setVelocity(push);
|
||||||
|
} else if (time < 0 && time > -10){
|
||||||
|
//push him some more in the same direction
|
||||||
|
player.setVelocity(push);
|
||||||
|
} else {
|
||||||
|
//when more alc, push him more often
|
||||||
|
time = (int)(Math.random() * (201.0 - (drunkeness * 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//getter
|
||||||
|
public int getDrunkeness(){
|
||||||
|
return drunkeness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getQuality(){
|
||||||
|
return Math.round(quality / drunkeness);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -90,6 +90,13 @@ public class BRecipe {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean needsDistilling(){
|
||||||
|
if(distillruns == 0){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean needsToAge(){
|
public boolean needsToAge(){
|
||||||
if(age == 0){
|
if(age == 0){
|
||||||
return false;
|
return false;
|
||||||
@ -171,5 +178,9 @@ public class BRecipe {
|
|||||||
return difficulty;
|
return difficulty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAlcohol(){
|
||||||
|
return alcohol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -12,8 +12,6 @@ import org.bukkit.inventory.BrewerInventory;
|
|||||||
|
|
||||||
import com.dre.brewery.BIngredients;
|
import com.dre.brewery.BIngredients;
|
||||||
|
|
||||||
import com.dre.brewery.P;
|
|
||||||
|
|
||||||
public class Brew {
|
public class Brew {
|
||||||
|
|
||||||
public static Map<Integer,Brew> potions=new HashMap<Integer,Brew>();
|
public static Map<Integer,Brew> potions=new HashMap<Integer,Brew>();
|
||||||
@ -24,6 +22,7 @@ public class Brew {
|
|||||||
private int quality;
|
private int quality;
|
||||||
private int distillRuns;
|
private int distillRuns;
|
||||||
private float ageTime;
|
private float ageTime;
|
||||||
|
private int alcohol;
|
||||||
|
|
||||||
public Brew(int uid,BIngredients ingredients){
|
public Brew(int uid,BIngredients ingredients){
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
@ -31,9 +30,10 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//quality already set
|
//quality already set
|
||||||
public Brew(int uid,int quality,BIngredients ingredients){
|
public Brew(int uid,int quality,int alcohol,BIngredients ingredients){
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
|
this.alcohol = calcAlcohol(alcohol);
|
||||||
potions.put(uid,this);
|
potions.put(uid,this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +91,39 @@ public class Brew {
|
|||||||
return null;
|
return null;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
//calculate alcohol from recipe
|
||||||
|
public int calcAlcohol(int alc){
|
||||||
|
if(distillRuns == 0){
|
||||||
|
distillRuns = 1;
|
||||||
|
}
|
||||||
|
alc /= distillRuns;
|
||||||
|
alc *= distillRuns * ((float)quality / 10.0);
|
||||||
|
return alc;
|
||||||
|
}
|
||||||
|
|
||||||
|
//calculating quality
|
||||||
|
public int calcQuality(BRecipe recipe,byte wood){
|
||||||
|
//calculate quality from all of the factors
|
||||||
|
float quality =(
|
||||||
|
|
||||||
|
ingredients.getIngredientQuality(recipe) +
|
||||||
|
ingredients.getCookingQuality(recipe) +
|
||||||
|
ingredients.getWoodQuality(recipe,wood) +
|
||||||
|
ingredients.getAgeQuality(recipe,ageTime));
|
||||||
|
|
||||||
|
quality /= 4;
|
||||||
|
return (int)Math.round(quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getQuality(){
|
||||||
|
return quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
//return prev calculated alcohol
|
||||||
|
public int getAlcohol(){
|
||||||
|
return alcohol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -116,15 +149,7 @@ public class Brew {
|
|||||||
BRecipe recipe = brew.ingredients.getdistillRecipe();
|
BRecipe recipe = brew.ingredients.getdistillRecipe();
|
||||||
|
|
||||||
if(recipe != null){
|
if(recipe != null){
|
||||||
//calculate quality of ingredients and cookingtime
|
brew.quality = brew.calcQuality(recipe,(byte)0);
|
||||||
float quality = brew.ingredients.getIngredientQuality(recipe) + brew.ingredients.getCookingQuality(recipe);
|
|
||||||
quality /= 2;
|
|
||||||
|
|
||||||
/*if(recipe.getDistillRuns() > 1){
|
|
||||||
quality -= Math.abs(recipe.getDistillRuns() - (brew.distillRuns + 1)) * 2;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
brew.quality = (int)Math.round(quality);
|
|
||||||
P.p.log("destilled "+recipe.getName(5)+" has Quality: "+brew.quality);
|
P.p.log("destilled "+recipe.getName(5)+" has Quality: "+brew.quality);
|
||||||
brew.distillRuns += 1;
|
brew.distillRuns += 1;
|
||||||
//distillRuns will have an effect on the amount of alcohol, not the quality
|
//distillRuns will have an effect on the amount of alcohol, not the quality
|
||||||
@ -133,6 +158,7 @@ public class Brew {
|
|||||||
lore.add(brew.distillRuns+" fach Destilliert");
|
lore.add(brew.distillRuns+" fach Destilliert");
|
||||||
potionMeta.setLore(lore);
|
potionMeta.setLore(lore);
|
||||||
}
|
}
|
||||||
|
brew.alcohol = brew.calcAlcohol(recipe.getAlcohol());
|
||||||
|
|
||||||
potionMeta.setDisplayName(recipe.getName(brew.quality));
|
potionMeta.setDisplayName(recipe.getName(brew.quality));
|
||||||
|
|
||||||
@ -165,22 +191,16 @@ public class Brew {
|
|||||||
if(brew.ageTime > 0.5){
|
if(brew.ageTime > 0.5){
|
||||||
BRecipe recipe = brew.ingredients.getAgeRecipe(wood,brew.ageTime);
|
BRecipe recipe = brew.ingredients.getAgeRecipe(wood,brew.ageTime);
|
||||||
if(recipe != null){
|
if(recipe != null){
|
||||||
|
if(!recipe.needsDistilling() || brew.distillRuns > 0){
|
||||||
|
|
||||||
//calculate quality from all of the factors
|
brew.quality = brew.calcQuality(recipe,wood);
|
||||||
float quality =(
|
brew.alcohol = brew.calcAlcohol(recipe.getAlcohol());
|
||||||
|
P.p.log("Final "+recipe.getName(5)+" has Quality: "+brew.quality);
|
||||||
|
|
||||||
brew.ingredients.getIngredientQuality(recipe) +
|
potionMeta.setDisplayName(recipe.getName(brew.quality));
|
||||||
brew.ingredients.getCookingQuality(recipe) +
|
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
|
||||||
brew.ingredients.getWoodQuality(recipe,wood) +
|
item.setItemMeta(potionMeta);
|
||||||
brew.ingredients.getAgeQuality(recipe,brew.ageTime));
|
}
|
||||||
|
|
||||||
quality /= 4;
|
|
||||||
brew.quality = (int)Math.round(quality);
|
|
||||||
P.p.log("Final "+recipe.getName(5)+" has Quality: "+brew.quality);
|
|
||||||
|
|
||||||
potionMeta.setDisplayName(recipe.getName(brew.quality));
|
|
||||||
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false));
|
|
||||||
item.setItemMeta(potionMeta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.dre.brewery.listeners;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.inventory.BrewEvent;
|
import org.bukkit.event.inventory.BrewEvent;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -22,8 +23,7 @@ import com.dre.brewery.BCauldron;
|
|||||||
import com.dre.brewery.BIngredients;
|
import com.dre.brewery.BIngredients;
|
||||||
import com.dre.brewery.Brew;
|
import com.dre.brewery.Brew;
|
||||||
import com.dre.brewery.Barrel;
|
import com.dre.brewery.Barrel;
|
||||||
|
import com.dre.brewery.BPlayer;
|
||||||
import com.dre.brewery.P;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener{
|
public class PlayerListener implements Listener{
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
@ -130,23 +130,29 @@ public class PlayerListener implements Listener{
|
|||||||
//player drinks a custom potion
|
//player drinks a custom potion
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPlayerItemConsume(PlayerItemConsumeEvent event){
|
public void onPlayerItemConsume(PlayerItemConsumeEvent event){
|
||||||
if(event.getItem() != null){
|
ItemStack item = event.getItem();
|
||||||
if(event.getItem().getType() == Material.POTION){
|
if(item != null){
|
||||||
if(event.getItem().hasItemMeta()){
|
if(item.getType() == Material.POTION){
|
||||||
PotionMeta potionMeta = ((PotionMeta) event.getItem().getItemMeta());
|
if(item.hasItemMeta()){
|
||||||
|
PotionMeta potionMeta = ((PotionMeta) item.getItemMeta());
|
||||||
if(potionMeta.hasCustomEffect(PotionEffectType.REGENERATION)){
|
if(potionMeta.hasCustomEffect(PotionEffectType.REGENERATION)){
|
||||||
for(PotionEffect effect:potionMeta.getCustomEffects()){
|
for(PotionEffect effect:potionMeta.getCustomEffects()){
|
||||||
if(effect.getType().getId() == 10){
|
if(effect.getType().getId() == 10){
|
||||||
//tell him the ID for testing
|
if(BPlayer.drink(potionMeta,event.getPlayer())){
|
||||||
P.p.msg(event.getPlayer(),"ID: "+effect.getDuration());
|
Brew.remove(item);
|
||||||
|
item.setType(Material.POTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//player walks while drunk, push him around!
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onPlayerMove(PlayerMoveEvent event){
|
||||||
|
BPlayer.playerMove(event);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user