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.*;
|
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;
|
|
|
|
import com.eu.habbo.threading.runnables.RoomUnitVendingMachineAction;
|
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-01-28 14:24:03 +01: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 InteractionVendingMachine extends HabboItem {
|
|
|
|
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 boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isWalkable() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2018-07-06 15:30:00 +02: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) {
|
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());
|
2018-07-06 15:30:00 +02:00
|
|
|
client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[Rotation.Calculate(client.getHabbo().getRoomUnit().getX(), client.getHabbo().getRoomUnit().getY(), this.getX(), this.getY())]);
|
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());
|
|
|
|
}
|
|
|
|
this.setExtradata("1");
|
|
|
|
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
|
|
|
|
Emulator.getThreading().run(this, 1000);
|
|
|
|
Emulator.getThreading().run(new RoomUnitGiveHanditem(client.getHabbo().getRoomUnit(), room, this.getBaseItem().getRandomVendingItem()));
|
2018-12-22 11:39:00 +01:00
|
|
|
|
2019-05-26 20:14:53 +02: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);
|
2020-01-27 21:38:41 +01:00
|
|
|
|
|
|
|
super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"});
|
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
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2020-02-05 19:17:54 +01:00
|
|
|
}, 500));
|
2020-01-28 14:24:03 +01:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
client.getHabbo().getRoomUnit().setGoalLocation(tile);
|
2020-01-28 14:24:03 +01:00
|
|
|
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), tile, room, onSuccess, onFail));
|
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 onWalkOn(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 onWalkOff(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 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void serializeExtradata(ServerMessage serverMessage) {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt((this.isLimited() ? 256 : 0));
|
|
|
|
serverMessage.appendString(this.getExtradata());
|
|
|
|
|
|
|
|
super.serializeExtradata(serverMessage);
|
|
|
|
}
|
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;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|