Fixed overcomplicated implementation

This commit is contained in:
Stankman 2023-06-27 00:04:47 -05:00
parent 13e882021b
commit 88c4e0b288
4 changed files with 35 additions and 39 deletions

View File

@ -5,8 +5,4 @@ import com.eu.habbo.habbohotel.rooms.RoomTile;
public interface IWiredPeriodical { public interface IWiredPeriodical {
int getInterval(); int getInterval();
void setInterval(int value); void setInterval(int value);
boolean isTriggerTileUpdated();
void setTriggerTileUpdated(boolean value);
RoomTile getOldTile();
void setOldTile(RoomTile value);
} }

View File

@ -22,12 +22,6 @@ import java.sql.SQLException;
public class WiredTriggerRepeater extends InteractionWiredTrigger implements IWiredPeriodical, WiredTriggerReset { public class WiredTriggerRepeater extends InteractionWiredTrigger implements IWiredPeriodical, WiredTriggerReset {
public final int PARAM_REPEAT_TIME = 0; public final int PARAM_REPEAT_TIME = 0;
protected int counter = 0; protected int counter = 0;
@Getter
@Setter
private boolean triggerTileUpdated;
@Getter
@Setter
private RoomTile oldTile;
@Setter @Setter
private int interval; private int interval;
@ -53,15 +47,25 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements IWi
@Override @Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
this.triggerTileUpdated = true; if(room.getTriggersOnRoom().containsKey(oldLocation)) {
this.oldTile = oldLocation; if(room.getTriggersOnRoom().get(oldLocation).getId() == this.getId()) {
room.getTriggersOnRoom().remove(oldLocation);
}
}
super.onMove(room, oldLocation, newLocation); super.onMove(room, oldLocation, newLocation);
} }
@Override @Override
public void onPickUp(Room room) { public void onPickUp(Room room) {
this.triggerTileUpdated = true; RoomTile oldLocation = room.getLayout().getTile(this.getX(), this.getY());
this.oldTile = room.getLayout().getTile(this.getX(), this.getY());
if(room.getTriggersOnRoom().containsKey(oldLocation)) {
if(room.getTriggersOnRoom().get(oldLocation).getId() == this.getId()) {
room.getTriggersOnRoom().remove(oldLocation);
}
}
super.onPickUp(room); super.onPickUp(room);
} }

View File

@ -20,12 +20,6 @@ import java.sql.SQLException;
public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements IWiredPeriodical, WiredTriggerReset { public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements IWiredPeriodical, WiredTriggerReset {
public final int PARAM_REPEAT_TIME = 0; public final int PARAM_REPEAT_TIME = 0;
protected int counter = 0; protected int counter = 0;
@Getter
@Setter
private boolean triggerTileUpdated;
@Getter
@Setter
private RoomTile oldTile;
@Setter @Setter
private int interval; private int interval;
public WiredTriggerRepeaterLong(ResultSet set, Item baseItem) throws SQLException { public WiredTriggerRepeaterLong(ResultSet set, Item baseItem) throws SQLException {
@ -50,20 +44,30 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
@Override @Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
this.triggerTileUpdated = true; if(room.getTriggersOnRoom().containsKey(oldLocation)) {
this.oldTile = oldLocation; if(room.getTriggersOnRoom().get(oldLocation).getId() == this.getId()) {
room.getTriggersOnRoom().remove(oldLocation);
}
}
super.onMove(room, oldLocation, newLocation); super.onMove(room, oldLocation, newLocation);
} }
@Override @Override
public void onPickUp(Room room) { public void onPickUp(Room room) {
this.triggerTileUpdated = true; RoomTile oldLocation = room.getLayout().getTile(this.getX(), this.getY());
this.oldTile = room.getLayout().getTile(this.getX(), this.getY());
if(room.getTriggersOnRoom().containsKey(oldLocation)) {
if(room.getTriggersOnRoom().get(oldLocation).getId() == this.getId()) {
room.getTriggersOnRoom().remove(oldLocation);
}
}
super.onPickUp(room); super.onPickUp(room);
} }
public int getInterval() { public int getInterval() {
return this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 500; return this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 5000;
} }
@Override @Override

View File

@ -4399,23 +4399,15 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return; return;
} }
if(((IWiredPeriodical) trigger).isTriggerTileUpdated()) {
if(this.triggersOnRoom.containsKey(((IWiredPeriodical) trigger).getOldTile())) {
if(this.triggersOnRoom.get(((IWiredPeriodical) trigger).getOldTile()).getId() == trigger.getId() || this.triggersOnRoom.get(((IWiredPeriodical) trigger).getOldTile()) == null) {
this.triggersOnRoom.remove(((IWiredPeriodical) trigger).getOldTile());
}
}
((IWiredPeriodical) trigger).setTriggerTileUpdated(false);
((IWiredPeriodical) trigger).setOldTile(null);
}
RoomTile triggerTile = this.layout.getTile(trigger.getX(), trigger.getY()); RoomTile triggerTile = this.layout.getTile(trigger.getX(), trigger.getY());
if (this.triggersOnRoom.containsKey(triggerTile)) { if (this.triggersOnRoom.containsKey(triggerTile)) {
if (this.triggersOnRoom.get(triggerTile) == null || (this.triggersOnRoom.get(triggerTile).getId() != trigger.getId() && ((IWiredPeriodical) trigger).getInterval() <= ((IWiredPeriodical) this.triggersOnRoom.get(triggerTile)).getInterval())) { if(this.triggersOnRoom.get(triggerTile).getId() != trigger.getId()) {
this.triggersOnRoom.put(triggerTile, trigger); if(((IWiredPeriodical) this.triggersOnRoom.get(triggerTile)).getInterval() <= ((IWiredPeriodical) trigger).getInterval()) {
} else if (this.triggersOnRoom.get(triggerTile).getId() != trigger.getId() && ((IWiredPeriodical) this.triggersOnRoom.get(triggerTile)).getInterval() <= ((IWiredPeriodical) trigger).getInterval()) { return;
return; } else {
this.triggersOnRoom.put(triggerTile, trigger);
}
} }
} else { } else {
this.triggersOnRoom.put(triggerTile, trigger); this.triggersOnRoom.put(triggerTile, trigger);