2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
|
|
|
|
|
|
|
|
import com.eu.habbo.habbohotel.bots.Bot;
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
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.procedure.TObjectProcedure;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
|
2018-07-06 15:30:00 +02:00
|
|
|
public static final WiredEffectType type = WiredEffectType.BOT_FOLLOW_AVATAR;
|
|
|
|
|
|
|
|
private String botName = "";
|
|
|
|
private int mode = 0;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectBotFollowHabbo(ResultSet set, Item baseItem) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set, baseItem);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectBotFollowHabbo(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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(this.botName);
|
|
|
|
message.appendInt(1);
|
|
|
|
message.appendInt(this.mode);
|
|
|
|
message.appendInt(1);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(this.getDelay());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.requiresTriggeringUser()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
List<Integer> invalidTriggers = new ArrayList<>();
|
2019-05-26 20:14:53 +02:00
|
|
|
room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(new TObjectProcedure<InteractionWiredTrigger>() {
|
2018-07-06 15:30:00 +02:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean execute(InteractionWiredTrigger object) {
|
|
|
|
if (!object.isTriggeredByRoomUnit()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
invalidTriggers.add(object.getBaseItem().getSpriteId());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
message.appendInt(invalidTriggers.size());
|
2019-05-26 20:14:53 +02:00
|
|
|
for (Integer i : invalidTriggers) {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(i);
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean saveData(ClientMessage packet, GameClient gameClient) {
|
2018-07-06 15:30:00 +02:00
|
|
|
packet.readInt();
|
|
|
|
|
|
|
|
this.mode = packet.readInt();
|
|
|
|
this.botName = packet.readString().replace("\t", "");
|
|
|
|
packet.readInt();
|
|
|
|
this.setDelay(packet.readInt());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 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
|
|
|
List<Bot> bots = room.getBots(this.botName);
|
2019-05-26 20:14:53 +02:00
|
|
|
for (Bot bot : bots) {
|
|
|
|
if (this.mode == 1)
|
2018-07-06 15:30:00 +02:00
|
|
|
bot.startFollowingHabbo(habbo);
|
|
|
|
else
|
|
|
|
bot.stopFollowingHabbo();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getWiredData() {
|
|
|
|
return this.getDelay() + "" + ((char) 9) + "" + this.mode + "" + ((char) 9) + this.botName;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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(((char) 9) + "");
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (data.length == 3) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.setDelay(Integer.valueOf(data[0]));
|
|
|
|
this.mode = (data[1].equalsIgnoreCase("1") ? 1 : 0);
|
|
|
|
this.botName = data[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPickUp() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.botName = "";
|
|
|
|
this.mode = 0;
|
|
|
|
this.setDelay(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean requiresTriggeringUser() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|