Browse Source

Box Tracker

lakebane-master
FatBoy-DOTC 7 months ago
parent
commit
83499816eb
  1. 3
      src/engine/InterestManagement/InterestManager.java
  2. 43
      src/engine/util/BoxTracker.java

3
src/engine/InterestManagement/InterestManager.java

@ -25,6 +25,7 @@ import engine.net.client.msg.MoveToPointMsg;
import engine.net.client.msg.UnloadObjectsMsg; import engine.net.client.msg.UnloadObjectsMsg;
import engine.objects.*; import engine.objects.*;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.util.BoxTracker;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
@ -524,7 +525,7 @@ public enum InterestManager implements Runnable {
player.setDirtyLoad(true); player.setDirtyLoad(true);
updateStaticList(player, origin); updateStaticList(player, origin);
updateMobileList(player, origin); updateMobileList(player, origin);
//PlayerCharacter.checkIfBoxed(player); BoxTracker.addPlayer(origin.machineID,player);
} }

43
src/engine/util/BoxTracker.java

@ -0,0 +1,43 @@
package engine.util;
import engine.objects.PlayerCharacter;
import java.util.ArrayList;
import java.util.HashMap;
public class BoxTracker {
private static final HashMap<String, ArrayList<PlayerCharacter>> players_by_machine = new HashMap<>();
public static void addPlayer(String machineId, PlayerCharacter player) {
synchronized (players_by_machine) {
ArrayList<PlayerCharacter> players = players_by_machine.get(machineId);
if (players != null) {
player.isBoxed = true;
players.add(player);
} else {
players = new ArrayList<>();
players.add(player);
players_by_machine.put(machineId, players);
}
}
}
public static ArrayList<PlayerCharacter> getPlayers(String machineId) {
synchronized (players_by_machine) {
return new ArrayList<>(players_by_machine.getOrDefault(machineId, new ArrayList<>()));
}
}
public static void removePlayer(String machineId, PlayerCharacter player) {
synchronized (players_by_machine) {
ArrayList<PlayerCharacter> players = players_by_machine.get(machineId);
if (players != null) {
players.remove(player);
if (players.isEmpty()) {
players_by_machine.remove(machineId);
}
}
}
}
}
Loading…
Cancel
Save