Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java
2019-07-30 13:45:39 +03:00

133 lines
4.3 KiB
Java

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.wired.highscores.WiredHighscoreRow;
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.highscores.WiredHighscoreClearType;
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreScoreType;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
public class InteractionWiredHighscore extends HabboItem {
public WiredHighscoreScoreType scoreType;
public WiredHighscoreClearType clearType;
private List<WiredHighscoreRow> data;
public InteractionWiredHighscore(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.scoreType = WiredHighscoreScoreType.CLASSIC;
this.clearType = WiredHighscoreClearType.ALLTIME;
try {
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];
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
this.reloadData();
}
public InteractionWiredHighscore(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.scoreType = WiredHighscoreScoreType.CLASSIC;
this.clearType = WiredHighscoreClearType.ALLTIME;
try {
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];
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
this.reloadData();
}
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
return true;
}
@Override
public boolean isWalkable() {
return true;
}
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (this.getExtradata() == null || this.getExtradata().isEmpty() || this.getExtradata().length() == 0) {
this.setExtradata("0");
}
try {
int state = Integer.valueOf(this.getExtradata());
this.setExtradata(Math.abs(state - 1) + "");
room.updateItem(this);
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
}
@Override
public void serializeExtradata(ServerMessage serverMessage) {
serverMessage.appendInt(6);
serverMessage.appendString(this.getExtradata());
serverMessage.appendInt(this.scoreType.type);
serverMessage.appendInt(this.clearType.type);
if (this.data != null) {
serverMessage.appendInt(this.data.size());
for (WiredHighscoreRow row : this.data) {
serverMessage.appendInt(row.getValue());
serverMessage.appendInt(row.getUsers().size());
for (String username : row.getUsers()) {
serverMessage.appendString(username);
}
}
} else {
serverMessage.appendInt(0);
}
super.serializeExtradata(serverMessage);
}
@Override
public void onPlace(Room room) {
this.reloadData();
super.onPlace(room);
}
@Override
public void onPickUp(Room room) {
if (this.data != null) {
this.data.clear();
}
}
public void reloadData() {
this.data = Emulator.getGameEnvironment().getItemManager().getHighscoreManager().getHighscoreRowsForItem(this.getId(), this.clearType, this.scoreType);
}
}