Skip to content
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.

Commit

Permalink
Add get pet stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Quackster committed May 7, 2024
1 parent abbcde6 commit d34b5ce
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.alexdev.kepler.game.player.Player;
import org.alexdev.kepler.game.room.RoomManager;
import org.alexdev.kepler.log.Log;
import org.alexdev.kepler.messages.incoming.pets.GETPETSTAT;
import org.alexdev.kepler.messages.incoming.catalogue.GCAP;
import org.alexdev.kepler.messages.incoming.catalogue.GCIX;
import org.alexdev.kepler.messages.incoming.catalogue.GET_ALIAS_LIST;
Expand Down Expand Up @@ -41,10 +42,7 @@
import org.alexdev.kepler.messages.incoming.rooms.moderation.*;
import org.alexdev.kepler.messages.incoming.rooms.pool.*;
import org.alexdev.kepler.messages.incoming.rooms.settings.*;
import org.alexdev.kepler.messages.incoming.rooms.teleporter.DOORGOIN;
import org.alexdev.kepler.messages.incoming.rooms.teleporter.GETDOORFLAT;
import org.alexdev.kepler.messages.incoming.rooms.teleporter.GOVIADOOR;
import org.alexdev.kepler.messages.incoming.rooms.teleporter.INTODOOR;
import org.alexdev.kepler.messages.incoming.rooms.user.*;
import org.alexdev.kepler.messages.incoming.songs.*;
import org.alexdev.kepler.messages.incoming.trade.*;
Expand Down Expand Up @@ -84,6 +82,7 @@ private MessageHandler() {
registerNavigatorPackets();
registerRoomPackets();
registerRoomUserPackets();
registerPetPackets();
registerRoomBadgesPackets();
registerRoomPoolPackets();
registerRoomSettingsPackets();
Expand Down Expand Up @@ -241,6 +240,12 @@ private void registerRoomUserPackets() {
registerEvent(117, new IIM());
}

/**
* Register pet packets.
*/
private void registerPetPackets() {
registerEvent(128, new GETPETSTAT());
}

/**
* Register room badges packets;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.alexdev.kepler.messages.incoming.pets;

import org.alexdev.kepler.game.entity.EntityType;
import org.alexdev.kepler.game.pets.Pet;
import org.alexdev.kepler.game.player.Player;
import org.alexdev.kepler.game.room.Room;
import org.alexdev.kepler.messages.outgoing.pets.PETSTAT;
import org.alexdev.kepler.messages.types.MessageEvent;
import org.alexdev.kepler.server.netty.streams.NettyRequest;

public class GETPETSTAT implements MessageEvent {
@Override
public void handle(Player player, NettyRequest reader) throws Exception {
if (player.getRoomUser().getRoom() == null) {
return;
}

Room room = player.getRoomUser().getRoom();
String[] petData = reader.readString().split(Character.toString((char)4));

int petId = Integer.parseInt(petData[0]);
String petName = petData[1];

Pet pet = (Pet) room.getEntityManager().getByInstanceId(petId);

if (pet == null) {
return;
}

player.send(new PETSTAT(pet));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.alexdev.kepler.messages.outgoing.pets;

import org.alexdev.kepler.game.pets.Pet;
import org.alexdev.kepler.messages.types.MessageComposer;
import org.alexdev.kepler.server.netty.streams.NettyResponse;

public class PETSTAT extends MessageComposer {
private final Pet pet;

public PETSTAT(Pet pet) {
this.pet = pet;
}

@Override
public void compose(NettyResponse response) {
response.writeInt(this.pet.getRoomUser().getInstanceId());
response.writeInt(this.pet.getAge());
response.writeInt(this.pet.getHunger());
response.writeInt(this.pet.getThirst());
response.writeInt(this.pet.getHappiness());
response.writeInt(this.pet.getDetails().getNatureNegative());
response.writeInt(this.pet.getDetails().getNaturePositive());
}

@Override
public short getHeader() {
return 210; // "CR"
}
}

0 comments on commit d34b5ce

Please sign in to comment.