2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
|
|
|
|
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.games.Game;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
|
|
|
|
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 gnu.trove.iterator.TObjectIntIterator;
|
|
|
|
import gnu.trove.map.TObjectIntMap;
|
|
|
|
import gnu.trove.map.hash.TObjectIntHashMap;
|
|
|
|
import gnu.trove.procedure.TObjectProcedure;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.AbstractMap;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public class WiredEffectGiveScore extends InteractionWiredEffect
|
|
|
|
{
|
|
|
|
public static final WiredEffectType type = WiredEffectType.GIVE_SCORE;
|
|
|
|
|
|
|
|
private int score;
|
|
|
|
private int count;
|
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
private TObjectIntMap<Map.Entry<Integer, Integer>> data = new TObjectIntHashMap<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
public WiredEffectGiveScore(ResultSet set, Item baseItem) throws SQLException
|
|
|
|
{
|
|
|
|
super(set, baseItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
public WiredEffectGiveScore(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
|
|
|
|
{
|
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff)
|
|
|
|
{
|
|
|
|
Habbo habbo = room.getHabbo(roomUnit);
|
|
|
|
|
|
|
|
if(habbo != null && habbo.getHabboInfo().getCurrentGame() != null)
|
|
|
|
{
|
|
|
|
Game game = room.getGame(habbo.getHabboInfo().getCurrentGame());
|
|
|
|
|
|
|
|
if(game == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TObjectIntIterator<Map.Entry<Integer, Integer>> iterator = this.data.iterator();
|
|
|
|
|
|
|
|
for(int i = this.data.size(); i-- > 0; )
|
|
|
|
{
|
|
|
|
iterator.advance();
|
|
|
|
|
|
|
|
Map.Entry<Integer, Integer> map = iterator.key();
|
|
|
|
|
|
|
|
if(map.getValue() == habbo.getHabboInfo().getId())
|
|
|
|
{
|
|
|
|
if(map.getKey() == game.getStartTime())
|
|
|
|
{
|
|
|
|
if(iterator.value() < this.count)
|
|
|
|
{
|
|
|
|
iterator.setValue(iterator.value() + 1);
|
|
|
|
|
|
|
|
habbo.getHabboInfo().getGamePlayer().addScore(this.score);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
this.data.put(new AbstractMap.SimpleEntry<>(game.getStartTime(), habbo.getHabboInfo().getId()), 1);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
if (habbo.getHabboInfo().getGamePlayer() != null)
|
|
|
|
{
|
|
|
|
habbo.getHabboInfo().getGamePlayer().addScore(this.score);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getWiredData()
|
|
|
|
{
|
|
|
|
return this.score + ";" + this.count + ";" + this.getDelay();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadWiredData(ResultSet set, Room room) throws SQLException
|
|
|
|
{
|
|
|
|
String[] data = set.getString("wired_data").split(";");
|
|
|
|
|
|
|
|
if(data.length == 3)
|
|
|
|
{
|
|
|
|
this.score = Integer.valueOf(data[0]);
|
|
|
|
this.count = Integer.valueOf(data[1]);
|
|
|
|
this.setDelay(Integer.valueOf(data[2]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickUp()
|
|
|
|
{
|
|
|
|
this.score = 0;
|
|
|
|
this.count = 0;
|
|
|
|
this.setDelay(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WiredEffectType getType()
|
|
|
|
{
|
|
|
|
return WiredEffectGiveScore.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void serializeWiredData(ServerMessage message, Room room)
|
|
|
|
{
|
|
|
|
message.appendBoolean(false);
|
|
|
|
message.appendInt(5);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getBaseItem().getSpriteId());
|
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString("");
|
|
|
|
message.appendInt(2);
|
|
|
|
message.appendInt(this.score);
|
|
|
|
message.appendInt(this.count);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(this.getDelay());
|
|
|
|
|
|
|
|
if (this.requiresTriggeringUser())
|
|
|
|
{
|
|
|
|
List<Integer> invalidTriggers = new ArrayList<>();
|
|
|
|
room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(new TObjectProcedure<InteractionWiredTrigger>()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean execute(InteractionWiredTrigger object)
|
|
|
|
{
|
|
|
|
if (!object.isTriggeredByRoomUnit())
|
|
|
|
{
|
|
|
|
invalidTriggers.add(object.getBaseItem().getSpriteId());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
message.appendInt(invalidTriggers.size());
|
|
|
|
for (Integer i : invalidTriggers)
|
|
|
|
{
|
|
|
|
message.appendInt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean saveData(ClientMessage packet, GameClient gameClient)
|
|
|
|
{
|
|
|
|
packet.readInt();
|
|
|
|
|
|
|
|
this.score = packet.readInt();
|
|
|
|
this.count = packet.readInt();
|
|
|
|
packet.readString();
|
|
|
|
packet.readInt();
|
|
|
|
this.setDelay(packet.readInt());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean requiresTriggeringUser()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|