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

158 lines
5.7 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions;
2019-05-12 12:26:40 +02:00
import com.eu.habbo.Emulator;
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.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;
2019-03-18 02:22:00 +01:00
import com.eu.habbo.messages.outgoing.rooms.items.ItemIntStateComposer;
2019-05-12 12:26:40 +02:00
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-12 12:26:40 +02:00
import java.util.ArrayList;
import java.util.List;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class InteractionOneWayGate extends HabboItem {
2019-05-12 12:26:40 +02:00
private boolean walkable = false;
2019-05-26 20:14:53 +02:00
public InteractionOneWayGate(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 InteractionOneWayGate(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 boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
2019-05-12 12:26:40 +02:00
return this.getBaseItem().allowWalk();
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public boolean isWalkable() {
2019-05-12 12:26:40 +02:00
return walkable;
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 serializeExtradata(ServerMessage serverMessage) {
if (this.getExtradata().length() == 0) {
2018-07-06 15:30:00 +02:00
this.setExtradata("0");
this.needsUpdate(true);
}
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage);
}
@Override
2019-05-26 20:14:53 +02:00
public void onClick(final GameClient client, final 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) {
2019-05-12 12:26:40 +02:00
RoomTile tileInfront = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation());
2019-05-26 20:14:53 +02:00
if (tileInfront == null)
2019-05-12 12:26:40 +02:00
return;
RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY());
2019-05-26 20:14:53 +02:00
if (currentLocation == null)
2019-05-12 12:26:40 +02:00
return;
RoomUnit unit = client.getHabbo().getRoomUnit();
2019-05-26 20:14:53 +02:00
if (unit == null)
2019-05-12 12:26:40 +02:00
return;
2018-07-06 15:30:00 +02:00
2019-05-12 12:26:40 +02:00
2019-05-26 20:14:53 +02:00
if (tileInfront.x == unit.getX() && tileInfront.y == unit.getY()) {
if (!currentLocation.hasUnits()) {
2019-05-12 12:26:40 +02:00
List<Runnable> onSuccess = new ArrayList<Runnable>();
List<Runnable> onFail = new ArrayList<Runnable>();
onSuccess.add(() -> {
unit.setCanLeaveRoomByDoor(false);
2019-05-12 12:26:40 +02:00
walkable = this.getBaseItem().allowWalk();
RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation() + 4);
unit.setGoalLocation(tile);
Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onFail, onFail));
2019-05-12 12:26:40 +02:00
});
onFail.add(() -> {
unit.setCanLeaveRoomByDoor(true);
2019-05-12 12:26:40 +02:00
walkable = this.getBaseItem().allowWalk();
room.updateTile(currentLocation);
room.sendComposer(new ItemIntStateComposer(this.getId(), 0).compose());
unit.removeOverrideTile(currentLocation);
});
walkable = true;
room.updateTile(currentLocation);
unit.addOverrideTile(currentLocation);
unit.setGoalLocation(currentLocation);
Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail));
room.sendComposer(new ItemIntStateComposer(this.getId(), 1).compose());
/*
2018-07-06 15:30:00 +02:00
room.scheduledTasks.add(new Runnable()
{
@Override
public void run()
{
2018-11-17 14:28:00 +01:00
gate.roomUnitID = client.getHabbo().getRoomUnit().getId();
2018-07-06 15:30:00 +02:00
room.updateTile(gatePosition);
2019-03-18 02:22:00 +01:00
client.getHabbo().getRoomUnit().setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(InteractionOneWayGate.this.getX(), InteractionOneWayGate.this.getY()), InteractionOneWayGate.this.getRotation() + 4));
2018-07-06 15:30:00 +02:00
}
});
2019-05-12 12:26:40 +02:00
*/
2018-07-06 15:30:00 +02:00
}
}
}
}
2019-05-26 20:14:53 +02:00
private void refresh(Room room) {
2019-03-18 02:22:00 +01:00
this.setExtradata("0");
room.sendComposer(new ItemIntStateComposer(this.getId(), 0).compose());
2018-07-06 15:30:00 +02:00
room.updateTile(room.getLayout().getTile(this.getX(), this.getY()));
}
2019-05-12 12:26:40 +02:00
2018-07-06 15:30:00 +02:00
@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");
2019-03-18 02:22:00 +01:00
this.refresh(room);
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);
}
@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-03-18 02:22:00 +01:00
this.refresh(room);
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onPlace(Room room) {
2018-07-06 15:30:00 +02:00
super.onPlace(room);
2019-03-18 02:22:00 +01:00
this.refresh(room);
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
2018-07-06 15:30:00 +02:00
super.onMove(room, oldLocation, newLocation);
2019-03-18 02:22:00 +01:00
this.refresh(room);
2018-07-06 15:30:00 +02:00
}
}