2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.commands;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.core.RoomUserPetComposer;
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.pets.PetData;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnitType;
|
|
|
|
import com.eu.habbo.messages.outgoing.generic.alerts.MessagesForYouComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserRemoveComposer;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class TransformCommand extends Command {
|
|
|
|
protected TransformCommand() {
|
2018-07-06 15:30:00 +02:00
|
|
|
super("cmd_transform", new String[]{"transform"});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean handle(GameClient gameClient, String[] params) throws Exception {
|
|
|
|
if (params.length == 1) {
|
2019-03-18 02:22:00 +01:00
|
|
|
StringBuilder petNames = new StringBuilder();
|
|
|
|
petNames.append(Emulator.getTexts().getValue("commands.generic.cmd_transform.title"));
|
|
|
|
petNames.append("\r------------------------------------------------------------------------------\r");
|
2018-07-06 15:30:00 +02:00
|
|
|
ArrayList<PetData> petData = new ArrayList<>(Emulator.getGameEnvironment().getPetManager().getPetData());
|
|
|
|
Collections.sort(petData);
|
|
|
|
String line = Emulator.getTexts().getValue("commands.generic.cmd_transform.line");
|
2019-05-26 20:14:53 +02:00
|
|
|
for (PetData p : petData) {
|
2019-03-18 02:22:00 +01:00
|
|
|
petNames.append(line.replace("%id%", p.getType() + "").replace("%name%", p.getName())).append("\r");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
gameClient.sendResponse(new MessagesForYouComposer(new String[]{petNames.toString()}));
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
String petName = params[1];
|
|
|
|
PetData petData = Emulator.getGameEnvironment().getPetManager().getPetData(petName);
|
|
|
|
|
|
|
|
int race = 0;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (params.length >= 3) {
|
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
race = Integer.valueOf(params[2]);
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String color = "FFFFFF";
|
2019-05-26 20:14:53 +02:00
|
|
|
if (params.length >= 4) {
|
2018-07-06 15:30:00 +02:00
|
|
|
color = params[3];
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (petData != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
RoomUnit roomUnit = gameClient.getHabbo().getRoomUnit();
|
|
|
|
roomUnit.setRoomUnitType(RoomUnitType.PET);
|
|
|
|
gameClient.getHabbo().getHabboStats().cache.put("pet_type", petData);
|
|
|
|
gameClient.getHabbo().getHabboStats().cache.put("pet_race", race);
|
|
|
|
gameClient.getHabbo().getHabboStats().cache.put("pet_color", color);
|
|
|
|
gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserRemoveComposer(gameClient.getHabbo().getRoomUnit()).compose());
|
|
|
|
gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserPetComposer(petData.getType(), race, color, gameClient.getHabbo()).compose());
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
//Pet Not Found
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|