Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java

163 lines
6.9 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.habbohotel.bots.Bot;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.*;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class InteractionMultiHeight extends HabboItem {
public InteractionMultiHeight(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);
}
2019-05-26 20:14:53 +02:00
public InteractionMultiHeight(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
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-11-17 14:28:00 +01:00
return this.getBaseItem().allowWalk();
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
super.onClick(client, room, objects);
2019-05-26 20:14:53 +02:00
if (client != null) {
2018-07-06 15:30:00 +02:00
if (!room.hasRights(client.getHabbo()) && !(objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE))
return;
}
2019-05-26 20:14:53 +02:00
if (objects.length > 0) {
if (objects[0] instanceof Integer && room != null) {
HabboItem topItem = room.getTopItemAt(this.getX(), this.getY());
if (topItem != null && !topItem.equals(this)) { // multiheight items cannot change height even if there is a stackable item on top - no items allowed on top
return;
}
2018-07-06 15:30:00 +02:00
this.needsUpdate(true);
2019-05-26 20:14:53 +02:00
if (this.getExtradata().length() == 0)
2018-07-06 15:30:00 +02:00
this.setExtradata("0");
2019-05-26 20:14:53 +02:00
if (this.getBaseItem().getMultiHeights().length > 0) {
2018-07-06 15:30:00 +02:00
this.setExtradata("" + (Integer.valueOf(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length));
this.needsUpdate(true);
2018-10-07 00:28:00 +02:00
room.updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()));
2018-07-06 15:30:00 +02:00
room.updateItemState(this);
2018-12-22 11:39:00 +01:00
//room.sendComposer(new UpdateStackHeightComposer(this.getX(), this.getY(), this.getBaseItem().getMultiHeights()[Integer.valueOf(this.getExtradata())] * 256.0D).compose());
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
if (this.isWalkable()) {
List<RoomUnit> unitsOnItem = new ArrayList<>();
unitsOnItem.addAll(room.getHabbosOnItem(this).stream().map(Habbo::getRoomUnit).filter(Objects::nonNull).collect(Collectors.toList()));
unitsOnItem.addAll(room.getBotsOnItem(this).stream().map(Bot::getRoomUnit).filter(Objects::nonNull).collect(Collectors.toList()));
2018-07-06 15:30:00 +02:00
THashSet<RoomUnit> updatedUnits = new THashSet<>();
for (RoomUnit unit : unitsOnItem) {
if (unit.hasStatus(RoomUnitStatus.MOVE))
2018-07-06 15:30:00 +02:00
continue;
2019-05-26 20:14:53 +02:00
if (this.getBaseItem().getMultiHeights().length >= 0) {
if (this.getBaseItem().allowSit()) {
unit.setStatus(RoomUnitStatus.SIT, this.getBaseItem().getMultiHeights()[(this.getExtradata().isEmpty() ? 0 : Integer.valueOf(this.getExtradata()) % (this.getBaseItem().getMultiHeights().length))] * 1.0D + "");
2019-05-26 20:14:53 +02:00
} else {
unit.setZ(unit.getCurrentLocation().getStackHeight());
unit.setPreviousLocationZ(unit.getZ());
2018-07-06 15:30:00 +02:00
}
}
updatedUnits.add(unit);
2018-07-06 15:30:00 +02:00
}
2018-07-06 15:30:00 +02:00
room.sendComposer(new RoomUserStatusComposer(updatedUnits, true).compose());
}
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) {
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 (roomUnit != null) {
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) {
if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) {
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().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) {
2019-03-18 02:22:00 +01:00
room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1);
2018-07-06 15:30:00 +02:00
return;
}
2019-05-26 20:14:53 +02:00
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) {
2019-03-18 02:22:00 +01:00
room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1);
2018-07-06 15:30:00 +02:00
}
}
}
}
}
}
@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
super.onWalkOff(roomUnit, room, objects);
2019-05-26 20:14:53 +02:00
if (roomUnit != null) {
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) {
if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) {
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().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) {
2019-03-18 02:22:00 +01:00
room.giveEffect(habbo, 0, -1);
2018-07-06 15:30:00 +02:00
return;
}
2019-05-26 20:14:53 +02:00
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) {
2019-03-18 02:22:00 +01:00
room.giveEffect(habbo, 0, -1);
2018-07-06 15:30:00 +02:00
}
}
}
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public boolean allowWiredResetState() {
2018-07-06 15:30:00 +02:00
return true;
}
}