2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import com.eu.habbo.threading.runnables.hopper.HopperActionOne;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class InteractionHopper extends HabboItem {
|
|
|
|
public InteractionHopper(ResultSet set, Item baseItem) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set, baseItem);
|
2019-05-24 12:51:41 +02:00
|
|
|
this.setExtradata("0");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionHopper(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-24 12:51:41 +02:00
|
|
|
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 false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isWalkable() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 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 (room != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
RoomTile loc = HabboItem.getSquareInFront(room.getLayout(), this);
|
2019-05-26 20:14:53 +02:00
|
|
|
if (loc != null) {
|
|
|
|
if (this.canUseTeleport(client, loc, room)) {
|
2018-07-06 15:30:00 +02:00
|
|
|
client.getHabbo().getRoomUnit().isTeleporting = true;
|
|
|
|
this.setExtradata("1");
|
|
|
|
room.updateItemState(this);
|
|
|
|
|
|
|
|
Emulator.getThreading().run(new HopperActionOne(this, room, client), 500);
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
client.getHabbo().getRoomUnit().setGoalLocation(loc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPickUp(Room room) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.setExtradata("0");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void run() {
|
|
|
|
if (!this.getExtradata().equals("0")) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.setExtradata("0");
|
|
|
|
|
|
|
|
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
2019-05-26 20:14:53 +02:00
|
|
|
if (room != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
room.updateItemState(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.run();
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
protected boolean canUseTeleport(GameClient client, RoomTile front, Room room) {
|
|
|
|
if (client.getHabbo().getRoomUnit().getX() != front.x)
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (client.getHabbo().getRoomUnit().getY() != front.y)
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (client.getHabbo().getRoomUnit().isTeleporting)
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (!room.getHabbosAt(this.getX(), this.getY()).isEmpty())
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
return this.getExtradata().equals("0");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|