Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagField.java

82 lines
2.5 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions.games.tag;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.tag.TagGame;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public abstract class InteractionTagField extends HabboItem {
2018-07-06 15:30:00 +02:00
public Class<? extends Game> gameClazz;
2019-05-26 20:14:53 +02:00
public InteractionTagField(ResultSet set, Item baseItem, Class<? extends Game> gameClazz) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, baseItem);
this.gameClazz = gameClazz;
}
2019-05-26 20:14:53 +02:00
public InteractionTagField(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, Class<? extends Game> gameClazz) {
2018-07-06 15:30:00 +02:00
super(id, userId, item, extradata, limitedStack, limitedSells);
this.gameClazz = gameClazz;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
2018-07-06 15:30:00 +02:00
Habbo habbo = room.getHabbo(roomUnit);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
2018-07-06 15:30:00 +02:00
return habbo.getHabboInfo().getCurrentGame() == null || habbo.getHabboInfo().getCurrentGame() == this.gameClazz;
}
2019-05-26 20:14:53 +02:00
return false;
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public boolean isWalkable() {
2018-07-06 15:30:00 +02:00
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
Habbo habbo = room.getHabbo(roomUnit);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
if (habbo.getHabboInfo().getCurrentGame() == null) {
2018-07-06 15:30:00 +02:00
TagGame game = (TagGame) room.getGame(this.gameClazz);
2019-05-26 20:14:53 +02:00
if (game == null) {
2018-07-06 15:30:00 +02:00
game = (TagGame) this.gameClazz.getDeclaredConstructor(Room.class).newInstance(room);
room.addGame(game);
}
game.addHabbo(habbo, null);
habbo.getHabboInfo().setCurrentGame(this.gameClazz);
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void serializeExtradata(ServerMessage serverMessage) {
2018-07-06 15:30:00 +02:00
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage);
}
}