2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.pets;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.achievements.AchievementManager;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
2018-09-12 18:45:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.pets.PetStatusUpdateComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetRespectComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
2019-03-18 02:22:00 +01:00
|
|
|
import org.apache.commons.math3.util.Pair;
|
2020-05-04 22:24:09 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class MonsterplantPet extends Pet implements IPetLook {
|
2020-05-04 22:24:09 +02:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(MonsterplantPet.class);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public static final Map<Integer, Pair<String, Integer>> bodyRarity = new LinkedHashMap<Integer, Pair<String, Integer>>() {
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
this.put(1, new Pair<>("Blungon", 0));
|
|
|
|
this.put(2, new Pair<>("Wailzor", 1));
|
|
|
|
this.put(3, new Pair<>("Stumpy", 1));
|
|
|
|
this.put(4, new Pair<>("Sunspike", 2));
|
2020-04-27 03:34:57 +02:00
|
|
|
this.put(5, new Pair<>("Squarg", 0));
|
2019-03-18 02:22:00 +01:00
|
|
|
this.put(6, new Pair<>("Shroomer", 3));
|
|
|
|
this.put(7, new Pair<>("Zuchinu", 3));
|
2020-04-27 03:34:57 +02:00
|
|
|
this.put(8, new Pair<>("Abysswirl", 5));
|
|
|
|
this.put(9, new Pair<>("Weggylum", 2));
|
2019-03-18 02:22:00 +01:00
|
|
|
this.put(10, new Pair<>("Wystique", 4));
|
|
|
|
this.put(11, new Pair<>("Hairbullis", 4));
|
|
|
|
this.put(12, new Pair<>("Snozzle", 5)); //Rarity???
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
};
|
2019-05-26 20:14:53 +02:00
|
|
|
public static final Map<Integer, Pair<String, Integer>> colorRarity = new LinkedHashMap<Integer, Pair<String, Integer>>() {
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
this.put(0, new Pair<>("Aenueus", 0));
|
|
|
|
this.put(1, new Pair<>("Griseus", 1));
|
|
|
|
this.put(2, new Pair<>("Phoenicus", 2));
|
2020-04-27 03:34:57 +02:00
|
|
|
this.put(3, new Pair<>("Viridulus", 1));
|
|
|
|
this.put(4, new Pair<>("Cyaneus", 5));
|
2019-03-18 02:22:00 +01:00
|
|
|
this.put(5, new Pair<>("Incarnatus", 2));
|
|
|
|
this.put(6, new Pair<>("Azureus", 4));
|
|
|
|
this.put(7, new Pair<>("Atamasc", 4));
|
2020-04-27 03:34:57 +02:00
|
|
|
this.put(8, new Pair<>("Amethyst", 3));
|
|
|
|
this.put(9, new Pair<>("Fulvus", 0));
|
|
|
|
this.put(10, new Pair<>("Cinereus", 3));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
};
|
2018-09-28 21:25:00 +02:00
|
|
|
public static final ArrayList<Pair<String, Integer>> indexedBody = new ArrayList<>(MonsterplantPet.bodyRarity.values());
|
|
|
|
public static final ArrayList<Pair<String, Integer>> indexedColors = new ArrayList<>(MonsterplantPet.colorRarity.values());
|
2019-05-26 20:14:53 +02:00
|
|
|
public static int growTime = (30 * 60);
|
|
|
|
public static int timeToLive = (3 * 24 * 60 * 60); //3 days
|
2018-07-06 15:30:00 +02:00
|
|
|
private final int nose;
|
|
|
|
private final int noseColor;
|
|
|
|
private final int eyes;
|
|
|
|
private final int eyesColor;
|
|
|
|
private final int mouth;
|
|
|
|
private final int mouthColor;
|
2019-05-26 20:14:53 +02:00
|
|
|
public String look;
|
|
|
|
private int type;
|
|
|
|
private int hue;
|
2018-07-06 15:30:00 +02:00
|
|
|
private int deathTimestamp = Emulator.getIntUnixTimestamp() + timeToLive;
|
|
|
|
private boolean canBreed = true;
|
|
|
|
private boolean publiclyBreedable = false;
|
|
|
|
private int growthStage = 0;
|
2019-08-01 19:40:49 +02:00
|
|
|
private boolean hasDied = false;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public MonsterplantPet(ResultSet set) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set);
|
|
|
|
this.type = set.getInt("mp_type");
|
|
|
|
this.hue = set.getInt("mp_color");
|
|
|
|
this.nose = set.getInt("mp_nose");
|
|
|
|
this.noseColor = set.getInt("mp_nose_color");
|
|
|
|
this.eyes = set.getInt("mp_eyes");
|
|
|
|
this.eyesColor = set.getInt("mp_eyes_color");
|
|
|
|
this.mouth = set.getInt("mp_mouth");
|
|
|
|
this.mouthColor = set.getInt("mp_mouth_color");
|
|
|
|
this.deathTimestamp = set.getInt("mp_death_timestamp");
|
|
|
|
this.publiclyBreedable = set.getString("mp_allow_breed").equals("1");
|
|
|
|
this.canBreed = set.getString("mp_breedable").equals("1");
|
2019-08-01 19:40:49 +02:00
|
|
|
this.hasDied = set.getInt("mp_is_dead") == 1;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public MonsterplantPet(int userId, int type, int hue, int nose, int noseColor, int mouth, int mouthColor, int eyes, int eyesColor) {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(16, 0, "", "", userId);
|
|
|
|
|
|
|
|
this.type = type;
|
|
|
|
this.hue = hue;
|
|
|
|
this.nose = nose;
|
|
|
|
this.noseColor = noseColor;
|
|
|
|
this.mouth = mouth;
|
|
|
|
this.mouthColor = mouthColor;
|
|
|
|
this.eyes = eyes;
|
|
|
|
this.eyesColor = eyesColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getName() {
|
2018-07-06 15:30:00 +02:00
|
|
|
String name = "Unknownis";
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (colorRarity.containsKey(this.hue)) {
|
2018-07-06 15:30:00 +02:00
|
|
|
name = colorRarity.get(this.hue).getKey();
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (bodyRarity.containsKey(this.type)) {
|
2018-07-06 15:30:00 +02:00
|
|
|
name += " " + bodyRarity.get(this.type).getKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void run() {
|
|
|
|
if (this.needsUpdate) {
|
2018-07-06 15:30:00 +02:00
|
|
|
super.run();
|
|
|
|
|
2019-08-01 19:40:49 +02:00
|
|
|
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET mp_type = ?, mp_color = ?, mp_nose = ?, mp_eyes = ?, mp_mouth = ?, mp_nose_color = ?, mp_eyes_color = ?, mp_mouth_color = ?, mp_death_timestamp = ?, mp_breedable = ?, mp_allow_breed = ?, mp_is_dead = ? WHERE id = ?")) {
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.setInt(1, this.type);
|
|
|
|
statement.setInt(2, this.hue);
|
|
|
|
statement.setInt(3, this.nose);
|
|
|
|
statement.setInt(4, this.eyes);
|
|
|
|
statement.setInt(5, this.mouth);
|
|
|
|
statement.setInt(6, this.noseColor);
|
|
|
|
statement.setInt(7, this.eyesColor);
|
|
|
|
statement.setInt(8, this.mouthColor);
|
|
|
|
statement.setInt(9, this.deathTimestamp);
|
|
|
|
statement.setString(10, this.canBreed ? "1" : "0");
|
|
|
|
statement.setString(11, this.publiclyBreedable ? "1" : "0");
|
2019-08-01 19:40:49 +02:00
|
|
|
statement.setInt(12, this.hasDied ? 1 : 0);
|
|
|
|
statement.setInt(13, this.id);
|
2018-07-06 15:30:00 +02:00
|
|
|
statement.execute();
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (SQLException e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.error("Caught SQL exception", e);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void cycle() {
|
|
|
|
if (this.room != null && this.roomUnit != null) {
|
|
|
|
if (this.isDead()) {
|
2018-09-12 18:45:00 +02:00
|
|
|
this.roomUnit.removeStatus(RoomUnitStatus.GESTURE);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-08-01 19:40:49 +02:00
|
|
|
if (!this.hasDied) {
|
2018-07-06 15:30:00 +02:00
|
|
|
AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId), Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantGardenOfDeath"));
|
2019-08-01 19:40:49 +02:00
|
|
|
|
|
|
|
this.hasDied = true;
|
|
|
|
this.needsUpdate = true;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2018-09-12 18:45:00 +02:00
|
|
|
|
|
|
|
this.roomUnit.clearStatus();
|
|
|
|
this.roomUnit.setStatus(RoomUnitStatus.RIP, "");
|
|
|
|
this.packetUpdate = true;
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
int difference = Emulator.getIntUnixTimestamp() - this.created + 1;
|
2019-05-26 20:14:53 +02:00
|
|
|
if (difference >= growTime) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.growthStage = 7;
|
|
|
|
boolean clear = false;
|
2019-05-26 20:14:53 +02:00
|
|
|
for (RoomUnitStatus s : this.roomUnit.getStatusMap().keySet()) {
|
|
|
|
if (s.equals(RoomUnitStatus.GROW)) {
|
2018-07-06 15:30:00 +02:00
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (clear) {
|
2019-03-18 02:22:00 +01:00
|
|
|
this.roomUnit.clearStatus();
|
|
|
|
this.packetUpdate = true;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
int g = (int) Math.ceil(difference / (growTime / 7.0));
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (g > this.growthStage) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.growthStage = g;
|
2019-03-18 02:22:00 +01:00
|
|
|
this.roomUnit.clearStatus();
|
|
|
|
this.roomUnit.setStatus(RoomUnitStatus.fromString("grw" + this.growthStage), "");
|
|
|
|
this.packetUpdate = true;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (Emulator.getRandom().nextInt(1000) < 10) {
|
2018-07-06 15:30:00 +02:00
|
|
|
super.updateGesture(Emulator.getIntUnixTimestamp());
|
|
|
|
this.packetUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-22 11:39:00 +01:00
|
|
|
|
|
|
|
super.cycle();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getType() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.type;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getRarity() {
|
|
|
|
if (bodyRarity.containsKey(this.type) && colorRarity.containsKey(this.hue)) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return bodyRarity.get(this.type).getValue() + colorRarity.get(this.hue).getValue();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getLook() {
|
2019-03-18 02:22:00 +01:00
|
|
|
return "16 0 FFFFFF " +
|
2018-07-06 15:30:00 +02:00
|
|
|
"5 " +
|
|
|
|
"0 -1 10 " +
|
2019-05-26 20:14:53 +02:00
|
|
|
"1 " + this.type + " " + this.hue + " " +
|
2018-07-06 15:30:00 +02:00
|
|
|
"2 " + this.mouth + " " + this.mouthColor + " " +
|
2019-05-26 20:14:53 +02:00
|
|
|
"3 " + this.nose + " " + this.noseColor + " " +
|
|
|
|
"4 " + this.eyes + " " + this.eyesColor;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void serialize(ServerMessage message) {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString(this.getName());
|
|
|
|
message.appendInt(this.petData.getType());
|
|
|
|
message.appendInt(this.race);
|
2019-03-18 02:22:00 +01:00
|
|
|
message.appendString(this.getLook().substring(5));
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(this.getRarity());
|
|
|
|
message.appendInt(5);
|
2019-05-26 20:14:53 +02:00
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(-1);
|
|
|
|
message.appendInt(10);
|
|
|
|
message.appendInt(1);
|
|
|
|
message.appendInt(this.type);
|
|
|
|
message.appendInt(this.hue);
|
|
|
|
message.appendInt(2);
|
|
|
|
message.appendInt(this.mouth);
|
|
|
|
message.appendInt(this.mouthColor);
|
|
|
|
message.appendInt(3);
|
|
|
|
message.appendInt(this.nose);
|
|
|
|
message.appendInt(this.noseColor);
|
|
|
|
message.appendInt(4);
|
|
|
|
message.appendInt(this.eyes);
|
|
|
|
message.appendInt(this.eyesColor);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
message.appendInt(this.growthStage);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int remainingTimeToLive() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return Math.max(0, this.deathTimestamp - Emulator.getIntUnixTimestamp());
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isDead() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return Emulator.getIntUnixTimestamp() >= this.deathTimestamp;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setDeathTimestamp(int deathTimestamp) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.deathTimestamp = deathTimestamp;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getGrowthStage() {
|
2019-03-18 02:22:00 +01:00
|
|
|
return this.growthStage;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int remainingGrowTime() {
|
|
|
|
if (this.growthStage == 7) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Math.max(0, growTime - (Emulator.getIntUnixTimestamp() - this.created));
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isFullyGrown() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.growthStage == 7;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean canBreed() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.canBreed;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setCanBreed(boolean canBreed) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.canBreed = canBreed;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean breedable() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.isFullyGrown() && this.canBreed && !this.isDead();
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isPubliclyBreedable() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.publiclyBreedable;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setPubliclyBreedable(boolean isPubliclyBreedable) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.publiclyBreedable = isPubliclyBreedable;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void breed(MonsterplantPet pet) {
|
|
|
|
if (this.canBreed && pet.canBreed) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.canBreed = false;
|
|
|
|
this.publiclyBreedable = false;
|
|
|
|
|
|
|
|
pet.setCanBreed(false);
|
|
|
|
pet.setPubliclyBreedable(false);
|
2018-09-28 21:25:00 +02:00
|
|
|
this.room.sendComposer(new PetStatusUpdateComposer(pet).compose());
|
2018-07-06 15:30:00 +02:00
|
|
|
this.room.sendComposer(new PetStatusUpdateComposer(this).compose());
|
|
|
|
|
2018-09-12 18:45:00 +02:00
|
|
|
this.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "reb");
|
|
|
|
pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "reb");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
this.room.sendComposer(new RoomUserStatusComposer(this.getRoomUnit()).compose());
|
|
|
|
this.room.sendComposer(new RoomUserStatusComposer(pet.getRoomUnit()).compose());
|
|
|
|
|
2018-09-12 18:45:00 +02:00
|
|
|
this.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE);
|
|
|
|
pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
Habbo ownerOne = this.room.getHabbo(this.getUserId());
|
|
|
|
Habbo ownerTwo = null;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.getUserId() != pet.getUserId()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
ownerTwo = this.room.getHabbo(pet.getUserId());
|
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
Item seedBase;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.getRarity() < 8 || pet.getRarity() < 8 || Emulator.getRandom().nextInt(100) > this.getRarity() + pet.getRarity()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
seedBase = Emulator.getGameEnvironment().getItemManager().getItem(Emulator.getConfig().getInt("monsterplant.seed.item_id"));
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
seedBase = Emulator.getGameEnvironment().getItemManager().getItem(Emulator.getConfig().getInt("monsterplant.seed_rare.item_id"));
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (seedBase != null) {
|
2019-03-18 02:22:00 +01:00
|
|
|
HabboItem seed;
|
2019-05-26 20:14:53 +02:00
|
|
|
if (ownerOne != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
AchievementManager.progressAchievement(ownerOne, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantBreeder"), 5);
|
|
|
|
seed = Emulator.getGameEnvironment().getItemManager().createItem(ownerOne.getHabboInfo().getId(), seedBase, 0, 0, "");
|
|
|
|
ownerOne.getInventory().getItemsComponent().addItem(seed);
|
|
|
|
ownerOne.getClient().sendResponse(new AddHabboItemComposer(seed));
|
|
|
|
ownerOne.getClient().sendResponse(new InventoryRefreshComposer());
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (ownerTwo != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
AchievementManager.progressAchievement(ownerTwo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantBreeder"), 5);
|
|
|
|
seed = Emulator.getGameEnvironment().getItemManager().createItem(ownerTwo.getHabboInfo().getId(), seedBase, 0, 0, "");
|
|
|
|
ownerTwo.getInventory().getItemsComponent().addItem(seed);
|
|
|
|
ownerTwo.getClient().sendResponse(new AddHabboItemComposer(seed));
|
|
|
|
ownerTwo.getClient().sendResponse(new InventoryRefreshComposer());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 04:21:38 +02:00
|
|
|
private boolean mayScratch() {
|
|
|
|
// Monsterplant petting is available when:
|
|
|
|
// ((energy / max_energy) < 0.98) = true
|
|
|
|
// You can find the minimum deathTimestamp by solving (insert a timestamp for timestamp, solve for death_timestamp):
|
|
|
|
// (((death_timestamp - timestamp) / 259200)) < 0.98
|
|
|
|
// This information was found in the Habbo swf, com.sulake.habbo.ui.widget.infostand.InfoStandPetView.as
|
|
|
|
// this._Str_2304("pettreat", ((_local_3 / _local_4) < 0.98));
|
|
|
|
final float energy = this.getEnergy();
|
|
|
|
final float energyMax = this.getMaxEnergy();
|
|
|
|
|
|
|
|
return ((energy / energyMax) < 0.98);
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getMaxEnergy() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return MonsterplantPet.timeToLive;
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getEnergy() {
|
|
|
|
if (this.isDead()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.deathTimestamp - Emulator.getIntUnixTimestamp();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-07 04:21:38 +02:00
|
|
|
public synchronized void scratched(Habbo habbo) {
|
|
|
|
if (this.mayScratch()) {
|
|
|
|
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantTreater"), 5);
|
|
|
|
this.setDeathTimestamp(Emulator.getIntUnixTimestamp() + MonsterplantPet.timeToLive);
|
|
|
|
this.addHappyness(10);
|
|
|
|
this.addExperience(10);
|
|
|
|
this.room.sendComposer(new PetStatusUpdateComposer(this).compose());
|
|
|
|
this.room.sendComposer(new RoomPetRespectComposer(this, RoomPetRespectComposer.PET_TREATED).compose());
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2018-12-22 11:39:00 +01:00
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean canWalk() {
|
2018-12-22 11:39:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|