|
|
|
@ -32,6 +32,7 @@ import engine.server.MBServerStatics;
@@ -32,6 +32,7 @@ import engine.server.MBServerStatics;
|
|
|
|
|
import engine.server.world.WorldServer; |
|
|
|
|
import engine.workthreads.DestroyCityThread; |
|
|
|
|
import engine.workthreads.TransferCityThread; |
|
|
|
|
import org.joda.time.DateTime; |
|
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
|
import java.sql.ResultSet; |
|
|
|
@ -39,6 +40,7 @@ import java.sql.SQLException;
@@ -39,6 +40,7 @@ import java.sql.SQLException;
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.ZoneId; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
@ -88,6 +90,9 @@ public class City extends AbstractWorldObject {
@@ -88,6 +90,9 @@ public class City extends AbstractWorldObject {
|
|
|
|
|
private boolean reverseKOS = false; |
|
|
|
|
private String hash; |
|
|
|
|
|
|
|
|
|
public final HashMap<Integer,Long> _recentMemory = new HashMap<>(); |
|
|
|
|
HashMap<Guild,ArrayList<Integer>> dividedPlayers; |
|
|
|
|
public Integer totalPlayers; |
|
|
|
|
/** |
|
|
|
|
* ResultSet Constructor |
|
|
|
|
*/ |
|
|
|
@ -980,23 +985,14 @@ public class City extends AbstractWorldObject {
@@ -980,23 +985,14 @@ public class City extends AbstractWorldObject {
|
|
|
|
|
|
|
|
|
|
public void onEnter() { |
|
|
|
|
|
|
|
|
|
HashSet<AbstractWorldObject> currentPlayers; |
|
|
|
|
HashSet<Integer> currentMemory; |
|
|
|
|
PlayerCharacter player; |
|
|
|
|
|
|
|
|
|
// Gather current list of players within the zone bounds
|
|
|
|
|
this.onEnterZerg(); |
|
|
|
|
|
|
|
|
|
currentPlayers = WorldGrid.getObjectsInRangePartial(this.location, CityBoundsType.ZONE.extents * 2, MBServerStatics.MASK_PLAYER); |
|
|
|
|
currentMemory = new HashSet<>(); |
|
|
|
|
for (Integer id : this._playerMemory) { |
|
|
|
|
|
|
|
|
|
for (AbstractWorldObject playerObject : currentPlayers) { |
|
|
|
|
|
|
|
|
|
if (playerObject == null) |
|
|
|
|
PlayerCharacter player = PlayerCharacter.getFromCache(id); |
|
|
|
|
if (player == null) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
player = (PlayerCharacter) playerObject; |
|
|
|
|
currentMemory.add(player.getObjectUUID()); |
|
|
|
|
|
|
|
|
|
// Player is already in our memory
|
|
|
|
|
|
|
|
|
|
if (_playerMemory.contains(player.getObjectUUID())) |
|
|
|
@ -1012,64 +1008,7 @@ public class City extends AbstractWorldObject {
@@ -1012,64 +1008,7 @@ public class City extends AbstractWorldObject {
|
|
|
|
|
//add spire effects.
|
|
|
|
|
if (this.getEffects().size() > 0) |
|
|
|
|
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() { |
|
|
|
@ -1442,4 +1381,125 @@ public class City extends AbstractWorldObject {
@@ -1442,4 +1381,125 @@ public class City extends AbstractWorldObject {
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|