2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
|
2019-05-01 03:02:51 +02:00
|
|
|
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile;
|
2019-04-22 01:42:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.*;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
2019-04-22 01:42:00 +02:00
|
|
|
import com.eu.habbo.util.pathfinding.Rotation;
|
2018-07-06 15:30:00 +02:00
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
public class WiredEffectMoveFurniTowards extends InteractionWiredEffect
|
|
|
|
{
|
|
|
|
public static final WiredEffectType type = WiredEffectType.CHASE;
|
|
|
|
|
|
|
|
private THashSet<HabboItem> items;
|
|
|
|
|
|
|
|
public WiredEffectMoveFurniTowards(ResultSet set, Item baseItem) throws SQLException
|
|
|
|
{
|
|
|
|
super(set, baseItem);
|
2019-03-18 02:22:00 +01:00
|
|
|
this.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public WiredEffectMoveFurniTowards(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
|
|
|
|
{
|
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
2019-03-18 02:22:00 +01:00
|
|
|
this.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff)
|
|
|
|
{
|
2018-09-28 21:25:00 +02:00
|
|
|
THashSet<HabboItem> items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
for(HabboItem item : this.items)
|
|
|
|
{
|
|
|
|
if (item.getRoomId() == 0)
|
|
|
|
items.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items.removeAll(items);
|
|
|
|
|
|
|
|
for(HabboItem item : this.items)
|
|
|
|
{
|
2019-04-22 01:42:00 +02:00
|
|
|
RoomTile furniLocation = room.getLayout().getTile(item.getX(), item.getY());
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
boolean collided = false;
|
2019-04-22 01:42:00 +02:00
|
|
|
double shortest = 3 + Math.max(item.getBaseItem().getWidth(), item.getBaseItem().getLength());
|
2018-07-06 15:30:00 +02:00
|
|
|
Habbo target = null;
|
2019-04-22 01:42:00 +02:00
|
|
|
THashSet<RoomTile> tiles = room.getLayout().getTilesAt(furniLocation, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
|
2018-09-28 21:25:00 +02:00
|
|
|
for (Habbo habbo : room.getHabbos())
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-04-22 01:42:00 +02:00
|
|
|
RoomTile currentLocation = habbo.getRoomUnit().getCurrentLocation();
|
|
|
|
for (RoomTile t : tiles)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-04-22 01:42:00 +02:00
|
|
|
if (currentLocation.x == t.x || currentLocation.y == t.y)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-04-22 01:42:00 +02:00
|
|
|
double distance = t.distance(habbo.getRoomUnit().getCurrentLocation());
|
|
|
|
if (distance == 1)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-04-22 01:42:00 +02:00
|
|
|
Emulator.getThreading().run(new Runnable()
|
2018-09-28 21:25:00 +02:00
|
|
|
{
|
2019-04-22 01:42:00 +02:00
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
WiredHandler.handle(WiredTriggerType.COLLISION, habbo.getRoomUnit(), room, new Object[]{item});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
collided = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean valid = true;
|
|
|
|
for (RoomTile tile : room.getLayout().getTilesInFront(habbo.getRoomUnit().getCurrentLocation(), Rotation.Calculate(currentLocation.x, currentLocation.y, t.x, t.y), (int) Math.ceil(distance)))
|
|
|
|
{
|
|
|
|
if (tile.state == RoomTileState.INVALID)
|
|
|
|
{
|
|
|
|
valid = false;
|
|
|
|
break;
|
2018-09-28 21:25:00 +02:00
|
|
|
}
|
|
|
|
|
2019-04-22 01:42:00 +02:00
|
|
|
if (tile == t)
|
|
|
|
{
|
|
|
|
//Do not look further in case of rounding error.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-04-22 01:42:00 +02:00
|
|
|
if (valid && distance <= shortest)
|
|
|
|
{
|
|
|
|
target = habbo;
|
|
|
|
shortest = distance;
|
|
|
|
}
|
2018-09-28 21:25:00 +02:00
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2018-09-28 21:25:00 +02:00
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
if (collided)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-09-28 21:25:00 +02:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
if(target != null)
|
|
|
|
{
|
2019-04-22 01:42:00 +02:00
|
|
|
for (RoomTile tile : tiles)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-04-22 01:42:00 +02:00
|
|
|
if (target.getRoomUnit().getX() == tile.x)
|
|
|
|
{
|
|
|
|
if (tile.y < target.getRoomUnit().getY())
|
|
|
|
y++;
|
|
|
|
else
|
|
|
|
y--;
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else if (target.getRoomUnit().getY() == tile.y)
|
|
|
|
{
|
|
|
|
if (tile.x < target.getRoomUnit().getX())
|
|
|
|
x++;
|
|
|
|
else
|
|
|
|
x--;
|
|
|
|
break;
|
|
|
|
} else if (target.getRoomUnit().getX() - tile.x > target.getRoomUnit().getY() - tile.y)
|
|
|
|
{
|
|
|
|
if (target.getRoomUnit().getX() - tile.x > 0)
|
|
|
|
x++;
|
|
|
|
else
|
|
|
|
x--;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (target.getRoomUnit().getY() - tile.y > 0)
|
|
|
|
y++;
|
|
|
|
else
|
|
|
|
y--;
|
|
|
|
break;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2018-09-28 21:25:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (Emulator.getRandom().nextInt(4))
|
|
|
|
{
|
|
|
|
case 0: x--; break;
|
|
|
|
case 1: x++; break;
|
|
|
|
case 2: y--; break;
|
|
|
|
case 3: y++; break;
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-01 03:02:51 +02:00
|
|
|
boolean validMove = true;
|
2018-09-28 21:25:00 +02:00
|
|
|
RoomTile newTile = room.getLayout().getTile((short) (item.getX() + x), (short) (item.getY() + y));
|
2019-05-01 03:02:51 +02:00
|
|
|
if(room.getLayout().getTilesAt(newTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()) == null) {
|
|
|
|
validMove = false;
|
|
|
|
}
|
|
|
|
for(RoomTile t : room.getLayout().getTilesAt(newTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())) {
|
|
|
|
if ((item instanceof InteractionFreezeTile || item instanceof InteractionBattleBanzaiTile) && room.hasItemsAt(t.x, t.y)) {
|
|
|
|
validMove = false;
|
|
|
|
}
|
|
|
|
if (t == null || (t.state == RoomTileState.OPEN && !t.isWalkable()) || t.state == RoomTileState.BLOCKED || t.state == RoomTileState.INVALID || !room.furnitureFitsAt(t, item, item.getRotation()).equals(FurnitureMovementError.NONE) || !room.getLayout().tileExists(t.x, t.y)) {
|
|
|
|
validMove = false;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-01 03:02:51 +02:00
|
|
|
if(validMove) {
|
|
|
|
room.slideFurniTo(item, newTile, item.getRotation());
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getWiredData()
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
if(this.items != null && !this.items.isEmpty())
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
|
|
|
for (HabboItem item : this.items)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
wiredData.append(item.getId()).append(";");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
return wiredData.toString();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadWiredData(ResultSet set, Room room) throws SQLException
|
|
|
|
{
|
2018-09-28 21:25:00 +02:00
|
|
|
this.items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
String[] wiredData = set.getString("wired_data").split("\t");
|
|
|
|
|
|
|
|
if (wiredData.length >= 1)
|
|
|
|
{
|
|
|
|
this.setDelay(Integer.valueOf(wiredData[0]));
|
|
|
|
}
|
|
|
|
if (wiredData.length == 2)
|
|
|
|
{
|
|
|
|
if (wiredData[1].contains(";"))
|
|
|
|
{
|
|
|
|
for (String s : wiredData[1].split(";"))
|
|
|
|
{
|
|
|
|
HabboItem item = room.getHabboItem(Integer.valueOf(s));
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
this.items.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPickUp()
|
|
|
|
{
|
|
|
|
this.items.clear();
|
|
|
|
this.setDelay(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WiredEffectType getType()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void serializeWiredData(ServerMessage message, Room room)
|
|
|
|
{
|
2018-09-28 21:25:00 +02:00
|
|
|
THashSet<HabboItem> items = new THashSet<>();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
for(HabboItem item : this.items)
|
|
|
|
{
|
|
|
|
if(item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
|
|
|
|
items.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(HabboItem item : items)
|
|
|
|
{
|
|
|
|
this.items.remove(item);
|
|
|
|
}
|
|
|
|
message.appendBoolean(false);
|
|
|
|
message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
|
|
|
|
message.appendInt(this.items.size());
|
|
|
|
for(HabboItem item : this.items)
|
|
|
|
message.appendInt(item.getId());
|
|
|
|
|
|
|
|
message.appendInt(this.getBaseItem().getSpriteId());
|
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString("");
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getType().code);
|
|
|
|
message.appendInt(this.getDelay());
|
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean saveData(ClientMessage packet, GameClient gameClient)
|
|
|
|
{
|
|
|
|
packet.readInt();
|
|
|
|
packet.readString();
|
|
|
|
|
|
|
|
this.items.clear();
|
|
|
|
|
|
|
|
int count = packet.readInt();
|
|
|
|
|
|
|
|
for(int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setDelay(packet.readInt());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-12 18:45:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected long requiredCooldown()
|
|
|
|
{
|
|
|
|
return 495;
|
|
|
|
}
|
2019-05-01 03:20:24 +02:00
|
|
|
}
|