diff --git a/src/engine/gameManager/ZergManager.java b/src/engine/gameManager/ZergManager.java index a340b0e0..90c48350 100644 --- a/src/engine/gameManager/ZergManager.java +++ b/src/engine/gameManager/ZergManager.java @@ -1,5 +1,9 @@ package engine.gameManager; +import engine.objects.Building; import engine.objects.Guild; +import engine.objects.Mine; +import engine.server.MBServerStatics; + public class ZergManager { public static float getCurrentMultiplier(int count, int maxCount){ @@ -192,4 +196,17 @@ public class ZergManager { default: return 1.0f; } } + + public static void MineTracker(Mine mine){ + Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID()); + if(tower == null) + return; + + float affectedRange = MBServerStatics.CHARACTER_LOAD_RANGE * 3; + mine.zergTracker.compileCurrent(tower.loc, affectedRange); + mine.zergTracker.sortByNation(); + mine.zergTracker.compileLeaveQue(tower.loc, affectedRange); + mine.zergTracker.processLeaveQue(); + mine.zergTracker.applyMultiplier(mine.capSize); + } } diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index df1be7a0..435d7f63 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -67,6 +67,8 @@ public class Mine extends AbstractGameObject { public HashMap oldBuildings; public HashMap mineAttendees = new HashMap<>(); + public ZergTracker zergTracker; + /** * ResultSet Constructor */ diff --git a/src/engine/objects/ZergTracker.java b/src/engine/objects/ZergTracker.java new file mode 100644 index 00000000..e6c14f1d --- /dev/null +++ b/src/engine/objects/ZergTracker.java @@ -0,0 +1,88 @@ +package engine.objects; + +import engine.InterestManagement.WorldGrid; +import engine.gameManager.ZergManager; +import engine.math.Vector3fImmutable; +import engine.server.MBServerStatics; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +public class ZergTracker { + public ArrayList inRangeCurrent; + public HashMap> playersByNation; + public HashMap leaveQue; + public ArrayList totalAttended; + + public ZergTracker(){ + this.inRangeCurrent = new ArrayList<>(); + this.playersByNation = new HashMap<>(); + this.leaveQue = new HashMap<>(); + this.totalAttended = new ArrayList<>(); + } + + public void compileCurrent(Vector3fImmutable loc, float range){ + this.inRangeCurrent = new ArrayList<>(); + HashSet current = WorldGrid.getObjectsInRangePartial(loc,range, MBServerStatics.MASK_PLAYER); + for(AbstractWorldObject awo : current){ + this.inRangeCurrent.add((PlayerCharacter)awo); + if(!this.totalAttended.contains((PlayerCharacter)awo)) + this.totalAttended.add((PlayerCharacter)awo); + } + } + + public void sortByNation(){ + this.playersByNation = new HashMap<>(); + for(PlayerCharacter pc : this.inRangeCurrent){ + Guild nation = pc.guild.getNation(); + if(this.playersByNation.containsKey(nation)){ + this.playersByNation.get(nation).add(pc); + }else{ + ArrayList newList = new ArrayList<>(); + newList.add(pc); + this.playersByNation.put(nation,newList); + } + } + for(PlayerCharacter pc : this.leaveQue.keySet()){ + Guild nation = pc.guild.getNation(); + if(this.playersByNation.containsKey(nation)){ + this.playersByNation.get(nation).add(pc); + }else{ + ArrayList newList = new ArrayList<>(); + newList.add(pc); + this.playersByNation.put(nation,newList); + } + } + } + + public void processLeaveQue(){ + ArrayList toRemove = new ArrayList<>(); + for(PlayerCharacter pc : this.leaveQue.keySet()){ + if(System.currentTimeMillis() > this.leaveQue.get(pc) + MBServerStatics.THREE_MINUTES){ + toRemove.add(pc); + } + } + for(PlayerCharacter pc : toRemove){ + this.leaveQue.remove(pc); + pc.ZergMultiplier = 1.0f; + this.totalAttended.remove(pc); + } + } + + public void compileLeaveQue(Vector3fImmutable loc, float range){ + HashSet current = WorldGrid.getObjectsInRangePartial(loc,range, MBServerStatics.MASK_PLAYER); + for(PlayerCharacter pc : totalAttended){ + if(!current.contains(pc) && !this.leaveQue.containsKey(pc)){ + this.leaveQue.put(pc,System.currentTimeMillis()); + } + } + } + + public void applyMultiplier(int cap){ + for(PlayerCharacter pc : this.inRangeCurrent){ + int count = this.playersByNation.get(pc.guild.getNation()).size(); + pc. ZergMultiplier = ZergManager.getCurrentMultiplier(cap,count); + } + } +} diff --git a/src/engine/server/MBServerStatics.java b/src/engine/server/MBServerStatics.java index c4ee2d89..6cba5868 100644 --- a/src/engine/server/MBServerStatics.java +++ b/src/engine/server/MBServerStatics.java @@ -379,6 +379,7 @@ public class MBServerStatics { // Mine related public static final int MINE_EARLY_WINDOW = 16; // 4pm public static final int MINE_LATE_WINDOW = 0; // Midnight + public static final Long THREE_MINUTES = 180000L; public static boolean DEBUG_PROTOCOL = false; public static int SPATIAL_HASH_BUCKETSX = 16384; public static int SPATIAL_HASH_BUCKETSY = 12288;