2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
2018-09-28 21:25:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
2018-09-12 18:45:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.*;
|
2020-02-05 23:56:40 +01:00
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.habbohotel.users.HabboGender;
|
2018-09-28 21:25:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
|
2018-09-28 21:25:00 +02:00
|
|
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
|
2020-01-28 14:24:03 +01:00
|
|
|
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.util.pathfinding.Rotation;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2020-02-05 23:56:40 +01:00
|
|
|
import java.util.concurrent.ExecutionException;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2020-06-07 15:03:38 +02:00
|
|
|
public class InteractionVendingMachine extends InteractionDefault {
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionVendingMachine(ResultSet set, Item baseItem) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set, baseItem);
|
2018-12-22 11:39:00 +01:00
|
|
|
this.setExtradata("0");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionVendingMachine(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);
|
2018-12-22 11:39:00 +01:00
|
|
|
this.setExtradata("0");
|
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 (client != null) {
|
2020-02-06 00:16:51 +01:00
|
|
|
RoomTile tile = this.getRequiredTile(client.getHabbo(), room);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
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) {
|
2020-01-28 15:09:59 +01:00
|
|
|
if (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) && (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || tile.equals(client.getHabbo().getRoomUnit().getGoal()))) {
|
|
|
|
room.updateHabbo(client.getHabbo());
|
2020-02-05 23:56:40 +01:00
|
|
|
this.rotateToMachine(client.getHabbo().getRoomUnit());
|
2018-09-12 18:45:00 +02:00
|
|
|
client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
|
2018-07-06 15:30:00 +02:00
|
|
|
room.scheduledComposers.add(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
|
|
|
|
}
|
2020-02-05 23:56:40 +01:00
|
|
|
|
|
|
|
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"});
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
this.setExtradata("1");
|
|
|
|
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
|
2018-12-22 11:39:00 +01:00
|
|
|
|
2020-02-05 23:56:40 +01:00
|
|
|
Emulator.getThreading().run(() -> {
|
|
|
|
Emulator.getThreading().run(this, 1000);
|
|
|
|
this.giveVendingMachineItem(client.getHabbo(), room);
|
2020-01-27 21:38:41 +01:00
|
|
|
|
2020-02-05 23:56:40 +01:00
|
|
|
if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M)
|
|
|
|
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
|
|
|
|
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
|
|
|
|
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
|
|
|
|
}, 500);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
|
|
|
if (!tile.isWalkable() && tile.state != RoomTileState.SIT && tile.state != RoomTileState.LAY) {
|
|
|
|
for (RoomTile t : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) {
|
|
|
|
if (t != null && t.isWalkable()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
tile = t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-28 14:24:03 +01:00
|
|
|
|
2020-02-05 23:56:40 +01:00
|
|
|
RoomTile finalTile = tile;
|
2020-02-27 22:16:36 +01:00
|
|
|
client.getHabbo().getRoomUnit().setGoalLocation(tile);
|
|
|
|
|
|
|
|
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), tile, room, () -> {
|
2020-02-05 23:56:40 +01:00
|
|
|
this.setExtradata("1");
|
|
|
|
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
|
|
|
|
|
2020-01-28 14:24:03 +01:00
|
|
|
try {
|
2020-02-05 23:56:40 +01:00
|
|
|
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"});
|
2020-01-28 14:24:03 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2020-02-05 23:56:40 +01:00
|
|
|
|
|
|
|
Emulator.getThreading().run(() -> {
|
2020-02-27 22:16:36 +01:00
|
|
|
client.getHabbo().getRoomUnit().setMoveBlockingTask(Emulator.getThreading().run(() -> {
|
2020-02-05 23:56:40 +01:00
|
|
|
if (client.getHabbo().getRoomUnit().getCurrentLocation().equals(finalTile)) {
|
|
|
|
this.rotateToMachine(client.getHabbo().getRoomUnit());
|
|
|
|
room.sendComposer(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Emulator.getThreading().run(() -> {
|
|
|
|
Emulator.getThreading().run(this, 1000);
|
|
|
|
this.giveVendingMachineItem(client.getHabbo(), room);
|
|
|
|
|
|
|
|
if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M)
|
|
|
|
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
|
|
|
|
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
|
|
|
|
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
|
|
|
|
}, 500).get();
|
|
|
|
} catch (InterruptedException | ExecutionException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2020-02-27 22:16:36 +01:00
|
|
|
}, 300));
|
2020-02-05 23:56:40 +01:00
|
|
|
}, 250);
|
2020-02-27 22:16:36 +01:00
|
|
|
}, null));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void run() {
|
2018-07-06 15:30:00 +02:00
|
|
|
super.run();
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.getExtradata().equals("1")) {
|
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.updateItem(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 00:28:00 +02:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isUsable() {
|
2018-10-07 00:28:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-02-05 23:56:40 +01:00
|
|
|
|
|
|
|
private void rotateToMachine(RoomUnit unit) {
|
2020-06-07 14:49:26 +02:00
|
|
|
if (unit.getCurrentLocation().getState() != RoomTileState.OPEN) {
|
|
|
|
// if sitting on a chair or laying on a bed, skip rotating altogether
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-05 23:56:40 +01:00
|
|
|
RoomUserRotation rotation = RoomUserRotation.values()[Rotation.Calculate(unit.getX(), unit.getY(), this.getX(), this.getY())];
|
|
|
|
boolean onlyHead = false;
|
|
|
|
|
|
|
|
switch (unit.getBodyRotation()) {
|
|
|
|
case NORTH_EAST:
|
|
|
|
if (rotation.equals(RoomUserRotation.NORTH) || rotation.equals(RoomUserRotation.EAST))
|
|
|
|
onlyHead = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NORTH_WEST:
|
|
|
|
if (rotation.equals(RoomUserRotation.NORTH) || rotation.equals(RoomUserRotation.WEST))
|
|
|
|
onlyHead = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUTH_EAST:
|
|
|
|
if (rotation.equals(RoomUserRotation.SOUTH) || rotation.equals(RoomUserRotation.EAST))
|
|
|
|
onlyHead = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUTH_WEST:
|
|
|
|
if (rotation.equals(RoomUserRotation.SOUTH) || rotation.equals(RoomUserRotation.WEST))
|
|
|
|
onlyHead = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onlyHead) {
|
|
|
|
unit.setHeadRotation(rotation);
|
|
|
|
} else {
|
|
|
|
unit.setRotation(rotation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void giveVendingMachineItem(Habbo habbo, Room room) {
|
|
|
|
Emulator.getThreading().run(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.getBaseItem().getRandomVendingItem()));
|
|
|
|
}
|
2020-02-06 00:16:51 +01:00
|
|
|
|
|
|
|
public RoomTile getRequiredTile(Habbo habbo, Room room) {
|
|
|
|
return getSquareInFront(room.getLayout(), this);
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|