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

87 lines
2.4 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;
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
2018-09-12 18:45:00 +02:00
public PetCommand(ResultSet set, PetAction action) throws SQLException
2018-07-06 15:30:00 +02:00
{
2018-09-12 18:45:00 +02:00
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
public int compareTo(PetCommand o)
{
return this.level - o.level;
}
2018-09-12 18:45:00 +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)
{
pet.say(pet.petData.randomVocal(PetVocalsType.DISOBEY));
return;
}
if (this.action != null)
{
if (this.action.petTask != pet.getTask())
{
if (this.action.stopsPetWalking)
{
pet.getRoomUnit().setGoalLocation(pet.getRoomUnit().getCurrentLocation());
}
if (this.action.apply(pet, habbo, data))
{
for (RoomUnitStatus status : this.action.statusToRemove)
{
pet.getRoomUnit().removeStatus(status);
}
for (RoomUnitStatus status : this.action.statusToSet)
{
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
}