Browse Source

Zerg Mechanic for Mines

lakebane-new
FatBoy-DOTC 5 months ago
parent
commit
e5133211a9
  1. 13
      src/engine/gameManager/SimulationManager.java
  2. 92
      src/engine/gameManager/ZergManager.java
  3. 80
      src/engine/objects/Mine.java
  4. 2
      src/engine/objects/PlayerCharacter.java

13
src/engine/gameManager/SimulationManager.java

@ -10,10 +10,7 @@ package engine.gameManager; @@ -10,10 +10,7 @@ package engine.gameManager;
import engine.Enum;
import engine.Enum.GameObjectType;
import engine.objects.AbstractGameObject;
import engine.objects.City;
import engine.objects.PlayerCharacter;
import engine.objects.Runegate;
import engine.objects.*;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
@ -33,7 +30,7 @@ public enum SimulationManager { @@ -33,7 +30,7 @@ public enum SimulationManager {
SERVERHEARTBEAT;
private static final long CITY_PULSE = 2000;
private static final long RUNEGATE_PULSE = 3000;
private static final long RUNEGATE_PULSE = 1000;
private static final long UPDATE_PULSE = 1000;
private static final long FlIGHT_PULSE = 100;
public static Duration executionTime = Duration.ofNanos(1);
@ -203,8 +200,12 @@ public enum SimulationManager { @@ -203,8 +200,12 @@ public enum SimulationManager {
city = (City) cityObject;
city.onEnter();
}
for(Mine mine : Mine.getMines()){
if(mine != null)
mine.onEnter();
}
_cityPulseTime = System.currentTimeMillis() + CITY_PULSE;
}
/*

92
src/engine/gameManager/ZergManager.java

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
package engine.gameManager;
import engine.objects.Guild;
public class ZergManager {
public static float getCurrentMultiplier(int count, int maxCount){
switch(maxCount) {
case 3:
return getMultiplier3Man(count);
case 5:
return getMultiplier5Man(count);
case 10:
return getMultiplier10Man(count);
default:
return getMultiplier20Man(count);
}
}
public static float getMultiplier3Man(int count) {
if(count < 4)
return 1.0f;
if(count > 6)
return 0.0f;
switch(count){
case 4:
return 0.75f;
case 5:
return 0.60f;
case 6:
return 0.37f;
}
return 1.0f;
}
public static float getMultiplier5Man(int count) {
if(count < 6)
return 1.0f;
if(count > 10)
return 0.0f;
switch(count){
case 6:
return 0.75f;
case 7:
return 0.67f;
case 8:
return 0.56f;
case 9:
return 0.43f;
case 10:
return 0.25f;
}
return 1.0f;
}
public static float getMultiplier10Man(int count) {
if(count < 11)
return 1.0f;
if(count > 20)
return 0.0f;
switch(count){
case 11:
return 0.75f;
case 12:
return 0.71f;
case 13:
return 0.67f;
case 14:
return 0.62f;
case 15:
return 0.56f;
case 16:
return 0.50f;
case 17:
return 0.43f;
case 18:
return 0.35f;
case 19:
return 0.25f;
case 20:
return 0.14f;
}
return 1.0f;
}
public static float getMultiplier20Man(int count) {
return getMultiplier10Man(count * 2);
}
}

80
src/engine/objects/Mine.java

@ -11,10 +11,7 @@ package engine.objects; @@ -11,10 +11,7 @@ package engine.objects;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager;
import engine.gameManager.*;
import engine.net.ByteBufferWriter;
import engine.net.client.msg.ErrorPopupMsg;
import engine.server.MBServerStatics;
@ -25,6 +22,9 @@ import java.sql.ResultSet; @@ -25,6 +22,9 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import static engine.gameManager.DbManager.MineQueries;
@ -55,6 +55,8 @@ public class Mine extends AbstractGameObject { @@ -55,6 +55,8 @@ public class Mine extends AbstractGameObject {
public int openMinute;
public int capSize;
public LocalDateTime liveTime;
public final HashSet<Integer> _playerMemory = new HashSet<>();
public ArrayList<PlayerCharacter> affectedPlayers = new ArrayList<>();
/**
* ResultSet Constructor
@ -570,5 +572,75 @@ public class Mine extends AbstractGameObject { @@ -570,5 +572,75 @@ public class Mine extends AbstractGameObject {
}
return (int) totalModded;
}
public void onEnter() {
Building tower = BuildingManager.getBuildingFromCache(this.buildingID);
if(tower == null)
return;
// Gather current list of players within the zone bounds
HashSet<AbstractWorldObject> currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents, MBServerStatics.MASK_PLAYER);
HashMap<Guild,ArrayList<PlayerCharacter>> charactersByNation = new HashMap<>();
ArrayList<Guild> updatedNations = new ArrayList<>();
for (AbstractWorldObject playerObject : currentPlayers) {
if (playerObject == null)
continue;
PlayerCharacter player = (PlayerCharacter) playerObject;
if(!this._playerMemory.contains(player.getObjectUUID())){
this._playerMemory.add(player.getObjectUUID());
}
Guild nation = player.guild.getNation();
if(charactersByNation.containsKey(nation)){
if(!charactersByNation.get(nation).contains(player)) {
charactersByNation.get(nation).add(player);
if(!updatedNations.contains(nation)){
updatedNations.add(nation);
}
}
}else{
ArrayList<PlayerCharacter> players = new ArrayList<>();
players.add(player);
charactersByNation.put(nation,players);
if(!updatedNations.contains(nation)){
updatedNations.add(nation);
}
}
}
for(Guild nation : updatedNations){
float multiplier = ZergManager.getCurrentMultiplier(charactersByNation.get(nation).size(),this.capSize);
for(PlayerCharacter player : charactersByNation.get(nation)){
player.ZergMultiplier = multiplier;
}
}
try
{
this.onExit(this._playerMemory);
}
catch(Exception ignored){
}
}
private void onExit(HashSet<Integer> currentMemory) {
Building tower = BuildingManager.getBuildingFromCache(this.buildingID);
if(tower == null)
return;
ArrayList<Integer>toRemove = new ArrayList<>();
HashSet<AbstractWorldObject> currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents, MBServerStatics.MASK_PLAYER);
for(Integer id : currentMemory){
PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(id);
if(currentPlayers.contains(pc) == false){
toRemove.add(id);
pc.ZergMultiplier = 1.0f;
}
}
// Remove players from city memory
_playerMemory.removeAll(toRemove);
}
}

2
src/engine/objects/PlayerCharacter.java

@ -175,6 +175,8 @@ public class PlayerCharacter extends AbstractCharacter { @@ -175,6 +175,8 @@ public class PlayerCharacter extends AbstractCharacter {
private boolean dirtyLoad = true;
private final ReadWriteLock dirtyLock = new ReentrantReadWriteLock(true);
public float ZergMultiplier = 1.0f;
/**
* No Id Constructor
*/

Loading…
Cancel
Save