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

174 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
public class InteractionOneWayGate extends HabboItem
{
2019-05-12 12:26:40 +02:00
private boolean walkable = false;
2018-07-06 15:30:00 +02:00
public InteractionOneWayGate(ResultSet set, Item baseItem) throws SQLException
{
super(set, baseItem);
}
public InteractionOneWayGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
{
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
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
public boolean isWalkable()
{
2019-05-12 12:26:40 +02:00
return walkable;
2018-07-06 15:30:00 +02:00
}
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception
{
}
@Override
public void serializeExtradata(ServerMessage serverMessage)
{
if(this.getExtradata().length() == 0)
{
this.setExtradata("0");
this.needsUpdate(true);
}
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage);
}
@Override
public void onClick(final GameClient client, final Room room, Object[] objects) throws Exception
{
super.onClick(client, room, objects);
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());
if(tileInfront == null)
return;
RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY());
if(currentLocation == null)
return;
RoomUnit unit = client.getHabbo().getRoomUnit();
if(unit == null)
return;
2018-07-06 15:30:00 +02:00
2019-05-12 12:26:40 +02:00
if (tileInfront.x == unit.getX() && tileInfront.y == unit.getY())
2018-07-06 15:30:00 +02:00
{
2019-05-12 12:26:40 +02:00
if(!currentLocation.hasUnits())
2018-07-06 15:30:00 +02:00
{
2019-05-12 12:26:40 +02:00
List<Runnable> onSuccess = new ArrayList<Runnable>();
List<Runnable> onFail = new ArrayList<Runnable>();
onSuccess.add(() -> {
walkable = this.getBaseItem().allowWalk();
room.updateTile(currentLocation);
room.sendComposer(new ItemIntStateComposer(this.getId(), 0).compose());
unit.removeOverrideTile(currentLocation);
unit.setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation() + 4));
});
onFail.add(() -> {
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
}
}
}
}
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
public void onPickUp(Room room)
{
this.setExtradata("0");
2019-03-18 02:22:00 +01:00
this.refresh(room);
2018-07-06 15:30:00 +02:00
}
@Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception
{
super.onWalkOn(roomUnit, room, objects);
}
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception
{
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
public void onPlace(Room room)
{
super.onPlace(room);
2019-03-18 02:22:00 +01:00
this.refresh(room);
2018-07-06 15:30:00 +02:00
}
@Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation)
{
super.onMove(room, oldLocation, newLocation);
2019-03-18 02:22:00 +01:00
this.refresh(room);
2018-07-06 15:30:00 +02:00
}
}