fix previous enable

This commit is contained in:
brenoepic 2022-04-16 03:19:11 -03:00 committed by Harmonic
parent a23fb4f8cd
commit 0fb8dad0ea
2 changed files with 74 additions and 45 deletions

View File

@ -48,7 +48,7 @@ public class InteractionDefault extends HabboItem {
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
super.onMove(room, oldLocation, newLocation);
if(room.getItemsAt(oldLocation).stream().noneMatch(item -> item.getClass().isAssignableFrom(InteractionRoller.class))) {
if (room.getItemsAt(oldLocation).stream().noneMatch(item -> item.getClass().isAssignableFrom(InteractionRoller.class))) {
for (RoomUnit unit : room.getRoomUnits()) {
if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem()))
continue; // If the unit was previously on the furni...
@ -101,34 +101,40 @@ public class InteractionDefault extends HabboItem {
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
if (roomUnit != null) {
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) {
if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) {
Habbo habbo = room.getHabbo(roomUnit);
if (roomUnit == null || (this.getBaseItem().getEffectF() == 0 && this.getBaseItem().getEffectM() == 0)) return;
if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) {
room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1);
return;
}
if (habbo == null) return;
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) {
room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1);
}
}
} else if (roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)) {
Bot bot = room.getBot(roomUnit);
if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) {
if (roomUnit.getEffectId() > 0)
roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp());
room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1);
return;
}
if (bot != null) {
if (bot.getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && roomUnit.getEffectId() != this.getBaseItem().getEffectM()) {
room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectM(), -1);
return;
}
if (bot.getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && roomUnit.getEffectId() != this.getBaseItem().getEffectF()) {
room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectF(), -1);
}
}
}
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) {
if (roomUnit.getEffectId() > 0)
roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp());
room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1);
}
} else if (roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)) {
Bot bot = room.getBot(roomUnit);
if (bot == null) return;
if (bot.getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && roomUnit.getEffectId() != this.getBaseItem().getEffectM()) {
if (roomUnit.getEffectId() > 0)
roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp());
room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectM(), -1);
return;
}
if (bot.getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && roomUnit.getEffectId() != this.getBaseItem().getEffectF()) {
if (roomUnit.getEffectId() > 0)
roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp());
room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectF(), -1);
}
}
}
@ -141,6 +147,7 @@ public class InteractionDefault extends HabboItem {
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) {
int nextEffectM = 0;
int nextEffectF = 0;
int nextEffectDuration = -1;
if (objects != null && objects.length == 2) {
if (objects[0] instanceof RoomTile && objects[1] instanceof RoomTile) {
@ -151,9 +158,13 @@ public class InteractionDefault extends HabboItem {
return;
}
if(topItem != null) {
if (topItem != null) {
nextEffectM = topItem.getBaseItem().getEffectM();
nextEffectF = topItem.getBaseItem().getEffectF();
} else if (roomUnit.getPreviousEffectId() > 0) {
nextEffectF = roomUnit.getPreviousEffectId();
nextEffectM = roomUnit.getPreviousEffectId();
nextEffectDuration = roomUnit.getPreviousEffectEndTimestamp();
}
}
}
@ -164,12 +175,12 @@ public class InteractionDefault extends HabboItem {
if (habbo != null) {
if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) {
room.giveEffect(habbo, nextEffectM, -1);
room.giveEffect(habbo, nextEffectM, nextEffectDuration);
return;
}
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) {
room.giveEffect(habbo, nextEffectF, -1);
room.giveEffect(habbo, nextEffectF, nextEffectDuration);
}
}
} else if (roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)) {
@ -177,12 +188,12 @@ public class InteractionDefault extends HabboItem {
if (bot != null) {
if (bot.getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) {
room.giveEffect(roomUnit, nextEffectM, -1);
room.giveEffect(roomUnit, nextEffectM, nextEffectDuration);
return;
}
if (bot.getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) {
room.giveEffect(roomUnit, nextEffectF, -1);
room.giveEffect(roomUnit, nextEffectF, nextEffectDuration);
}
}
}

View File

@ -3,7 +3,8 @@ package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.*;
import com.eu.habbo.habbohotel.items.interactions.InteractionWater;
import com.eu.habbo.habbohotel.items.interactions.InteractionWaterItem;
import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.RideablePet;
@ -35,6 +36,7 @@ public class RoomUnit {
public boolean isWiredTeleporting = false;
public boolean isLeavingTeleporter = false;
public boolean isSwimming = false;
private final ConcurrentHashMap<RoomUnitStatus, String> status;
private final THashMap<String, Object> cacheable;
public boolean canRotate = true;
@ -72,6 +74,8 @@ public class RoomUnit {
private int walkTimeOut;
private int effectId;
private int effectEndTimestamp;
private int previousEffectId;
private int previousEffectEndTimestamp;
private ScheduledFuture moveBlockingTask;
private int timeInRoom;
@ -92,6 +96,8 @@ public class RoomUnit {
this.handItemTimestamp = 0;
this.walkTimeOut = Emulator.getIntUnixTimestamp();
this.effectId = 0;
this.previousEffectId = 0;
this.previousEffectEndTimestamp = -1;
this.isKicked = false;
this.overridableTiles = new THashSet<>();
this.timeInRoom = 0;
@ -252,7 +258,7 @@ public class RoomUnit {
this.status.remove(RoomUnitStatus.MOVE);
return false;
}
next = (RoomTile)this.path.pop();
next = (RoomTile) this.path.pop();
}
}
@ -491,15 +497,14 @@ public class RoomUnit {
public void setGoalLocation(RoomTile goalLocation) {
if (goalLocation != null) {
// if (goalLocation.state != RoomTileState.INVALID) {
this.setGoalLocation(goalLocation, false);
}
//}
// if (goalLocation.state != RoomTileState.INVALID) {
this.setGoalLocation(goalLocation, false);
}
//}
}
public void setGoalLocation(RoomTile goalLocation, boolean noReset) {
if (Emulator.getPluginManager().isRegistered(RoomUnitSetGoalEvent.class, false))
{
if (Emulator.getPluginManager().isRegistered(RoomUnitSetGoalEvent.class, false)) {
Event event = new RoomUnitSetGoalEvent(this.room, this, goalLocation);
Emulator.getPluginManager().fireEvent(event);
@ -553,8 +558,7 @@ public class RoomUnit {
this.room = room;
}
public void findPath()
{
public void findPath() {
if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.x, this.goalLocation.y) || this.canOverrideTile(this.goalLocation))) {
Deque<RoomTile> path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation, this);
if (path != null) this.path = path;
@ -624,6 +628,7 @@ public class RoomUnit {
return this.effectId;
}
public void setEffectId(int effectId, int endTimestamp) {
this.effectId = effectId;
this.effectEndTimestamp = endTimestamp;
@ -633,6 +638,19 @@ public class RoomUnit {
return this.effectEndTimestamp;
}
public int getPreviousEffectId() {
return this.previousEffectId;
}
public void setPreviousEffectId(int effectId, int endTimestamp) {
this.previousEffectId = effectId;
this.previousEffectEndTimestamp = endTimestamp;
}
public int getPreviousEffectEndTimestamp() {
return this.previousEffectEndTimestamp;
}
public int getWalkTimeOut() {
return this.walkTimeOut;
}
@ -780,7 +798,7 @@ public class RoomUnit {
}
public RoomTile getClosestAdjacentTile(short x, short y, boolean diagonal) {
if(room == null) return null;
if (room == null) return null;
RoomTile baseTile = room.getLayout().getTile(x, y);
@ -801,9 +819,9 @@ public class RoomUnit {
return this.getClosestTile(
rotations.stream()
.map(rotation -> room.getLayout().getTileInFront(baseTile, rotation))
.filter(t -> t != null && t.isWalkable() && (this.getCurrentLocation().equals(t) || !room.hasHabbosAt(t.x, t.y)))
.collect(Collectors.toList())
.map(rotation -> room.getLayout().getTileInFront(baseTile, rotation))
.filter(t -> t != null && t.isWalkable() && (this.getCurrentLocation().equals(t) || !room.hasHabbosAt(t.x, t.y)))
.collect(Collectors.toList())
);
}