Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java

154 lines
4.8 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
import com.eu.habbo.Emulator;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.GameTeam;
import com.eu.habbo.habbohotel.games.GameTeamColors;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
2018-07-06 15:30:00 +02:00
import gnu.trove.map.hash.TIntIntHashMap;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
2018-07-06 15:30:00 +02:00
public static final WiredEffectType type = WiredEffectType.GIVE_SCORE_TEAM;
private int points;
private int count;
private GameTeamColors teamColor = GameTeamColors.RED;
private TIntIntHashMap startTimes = new TIntIntHashMap();
2019-05-26 20:14:53 +02:00
public WiredEffectGiveScoreToTeam(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);
}
2019-05-26 20:14:53 +02:00
public WiredEffectGiveScoreToTeam(ResultSet set, Item baseItem) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, baseItem);
}
@Override
2019-05-26 20:14:53 +02:00
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
2018-07-06 15:30:00 +02:00
Habbo habbo = room.getHabbo(roomUnit);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
2018-07-06 15:30:00 +02:00
Class<? extends Game> game = habbo.getHabboInfo().getCurrentGame();
2019-05-26 20:14:53 +02:00
if (game != null) {
2018-07-06 15:30:00 +02:00
Game g = room.getGame(game);
2019-05-26 20:14:53 +02:00
if (g != null) {
2018-07-06 15:30:00 +02:00
int c = this.startTimes.get(g.getStartTime());
2019-05-26 20:14:53 +02:00
if (c < this.count) {
2018-07-06 15:30:00 +02:00
GameTeam team = g.getTeam(this.teamColor);
2019-05-26 20:14:53 +02:00
if (team != null) {
2018-07-06 15:30:00 +02:00
team.addTeamScore(this.points);
this.startTimes.put(g.getStartTime(), c++);
return true;
}
}
}
}
}
return false;
}
@Override
2019-05-26 20:14:53 +02:00
public String getWiredData() {
2018-07-06 15:30:00 +02:00
return this.points + ";" + this.count + ";" + this.teamColor.type + ";" + this.getDelay();
}
@Override
2019-05-26 20:14:53 +02:00
public void loadWiredData(ResultSet set, Room room) throws SQLException {
2018-07-06 15:30:00 +02:00
String[] data = set.getString("wired_data").split(";");
2019-05-26 20:14:53 +02:00
if (data.length == 4) {
2018-07-06 15:30:00 +02:00
this.points = Integer.valueOf(data[0]);
this.count = Integer.valueOf(data[1]);
this.teamColor = GameTeamColors.values()[Integer.valueOf(data[2])];
this.setDelay(Integer.valueOf(data[3]));
}
}
@Override
2019-05-26 20:14:53 +02:00
public void onPickUp() {
2018-07-06 15:30:00 +02:00
this.startTimes.clear();
this.points = 0;
this.count = 0;
this.teamColor = GameTeamColors.RED;
this.setDelay(0);
}
@Override
2019-05-26 20:14:53 +02:00
public WiredEffectType getType() {
2018-07-06 15:30:00 +02:00
return type;
}
@Override
2019-05-26 20:14:53 +02:00
public void serializeWiredData(ServerMessage message, Room room) {
2018-07-06 15:30:00 +02:00
message.appendBoolean(false);
message.appendInt(5);
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString("");
message.appendInt(3);
2019-05-26 20:14:53 +02:00
message.appendInt(this.points);
message.appendInt(this.count);
2019-06-10 18:06:22 +02:00
message.appendInt(this.teamColor.type);
2018-07-06 15:30:00 +02:00
message.appendInt(0);
message.appendInt(this.getType().code);
message.appendInt(this.getDelay());
message.appendInt(0);
}
@Override
public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
2018-07-06 15:30:00 +02:00
packet.readInt();
int points = packet.readInt();
if(points < 1 || points > 100)
throw new WiredSaveException("Points is invalid");
int timesPerGame = packet.readInt();
if(timesPerGame < 1 || timesPerGame > 10)
throw new WiredSaveException("Times per game is invalid");
int team = packet.readInt();
if(team < 1 || team > 4)
throw new WiredSaveException("Team is invalid");
2018-07-06 15:30:00 +02:00
packet.readString();
packet.readInt();
int delay = packet.readInt();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.points = points;
this.count = timesPerGame;
this.teamColor = GameTeamColors.values()[team];
this.setDelay(delay);
2018-07-06 15:30:00 +02:00
return true;
}
}