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

76 lines
2.2 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.pets;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
import com.eu.habbo.habbohotel.users.Habbo;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class PetCommand implements Comparable<PetCommand> {
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final int id;
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final String key;
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final int level;
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final int xp;
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final int energyCost;
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
public final int happynessCost;
2018-12-22 11:39:00 +01:00
2018-09-12 18:45:00 +02:00
public final PetAction action;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public PetCommand(ResultSet set, PetAction action) throws SQLException {
this.id = set.getInt("command_id");
this.key = set.getString("text");
this.level = set.getInt("required_level");
this.xp = set.getInt("reward_xp");
this.energyCost = set.getInt("cost_energy");
this.happynessCost = set.getInt("cost_happyness");
this.action = action;
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public int compareTo(PetCommand o) {
2018-07-06 15:30:00 +02:00
return this.level - o.level;
}
2018-09-12 18:45:00 +02:00
2019-05-26 20:14:53 +02:00
public void handle(Pet pet, Habbo habbo, String[] data) {
if (Emulator.getRandom().nextInt((pet.level - this.level <= 0 ? 2 : pet.level - this.level) + 2) == 0) {
2018-09-12 18:45:00 +02:00
pet.say(pet.petData.randomVocal(PetVocalsType.DISOBEY));
return;
}
2019-05-26 20:14:53 +02:00
if (this.action != null) {
if (this.action.petTask != pet.getTask()) {
if (this.action.stopsPetWalking) {
2018-09-12 18:45:00 +02:00
pet.getRoomUnit().setGoalLocation(pet.getRoomUnit().getCurrentLocation());
}
2019-05-26 20:14:53 +02:00
if (this.action.apply(pet, habbo, data)) {
for (RoomUnitStatus status : this.action.statusToRemove) {
2018-09-12 18:45:00 +02:00
pet.getRoomUnit().removeStatus(status);
}
2019-05-26 20:14:53 +02:00
for (RoomUnitStatus status : this.action.statusToSet) {
2018-09-12 18:45:00 +02:00
pet.getRoomUnit().setStatus(status, "0");
}
pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, this.action.gestureToSet);
pet.addEnergy(-this.energyCost);
pet.addHappyness(-this.happynessCost);
pet.addExperience(this.xp);
}
}
}
}
2018-07-06 15:30:00 +02:00
}