Effect items now apply correct effects when moved or removed - Closes #478

This commit is contained in:
Beny 2020-10-15 11:01:24 +02:00
parent d14fde712e
commit 353bb16327
2 changed files with 41 additions and 15 deletions

View File

@ -54,7 +54,7 @@ public class InteractionDefault extends HabboItem {
if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // but is not anymore...
try {
this.onWalkOff(unit, room, new Object[]{}); // the unit walked off!
this.onWalkOff(unit, room, new Object[]{ oldLocation, newLocation }); // the unit walked off!
} catch (Exception ignored) {
}
@ -137,14 +137,22 @@ public class InteractionDefault extends HabboItem {
if (roomUnit != null) {
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) {
int nextEffectM = 0;
int nextEffectF = 0;
if (objects != null && objects.length == 2) {
if (objects[0] instanceof RoomTile && objects[1] instanceof RoomTile) {
RoomTile goalTile = (RoomTile) objects[1];
HabboItem topItem = room.getTopItemAt(goalTile.x, goalTile.y);
RoomTile goalTile = (RoomTile) objects[0];
HabboItem topItem = room.getTopItemAt(goalTile.x, goalTile.y, (objects[0] != objects[1]) ? this : null);
if (topItem != null && (topItem.getBaseItem().getEffectM() == this.getBaseItem().getEffectM() || topItem.getBaseItem().getEffectF() == this.getBaseItem().getEffectF())) {
return;
}
if(topItem != null) {
nextEffectM = topItem.getBaseItem().getEffectM();
nextEffectF = topItem.getBaseItem().getEffectF();
}
}
}
@ -154,12 +162,12 @@ public class InteractionDefault extends HabboItem {
if (habbo != null) {
if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) {
room.giveEffect(habbo, 0, -1);
room.giveEffect(habbo, nextEffectM, -1);
return;
}
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) {
room.giveEffect(habbo, 0, -1);
room.giveEffect(habbo, nextEffectF, -1);
}
}
} else if (roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)) {
@ -167,12 +175,12 @@ public class InteractionDefault extends HabboItem {
if (bot != null) {
if (bot.getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) {
room.giveEffect(roomUnit, 0, -1);
room.giveEffect(roomUnit, nextEffectM, -1);
return;
}
if (bot.getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) {
room.giveEffect(roomUnit, 0, -1);
room.giveEffect(roomUnit, nextEffectF, -1);
}
}
}

View File

@ -380,23 +380,32 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
public void onPickUp(Room room) {
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) {
HabboItem topItem2 = room.getTopItemAt(this.getX(), this.getY(), this);
int nextEffectM = 0;
int nextEffectF = 0;
if(topItem2 != null) {
nextEffectM = topItem2.getBaseItem().getEffectM();
nextEffectF = topItem2.getBaseItem().getEffectF();
}
for (Habbo habbo : room.getHabbosOnItem(this)) {
if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) {
room.giveEffect(habbo, 0, -1);
room.giveEffect(habbo, nextEffectM, -1);
}
if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) {
room.giveEffect(habbo, 0, -1);
room.giveEffect(habbo, nextEffectF, -1);
}
}
for (Bot bot : room.getBotsAt(room.getLayout().getTile(this.getX(), this.getY()))) {
if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) {
room.giveEffect(bot.getRoomUnit(), 0, -1);
room.giveEffect(bot.getRoomUnit(), nextEffectM, -1);
}
if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) {
room.giveEffect(bot.getRoomUnit(), 0, -1);
room.giveEffect(bot.getRoomUnit(), nextEffectF, -1);
}
}
}
@ -404,6 +413,15 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) {
HabboItem topItem2 = room.getTopItemAt(oldLocation.x, oldLocation.y, this);
int nextEffectM = 0;
int nextEffectF = 0;
if(topItem2 != null) {
nextEffectM = topItem2.getBaseItem().getEffectM();
nextEffectF = topItem2.getBaseItem().getEffectF();
}
List<Habbo> oldHabbos = new ArrayList<>();
List<Habbo> newHabbos = new ArrayList<>();
List<Bot> oldBots = new ArrayList<>();
@ -424,11 +442,11 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
for (Habbo habbo : oldHabbos) {
if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) {
room.giveEffect(habbo, 0, -1);
room.giveEffect(habbo, nextEffectM, -1);
}
if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) {
room.giveEffect(habbo, 0, -1);
room.giveEffect(habbo, nextEffectF, -1);
}
}
@ -444,11 +462,11 @@ public abstract class HabboItem implements Runnable, IEventTriggers {
for (Bot bot : oldBots) {
if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) {
room.giveEffect(bot.getRoomUnit(), 0, -1);
room.giveEffect(bot.getRoomUnit(), nextEffectM, -1);
}
if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) {
room.giveEffect(bot.getRoomUnit(), 0, -1);
room.giveEffect(bot.getRoomUnit(), nextEffectF, -1);
}
}