2018-07-06 13:30:00 +00:00
|
|
|
package com.eu.habbo.habbohotel.crafting;
|
|
|
|
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import gnu.trove.map.hash.THashMap;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public class CraftingAltar {
|
2018-07-06 13:30:00 +00:00
|
|
|
private final Item baseItem;
|
|
|
|
private final THashSet<Item> ingredients;
|
|
|
|
private final THashMap<Integer, CraftingRecipe> recipes;
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public CraftingAltar(Item baseItem) {
|
|
|
|
this.baseItem = baseItem;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
this.ingredients = new THashSet<>(1);
|
2019-05-26 21:14:53 +03:00
|
|
|
this.recipes = new THashMap<>(1);
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public void addIngredient(Item item) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.ingredients.add(item);
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public boolean hasIngredient(Item item) {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.ingredients.contains(item);
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public Map<CraftingRecipe, Boolean> matchRecipes(Map<Item, Integer> amountMap) {
|
2019-03-18 01:22:00 +00:00
|
|
|
THashMap<CraftingRecipe, Boolean> foundRecepies = new THashMap<>(Math.max(1, this.recipes.size() / 3));
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
for (Map.Entry<Integer, CraftingRecipe> set : this.recipes.entrySet()) {
|
2018-07-06 13:30:00 +00:00
|
|
|
boolean contains = true;
|
2019-03-18 01:22:00 +00:00
|
|
|
boolean equals;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (set.getValue().isLimited() && !set.getValue().canBeCrafted()) {
|
2018-07-06 13:30:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
equals = amountMap.size() == set.getValue().getIngredients().size();
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
for (Map.Entry<Item, Integer> entry : amountMap.entrySet()) {
|
|
|
|
if (contains) {
|
|
|
|
if (set.getValue().getIngredients().containsKey(entry.getKey())) {
|
|
|
|
if (set.getValue().getIngredients().get(entry.getKey()).equals(entry.getValue())) {
|
2018-07-06 13:30:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
equals = false;
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (set.getValue().getIngredients().get(entry.getKey()) > entry.getValue()) {
|
2018-07-06 13:30:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contains = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (contains) {
|
2018-07-06 13:30:00 +00:00
|
|
|
foundRecepies.put(set.getValue(), equals);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundRecepies;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public void addRecipe(CraftingRecipe recipe) {
|
2018-07-06 13:30:00 +00:00
|
|
|
this.recipes.put(recipe.getId(), recipe);
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public CraftingRecipe getRecipe(int id) {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.recipes.get(id);
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public CraftingRecipe getRecipe(String name) {
|
|
|
|
for (Map.Entry<Integer, CraftingRecipe> set : this.recipes.entrySet()) {
|
|
|
|
if (set.getValue().getName().equals(name)) {
|
2018-07-06 13:30:00 +00:00
|
|
|
return set.getValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public CraftingRecipe getRecipe(Map<Item, Integer> items) {
|
|
|
|
for (Map.Entry<Integer, CraftingRecipe> set : this.recipes.entrySet()) {
|
2018-07-06 13:30:00 +00:00
|
|
|
CraftingRecipe recipe = set.getValue();
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
for (Map.Entry<Item, Integer> entry : recipe.getIngredients().entrySet()) {
|
|
|
|
if (!(items.containsKey(entry.getKey()) && items.get(entry.getKey()).equals(entry.getValue()))) {
|
2018-07-06 13:30:00 +00:00
|
|
|
recipe = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (recipe != null) {
|
2018-07-06 13:30:00 +00:00
|
|
|
return recipe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public List<CraftingRecipe> getRecipesForHabbo(Habbo habbo) {
|
2018-09-28 19:25:00 +00:00
|
|
|
List<CraftingRecipe> recipeList = new ArrayList<>();
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
for (Map.Entry<Integer, CraftingRecipe> set : this.recipes.entrySet()) {
|
|
|
|
if (!set.getValue().isSecret() || habbo.getHabboStats().hasRecipe(set.getValue().getId())) {
|
2018-07-06 13:30:00 +00:00
|
|
|
recipeList.add(set.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return recipeList;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public Item getBaseItem() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.baseItem;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public Collection<Item> getIngredients() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.ingredients;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public Collection<CraftingRecipe> getRecipes() {
|
2018-07-06 13:30:00 +00:00
|
|
|
return this.recipes.values();
|
|
|
|
}
|
|
|
|
}
|