mine zerg tracker
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ public class Mine extends AbstractGameObject {
|
||||
public HashMap<Integer,Integer> oldBuildings;
|
||||
public HashMap<Integer, Long> mineAttendees = new HashMap<>();
|
||||
|
||||
public ZergTracker zergTracker;
|
||||
|
||||
/**
|
||||
* ResultSet Constructor
|
||||
*/
|
||||
|
||||
@@ -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<PlayerCharacter> inRangeCurrent;
|
||||
public HashMap<Guild,ArrayList<PlayerCharacter>> playersByNation;
|
||||
public HashMap<PlayerCharacter,Long> leaveQue;
|
||||
public ArrayList<PlayerCharacter> 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<AbstractWorldObject> 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<PlayerCharacter> 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<PlayerCharacter> newList = new ArrayList<>();
|
||||
newList.add(pc);
|
||||
this.playersByNation.put(nation,newList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void processLeaveQue(){
|
||||
ArrayList<PlayerCharacter> 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<AbstractWorldObject> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user