mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-18 15:36:27 +01:00
Changed Periodical Wired Cycle to Room
This commit is contained in:
parent
f05fab12f4
commit
13e882021b
@ -0,0 +1,12 @@
|
||||
package com.eu.habbo.habbohotel.items.interactions.wired.interfaces;
|
||||
|
||||
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
||||
|
||||
public interface IWiredPeriodical {
|
||||
int getInterval();
|
||||
void setInterval(int value);
|
||||
boolean isTriggerTileUpdated();
|
||||
void setTriggerTileUpdated(boolean value);
|
||||
RoomTile getOldTile();
|
||||
void setOldTile(RoomTile value);
|
||||
}
|
@ -4,21 +4,33 @@ import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.items.ICycleable;
|
||||
import com.eu.habbo.habbohotel.items.Item;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredPeriodical;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
||||
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
||||
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset {
|
||||
public class WiredTriggerRepeater extends InteractionWiredTrigger implements IWiredPeriodical, WiredTriggerReset {
|
||||
public final int PARAM_REPEAT_TIME = 0;
|
||||
protected int counter = 0;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean triggerTileUpdated;
|
||||
@Getter
|
||||
@Setter
|
||||
private RoomTile oldTile;
|
||||
@Setter
|
||||
private int interval;
|
||||
|
||||
public WiredTriggerRepeater(ResultSet set, Item baseItem) throws SQLException {
|
||||
super(set, baseItem);
|
||||
}
|
||||
@ -41,44 +53,20 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
|
||||
|
||||
@Override
|
||||
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
|
||||
if(room.getTriggersOnRoom().containsValue(this)) {
|
||||
room.getTriggersOnRoom().remove(oldLocation.getX() + ";" + oldLocation.getY());
|
||||
}
|
||||
|
||||
this.triggerTileUpdated = true;
|
||||
this.oldTile = oldLocation;
|
||||
super.onMove(room, oldLocation, newLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickUp(Room room) {
|
||||
if(room.getTriggersOnRoom().containsValue(this)) {
|
||||
room.getTriggersOnRoom().remove(this.getX() + ";" + this.getY());
|
||||
}
|
||||
|
||||
this.triggerTileUpdated = true;
|
||||
this.oldTile = room.getLayout().getTile(this.getX(), this.getY());
|
||||
super.onPickUp(room);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cycle(Room room) {
|
||||
String key = this.getX() + ";" + this.getY();
|
||||
|
||||
if(room.getTriggersOnRoom().containsKey(key)) {
|
||||
if(room.getTriggersOnRoom().get(key).getId() != this.getId()) {
|
||||
if(!(room.getTriggersOnRoom().get(key) instanceof WiredTriggerRepeaterLong) && room.getTriggersOnRoom().get(key).getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) <= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
room.getTriggersOnRoom().put(key, this);
|
||||
|
||||
this.counter += 500;
|
||||
if (this.counter >= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 500) {
|
||||
this.counter = 0;
|
||||
if (this.getRoomId() != 0) {
|
||||
if (room.isLoaded()) {
|
||||
WiredHandler.handle(this, null, room, new Object[]{this});
|
||||
}
|
||||
}
|
||||
}
|
||||
public int getInterval() {
|
||||
return this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 500;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,20 +4,30 @@ import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.items.ICycleable;
|
||||
import com.eu.habbo.habbohotel.items.Item;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredPeriodical;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.rooms.RoomTile;
|
||||
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
||||
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset {
|
||||
public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements IWiredPeriodical, WiredTriggerReset {
|
||||
public final int PARAM_REPEAT_TIME = 0;
|
||||
private int counter = 0;
|
||||
|
||||
protected int counter = 0;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean triggerTileUpdated;
|
||||
@Getter
|
||||
@Setter
|
||||
private RoomTile oldTile;
|
||||
@Setter
|
||||
private int interval;
|
||||
public WiredTriggerRepeaterLong(ResultSet set, Item baseItem) throws SQLException {
|
||||
super(set, baseItem);
|
||||
}
|
||||
@ -40,44 +50,20 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
|
||||
|
||||
@Override
|
||||
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
|
||||
if(room.getTriggersOnRoom().containsValue(this)) {
|
||||
room.getTriggersOnRoom().remove(oldLocation.getX() + ";" + oldLocation.getY());
|
||||
}
|
||||
|
||||
this.triggerTileUpdated = true;
|
||||
this.oldTile = oldLocation;
|
||||
super.onMove(room, oldLocation, newLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickUp(Room room) {
|
||||
if(room.getTriggersOnRoom().containsValue(this)) {
|
||||
room.getTriggersOnRoom().remove(this.getX() + ";" + this.getY());
|
||||
}
|
||||
|
||||
this.triggerTileUpdated = true;
|
||||
this.oldTile = room.getLayout().getTile(this.getX(), this.getY());
|
||||
super.onPickUp(room);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cycle(Room room) {
|
||||
String key = this.getX() + ";" + this.getY();
|
||||
|
||||
if(room.getTriggersOnRoom().containsKey(key)) {
|
||||
if(room.getTriggersOnRoom().get(key).getId() != this.getId()) {
|
||||
if(room.getTriggersOnRoom().get(key).getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) <= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
room.getTriggersOnRoom().put(key, this);
|
||||
|
||||
this.counter += 500;
|
||||
if (this.counter >= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 5000) {
|
||||
this.counter = 0;
|
||||
if (this.getRoomId() != 0) {
|
||||
if (room.isLoaded()) {
|
||||
WiredHandler.handle(this, null, room, new Object[]{this});
|
||||
}
|
||||
}
|
||||
}
|
||||
public int getInterval() {
|
||||
return this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 500;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,6 +22,8 @@ import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField;
|
||||
import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole;
|
||||
import com.eu.habbo.habbohotel.items.interactions.pets.*;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredPeriodical;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerRepeaterLong;
|
||||
import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
|
||||
import com.eu.habbo.habbohotel.permissions.Permission;
|
||||
import com.eu.habbo.habbohotel.pets.Pet;
|
||||
@ -292,11 +294,18 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
private RoomSpecialTypes roomSpecialTypes;
|
||||
@Getter
|
||||
private TraxManager traxManager;
|
||||
@Getter
|
||||
private HashMap<String, InteractionWiredTrigger> triggersOnRoom;
|
||||
private boolean cycleOdd;
|
||||
@Getter
|
||||
private long cycleTimestamp;
|
||||
@Getter
|
||||
@Setter
|
||||
private ScheduledFuture wiredPeriodicalCycle;
|
||||
@Getter
|
||||
@Setter
|
||||
final HashMap<RoomTile, InteractionWiredTrigger> triggersOnRoom;
|
||||
@Getter
|
||||
@Setter
|
||||
private int periodicalTick;
|
||||
|
||||
public Room(ResultSet set) throws SQLException {
|
||||
this.id = set.getInt("id");
|
||||
@ -383,7 +392,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
this.activeTrades = new THashSet<>(0);
|
||||
this.rights = new TIntArrayList();
|
||||
this.userVotes = new ArrayList<>();
|
||||
|
||||
this.triggersOnRoom = new HashMap<>();
|
||||
this.periodicalTick = 0;
|
||||
}
|
||||
|
||||
public synchronized void loadData() {
|
||||
@ -410,7 +421,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
this.loadBots(connection);
|
||||
this.loadPets(connection);
|
||||
this.loadWordFilter(connection);
|
||||
// this.loadWiredData(connection);
|
||||
this.startPeriodicalCycle();
|
||||
|
||||
this.idleCycles = 0;
|
||||
this.loaded = true;
|
||||
@ -908,6 +919,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
if (Emulator.getPluginManager().fireEvent(new RoomUnloadingEvent(this)).isCancelled())
|
||||
return;
|
||||
|
||||
if(this.wiredPeriodicalCycle != null) {
|
||||
this.wiredPeriodicalCycle.cancel(true);
|
||||
}
|
||||
|
||||
if (this.loaded) {
|
||||
try {
|
||||
|
||||
@ -4356,4 +4371,64 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
THashSet<RoomUnit> roomUnits = getRoomUnits();
|
||||
return roomUnits.stream().filter(unit -> unit.getCurrentLocation() == tile).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private void startPeriodicalCycle() {
|
||||
this.wiredPeriodicalCycle = Emulator.getThreading().run(() -> {
|
||||
if(Emulator.isShuttingDown) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.startPeriodicalCycle();
|
||||
|
||||
List<InteractionWiredTrigger> periodicals = new ArrayList<>();
|
||||
|
||||
if(this.getRoomSpecialTypes().getTriggers(WiredTriggerType.PERIODICALLY) != null) {
|
||||
periodicals.addAll(this.getRoomSpecialTypes().getTriggers(WiredTriggerType.PERIODICALLY));
|
||||
}
|
||||
|
||||
if(this.getRoomSpecialTypes().getTriggers(WiredTriggerType.PERIODICALLY_LONG) != null) {
|
||||
periodicals.addAll(this.getRoomSpecialTypes().getTriggers(WiredTriggerType.PERIODICALLY_LONG));
|
||||
}
|
||||
|
||||
if(periodicals.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
periodicals.parallelStream().forEach(trigger -> {
|
||||
if(!(trigger instanceof IWiredPeriodical)) {
|
||||
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());
|
||||
|
||||
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())) {
|
||||
this.triggersOnRoom.put(triggerTile, trigger);
|
||||
} else if (this.triggersOnRoom.get(triggerTile).getId() != trigger.getId() && ((IWiredPeriodical) this.triggersOnRoom.get(triggerTile)).getInterval() <= ((IWiredPeriodical) trigger).getInterval()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.triggersOnRoom.put(triggerTile, trigger);
|
||||
}
|
||||
|
||||
if(this.periodicalTick % (((IWiredPeriodical) trigger).getInterval() / 500) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
WiredHandler.handle(trigger, null, this, new Object[]{trigger});
|
||||
});
|
||||
|
||||
++this.periodicalTick;
|
||||
}, 500L);
|
||||
}
|
||||
}
|
||||
|
@ -27,10 +27,8 @@ import gnu.trove.map.hash.THashMap;
|
||||
import gnu.trove.set.hash.THashSet;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RoomSpecialTypes {
|
||||
private final THashMap<Integer, InteractionBattleBanzaiTeleporter> banzaiTeleporters;
|
||||
@ -40,7 +38,7 @@ public class RoomSpecialTypes {
|
||||
private final THashMap<Integer, InteractionPetToy> petToys;
|
||||
private final THashMap<Integer, InteractionRoller> rollers;
|
||||
|
||||
private final THashMap<WiredTriggerType, THashSet<InteractionWiredTrigger>> wiredTriggers;
|
||||
private final HashMap<WiredTriggerType, List<InteractionWiredTrigger>> wiredTriggers;
|
||||
private final THashMap<WiredEffectType, THashSet<InteractionWiredEffect>> wiredEffects;
|
||||
private final THashMap<WiredConditionType, THashSet<InteractionWiredCondition>> wiredConditions;
|
||||
private final THashMap<Integer, InteractionWiredExtra> wiredExtras;
|
||||
@ -61,7 +59,7 @@ public class RoomSpecialTypes {
|
||||
this.petToys = new THashMap<>(0);
|
||||
this.rollers = new THashMap<>(0);
|
||||
|
||||
this.wiredTriggers = new THashMap<>(0);
|
||||
this.wiredTriggers = new HashMap<>(0);
|
||||
this.wiredEffects = new THashMap<>(0);
|
||||
this.wiredConditions = new THashMap<>(0);
|
||||
this.wiredExtras = new THashMap<>(0);
|
||||
@ -229,7 +227,7 @@ public class RoomSpecialTypes {
|
||||
|
||||
public InteractionWiredTrigger getTrigger(int itemId) {
|
||||
synchronized (this.wiredTriggers) {
|
||||
for (Map.Entry<WiredTriggerType, THashSet<InteractionWiredTrigger>> map : this.wiredTriggers.entrySet()) {
|
||||
for (Map.Entry<WiredTriggerType, List<InteractionWiredTrigger>> map : this.wiredTriggers.entrySet()) {
|
||||
for (InteractionWiredTrigger trigger : map.getValue()) {
|
||||
if (trigger.getId() == itemId)
|
||||
return trigger;
|
||||
@ -244,7 +242,7 @@ public class RoomSpecialTypes {
|
||||
synchronized (this.wiredTriggers) {
|
||||
THashSet<InteractionWiredTrigger> triggers = new THashSet<>();
|
||||
|
||||
for (Map.Entry<WiredTriggerType, THashSet<InteractionWiredTrigger>> map : this.wiredTriggers.entrySet()) {
|
||||
for (Map.Entry<WiredTriggerType, List<InteractionWiredTrigger>> map : this.wiredTriggers.entrySet()) {
|
||||
triggers.addAll(map.getValue());
|
||||
}
|
||||
|
||||
@ -252,7 +250,7 @@ public class RoomSpecialTypes {
|
||||
}
|
||||
}
|
||||
|
||||
public THashSet<InteractionWiredTrigger> getTriggers(WiredTriggerType type) {
|
||||
public List<InteractionWiredTrigger> getTriggers(WiredTriggerType type) {
|
||||
return this.wiredTriggers.get(type);
|
||||
}
|
||||
|
||||
@ -260,7 +258,7 @@ public class RoomSpecialTypes {
|
||||
synchronized (this.wiredTriggers) {
|
||||
THashSet<InteractionWiredTrigger> triggers = new THashSet<>();
|
||||
|
||||
for (Map.Entry<WiredTriggerType, THashSet<InteractionWiredTrigger>> map : this.wiredTriggers.entrySet()) {
|
||||
for (Map.Entry<WiredTriggerType, List<InteractionWiredTrigger>> map : this.wiredTriggers.entrySet()) {
|
||||
for (InteractionWiredTrigger trigger : map.getValue()) {
|
||||
if (trigger.getX() == x && trigger.getY() == y)
|
||||
triggers.add(trigger);
|
||||
@ -274,7 +272,7 @@ public class RoomSpecialTypes {
|
||||
public void addTrigger(InteractionWiredTrigger trigger) {
|
||||
synchronized (this.wiredTriggers) {
|
||||
if (!this.wiredTriggers.containsKey(trigger.getType()))
|
||||
this.wiredTriggers.put(trigger.getType(), new THashSet<>());
|
||||
this.wiredTriggers.put(trigger.getType(), new ArrayList<>());
|
||||
|
||||
this.wiredTriggers.get(trigger.getType()).add(trigger);
|
||||
}
|
||||
@ -354,7 +352,6 @@ public class RoomSpecialTypes {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public InteractionWiredCondition getCondition(int itemId) {
|
||||
synchronized (this.wiredConditions) {
|
||||
for (Map.Entry<WiredConditionType, THashSet<InteractionWiredCondition>> map : this.wiredConditions.entrySet()) {
|
||||
|
@ -51,7 +51,7 @@ public class WiredHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
THashSet<InteractionWiredTrigger> triggers = room.getRoomSpecialTypes().getTriggers(triggerType);
|
||||
List<InteractionWiredTrigger> triggers = room.getRoomSpecialTypes().getTriggers(triggerType);
|
||||
|
||||
if (triggers == null || triggers.isEmpty()) {
|
||||
return false;
|
||||
@ -102,7 +102,7 @@ public class WiredHandler {
|
||||
if (room.getRoomSpecialTypes() == null)
|
||||
return false;
|
||||
|
||||
THashSet<InteractionWiredTrigger> triggers = room.getRoomSpecialTypes().getTriggers(WiredTriggerType.CUSTOM);
|
||||
List<InteractionWiredTrigger> triggers = room.getRoomSpecialTypes().getTriggers(WiredTriggerType.CUSTOM);
|
||||
|
||||
if (triggers == null || triggers.isEmpty())
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user