List<Integer> speciesList = new ArrayList<Integer>(totalSpeciesList.keySet());
Collections.shuffle(speciesList);
for (int species_id : speciesList) {
SpeciesType species = GameServer.getInstance().getSpecies(species_id);
int gDiff = 0, rDiff = 0;
boolean hasGrowth = true, hasReduced = true;
for (int node_id : species.getNodeList()) {
int diff = speciesDifference.get(node_id) / species.getNodeAmount(node_id);
// Check Growth
if (diff > 0) {
gDiff = gDiff == 0 ? diff : Math.min(diff, gDiff);
} else {
hasGrowth = false;
}
// Check Reduction
if (diff < 0) {
rDiff = rDiff == 0 ? diff : Math.max(diff, rDiff);
} else {
hasReduced = false;
}
}
if (hasGrowth) {
System.out.println(" " + species.getSpeciesName() + " Species[" + species.getID() + "] increased by " + gDiff);
for (int node_id : species.getNodeList()) {
int amount = gDiff * species.getNodeAmount(node_id);
speciesDifference.put(node_id, speciesDifference.get(node_id) - amount);
System.out.println(" Node[" + node_id + "] increased by " + amount);
}
gameEngine.createOrganismsByBirth(species.getID(), zone.getID(), gDiff);
} else if (hasReduced) {
System.out.println(" " + species.getSpeciesName() + " Species[" + species.getID() + "] decreased by " + Math.abs(rDiff));
for (int node_id : species.getNodeList()) {
int amount = rDiff * species.getNodeAmount(node_id);
speciesDifference.put(node_id, speciesDifference.get(node_id) - amount);
System.out.println(" Node[" + node_id + "] decreased by " + Math.abs(amount));
}
gameEngine.removeOrganismsByDeath(species.getID(), zone.getID(), Math.abs(rDiff));
}
}
ZoneDAO.updateBiomass(zone.getID(), zone.getMaxBiomass(), zone.getPrevBiomass(), zone.getTotalBiomass());