Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java

516 lines
21 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.pets;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
2020-02-08 17:22:06 +01:00
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionNest;
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetDrink;
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetFood;
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetToy;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.habbohotel.pets.actions.*;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import gnu.trove.map.TIntIntMap;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.map.hash.TIntObjectHashMap;
2018-12-22 11:39:00 +01:00
import gnu.trove.procedure.TIntObjectProcedure;
2018-07-06 15:30:00 +02:00
import gnu.trove.set.hash.THashSet;
2018-12-22 11:39:00 +01:00
import org.apache.commons.math3.distribution.NormalDistribution;
2018-07-06 15:30:00 +02:00
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
2019-05-26 20:14:53 +02:00
public class PetManager {
public static final int[] experiences = new int[]{100, 200, 400, 600, 900, 1300, 1800, 2400, 3200, 4300, 5700, 7600, 10100, 13300, 17500, 23000, 30200, 39600, 51900};
static int[] skins = new int[]{0, 1, 6, 7};
public final THashMap<Integer, PetAction> petActions = new THashMap<Integer, PetAction>() {
2018-09-12 18:45:00 +02:00
{
2019-03-18 02:22:00 +01:00
this.put(0, new ActionFree());
this.put(1, new ActionSit());
this.put(2, new ActionDown());
this.put(3, new ActionHere());
this.put(4, new ActionBeg());
this.put(5, new ActionPlayDead());
this.put(6, new ActionStay());
this.put(7, new ActionFollow());
this.put(8, new ActionStand());
this.put(9, new ActionJump());
this.put(10, new ActionSpeak());
this.put(11, new ActionPlay());
this.put(12, new ActionSilent());
this.put(13, new ActionNest());
this.put(14, new ActionDrink());
this.put(15, new ActionFollowLeft());
this.put(16, new ActionFollowRight());
this.put(17, new ActionPlayFootball());
this.put(24, new ActionMoveForward());
this.put(25, new ActionTurnLeft());
this.put(26, new ActionTurnRight());
this.put(27, new ActionRelax());
this.put(28, new ActionCroak());
this.put(29, new ActionDip());
this.put(30, new ActionWave());
this.put(35, new ActionWings());
this.put(36, new ActionBreatheFire());
this.put(38, new ActionTorch());
this.put(43, new ActionEat());
this.put(46, new ActionBreed());
2018-09-12 18:45:00 +02:00
}
};
2019-05-26 20:14:53 +02:00
private final THashMap<Integer, THashSet<PetRace>> petRaces;
private final THashMap<Integer, PetData> petData;
private final TIntIntMap breedingPetType;
private final THashMap<Integer, TIntObjectHashMap<ArrayList<PetBreedingReward>>> breedingReward;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public PetManager() {
2018-07-06 15:30:00 +02:00
long millis = System.currentTimeMillis();
2018-09-28 21:25:00 +02:00
this.petRaces = new THashMap<>();
this.petData = new THashMap<>();
2018-07-06 15:30:00 +02:00
this.breedingPetType = new TIntIntHashMap();
2018-09-28 21:25:00 +02:00
this.breedingReward = new THashMap<>();
2018-07-06 15:30:00 +02:00
2019-05-05 06:46:35 +02:00
reloadPetData();
2018-07-06 15:30:00 +02:00
Emulator.getLogging().logStart("Pet Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)");
}
2019-05-26 20:14:53 +02:00
public static int getLevel(int experience) {
2019-06-30 22:05:03 +02:00
int index = -1;
2019-05-26 20:14:53 +02:00
for (int i = 0; i < experiences.length; i++) {
if (experiences[i] > experience) {
index = i;
break;
}
}
2019-06-30 22:05:03 +02:00
if(index == -1) { index = experiences.length; }
2019-05-26 20:14:53 +02:00
return index + 1;
}
public static int maxEnergy(int level) {
//TODO: Add energy calculation.
return 100 * level;
}
public static int randomBody(int minimumRarity) {
int randomRarity = random(Math.max(minimumRarity - 1, 0), MonsterplantPet.bodyRarity.size(), 2.0);
return MonsterplantPet.bodyRarity.get(MonsterplantPet.bodyRarity.keySet().toArray()[randomRarity]).getValue();
}
public static int randomColor(int minimumRarity) {
int randomRarity = random(Math.max(minimumRarity - 1, 0), MonsterplantPet.colorRarity.size(), 2.0);
return MonsterplantPet.colorRarity.get(MonsterplantPet.colorRarity.keySet().toArray()[randomRarity]).getValue();
}
public static int random(int low, int high, double bias) {
double r = Math.random();
r = Math.pow(r, bias);
return (int) (low + (high - low) * r);
}
public static Pet loadPet(ResultSet set) throws SQLException {
if (set.getInt("type") == 15)
return new HorsePet(set);
else if (set.getInt("type") == 16)
return new MonsterplantPet(set);
else if (set.getInt("type") == 26 || set.getInt("type") == 27)
return new GnomePet(set);
else
return new Pet(set);
}
public static NormalDistribution getNormalDistributionForBreeding(int levelOne, int levelTwo) {
return getNormalDistributionForBreeding((levelOne + levelTwo) / 2);
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public static NormalDistribution getNormalDistributionForBreeding(double avgLevel) {
return new NormalDistribution(avgLevel, (20 - (avgLevel / 2)) / 2);
}
public void reloadPetData() {
2019-05-05 06:46:35 +02:00
this.petRaces.clear();
this.petData.clear();
this.breedingPetType.clear();
this.breedingReward.clear();
2019-05-26 20:14:53 +02:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
2018-07-06 15:30:00 +02:00
this.loadRaces(connection);
2019-05-05 06:46:35 +02:00
this.loadPetData(connection);
this.loadPetCommands(connection);
this.loadPetBreeding(connection);
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2018-07-06 15:30:00 +02:00
Emulator.getLogging().logSQLException(e);
2019-05-05 06:46:35 +02:00
Emulator.getLogging().logErrorLine("Pet Manager -> Failed to load!");
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
private void loadRaces(Connection connection) {
2018-07-06 15:30:00 +02:00
this.petRaces.clear();
2019-05-26 20:14:53 +02:00
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_breeds ORDER BY race, color_one, color_two ASC")) {
while (set.next()) {
if (this.petRaces.get(set.getInt("race")) == null)
2018-09-28 21:25:00 +02:00
this.petRaces.put(set.getInt("race"), new THashSet<>());
2018-07-06 15:30:00 +02:00
this.petRaces.get(set.getInt("race")).add(new PetRace(set));
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2019-05-24 00:57:22 +02:00
Emulator.getLogging().logSQLException(e);
}
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
private void loadPetData(Connection connection) {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_actions ORDER BY pet_type ASC")) {
while (set.next()) {
2018-07-06 15:30:00 +02:00
this.petData.put(set.getInt("pet_type"), new PetData(set));
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2019-05-24 00:57:22 +02:00
Emulator.getLogging().logSQLException(e);
}
2018-07-06 15:30:00 +02:00
this.loadPetItems(connection);
this.loadPetVocals(connection);
}
2019-05-26 20:14:53 +02:00
private void loadPetItems(Connection connection) {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_items")) {
while (set.next()) {
2018-07-06 15:30:00 +02:00
Item baseItem = Emulator.getGameEnvironment().getItemManager().getItem(set.getInt("item_id"));
2019-05-26 20:14:53 +02:00
if (baseItem != null) {
if (set.getInt("pet_id") == -1) {
if (baseItem.getInteractionType().getType() == InteractionNest.class)
PetData.generalNestItems.add(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetFood.class)
PetData.generalFoodItems.add(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetDrink.class)
PetData.generalDrinkItems.add(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetToy.class)
PetData.generalToyItems.add(baseItem);
} else {
2018-07-06 15:30:00 +02:00
PetData data = this.getPetData(set.getInt("pet_id"));
2019-05-26 20:14:53 +02:00
if (data != null) {
if (baseItem.getInteractionType().getType() == InteractionNest.class)
data.addNest(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetFood.class)
data.addFoodItem(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetDrink.class)
data.addDrinkItem(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetToy.class)
data.addToyItem(baseItem);
2018-07-06 15:30:00 +02:00
}
}
}
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2019-05-24 00:57:22 +02:00
Emulator.getLogging().logSQLException(e);
}
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
private void loadPetVocals(Connection connection) {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_vocals")) {
while (set.next()) {
if (set.getInt("pet_id") >= 0) {
if (this.petData.containsKey(set.getInt("pet_id"))) {
2018-11-17 14:28:00 +01:00
PetVocalsType petVocalsType = PetVocalsType.valueOf(set.getString("type").toUpperCase());
2019-05-26 20:14:53 +02:00
if (petVocalsType != null) {
2018-11-17 14:28:00 +01:00
this.petData.get(set.getInt("pet_id")).petVocals.get(petVocalsType).add(new PetVocal(set.getString("message")));
2019-05-26 20:14:53 +02:00
} else {
2018-11-17 14:28:00 +01:00
Emulator.getLogging().logErrorLine("Unknown pet vocal type " + set.getString("type"));
}
2019-05-26 20:14:53 +02:00
} else {
2018-09-12 18:45:00 +02:00
Emulator.getLogging().logErrorLine("Missing pet_actions table entry for pet id " + set.getInt("pet_id"));
}
2019-05-26 20:14:53 +02:00
} else {
if (!PetData.generalPetVocals.containsKey(PetVocalsType.valueOf(set.getString("type").toUpperCase())))
2018-09-28 21:25:00 +02:00
PetData.generalPetVocals.put(PetVocalsType.valueOf(set.getString("type").toUpperCase()), new THashSet<>());
2018-07-06 15:30:00 +02:00
PetData.generalPetVocals.get(PetVocalsType.valueOf(set.getString("type").toUpperCase())).add(new PetVocal(set.getString("message")));
}
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2019-05-24 00:57:22 +02:00
Emulator.getLogging().logSQLException(e);
}
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
private void loadPetCommands(Connection connection) {
2018-09-28 21:25:00 +02:00
THashMap<Integer, PetCommand> commandsList = new THashMap<>();
2019-05-26 20:14:53 +02:00
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_commands_data")) {
while (set.next()) {
commandsList.put(set.getInt("command_id"), new PetCommand(set, this.petActions.get(set.getInt("command_id"))));
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2019-05-24 00:57:22 +02:00
Emulator.getLogging().logSQLException(e);
}
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_commands ORDER BY pet_id ASC")) {
while (set.next()) {
2018-07-06 15:30:00 +02:00
PetData data = this.petData.get(set.getInt("pet_id"));
2019-05-26 20:14:53 +02:00
if (data != null) {
2018-07-06 15:30:00 +02:00
data.getPetCommands().add(commandsList.get(set.getInt("command_id")));
}
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2019-05-24 00:57:22 +02:00
Emulator.getLogging().logSQLException(e);
}
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
private void loadPetBreeding(Connection connection) {
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_breeding")) {
while (set.next()) {
2018-07-06 15:30:00 +02:00
this.breedingPetType.put(set.getInt("pet_id"), set.getInt("offspring_id"));
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2019-05-24 00:57:22 +02:00
Emulator.getLogging().logSQLException(e);
}
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
try (Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM pet_breeding_races")) {
while (set.next()) {
2018-07-06 15:30:00 +02:00
PetBreedingReward reward = new PetBreedingReward(set);
2019-05-26 20:14:53 +02:00
if (!this.breedingReward.containsKey(reward.petType)) {
2018-09-28 21:25:00 +02:00
this.breedingReward.put(reward.petType, new TIntObjectHashMap<>());
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
if (!this.breedingReward.get(reward.petType).containsKey(reward.rarityLevel)) {
2018-09-28 21:25:00 +02:00
this.breedingReward.get(reward.petType).put(reward.rarityLevel, new ArrayList<>());
2018-07-06 15:30:00 +02:00
}
this.breedingReward.get(reward.petType).get(reward.rarityLevel).add(reward);
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2019-05-24 00:57:22 +02:00
Emulator.getLogging().logSQLException(e);
}
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public THashSet<PetRace> getBreeds(String petName) {
if (!petName.startsWith("a0 pet")) {
2018-07-06 15:30:00 +02:00
Emulator.getLogging().logErrorLine("Pet " + petName + " not found. Make sure it matches the pattern \"a0 pet<pet_id>\"!");
return null;
}
2019-05-26 20:14:53 +02:00
try {
2018-07-06 15:30:00 +02:00
int petId = Integer.valueOf(petName.split("t")[1]);
return this.petRaces.get(petId);
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2019-03-18 02:22:00 +01:00
Emulator.getLogging().logErrorLine(e);
2018-07-06 15:30:00 +02:00
}
return null;
}
2019-05-26 20:14:53 +02:00
public TIntObjectHashMap<ArrayList<PetBreedingReward>> getBreedingRewards(int petType) {
2018-12-22 11:39:00 +01:00
return this.breedingReward.get(petType);
}
2019-05-26 20:14:53 +02:00
public int getRarityForOffspring(Pet pet) {
2018-12-22 11:39:00 +01:00
final int[] rarityLevel = {0};
TIntObjectHashMap<ArrayList<PetBreedingReward>> offspringList = this.breedingReward.get(pet.getPetData().getType());
2019-05-26 20:14:53 +02:00
offspringList.forEachEntry(new TIntObjectProcedure<ArrayList<PetBreedingReward>>() {
2018-12-22 11:39:00 +01:00
@Override
2019-05-26 20:14:53 +02:00
public boolean execute(int i, ArrayList<PetBreedingReward> petBreedingRewards) {
for (PetBreedingReward reward : petBreedingRewards) {
if (reward.breed == pet.getRace()) {
2019-03-18 02:22:00 +01:00
rarityLevel[0] = i;
return false;
}
2018-12-22 11:39:00 +01:00
}
return true;
}
});
return 4 - rarityLevel[0];
}
2019-05-26 20:14:53 +02:00
public PetData getPetData(int type) {
synchronized (this.petData) {
if (this.petData.containsKey(type)) {
2018-07-06 15:30:00 +02:00
return this.petData.get(type);
2019-05-26 20:14:53 +02:00
} else {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
2018-07-06 15:30:00 +02:00
Emulator.getLogging().logErrorLine("Missing petdata for type " + type + ". Adding this to the database...");
2019-05-26 20:14:53 +02:00
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO pet_actions (pet_type) VALUES (?)")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, type);
statement.execute();
}
2019-05-26 20:14:53 +02:00
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM pet_actions WHERE pet_type = ? LIMIT 1")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, type);
2019-05-26 20:14:53 +02:00
try (ResultSet set = statement.executeQuery()) {
if (set.next()) {
2018-07-06 15:30:00 +02:00
PetData petData = new PetData(set);
this.petData.put(type, petData);
Emulator.getLogging().logErrorLine("Missing petdata for type " + type + " added to the database!");
return petData;
}
}
}
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2018-07-06 15:30:00 +02:00
Emulator.getLogging().logSQLException(e);
}
}
}
return null;
}
2019-05-26 20:14:53 +02:00
public PetData getPetData(String petName) {
synchronized (this.petData) {
for (Map.Entry<Integer, PetData> entry : this.petData.entrySet()) {
if (entry.getValue().getName().equalsIgnoreCase(petName)) {
2018-07-06 15:30:00 +02:00
return entry.getValue();
}
}
}
return null;
}
2019-05-26 20:14:53 +02:00
public Collection<PetData> getPetData() {
2018-07-06 15:30:00 +02:00
return this.petData.values();
}
2019-05-26 20:14:53 +02:00
public Pet createPet(Item item, String name, String race, String color, GameClient client) {
2018-07-06 15:30:00 +02:00
int type = Integer.valueOf(item.getName().toLowerCase().replace("a0 pet", ""));
2019-05-26 20:14:53 +02:00
if (this.petData.containsKey(type)) {
2018-09-28 21:25:00 +02:00
Pet pet;
if (type == 15)
pet = new HorsePet(type, Integer.valueOf(race), color, name, client.getHabbo().getHabboInfo().getId());
else if (type == 16)
2019-03-18 02:22:00 +01:00
pet = this.createMonsterplant(null, client.getHabbo(), false, null, 0);
2018-09-28 21:25:00 +02:00
else
pet = new Pet(type,
Integer.valueOf(race),
color,
name,
client.getHabbo().getHabboInfo().getId()
);
2018-07-06 15:30:00 +02:00
2018-09-28 21:25:00 +02:00
pet.needsUpdate = true;
pet.run();
return pet;
}
return null;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public Pet createPet(int type, String name, GameClient client) {
2018-12-22 11:39:00 +01:00
return this.createPet(type, Emulator.getRandom().nextInt(this.petRaces.get(type).size() + 1), name, client);
}
2019-05-26 20:14:53 +02:00
public Pet createPet(int type, int race, String name, GameClient client) {
if (this.petData.containsKey(type)) {
2018-12-22 11:39:00 +01:00
Pet pet = new Pet(type, race, "FFFFFF", name, client.getHabbo().getHabboInfo().getId());
2018-09-28 21:25:00 +02:00
pet.needsUpdate = true;
pet.run();
return pet;
}
return null;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public MonsterplantPet createMonsterplant(Room room, Habbo habbo, boolean rare, RoomTile t, int minimumRarity) {
2018-07-06 15:30:00 +02:00
MonsterplantPet pet = new MonsterplantPet(
habbo.getHabboInfo().getId(), //Owner ID
2019-03-18 02:22:00 +01:00
randomBody(rare ? 4 : minimumRarity),
randomColor(rare ? 4 : minimumRarity),
2018-09-28 21:25:00 +02:00
Emulator.getRandom().nextInt(12) + 1,
Emulator.getRandom().nextInt(11),
Emulator.getRandom().nextInt(12) + 1,
Emulator.getRandom().nextInt(11),
Emulator.getRandom().nextInt(12) + 1,
Emulator.getRandom().nextInt(11)
2018-07-06 15:30:00 +02:00
);
pet.setUserId(habbo.getHabboInfo().getId());
pet.setRoom(room);
pet.setRoomUnit(new RoomUnit());
pet.getRoomUnit().setPathFinderRoom(room);
pet.needsUpdate = true;
pet.run();
return pet;
}
2019-05-26 20:14:53 +02:00
public Pet createGnome(String name, Room room, Habbo habbo) {
2018-07-06 15:30:00 +02:00
Pet pet = new GnomePet(26, 0, "FFFFFF", name, habbo.getHabboInfo().getId(),
"5 " +
2019-05-26 20:14:53 +02:00
"0 -1 " + this.randomGnomeSkinColor() + " " +
"1 10" + (1 + Emulator.getRandom().nextInt(2)) + " " + this.randomGnomeColor() + " " +
"2 201 " + this.randomGnomeColor() + " " +
"3 30" + (1 + Emulator.getRandom().nextInt(2)) + " " + this.randomGnomeColor() + " " +
"4 40" + Emulator.getRandom().nextInt(2) + " " + this.randomGnomeColor()
);
2018-07-06 15:30:00 +02:00
pet.setUserId(habbo.getHabboInfo().getId());
pet.setRoom(room);
pet.setRoomUnit(new RoomUnit());
pet.getRoomUnit().setPathFinderRoom(room);
pet.needsUpdate = true;
pet.run();
return pet;
}
2019-05-26 20:14:53 +02:00
public Pet createLeprechaun(String name, Room room, Habbo habbo) {
2018-07-06 15:30:00 +02:00
Pet pet = new GnomePet(27, 0, "FFFFFF", name, habbo.getHabboInfo().getId(),
"5 " +
"0 -1 0 " +
"1 102 19 " +
"2 201 27 " +
"3 302 23 " +
"4 401 27"
);
pet.setUserId(habbo.getHabboInfo().getId());
pet.setRoom(room);
pet.setRoomUnit(new RoomUnit());
pet.getRoomUnit().setPathFinderRoom(room);
pet.needsUpdate = true;
pet.run();
return pet;
}
2019-05-26 20:14:53 +02:00
private int randomGnomeColor() {
2018-07-06 15:30:00 +02:00
int color = 19;
2019-05-26 20:14:53 +02:00
while (color == 19 || color == 27) {
2018-07-06 15:30:00 +02:00
color = Emulator.getRandom().nextInt(34);
}
return color;
}
2019-05-26 20:14:53 +02:00
private int randomLeprechaunColor() {
2018-07-06 15:30:00 +02:00
return Emulator.getRandom().nextInt(2) == 1 ? 19 : 27;
}
2019-05-26 20:14:53 +02:00
private int randomGnomeSkinColor() {
2018-07-06 15:30:00 +02:00
return skins[Emulator.getRandom().nextInt(skins.length)];
}
2019-05-26 20:14:53 +02:00
public boolean deletePet(Pet pet) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_pets WHERE id = ? LIMIT 1")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, pet.getId());
return statement.execute();
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2018-07-06 15:30:00 +02:00
Emulator.getLogging().logSQLException(e);
}
return false;
}
2018-12-22 11:39:00 +01:00
}