2018-12-22 11:39:00 +01: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;
|
2020-02-05 19:17:54 +01:00
|
|
|
import com.eu.habbo.habbohotel.rooms.*;
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
|
|
|
import com.eu.habbo.threading.runnables.RoomUnitVendingMachineAction;
|
2020-02-05 19:17:54 +01:00
|
|
|
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.util.pathfinding.Rotation;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2020-02-05 19:17:54 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2018-12-22 11:39:00 +01:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class InteractionEffectVendingMachine extends InteractionDefault {
|
|
|
|
public InteractionEffectVendingMachine(ResultSet set, Item baseItem) throws SQLException {
|
2018-12-22 11:39:00 +01:00
|
|
|
super(set, baseItem);
|
|
|
|
this.setExtradata("0");
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionEffectVendingMachine(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
|
2018-12-22 11:39:00 +01:00
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
|
|
|
this.setExtradata("0");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
|
2018-12-22 11:39:00 +01:00
|
|
|
super.onClick(client, room, objects);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (client != null) {
|
2018-12-22 11:39:00 +01:00
|
|
|
RoomTile tile = getSquareInFront(room.getLayout(), this);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (tile != null) {
|
|
|
|
if (tile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) {
|
|
|
|
if (this.getExtradata().equals("0") || this.getExtradata().length() == 0) {
|
2018-12-22 11:39:00 +01:00
|
|
|
room.updateHabbo(client.getHabbo());
|
2019-05-26 20:14:53 +02:00
|
|
|
if (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT)) {
|
2018-12-22 11:39:00 +01:00
|
|
|
client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[Rotation.Calculate(client.getHabbo().getRoomUnit().getX(), client.getHabbo().getRoomUnit().getY(), this.getX(), this.getY())]);
|
|
|
|
client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
|
|
|
|
room.scheduledComposers.add(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
|
|
|
|
}
|
|
|
|
this.setExtradata("1");
|
|
|
|
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
|
|
|
|
Emulator.getThreading().run(this, 1000);
|
|
|
|
HabboItem instance = this;
|
2019-05-26 20:14:53 +02:00
|
|
|
Emulator.getThreading().run(new Runnable() {
|
2018-12-22 11:39:00 +01:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void run() {
|
2019-03-18 02:22:00 +01:00
|
|
|
room.giveEffect(client.getHabbo().getRoomUnit(), instance.getBaseItem().getRandomVendingItem(), 30);
|
2018-12-22 11:39:00 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2020-02-05 19:17:54 +01:00
|
|
|
if (!tile.isWalkable() && tile.state != RoomTileState.SIT && tile.state != RoomTileState.LAY) {
|
2019-05-26 20:14:53 +02:00
|
|
|
for (RoomTile t : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) {
|
|
|
|
if (t != null && t.isWalkable()) {
|
2018-12-22 11:39:00 +01:00
|
|
|
tile = t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-05 19:17:54 +01:00
|
|
|
|
|
|
|
List<Runnable> onSuccess = new ArrayList<>();
|
|
|
|
List<Runnable> onFail = new ArrayList<>();
|
|
|
|
|
|
|
|
onSuccess.add(() -> Emulator.getThreading().run(() -> {
|
|
|
|
try {
|
|
|
|
this.onClick(client, room, objects);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}, 500));
|
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
client.getHabbo().getRoomUnit().setGoalLocation(tile);
|
2020-02-05 19:17:54 +01:00
|
|
|
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), tile, room, onSuccess, onFail));
|
2018-12-22 11:39:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|