Merge branch 'moving-furni-walkoff-fix' into 'dev'

Make onWalkOff trigger when a furni is moved from under a room unit

See merge request morningstar/Arcturus-Community!38
This commit is contained in:
Alejandro 2019-05-18 12:08:43 -04:00
commit 019b8c1cf6
4 changed files with 47 additions and 0 deletions

View File

@ -50,6 +50,23 @@ public class InteractionDefault extends HabboItem
return true;
}
@Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation)
{
super.onMove(room, oldLocation, newLocation);
for (RoomUnit unit : room.getRoomUnits()) {
if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // If the unit was previously on the furni...
if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // but is not anymore...
try {
this.onWalkOff(unit, room, new Object[]{}); // the unit walked off!
} catch (Exception ignored) {
}
}
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception
{

View File

@ -34,6 +34,8 @@ public class InteractionWater extends InteractionDefault
@Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation)
{
super.onMove(room, oldLocation, newLocation);
this.recalculate(room);
}

View File

@ -5702,5 +5702,27 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
return FurnitureMovementError.NONE;
}
public THashSet<RoomUnit> getRoomUnits() {
THashSet<RoomUnit> units = new THashSet<>();
for (Habbo habbo : this.currentHabbos.values()) {
if (habbo != null && habbo.getRoomUnit() != null && habbo.getRoomUnit().getRoom().getId() == this.getId()) {
units.add(habbo.getRoomUnit());
}
}
for (Pet pet : this.currentPets.valueCollection()) {
if (pet != null && pet.getRoomUnit() != null && pet.getRoomUnit().getRoom().getId() == this.getId()) {
units.add(pet.getRoomUnit());
}
}
for (Bot bot : this.currentBots.valueCollection()) {
if (bot != null && bot.getRoomUnit() != null && bot.getRoomUnit().getRoom().getId() == this.getId()) {
units.add(bot.getRoomUnit());
}
}
return units;
}
}

View File

@ -1,5 +1,7 @@
package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.users.HabboItem;
import gnu.trove.set.hash.THashSet;
import java.util.ArrayList;
@ -233,4 +235,8 @@ public class RoomTile
return this.units.size() > 0;
}
}
public boolean unitIsOnFurniOnTile(RoomUnit unit, Item item) {
return (unit.getX() >= this.x && unit.getX() < this.x + item.getLength()) && (unit.getY() >= this.y && unit.getY() < this.y + item.getWidth());
}
}