This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
Kepler-Server/src/main/java/org/alexdev/kepler/messages/incoming/pets/GETPETSTAT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Kepler-Server/src/main/java/org/alexdev/kepler/messages/outgoing/pets/PETSTAT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |