2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.crafting;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import gnu.trove.map.hash.THashMap;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class CraftingRecipe {
|
2018-07-06 15:30:00 +02:00
|
|
|
private final int id;
|
|
|
|
private final String name;
|
|
|
|
private final Item reward;
|
|
|
|
private final boolean secret;
|
|
|
|
private final String achievement;
|
|
|
|
private final boolean limited;
|
|
|
|
private final THashMap<Item, Integer> ingredients;
|
2019-05-26 20:14:53 +02:00
|
|
|
private int remaining;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public CraftingRecipe(ResultSet set) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.id = set.getInt("id");
|
|
|
|
this.name = set.getString("product_name");
|
|
|
|
this.reward = Emulator.getGameEnvironment().getItemManager().getItem(set.getInt("reward"));
|
|
|
|
this.secret = set.getString("secret").equals("1");
|
|
|
|
this.achievement = set.getString("achievement");
|
|
|
|
this.limited = set.getString("limited").equals("1");
|
|
|
|
this.remaining = set.getInt("remaining");
|
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
this.ingredients = new THashMap<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean canBeCrafted() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return !this.limited || this.remaining > 0;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public synchronized boolean decrease() {
|
|
|
|
if (this.remaining > 0) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.remaining--;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void addIngredient(Item item, int amount) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.ingredients.put(item, amount);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getAmountNeeded(Item item) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.ingredients.get(item);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean hasIngredient(Item item) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.ingredients.containsKey(item);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getId() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.id;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getName() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public Item getReward() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.reward;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isSecret() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.secret;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getAchievement() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.achievement;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isLimited() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.limited;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public THashMap<Item, Integer> getIngredients() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.ingredients;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getRemaining() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.remaining;
|
|
|
|
}
|
|
|
|
}
|