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

155 lines
5.3 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02: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.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
2019-07-30 12:45:39 +02:00
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreClearType;
2020-05-04 22:24:09 +02:00
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreRow;
2019-07-30 12:45:39 +02:00
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreScoreType;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.ServerMessage;
2020-05-04 22:24:09 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet;
import java.sql.SQLException;
2019-07-30 12:45:39 +02:00
import java.util.List;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class InteractionWiredHighscore extends HabboItem {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(InteractionWiredHighscore.class);
2018-07-06 15:30:00 +02:00
public WiredHighscoreScoreType scoreType;
public WiredHighscoreClearType clearType;
2019-07-30 12:45:39 +02:00
private List<WiredHighscoreRow> data;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public InteractionWiredHighscore(ResultSet set, Item baseItem) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, baseItem);
this.scoreType = WiredHighscoreScoreType.CLASSIC;
this.clearType = WiredHighscoreClearType.ALLTIME;
2019-05-26 20:14:53 +02:00
try {
2018-07-06 15:30:00 +02:00
String name = this.getBaseItem().getName().split("_")[1].toUpperCase().split("\\*")[0];
int ctype = Integer.valueOf(this.getBaseItem().getName().split("\\*")[1]) - 1;
this.scoreType = WiredHighscoreScoreType.valueOf(name);
this.clearType = WiredHighscoreClearType.values()[ctype];
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught exception", e);
2018-07-06 15:30:00 +02:00
}
2019-07-30 12:45:39 +02:00
this.reloadData();
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public InteractionWiredHighscore(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);
this.scoreType = WiredHighscoreScoreType.CLASSIC;
this.clearType = WiredHighscoreClearType.ALLTIME;
2019-05-26 20:14:53 +02:00
try {
2018-07-06 15:30:00 +02:00
String name = this.getBaseItem().getName().split("_")[1].toUpperCase().split("\\*")[0];
int ctype = Integer.valueOf(this.getBaseItem().getName().split("\\*")[1]) - 1;
this.scoreType = WiredHighscoreScoreType.valueOf(name);
this.clearType = WiredHighscoreClearType.values()[ctype];
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught exception", e);
2018-07-06 15:30:00 +02:00
}
2019-07-30 12:45:39 +02:00
this.reloadData();
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 true;
}
@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 onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (!((client != null && room != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType)))
return;
2019-05-26 20:14:53 +02:00
if (this.getExtradata() == null || this.getExtradata().isEmpty() || this.getExtradata().length() == 0) {
2018-07-06 15:30:00 +02:00
this.setExtradata("0");
}
2019-05-26 20:14:53 +02:00
try {
2018-07-06 15:30:00 +02:00
int state = Integer.valueOf(this.getExtradata());
this.setExtradata(Math.abs(state - 1) + "");
room.updateItem(this);
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught exception", e);
2018-07-06 15:30:00 +02:00
}
if(client != null && !(objects.length >= 2 && objects[1] instanceof WiredEffectType)) {
WiredHandler.handle(WiredTriggerType.STATE_CHANGED, client.getHabbo().getRoomUnit(), room, new Object[]{this});
}
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void serializeExtradata(ServerMessage serverMessage) {
2018-07-06 15:30:00 +02:00
serverMessage.appendInt(6);
serverMessage.appendString(this.getExtradata());
2019-07-30 12:45:39 +02:00
serverMessage.appendInt(this.scoreType.type);
serverMessage.appendInt(this.clearType.type);
2018-07-06 15:30:00 +02:00
2019-07-30 12:45:39 +02:00
if (this.data != null) {
int size = this.data.size();
if(size > 50) {
size = 50;
}
serverMessage.appendInt(size);
2018-07-06 15:30:00 +02:00
int count = 0;
2019-07-30 12:45:39 +02:00
for (WiredHighscoreRow row : this.data) {
if(count < 50) {
serverMessage.appendInt(row.getValue());
2018-07-06 15:30:00 +02:00
serverMessage.appendInt(row.getUsers().size());
for (String username : row.getUsers()) {
serverMessage.appendString(username);
}
2018-07-06 15:30:00 +02:00
}
count++;
2018-07-06 15:30:00 +02:00
}
2019-07-30 12:45:39 +02:00
} else {
serverMessage.appendInt(0);
2018-07-06 15:30:00 +02:00
}
super.serializeExtradata(serverMessage);
}
@Override
2019-05-26 20:14:53 +02:00
public void onPlace(Room room) {
2019-07-30 12:45:39 +02:00
this.reloadData();
2019-05-26 21:33:51 +02:00
super.onPlace(room);
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onPickUp(Room room) {
if (this.data != null) {
2018-07-06 15:30:00 +02:00
this.data.clear();
}
}
2019-07-30 12:45:39 +02:00
public void reloadData() {
this.data = Emulator.getGameEnvironment().getItemManager().getHighscoreManager().getHighscoreRowsForItem(this.getId(), this.clearType, this.scoreType);
2018-07-06 15:30:00 +02:00
}
}