Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTile.java

103 lines
3.1 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai;
2019-03-18 02:22:00 +01:00
import com.eu.habbo.habbohotel.games.GameState;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
2019-03-18 02:22:00 +01:00
import com.eu.habbo.habbohotel.rooms.RoomTile;
2018-07-06 15:30:00 +02:00
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;
2019-03-18 02:22:00 +01:00
import gnu.trove.set.hash.THashSet;
import org.apache.commons.math3.util.Pair;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet;
import java.sql.SQLException;
2019-03-18 02:22:00 +01:00
import java.util.List;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class InteractionBattleBanzaiTile extends HabboItem {
public InteractionBattleBanzaiTile(ResultSet set, Item baseItem) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, baseItem);
this.setExtradata("0");
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public InteractionBattleBanzaiTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
2018-07-06 15:30:00 +02:00
super(id, userId, item, extradata, limitedStack, limitedSells);
this.setExtradata("0");
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);
}
@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
return true;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean isWalkable() {
2018-12-22 11:39:00 +01:00
return true;
2018-07-06 15:30:00 +02:00
}
@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
super.onWalkOn(roomUnit, room, objects);
2019-05-26 20:14:53 +02:00
if (this.getExtradata().isEmpty())
2018-07-06 15:30:00 +02:00
this.setExtradata("0");
int state = Integer.valueOf(this.getExtradata());
2019-05-26 20:14:53 +02:00
if (state % 3 == 2)
2018-07-06 15:30:00 +02:00
return;
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;
2019-05-26 20:14:53 +02:00
if (this.isLocked())
2018-07-06 15:30:00 +02:00
return;
2019-05-26 20:14:53 +02:00
if (habbo.getHabboInfo().getCurrentGame() != null && habbo.getHabboInfo().getCurrentGame().equals(BattleBanzaiGame.class)) {
BattleBanzaiGame game = ((BattleBanzaiGame) room.getGame(BattleBanzaiGame.class));
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if (game == null)
2018-07-06 15:30:00 +02:00
return;
2019-05-26 20:14:53 +02:00
if (!game.state.equals(GameState.RUNNING))
2018-07-06 15:30:00 +02:00
return;
2019-03-18 02:22:00 +01:00
game.markTile(habbo, this, state);
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
public boolean isLocked() {
if (this.getExtradata().isEmpty())
2018-07-06 15:30:00 +02:00
return false;
return Integer.valueOf(this.getExtradata()) % 3 == 2;
}
2019-03-18 02:22:00 +01:00
@Override
2019-05-26 20:14:53 +02:00
public boolean canStackAt(Room room, List<Pair<RoomTile, THashSet<HabboItem>>> itemsAtLocation) {
for (Pair<RoomTile, THashSet<HabboItem>> set : itemsAtLocation) {
2019-03-18 02:22:00 +01:00
if (set.getValue() != null && !set.getValue().isEmpty()) return false;
}
return super.canStackAt(room, itemsAtLocation);
}
2018-07-06 15:30:00 +02:00
}