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.WiredHighscoreClearType;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHighscoreData;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHighscoreScoreType;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class InteractionWiredHighscore extends HabboItem {
|
2018-07-06 15:30:00 +02:00
|
|
|
public WiredHighscoreScoreType scoreType;
|
|
|
|
public WiredHighscoreClearType clearType;
|
|
|
|
|
|
|
|
private THashSet<WiredHighscoreData> data;
|
|
|
|
private int lastUpdate;
|
|
|
|
|
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) {
|
2018-07-06 15:30:00 +02:00
|
|
|
Emulator.getLogging().logErrorLine(e);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.getRoomId() > 0) {
|
2018-07-06 15:30:00 +02:00
|
|
|
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (room != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.reloadData(room);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2018-07-06 15:30:00 +02:00
|
|
|
Emulator.getLogging().logErrorLine(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 (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) + "");
|
|
|
|
this.reloadData(room);
|
|
|
|
room.updateItem(this);
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2018-07-06 15:30:00 +02:00
|
|
|
Emulator.getLogging().logErrorLine(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@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());
|
|
|
|
serverMessage.appendInt(this.scoreType.type); //score type
|
|
|
|
serverMessage.appendInt(this.clearType.type); //clear type
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.getRoomId() == 0) {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt(0);
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (room == null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt(0);
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
|
|
|
if (Emulator.getIntUnixTimestamp() - this.lastUpdate > 60 * 60) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.reloadData(room);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.data != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt(this.data.size()); //count
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (WiredHighscoreData dataSet : this.data) {
|
|
|
|
if (this.scoreType == WiredHighscoreScoreType.PERTEAM) {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt(dataSet.teamScore); //Team score
|
2019-05-26 20:14:53 +02:00
|
|
|
} else if (dataSet.usernames.length == 1) {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt(dataSet.score);
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt(dataSet.totalScore);
|
|
|
|
}
|
|
|
|
|
|
|
|
serverMessage.appendInt(dataSet.usernames.length); //Users count
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
for (String codeDragon : dataSet.usernames) {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendString(codeDragon);
|
|
|
|
}
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.serializeExtradata(serverMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPlace(Room room) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.reloadData(room);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
this.lastUpdate = 0;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
private void reloadData(Room room) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.data = room.getWiredHighscoreData(this.scoreType, this.clearType);
|
|
|
|
this.lastUpdate = Emulator.getIntUnixTimestamp();
|
|
|
|
}
|
|
|
|
}
|