From 60bf49df74501896b297a0841c884028c24c83c3 Mon Sep 17 00:00:00 2001 From: Harmonic Date: Fri, 6 Jan 2023 19:24:27 -0800 Subject: [PATCH] Added full comments to PetCommand.java --- .../eu/habbo/habbohotel/pets/PetCommand.java | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/PetCommand.java b/src/main/java/com/eu/habbo/habbohotel/pets/PetCommand.java index 3944cf96..153454e2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/PetCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/PetCommand.java @@ -8,28 +8,38 @@ import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import java.sql.ResultSet; import java.sql.SQLException; +/** + * A class representing a command that can be given to a pet. + */ public class PetCommand implements Comparable { + /** The ID of the command. */ public final int id; - + /** The key (name) of the command. */ public final String key; - + /** The level required to use the command. */ public final int level; - + /** The amount of XP rewarded for using the command. */ public final int xp; - + /** The cost in energy to use the command. */ public final int energyCost; - + /** The cost in happiness to use the command. */ public final int happynessCost; - + /** The action associated with the command. */ public final PetAction action; + /** + * Creates a new PetCommand instance. + * @param set The ResultSet to get data from. + * @param action The PetAction associated with the command. + * @throws SQLException If a database error occurs. + */ public PetCommand(ResultSet set, PetAction action) throws SQLException { this.id = set.getInt("command_id"); this.key = set.getString("text"); @@ -40,11 +50,24 @@ public class PetCommand implements Comparable { this.action = action; } + /** + * Compares this PetCommand to another PetCommand based on the required level to use them. + * @param o The other PetCommand to compare to. + * @return A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. + */ @Override public int compareTo(PetCommand o) { return this.level - o.level; } + /** + * Handles the execution of the command for a given pet, Habbo, and data. + * If the pet does not have enough energy or happiness, or if a random check fails, the pet will "disobey" the command. + * Otherwise, the action associated with the command is applied and the pet's energy, happiness, and experience are updated. + * @param pet The pet to execute the command on. + * @param habbo The Habbo giving the command. + * @param data The data associated with the command. + */ public void handle(Pet pet, Habbo habbo, String[] data) { // check if enough energy, happiness, and randomize do or dont || should possibly add if not hungry and thirsty but @brenoepic does those - oliver if (this.action != null && pet.energy > this.energyCost && pet.happyness > this.happynessCost && Emulator.getRandom().nextInt((pet.level - this.level <= 0 ? 2 : pet.level - this.level) + 2) == 0) { @@ -80,3 +103,4 @@ public class PetCommand implements Comparable { } } } +