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

53 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 InteractionEffectGiver extends InteractionDefault {
public InteractionEffectGiver(ResultSet set, Item baseItem) throws SQLException {
2018-12-22 11:39:00 +01:00
super(set, baseItem);
this.setExtradata("0");
2018-12-22 11:39:00 +01:00
}
2019-05-26 20:14:53 +02:00
public InteractionEffectGiver(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");
2018-12-22 11:39:00 +01:00
}
@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;
2019-03-18 02:22:00 +01:00
room.giveEffect(roomUnit, this.getBaseItem().getRandomVendingItem(), -1);
2018-12-22 11:39:00 +01:00
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);
2020-04-23 19:08:37 +02:00
Emulator.getThreading().run(() -> {
InteractionEffectGiver.this.setExtradata("0");
room.updateItem(instance);
2018-12-22 11:39:00 +01:00
}, 500);
}
}
}