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

164 lines
6.7 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.Collection;
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) {
this.setExtradata("" + (Integer.parseInt(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length));
2018-07-06 15:30:00 +02:00
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
}
}
}
}
2018-07-06 15:30:00 +02:00
public void updateUnitsOnItem(Room room) {
2020-10-15 08:35:59 +02:00
THashSet<RoomTile> occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation());
2020-10-15 08:35:59 +02:00
for(RoomTile tile : occupiedTiles) {
Collection<RoomUnit> unitsOnItem = room.getRoomUnitsAt(room.getLayout().getTile(tile.x, tile.y));
2020-10-15 08:35:59 +02:00
THashSet<RoomUnit> updatedUnits = new THashSet<>();
for (RoomUnit unit : unitsOnItem) {
if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoal() != tile)
2020-10-15 08:35:59 +02:00
continue;
if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) {
unit.sitUpdate = true;
unit.statusUpdate(true);
} else {
unit.setZ(unit.getCurrentLocation().getStackHeight());
unit.setPreviousLocationZ(unit.getZ());
unit.statusUpdate(true);
}
2018-07-06 15:30:00 +02:00
}
}
2020-10-15 08:35:59 +02:00
//room.sendComposer(new RoomUserStatusComposer(updatedUnits, true).compose());
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) {
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;
}
}