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

54 lines
2.0 KiB
Java
Raw Normal View History

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;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomLayout;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class InteractionHanditem extends InteractionDefault {
public InteractionHanditem(ResultSet set, Item baseItem) throws SQLException {
2018-12-22 11:39:00 +01:00
super(set, baseItem);
}
2019-05-26 20:14:53 +02:00
public InteractionHanditem(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);
}
@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);
if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentLocation(), room.getLayout().getTile(this.getX(), this.getY())) ||
2019-05-26 20:14:53 +02:00
(client.getHabbo().getRoomUnit().getCurrentLocation().x == this.getX() && client.getHabbo().getRoomUnit().getCurrentLocation().y == this.getY())) {
2018-12-22 11:39:00 +01:00
this.handle(room, client.getHabbo().getRoomUnit());
}
}
2019-05-26 20:14:53 +02:00
protected void handle(Room room, RoomUnit roomUnit) {
2018-12-22 11:39:00 +01:00
if (this.getExtradata().isEmpty()) this.setExtradata("0");
if (!this.getExtradata().equals("0")) return;
HabboItem instance = this;
room.giveHandItem(roomUnit, this.getBaseItem().getRandomVendingItem());
2019-05-26 20:14:53 +02:00
if (this.getBaseItem().getStateCount() > 1) {
2018-12-22 11:39:00 +01:00
this.setExtradata("1");
room.updateItem(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
InteractionHanditem.this.setExtradata("0");
2018-12-22 11:39:00 +01:00
room.updateItem(instance);
}
}, 500);
}
}
}