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;
|
2019-03-18 02:22:00 +01:00
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomTileState;
|
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 com.eu.habbo.messages.outgoing.rooms.items.ItemIntStateComposer;
|
2019-05-04 11:22:20 +02:00
|
|
|
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.threading.runnables.teleport.TeleportActionOne;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2019-05-04 11:22:20 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
public class InteractionTeleport extends HabboItem
|
|
|
|
{
|
|
|
|
private int targetId;
|
|
|
|
private int targetRoomId;
|
2019-05-04 11:22:20 +02:00
|
|
|
private int roomUnitID = -1;
|
|
|
|
private boolean walkable = false;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
public InteractionTeleport(ResultSet set, Item baseItem) throws SQLException
|
|
|
|
{
|
|
|
|
super(set, baseItem);
|
2019-05-04 11:22:20 +02:00
|
|
|
walkable = baseItem.allowWalk();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public InteractionTeleport(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
|
|
|
|
{
|
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
2019-05-04 11:22:20 +02:00
|
|
|
walkable = item.allowWalk();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void serializeExtradata(ServerMessage serverMessage)
|
|
|
|
{
|
|
|
|
serverMessage.appendInt((this.isLimited() ? 256 : 0));
|
|
|
|
serverMessage.appendString(this.getExtradata());
|
|
|
|
|
|
|
|
super.serializeExtradata(serverMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
return this.getBaseItem().allowWalk() || roomUnit.getId() == this.roomUnitID;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-04 11:22:20 +02:00
|
|
|
public boolean isWalkable() {
|
|
|
|
return walkable;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-04 11:22:20 +02:00
|
|
|
private void tryTeleport(GameClient client, Room room) {
|
|
|
|
/*
|
|
|
|
if user is on item, startTeleport
|
|
|
|
else if user is on infront, set state 1 and walk on item
|
|
|
|
else move to infront and interact
|
|
|
|
*/
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-04 11:22:20 +02:00
|
|
|
Habbo habbo = client.getHabbo();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-04 11:22:20 +02:00
|
|
|
if(habbo == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RoomUnit unit = habbo.getRoomUnit();
|
|
|
|
|
|
|
|
if(unit == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY());
|
|
|
|
|
|
|
|
if(currentLocation == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RoomTile infrontTile = room.getLayout().getTileInFront(currentLocation, this.getRotation());
|
|
|
|
|
|
|
|
if(!canUseTeleport(client, room))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(this.roomUnitID == unit.getId() && unit.getCurrentLocation().equals(currentLocation)) {
|
|
|
|
startTeleport(room, habbo);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2019-05-04 11:22:20 +02:00
|
|
|
else if(unit.getCurrentLocation().equals(currentLocation) || unit.getCurrentLocation().equals(infrontTile)) {
|
|
|
|
// set state 1 and walk on item
|
|
|
|
this.roomUnitID = unit.getId();
|
|
|
|
this.setExtradata("1");
|
|
|
|
room.updateItem(this);
|
|
|
|
unit.setGoalLocation(infrontTile);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-04 11:22:20 +02:00
|
|
|
List<Runnable> onSuccess = new ArrayList<Runnable>();
|
|
|
|
List<Runnable> onFail = new ArrayList<Runnable>();
|
|
|
|
|
|
|
|
onSuccess.add(() -> {
|
|
|
|
walkable = this.getBaseItem().allowWalk();
|
|
|
|
room.updateTile(currentLocation);
|
|
|
|
tryTeleport(client, room);
|
2019-05-12 09:59:01 +02:00
|
|
|
unit.removeOverrideTile(currentLocation);
|
2019-05-04 11:22:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
onFail.add(() -> {
|
|
|
|
walkable = this.getBaseItem().allowWalk();
|
|
|
|
room.updateTile(currentLocation);
|
|
|
|
this.setExtradata("0");
|
|
|
|
room.updateItem(this);
|
|
|
|
this.roomUnitID = -1;
|
2019-05-12 09:59:01 +02:00
|
|
|
unit.removeOverrideTile(currentLocation);
|
2019-05-04 11:22:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
walkable = true;
|
|
|
|
room.updateTile(currentLocation);
|
2019-05-12 09:59:01 +02:00
|
|
|
unit.addOverrideTile(currentLocation);
|
2019-05-04 11:22:20 +02:00
|
|
|
unit.setGoalLocation(currentLocation);
|
|
|
|
Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// walk to teleport and interact
|
|
|
|
List<Runnable> onSuccess = new ArrayList<Runnable>();
|
|
|
|
List<Runnable> onFail = new ArrayList<Runnable>();
|
|
|
|
|
|
|
|
onSuccess.add(() -> {
|
|
|
|
tryTeleport(client, room);
|
|
|
|
});
|
|
|
|
|
|
|
|
unit.setGoalLocation(infrontTile);
|
|
|
|
Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, infrontTile, room, onSuccess, onFail));
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-04 11:22:20 +02:00
|
|
|
public void onClick(GameClient client, Room room, Object[] objects) throws Exception
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-05-04 11:22:20 +02:00
|
|
|
super.onClick(client, room, objects);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-04 11:22:20 +02:00
|
|
|
if(room != null && client != null && objects.length <= 1)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-05-04 11:22:20 +02:00
|
|
|
tryTeleport(client, room);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-04 11:22:20 +02:00
|
|
|
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
if(!this.getExtradata().equals("0"))
|
|
|
|
{
|
|
|
|
this.setExtradata("0");
|
|
|
|
|
|
|
|
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
|
|
|
if(room != null)
|
|
|
|
{
|
|
|
|
room.updateItem(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickUp(Room room)
|
|
|
|
{
|
|
|
|
this.targetId = 0;
|
|
|
|
this.targetRoomId = 0;
|
2019-05-04 11:22:20 +02:00
|
|
|
this.roomUnitID = -1;
|
2018-07-06 15:30:00 +02:00
|
|
|
this.setExtradata("0");
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTargetId()
|
|
|
|
{
|
|
|
|
return this.targetId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTargetId(int targetId)
|
|
|
|
{
|
|
|
|
this.targetId = targetId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTargetRoomId()
|
|
|
|
{
|
|
|
|
return this.targetRoomId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTargetRoomId(int targetRoomId)
|
|
|
|
{
|
|
|
|
this.targetRoomId = targetRoomId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean allowWiredResetState()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-04 11:22:20 +02:00
|
|
|
public boolean canUseTeleport(GameClient client, Room room) {
|
|
|
|
|
|
|
|
Habbo habbo = client.getHabbo();
|
|
|
|
|
|
|
|
if(habbo == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RoomUnit unit = habbo.getRoomUnit();
|
|
|
|
|
|
|
|
if(unit == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(habbo.getHabboInfo().getRiding() != null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return this.roomUnitID == -1 || this.roomUnitID == unit.getId();
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
public void startTeleport(Room room, Habbo habbo)
|
|
|
|
{
|
2019-05-04 11:22:20 +02:00
|
|
|
if(habbo.getRoomUnit().isTeleporting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.roomUnitID = -1;
|
|
|
|
habbo.getRoomUnit().isTeleporting = true;
|
|
|
|
room.scheduledTasks.add(new TeleportActionOne(this, room, habbo.getClient()));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2018-10-07 00:28:00 +02:00
|
|
|
@Override
|
|
|
|
public boolean isUsable()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|