Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java

217 lines
8.2 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
2018-12-22 11:39:00 +01:00
import com.eu.habbo.habbohotel.bots.Bot;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.items.Item;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.habbohotel.pets.Pet;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
2018-12-22 11:39:00 +01:00
import com.eu.habbo.habbohotel.users.Habbo;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.users.HabboItem;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.THashMap;
2018-12-22 11:39:00 +01:00
import gnu.trove.set.hash.THashSet;
import org.apache.commons.math3.util.Pair;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet;
import java.sql.SQLException;
2018-12-22 11:39:00 +01:00
import java.util.List;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class InteractionWater extends InteractionDefault {
public InteractionWater(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 InteractionWater(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 onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
super.onMove(room, oldLocation, newLocation);
2018-07-06 15:30:00 +02:00
this.recalculate(room);
}
@Override
2019-05-26 20:14:53 +02:00
public void onPickUp(Room room) {
2018-07-06 15:30:00 +02:00
this.recalculate(room);
2018-12-22 11:39:00 +01:00
Object[] empty = new Object[]{};
2019-05-26 20:14:53 +02:00
for (Habbo habbo : room.getHabbosOnItem(this)) {
try {
2018-12-22 11:39:00 +01:00
this.onWalkOff(habbo.getRoomUnit(), room, empty);
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2018-12-22 11:39:00 +01:00
}
}
2019-05-26 20:14:53 +02:00
for (Bot bot : room.getBotsOnItem(this)) {
try {
2018-12-22 11:39:00 +01:00
this.onWalkOff(bot.getRoomUnit(), room, empty);
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2018-12-22 11:39:00 +01:00
}
}
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onPlace(Room room) {
2018-07-06 15:30:00 +02:00
this.recalculate(room);
2019-05-26 21:33:51 +02:00
super.onPlace(room);
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void refreshWaters(Room room) {
if (room == null) {
2018-07-06 15:30:00 +02:00
room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
}
2019-05-26 20:14:53 +02:00
int _1 = 0;
int _2 = 0;
int _3 = 0;
int _4 = 0;
int _5 = 0;
int _6 = 0;
int _7 = 0;
int _8 = 0;
int _9 = 0;
2018-07-06 15:30:00 +02:00
int _10 = 0;
int _11 = 0;
int _12 = 0;
2019-05-26 20:14:53 +02:00
for (HabboItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWaterItem.class)) {
2018-07-06 15:30:00 +02:00
((InteractionWaterItem) item).update();
}
2019-05-26 20:14:53 +02:00
if (!this.getBaseItem().getName().equalsIgnoreCase("bw_water_2")) {
2018-12-22 11:39:00 +01:00
if (room.waterTiles.containsKey(this.getX() - 1) && room.waterTiles.get(this.getX() - 1).contains(this.getY() - 1))
_1 = 1;
if (room.waterTiles.containsKey(this.getX()) && room.waterTiles.get(this.getX()).contains(this.getY() - 1))
_2 = 1;
if (room.waterTiles.containsKey(this.getX() + 1) && room.waterTiles.get(this.getX() + 1).contains(this.getY() - 1))
_3 = 1;
if (room.waterTiles.containsKey(this.getX() + 2) && room.waterTiles.get(this.getX() + 2).contains(this.getY() - 1))
_4 = 1;
if (room.waterTiles.containsKey(this.getX() - 1) && room.waterTiles.get(this.getX() - 1).contains(this.getY()))
_5 = 1;
if (room.waterTiles.containsKey(this.getX() + 2) && room.waterTiles.get(this.getX() + 2).contains(this.getY()))
_6 = 1;
if (room.waterTiles.containsKey(this.getX() - 1) && room.waterTiles.get(this.getX() - 1).contains(this.getY() + 1))
_7 = 1;
if (room.waterTiles.containsKey(this.getX() + 2) && room.waterTiles.get(this.getX() + 2).contains(this.getY() + 1))
_8 = 1;
if (room.waterTiles.containsKey(this.getX() - 1) && room.waterTiles.get(this.getX() - 1).contains(this.getY() + 2))
_9 = 1;
if (room.waterTiles.containsKey(this.getX()) && room.waterTiles.get(this.getX()).contains(this.getY() + 2))
_10 = 1;
if (room.waterTiles.containsKey(this.getX() + 1) && room.waterTiles.get(this.getX() + 1).contains(this.getY() + 2))
_11 = 1;
if (room.waterTiles.containsKey(this.getX() + 2) && room.waterTiles.get(this.getX() + 2).contains(this.getY() + 2))
_12 = 1;
}
//if (_1 == 0 && room.getLayout().isVoidTile((short)(this.getX() -1), (short) (this.getY() -1))) _1 = 1;
2019-05-26 20:14:53 +02:00
if (_2 == 0 && room.getLayout().isVoidTile(this.getX(), (short) (this.getY() - 1))) _2 = 1;
if (_3 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 1), (short) (this.getY() - 1))) _3 = 1;
2018-12-22 11:39:00 +01:00
//if (_4 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 2), (short) (this.getY() - 1))) _4 = 1;
2019-05-26 20:14:53 +02:00
if (_5 == 0 && room.getLayout().isVoidTile((short) (this.getX() - 1), this.getY())) _5 = 1;
if (_6 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 2), this.getY())) _6 = 1;
if (_7 == 0 && room.getLayout().isVoidTile((short) (this.getX() - 1), (short) (this.getY() + 1))) _7 = 1;
if (_8 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 2), (short) (this.getY() + 1))) _8 = 1;
2018-12-22 11:39:00 +01:00
//if (_9 == 0 && room.getLayout().isVoidTile((short)(this.getX() -1), (short) (this.getY() + 2))) _9 = 1;
if (_10 == 0 && room.getLayout().isVoidTile(this.getX(), (short) (this.getY() + 2))) _10 = 1;
if (_11 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 1), (short) (this.getY() + 2))) _11 = 1;
//if (_12 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 2), (short) (this.getY() + 2))) _12 = 1;
2018-07-06 15:30:00 +02:00
int result = 0;
2019-05-26 20:14:53 +02:00
result |= _1 << 11;
result |= _2 << 10;
result |= _3 << 9;
result |= _4 << 8;
result |= _5 << 7;
result |= _6 << 6;
result |= _7 << 5;
result |= _8 << 4;
result |= _9 << 3;
2018-07-06 15:30:00 +02:00
result |= _10 << 2;
result |= _11 << 1;
2019-05-26 20:14:53 +02:00
result |= _12;
2018-07-06 15:30:00 +02:00
this.setExtradata(result + "");
this.needsUpdate(true);
room.updateItem(this);
}
@Override
2019-05-27 02:02:30 +02:00
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
2018-09-12 18:45:00 +02:00
Pet pet = room.getPet(roomUnit);
2018-07-06 15:30:00 +02:00
2019-05-27 02:02:30 +02:00
if(pet == null)
return;
if (!pet.getRoomUnit().hasStatus(RoomUnitStatus.SWIM)) {
pet.getRoomUnit().setStatus(RoomUnitStatus.SWIM, "");
2018-07-06 15:30:00 +02:00
}
}
2019-05-27 02:02:30 +02:00
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOff(roomUnit, room, objects);
Pet pet = room.getPet(roomUnit);
if(pet == null)
return;
pet.getRoomUnit().removeStatus(RoomUnitStatus.SWIM);
}
2019-05-26 20:14:53 +02:00
private void recalculate(Room room) {
2019-03-18 02:22:00 +01:00
THashMap<Short, TIntArrayList> tiles = new THashMap<>();
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
for (HabboItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWater.class)) {
for (short i = 0; i < item.getBaseItem().getLength(); i++) {
for (short j = 0; j < item.getBaseItem().getWidth(); j++) {
if (!tiles.containsKey((short) (item.getX() + i))) {
tiles.put((short) (item.getX() + i), new TIntArrayList());
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
tiles.get((short) (item.getX() + i)).add(item.getY() + j);
2018-07-06 15:30:00 +02:00
}
}
}
room.waterTiles = tiles;
2019-05-26 20:14:53 +02:00
for (HabboItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWater.class)) {
((InteractionWater) item).refreshWaters(room);
2018-07-06 15:30:00 +02:00
}
}
@Override
2019-05-26 20:14:53 +02:00
public boolean allowWiredResetState() {
2018-07-06 15:30:00 +02:00
return false;
}
2018-12-22 11:39:00 +01:00
@Override
2019-05-26 20:14:53 +02:00
public boolean canToggle(Habbo habbo, Room room) {
2018-12-22 11:39:00 +01:00
return false;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean canStackAt(Room room, List<Pair<RoomTile, THashSet<HabboItem>>> itemsAtLocation) {
for (Pair<RoomTile, THashSet<HabboItem>> set : itemsAtLocation) {
for (HabboItem item : set.getValue()) {
if (!(item instanceof InteractionWater)) {
2018-12-22 11:39:00 +01:00
return false;
}
}
}
return super.canStackAt(room, itemsAtLocation);
}
2018-07-06 15:30:00 +02:00
}