Browse Source

bane mechanic for zerg measures

lakebane-master
FatBoy-DOTC 9 months ago
parent
commit
1db30e3c6b
  1. 2
      src/engine/gameManager/SimulationManager.java
  2. 37
      src/engine/gameManager/ZergManager.java
  3. 12
      src/engine/objects/Bane.java
  4. 200
      src/engine/objects/City.java
  5. 6
      src/engine/objects/Mine.java

2
src/engine/gameManager/SimulationManager.java

@ -239,7 +239,7 @@ public enum SimulationManager {
for (AbstractGameObject mineObject : mineList) { for (AbstractGameObject mineObject : mineList) {
mine = (Mine) mineObject; mine = (Mine) mineObject;
if(mine.isActive) if(mine.isActive)
mine.onEnter(); mine.onEnterZerg();
} }
_minePulseTime = System.currentTimeMillis() + CITY_PULSE; _minePulseTime = System.currentTimeMillis() + CITY_PULSE;

37
src/engine/gameManager/ZergManager.java

@ -1,11 +1,15 @@
package engine.gameManager; package engine.gameManager;
import engine.objects.Bane;
import engine.objects.Guild;
public class ZergManager { public class ZergManager {
public static float getMultiplier5Man(int count){ public static float getMultiplier5Man(int count){
float multiplier = 1.0f; float multiplier = 1.0f;
switch(count){ switch(count){
case 1: case 1:
case 2: case 2:
case 5:
multiplier += 0.0f; multiplier += 0.0f;
break; break;
case 3: case 3:
@ -14,9 +18,6 @@ public class ZergManager {
case 4: case 4:
multiplier += 0.2f; multiplier += 0.2f;
break; break;
case 5:
multiplier += 0.0f;
break;
case 6: case 6:
multiplier -= 0.2f; multiplier -= 0.2f;
break; break;
@ -163,4 +164,34 @@ public class ZergManager {
} }
return multiplier; return multiplier;
} }
public static int getBaneCapSize(Bane bane){
Guild defender = bane.getCity().getGuild();
int treesInNation = defender.getNation().getSubGuildList().size() + 1;
int capSize;
switch(treesInNation){
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
capSize = 20;
break;
case 7:
case 8:
case 9:
case 10:
capSize = 30;
break;
case 11:
case 12:
case 13:
case 14:
capSize = 40;
break;
default: capSize = 9999999;
}
return capSize;
}
} }

12
src/engine/objects/Bane.java

@ -17,10 +17,7 @@ import engine.InterestManagement.HeightMap;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.db.archive.BaneRecord; import engine.db.archive.BaneRecord;
import engine.db.archive.DataWarehouse; import engine.db.archive.DataWarehouse;
import engine.gameManager.BuildingManager; import engine.gameManager.*;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager;
import engine.job.JobScheduler; import engine.job.JobScheduler;
import engine.jobs.ActivateBaneJob; import engine.jobs.ActivateBaneJob;
import engine.jobs.BaneDefaultTimeJob; import engine.jobs.BaneDefaultTimeJob;
@ -52,6 +49,8 @@ public final class Bane {
// Internal cache for banes // Internal cache for banes
private ActivateBaneJob activateBaneJob; private ActivateBaneJob activateBaneJob;
public int capSize;
/** /**
* ResultSet Constructor * ResultSet Constructor
*/ */
@ -106,6 +105,8 @@ public final class Bane {
if (this.liveDate == null) if (this.liveDate == null)
setDefaultTime(); setDefaultTime();
this.capSize = ZergManager.getBaneCapSize(this);
} }
public static boolean summonBanestone(PlayerCharacter player, ClientConnection origin, int rank) { public static boolean summonBanestone(PlayerCharacter player, ClientConnection origin, int rank) {
@ -266,6 +267,7 @@ public final class Bane {
BaneRecord baneRecord = BaneRecord.borrow(bane, Enum.RecordEventType.PENDING); BaneRecord baneRecord = BaneRecord.borrow(bane, Enum.RecordEventType.PENDING);
DataWarehouse.pushToWarehouse(baneRecord); DataWarehouse.pushToWarehouse(baneRecord);
bane.capSize = ZergManager.getBaneCapSize(bane);
return true; return true;
} }
@ -341,7 +343,7 @@ public final class Bane {
} }
newBane = DbManager.BaneQueries.LOAD_BANE(city.getObjectUUID()); newBane = DbManager.BaneQueries.LOAD_BANE(city.getObjectUUID());
newBane.capSize = ZergManager.getBaneCapSize(newBane);
return newBane; return newBane;
} }

200
src/engine/objects/City.java

@ -32,6 +32,7 @@ import engine.server.MBServerStatics;
import engine.server.world.WorldServer; import engine.server.world.WorldServer;
import engine.workthreads.DestroyCityThread; import engine.workthreads.DestroyCityThread;
import engine.workthreads.TransferCityThread; import engine.workthreads.TransferCityThread;
import org.joda.time.DateTime;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -39,6 +40,7 @@ import java.sql.SQLException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -88,6 +90,9 @@ public class City extends AbstractWorldObject {
private boolean reverseKOS = false; private boolean reverseKOS = false;
private String hash; private String hash;
public final HashMap<Integer,Long> _recentMemory = new HashMap<>();
HashMap<Guild,ArrayList<Integer>> dividedPlayers;
public Integer totalPlayers;
/** /**
* ResultSet Constructor * ResultSet Constructor
*/ */
@ -980,23 +985,14 @@ public class City extends AbstractWorldObject {
public void onEnter() { public void onEnter() {
HashSet<AbstractWorldObject> currentPlayers; this.onEnterZerg();
HashSet<Integer> currentMemory;
PlayerCharacter player;
// Gather current list of players within the zone bounds
currentPlayers = WorldGrid.getObjectsInRangePartial(this.location, CityBoundsType.ZONE.extents * 2, MBServerStatics.MASK_PLAYER); for (Integer id : this._playerMemory) {
currentMemory = new HashSet<>();
for (AbstractWorldObject playerObject : currentPlayers) { PlayerCharacter player = PlayerCharacter.getFromCache(id);
if (player == null)
if (playerObject == null)
continue; continue;
player = (PlayerCharacter) playerObject;
currentMemory.add(player.getObjectUUID());
// Player is already in our memory // Player is already in our memory
if (_playerMemory.contains(player.getObjectUUID())) if (_playerMemory.contains(player.getObjectUUID()))
@ -1012,64 +1008,7 @@ public class City extends AbstractWorldObject {
//add spire effects. //add spire effects.
if (this.getEffects().size() > 0) if (this.getEffects().size() > 0)
this.applyAllCityEffects(player); this.applyAllCityEffects(player);
// Add player to our city's memory
_playerMemory.add(player.getObjectUUID());
// ***For debugging
// Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size());
}
try {
onExit(currentMemory);
} catch (Exception e) {
Logger.error(e.getMessage());
} }
PowersManager.applyZergBuff(this);
}
private void onExit(HashSet<Integer> currentMemory) {
PlayerCharacter player;
int playerUUID = 0;
HashSet<Integer> toRemove = new HashSet<>();
Iterator<Integer> iter = _playerMemory.iterator();
while (iter.hasNext()) {
playerUUID = iter.next();
player = PlayerCharacter.getFromCache(playerUUID);
if (this.isLocationWithinSiegeBounds(player.getLoc()))
continue;
// Remove players safezone status if warranted
// they can assumed to be not on the citygrid at
// this point.
player.setSafeZone(false);
this.removeAllCityEffects(player, false);
// We will remove this player after iteration is complete
// so store it in a temporary collection
toRemove.add(playerUUID);
// ***For debugging
// Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size());
}
// Remove players from city memory
_playerMemory.removeAll(toRemove);
for (Integer removalUUID : toRemove) {
if (this.cityOutlaws.contains(removalUUID))
this.cityOutlaws.remove(removalUUID);
}
PowersManager.removeZergBuff(toRemove);
} }
public int getWarehouseBuildingID() { public int getWarehouseBuildingID() {
@ -1442,4 +1381,125 @@ public class City extends AbstractWorldObject {
return true; return true;
} }
public void onEnterZerg() {
if(this.getBane() == null || this.getBane().getLiveDate().dayOfWeek() != DateTime.now().dayOfWeek() || this.getBane().getLiveDate().hourOfDay().get() < DateTime.now().hourOfDay().get() - 1)
return;
HashSet<AbstractWorldObject> currentPlayers;
PlayerCharacter player;
// Gather current list of players within the zone bounds
Building tower = this.getTOL();
currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents * 2, MBServerStatics.MASK_PLAYER);
boolean updated = false;
for (AbstractWorldObject playerObject : currentPlayers) {
if (playerObject == null)
continue;
player = (PlayerCharacter) playerObject;
// Player is already in our memory
if (_recentMemory.containsKey(player.getObjectUUID()))
_recentMemory.remove(player.getObjectUUID());
if (_playerMemory.contains(player.getObjectUUID()))
continue;
// Add player to our city's memory
_playerMemory.add(player.getObjectUUID());
updated = true;
// ***For debugging
// Logger.info("PlayerMemory for ", this.getCityName() + ": " + _playerMemory.size());
}
this.totalPlayers = this._playerMemory.size();
try {
if(onExitZerg(currentPlayers)){
updated = true;
}
} catch (Exception e) {
Logger.error(e.getMessage());
}
this.dividedPlayers = new HashMap<>();
for(Integer playerID : this._playerMemory){
player = PlayerCharacter.getFromCache(playerID);
Guild nation = player.getGuild().getNation(); Guild entry;
if(this.dividedPlayers.containsKey(nation)){
this.dividedPlayers.get(nation).add(playerID);
}else{
ArrayList<Integer> newEntry = new ArrayList<>();
newEntry.add(playerID);
this.dividedPlayers.put(nation,newEntry);
}
}
if(updated == true){
for(Integer playerID : this._playerMemory){
player = PlayerCharacter.getFromCache(playerID);
if(this.dividedPlayers.containsKey(player.getGuild().getNation())){
int count = this.dividedPlayers.get(player.getGuild().getNation()).size();
switch(this.getBane().capSize){
case 5:
player.ZergMultiplier = ZergManager.getMultiplier5Man(count);
break;
case 10:
player.ZergMultiplier = ZergManager.getMultiplier10Man(count);
break;
case 20:
player.ZergMultiplier = ZergManager.getMultiplier20Man(count);
break;
}
} else{
player.ZergMultiplier = 1.0f; //something went wrong reset to default until next cycle
}
}
}
}
private Boolean onExitZerg(HashSet<AbstractWorldObject> currentPlayers) {
PlayerCharacter player;
int playerUUID = 0;
HashSet<Integer> toRemove = new HashSet<>();
Iterator<Integer> iter = _playerMemory.iterator();
while (iter.hasNext()) {
playerUUID = iter.next();
player = PlayerCharacter.getFromCache(playerUUID);
if (currentPlayers.contains(player))
continue;
toRemove.add(playerUUID);
if(_recentMemory.containsKey(playerUUID) == false) {
_recentMemory.put(playerUUID, System.currentTimeMillis());
}
player.ZergMultiplier = 1.0f; // reset damage modifier to 1.0
this.removeAllCityEffects(player, false);
if (this.cityOutlaws.contains(playerUUID))
this.cityOutlaws.remove(playerUUID);
}
// Remove players from mine memory
//_playerMemory.removeAll(toRemove);
HashSet<Integer> purge = new HashSet<>();
for(Integer id : _recentMemory.keySet()){
if(System.currentTimeMillis() > _recentMemory.get(playerUUID) + 60000){
purge.add(id);
}
}
for(Integer id : purge){
_recentMemory.remove(id);
}
if(toRemove.isEmpty()){
return false;
}else{
return true;
}
}
} }

6
src/engine/objects/Mine.java

@ -582,7 +582,7 @@ public class Mine extends AbstractGameObject {
amount = amount / value; amount = amount / value;
return (int) amount; return (int) amount;
} }
public void onEnter() { public void onEnterZerg() {
HashSet<AbstractWorldObject> currentPlayers; HashSet<AbstractWorldObject> currentPlayers;
PlayerCharacter player; PlayerCharacter player;
@ -616,7 +616,7 @@ public class Mine extends AbstractGameObject {
} }
this.totalPlayers = this._playerMemory.size(); this.totalPlayers = this._playerMemory.size();
try { try {
if(onExit(currentPlayers)){ if(onExitZerg(currentPlayers)){
updated = true; updated = true;
} }
} catch (Exception e) { } catch (Exception e) {
@ -657,7 +657,7 @@ public class Mine extends AbstractGameObject {
} }
} }
private Boolean onExit(HashSet<AbstractWorldObject> currentPlayers) { private Boolean onExitZerg(HashSet<AbstractWorldObject> currentPlayers) {
PlayerCharacter player; PlayerCharacter player;
int playerUUID = 0; int playerUUID = 0;

Loading…
Cancel
Save