forked from MagicBane/Server
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
3.3 KiB
81 lines
3.3 KiB
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . |
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· |
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ |
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ |
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ |
|
// Magicbane Emulator Project © 2013 - 2022 |
|
// www.magicbane.com |
|
|
|
|
|
package engine.workthreads; |
|
|
|
import engine.Enum; |
|
import engine.InterestManagement.InterestManager; |
|
import engine.InterestManagement.WorldGrid; |
|
import engine.gameManager.*; |
|
import engine.math.Vector3fImmutable; |
|
import engine.objects.*; |
|
import engine.server.MBServerStatics; |
|
import org.pmw.tinylog.Logger; |
|
|
|
import java.time.LocalDateTime; |
|
import java.util.ArrayList; |
|
import java.util.HashMap; |
|
import java.util.HashSet; |
|
|
|
public class BoxFlagThread implements Runnable { |
|
|
|
public final static int THREAD_DELAY_SECONDS = 10; |
|
public BoxFlagThread() { |
|
|
|
} |
|
|
|
@Override |
|
public void run() { |
|
LocalDateTime nextPulse = LocalDateTime.now().minusMinutes(1); |
|
while(true){ |
|
if(LocalDateTime.now().isAfter(nextPulse)) { |
|
HashMap<String,ArrayList<PlayerCharacter>> PlayersByMachineID = new HashMap<>(); |
|
for(PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()){ |
|
if(PlayersByMachineID.containsKey(pc.getClientConnection().machineID)){ |
|
if(PlayersByMachineID.get(pc.getClientConnection().machineID).contains(pc) == false) |
|
PlayersByMachineID.get(pc.getClientConnection().machineID).add(pc); |
|
}else{ |
|
ArrayList<PlayerCharacter> newList = new ArrayList<>(); |
|
newList.add(pc); |
|
PlayersByMachineID.put(pc.getClientConnection().machineID,newList); |
|
} |
|
} |
|
|
|
for(String key : PlayersByMachineID.keySet()){ |
|
ArrayList<PlayerCharacter> machinePlayers = PlayersByMachineID.get(key); |
|
if(machinePlayers.size() > 1){ |
|
int unboxedCount = 0; |
|
for(PlayerCharacter pc : machinePlayers){ |
|
if(!pc.isBoxed) |
|
unboxedCount++; |
|
} |
|
|
|
if(unboxedCount > 1){ |
|
for(PlayerCharacter pc : machinePlayers){ |
|
pc.isBoxed = true; |
|
} |
|
machinePlayers.get(0).isBoxed = false; |
|
} |
|
}else{ |
|
machinePlayers.get(0).isBoxed = false; |
|
} |
|
} |
|
nextPulse = nextPulse.plusSeconds(THREAD_DELAY_SECONDS); |
|
} |
|
} |
|
} |
|
public static void startBoxFlagThread() { |
|
|
|
Thread boxFlag; |
|
boxFlag = new Thread(new BoxFlagThread()); |
|
|
|
boxFlag.setName("boxFlagThread"); |
|
boxFlag.start(); |
|
} |
|
}
|
|
|