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

158 lines
4.9 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.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.items.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class InteractionGymEquipment extends InteractionEffectTile implements ICycleable {
2018-12-22 11:39:00 +01:00
private int startTime = 0;
private int roomUnitId = -1;
2019-05-26 20:14:53 +02:00
public InteractionGymEquipment(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 InteractionGymEquipment(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 boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
2018-12-22 11:39:00 +01:00
return this.roomUnitId == -1 && super.canWalkOn(roomUnit, room, objects) && (roomUnit.getRoomUnitType().equals(RoomUnitType.USER) || roomUnit.getRoomUnitType().equals(RoomUnitType.BOT));
}
@Override
2019-05-26 20:14:53 +02:00
public boolean isWalkable() {
2018-12-22 11:39:00 +01:00
return this.roomUnitId == -1;
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-12-22 11:39:00 +01:00
super.onWalkOn(roomUnit, room, objects);
2019-05-26 20:14:53 +02:00
if (this.forceRotation()) {
2018-12-22 11:39:00 +01:00
roomUnit.setRotation(RoomUserRotation.fromValue(this.getRotation()));
roomUnit.canRotate = false;
}
this.roomUnitId = roomUnit.getId();
2019-05-26 20:14:53 +02:00
if (roomUnit.getRoomUnitType() == RoomUnitType.USER) {
2018-12-22 11:39:00 +01:00
Habbo habbo = room.getHabbo(roomUnit);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
2018-12-22 11:39:00 +01:00
this.startTime = Emulator.getIntUnixTimestamp();
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-12-22 11:39:00 +01:00
super.onWalkOff(roomUnit, room, objects);
2019-03-18 02:22:00 +01:00
room.giveEffect(roomUnit, 0, -1);
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
if (this.forceRotation()) {
2018-12-22 11:39:00 +01:00
roomUnit.canRotate = true;
}
this.reset(room);
}
2019-05-26 20:14:53 +02:00
public String achievementName() {
2018-12-22 11:39:00 +01:00
return Emulator.getConfig().getValue("hotel.furni.gym.achievement." + this.getBaseItem().getName(), "");
}
2019-05-26 20:14:53 +02:00
public boolean forceRotation() {
2018-12-22 11:39:00 +01:00
return Emulator.getConfig().getBoolean("hotel.furni.gym.forcerot." + this.getBaseItem().getName(), true);
}
@Override
2019-05-26 20:14:53 +02:00
public void cycle(Room room) {
if (this.roomUnitId != -1) {
2018-12-22 11:39:00 +01:00
Habbo habbo = room.getHabboByRoomUnitId(this.roomUnitId);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
2018-12-22 11:39:00 +01:00
int timestamp = Emulator.getIntUnixTimestamp();
2019-05-26 20:14:53 +02:00
if (timestamp - this.startTime >= 120) {
2019-03-18 02:22:00 +01:00
String achievement = this.achievementName();
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
if (!achievement.isEmpty()) {
2018-12-22 11:39:00 +01:00
AchievementManager.progressAchievement(habbo.getHabboInfo().getId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement(achievement));
}
this.startTime = timestamp;
}
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public void setRotation(int rotation) {
2018-12-22 11:39:00 +01:00
super.setRotation(rotation);
2019-05-26 20:14:53 +02:00
if (this.forceRotation() && this.roomUnitId != -1) {
2018-12-22 11:39:00 +01:00
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
2019-05-26 20:14:53 +02:00
if (room != null) {
2019-03-18 02:22:00 +01:00
RoomUnit roomUnit = this.getCurrentRoomUnit(room);
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
if (roomUnit != null) {
2018-12-22 11:39:00 +01:00
roomUnit.setRotation(RoomUserRotation.fromValue(rotation));
room.updateRoomUnit(roomUnit);
}
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public void onPickUp(Room room) {
2018-12-22 11:39:00 +01:00
super.onPickUp(room);
2019-05-26 20:14:53 +02:00
if (this.roomUnitId != -1) {
2018-12-22 11:39:00 +01:00
this.setEffect(room, 0);
}
this.reset(room);
}
@Override
2019-05-26 20:14:53 +02:00
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
2018-12-22 11:39:00 +01:00
super.onMove(room, oldLocation, newLocation);
2019-05-26 20:14:53 +02:00
if (!oldLocation.equals(newLocation)) {
2018-12-22 11:39:00 +01:00
this.setEffect(room, 0);
this.reset(room);
}
}
2019-05-26 20:14:53 +02:00
private void setEffect(Room room, int effectId) {
2018-12-22 11:39:00 +01:00
if (this.roomUnitId == -1) return;
2019-03-18 02:22:00 +01:00
room.giveEffect(this.getCurrentRoomUnit(room), effectId, -1);
2018-12-22 11:39:00 +01:00
}
2019-05-26 20:14:53 +02:00
private void reset(Room room) {
2018-12-22 11:39:00 +01:00
this.roomUnitId = -1;
this.startTime = 0;
this.setExtradata("0");
room.updateItem(this);
}
2019-05-26 20:14:53 +02:00
private RoomUnit getCurrentRoomUnit(Room room) {
2018-12-22 11:39:00 +01:00
Habbo habbo = room.getHabboByRoomUnitId(this.roomUnitId);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
2018-12-22 11:39:00 +01:00
return habbo.getRoomUnit();
2019-05-26 20:14:53 +02:00
} else {
2018-12-22 11:39:00 +01:00
Bot bot = room.getBotByRoomUnitId(this.roomUnitId);
2019-05-26 20:14:53 +02:00
if (bot != null) {
2018-12-22 11:39:00 +01:00
return bot.getRoomUnit();
}
}
return null;
}
}