Browse Source

Threads for Zerg Mechanics

lakebane-master
fatboy 8 months ago
parent
commit
f98f54139a
  1. 2
      src/engine/gameManager/CombatManager.java
  2. 281
      src/engine/gameManager/ZergManager.java
  3. 19
      src/engine/objects/Bane.java
  4. 137
      src/engine/objects/City.java
  5. 4
      src/engine/powers/effectmodifiers/HealthEffectModifier.java
  6. 4
      src/engine/powers/effectmodifiers/ManaEffectModifier.java
  7. 4
      src/engine/powers/effectmodifiers/StaminaEffectModifier.java
  8. 50
      src/engine/workthreads/ZergMechanicThread.java

2
src/engine/gameManager/CombatManager.java

@ -845,7 +845,7 @@ public enum CombatManager { @@ -845,7 +845,7 @@ public enum CombatManager {
mobTarget.handleDirectAggro(ac);
}
if(ac.getObjectType().equals(GameObjectType.PlayerCharacter) && tarAc.getObjectType().equals(GameObjectType.PlayerCharacter) && tarAc.equals(ac) == false){
damage *= ZergManager.getReducedZergMultiplier(ac,tarAc);
damage *= ((PlayerCharacter)ac).ZergMultiplier;
}
if (tarAc.getHealth() > 0)
d = tarAc.modifyHealth(-damage, ac, false);

281
src/engine/gameManager/ZergManager.java

@ -1,273 +1,108 @@ @@ -1,273 +1,108 @@
package engine.gameManager;
import engine.Enum;
import engine.objects.*;
public class ZergManager {
public static float getMultiplier5Man(int count, PlayerCharacter pc){
public static float getMultiplier3Man(int count){
float multiplier = 1.0f;
if(count <= 3)
return 1.0f;
if(count > 6)
return 0.2f;
switch(count){
case 1:
multiplier += 0.80f;
break;
case 2:
multiplier += 0.80f;
break;
case 3:
multiplier += 0.50f;
break;
case 4:
multiplier += 0.20f;
multiplier -= 0.37f;
break;
case 5:
multiplier += 0.0f;
break;
case 6:
multiplier -= 0.20f;
break;
case 7:
multiplier -= 0.40f;
break;
case 8:
multiplier -= 0.60f;
break;
default:
multiplier -= 0.80f;
case 6:
multiplier -= 0.75f;
break;
}
if(multiplier == 0.0f)
return 1.0f;
else
return multiplier;
return multiplier;
}
public static float getMultiplier10Man(int count, PlayerCharacter pc){
public static float getMultiplier5Man(int count){
float multiplier = 1.0f;
if(count <=4)
return 0.0f;
if(count <= 5)
return 1.0f;
if(count > 10)
return 0.2f;
switch(count){
case 5:
multiplier += 0.5f;
break;
case 6:
multiplier += 0.4f;
multiplier -= 0.25f;
break;
case 7:
multiplier += 0.3f;
multiplier -= 0.43f;
break;
case 8:
multiplier += 0.2f;
multiplier -= 0.56f;
break;
case 9:
multiplier += 0.1f;
multiplier -= 0.67f;
break;
case 10:
multiplier += 0.0f;
multiplier -= 0.75f;
break;
}
return multiplier;
}
public static float getMultiplier10Man(int count){
float multiplier = 1.0f;
if(count <= 10)
return 1.0f;
if(count > 20)
return 0.2f;
switch(count){
case 11:
multiplier -= 0.1f;
multiplier -= 0.14f;
break;
case 12:
multiplier -= 0.2f;
multiplier -= 0.25f;
break;
case 13:
multiplier -= 0.3f;
multiplier -= 0.35f;
break;
case 14:
multiplier -= 0.4f;
multiplier -= 0.43f;
break;
case 15:
multiplier -= 0.5f;
multiplier -= 0.50f;
break;
case 16:
multiplier -= 0.65f;
multiplier -= 0.56f;
break;
case 17:
multiplier -= 0.75f;
multiplier -= 0.62f;
break;
case 18:
multiplier -= 0.85f;
multiplier -= 0.67f;
break;
default:
multiplier -= 1.0f;
case 19:
multiplier -= 0.71f;
break;
}
ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier);
if(multiplier == 0.0f)
return 1.0f;
else
return multiplier;
}
public static float getMultiplier20Man(int count, PlayerCharacter pc){
float multiplier = 1.0f;
if(count < 10){
multiplier += 1.25f;
}else {
switch (count) {
case 10:
multiplier += 0.8f;
break;
case 11:
multiplier += 0.65f;
break;
case 12:
multiplier += 0.54f;
break;
case 13:
multiplier += 0.46f;
break;
case 14:
multiplier += 0.36f;
break;
case 15:
multiplier += 0.28f;
break;
case 16:
multiplier += 0.21f;
break;
case 17:
multiplier += 0.15f;
break;
case 18:
multiplier += 0.09f;
break;
case 19:
multiplier += 0.04f;
break;
case 20:
multiplier += 0.00f;
break;
case 21:
multiplier -= 0.04f;
break;
case 22:
multiplier -= 0.09f;
break;
case 23:
multiplier -= 0.15f;
break;
case 24:
multiplier -= 0.21f;
break;
case 25:
multiplier -= 0.28f;
break;
case 26:
multiplier -= 0.36f;
break;
case 27:
multiplier -= 0.46f;
break;
case 28:
multiplier -= 0.54f;
break;
case 29:
multiplier -= 0.65f;
break;
default:
multiplier -= 0.75f;
break;
}
}
ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier);
if(multiplier == 0.0f)
return 1.0f;
else
return multiplier;
}
public static int getBaneCapSize(Guild defender){
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;
case 20:
multiplier -= 0.75f;
break;
default: capSize = 9999999;
}
return capSize;
}
public static float getMultiplier30Man(int count, PlayerCharacter pc){
float multiplier = 1.0f;
ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier);
if(multiplier == 0.0f)
return 1.0f;
else
return multiplier;
}
public static float getMultiplier40Man(int count, PlayerCharacter pc){
float multiplier = 1.0f;
ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier);
if(multiplier == 0.0f)
return 1.0f;
else
return multiplier;
return multiplier;
}
public static float getMultiplierUnlimited(int count, PlayerCharacter pc){
float multiplier = 1.0f;
ChatManager.chatSystemInfo(pc,"Zerg Multiplier Set: " + multiplier);
if(multiplier == 0.0f)
return 1.0f;
else
return multiplier;
public static float getMultiplier20Man(int count){
return getMultiplier10Man(((int)(count * 0.5f)));
}
public static float getReducedZergMultiplier(AbstractCharacter sourceABS, AbstractCharacter targetABS){
if(sourceABS.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) == false || targetABS.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) == false)
return 1.0f;
PlayerCharacter source = (PlayerCharacter) sourceABS;
PlayerCharacter target = (PlayerCharacter) targetABS;
if(source.ZergMultiplier == 0.0f) {
if(Mine.getMine(source.mineAppliedID) != null && Mine.getMine(source.mineAppliedID)._playerMemory.contains(source.getObjectUUID()) == false ){
source.ZergMultiplier = 1.0f;
}
}
if(target.ZergMultiplier == 0.0f) {
if(Mine.getMine(target.mineAppliedID) != null && Mine.getMine(target.mineAppliedID)._playerMemory.contains(target.getObjectUUID()) == false){
target.ZergMultiplier = 1.0f;
}
}
if(source.ZergMultiplier == target.ZergMultiplier){
return 1.0f;
}
float returnMultiplier = 1.0f;
if(source.ZergMultiplier > 0 && target.ZergMultiplier > 0){
if(source.ZergMultiplier > target.ZergMultiplier) {
returnMultiplier = 1 + (source.ZergMultiplier - target.ZergMultiplier);
} else{
returnMultiplier = 1.0f;
}
}else if(source.ZergMultiplier < 0 && target.ZergMultiplier > 0){
returnMultiplier = source.ZergMultiplier;
} else if(source.ZergMultiplier < 0 && target.ZergMultiplier < 0){
returnMultiplier = source.ZergMultiplier;
} else if(source.ZergMultiplier > 0 && target.ZergMultiplier < 0){
returnMultiplier = source.ZergMultiplier;
}
if(returnMultiplier == 0.0f)
return 1.0f;
else{
return returnMultiplier;
}
public static float getMultiplier40Man(int count){
return getMultiplier10Man(((int)(count * 0.25f)));
}
}

19
src/engine/objects/Bane.java

@ -106,7 +106,11 @@ public final class Bane { @@ -106,7 +106,11 @@ public final class Bane {
if (this.liveDate == null)
setDefaultTime();
this.capSize = ZergManager.getBaneCapSize(this.getCity().getGuild());
if(this.getCity().getTOL().getRank() == 8)
this.capSize = 40;
else
this.capSize = 20;
this.getCity().setSiegesWithstood(this.capSize);
}
@ -268,7 +272,11 @@ public final class Bane { @@ -268,7 +272,11 @@ public final class Bane {
BaneRecord baneRecord = BaneRecord.borrow(bane, Enum.RecordEventType.PENDING);
DataWarehouse.pushToWarehouse(baneRecord);
bane.capSize = ZergManager.getBaneCapSize(bane.getCity().getGuild());
if(bane.getCity().getTOL().getRank() == 8)
bane.capSize = 40;
else
bane.capSize = 20;
bane.getCity().setSiegesWithstood(bane.capSize);
return true;
}
@ -345,7 +353,12 @@ public final class Bane { @@ -345,7 +353,12 @@ public final class Bane {
}
newBane = DbManager.BaneQueries.LOAD_BANE(city.getObjectUUID());
newBane.capSize = ZergManager.getBaneCapSize(newBane.getCity().getGuild());
if(newBane.getCity().getTOL().getRank() == 8)
newBane.capSize = 40;
else
newBane.capSize = 20;
newBane.getCity().setSiegesWithstood(newBane.capSize);
return newBane;
}

137
src/engine/objects/City.java

@ -326,7 +326,10 @@ public class City extends AbstractWorldObject { @@ -326,7 +326,10 @@ public class City extends AbstractWorldObject {
if(city.getBane() != null) {
writer.putInt(city.siegesWithstood);
} else{
writer.putInt(ZergManager.getBaneCapSize(city.getGuild()));
if(city.getTOL().getRank() == 8)
writer.putInt(40);
else
writer.putInt(20);
}
writer.put((byte) 1);
writer.put((byte) 0);
@ -989,8 +992,6 @@ public class City extends AbstractWorldObject { @@ -989,8 +992,6 @@ public class City extends AbstractWorldObject {
public void onEnter() {
this.onEnterZerg();
for (Integer id : this._playerMemory) {
PlayerCharacter player = PlayerCharacter.getFromCache(id);
@ -1385,134 +1386,4 @@ public class City extends AbstractWorldObject { @@ -1385,134 +1386,4 @@ 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,player);
break;
case 10:
player.ZergMultiplier = ZergManager.getMultiplier10Man(count,player);
break;
case 20:
player.ZergMultiplier = ZergManager.getMultiplier20Man(count,player);
break;
case 30:
player.ZergMultiplier = ZergManager.getMultiplier30Man(count,player);
break;
case 40:
player.ZergMultiplier = ZergManager.getMultiplier40Man(count,player);
break;
case 9999999:
player.ZergMultiplier = ZergManager.getMultiplierUnlimited(count,player);
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;
}
}
}

4
src/engine/powers/effectmodifiers/HealthEffectModifier.java

@ -318,8 +318,8 @@ public class HealthEffectModifier extends AbstractEffectModifier { @@ -318,8 +318,8 @@ public class HealthEffectModifier extends AbstractEffectModifier {
AbstractCharacter ac = (AbstractCharacter) awo;
if (ac.isSit())
damage *= 2.5f; // increase damage if sitting
if(ac.getObjectType().equals(GameObjectType.PlayerCharacter) && source.equals(ac) == false && ZergManager.getReducedZergMultiplier(source,ac) != 0.0f){
damage *= ZergManager.getReducedZergMultiplier(source,ac);
if(ac.getObjectType().equals(GameObjectType.PlayerCharacter) && source.equals(ac) == false){
damage *= ((PlayerCharacter)source).ZergMultiplier;
}
}

4
src/engine/powers/effectmodifiers/ManaEffectModifier.java

@ -207,8 +207,8 @@ public class ManaEffectModifier extends AbstractEffectModifier { @@ -207,8 +207,8 @@ public class ManaEffectModifier extends AbstractEffectModifier {
AbstractCharacter ac = (AbstractCharacter) awo;
if (ac.isSit())
damage *= 2.5f; // increase damage if sitting
if(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && source.equals(ac) == false && ZergManager.getReducedZergMultiplier(source,ac) != 0.0f){
damage *= ZergManager.getReducedZergMultiplier(source,ac);
if(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && !source.equals(ac)){
damage *= ((PlayerCharacter)source).ZergMultiplier;
}
}

4
src/engine/powers/effectmodifiers/StaminaEffectModifier.java

@ -205,8 +205,8 @@ public class StaminaEffectModifier extends AbstractEffectModifier { @@ -205,8 +205,8 @@ public class StaminaEffectModifier extends AbstractEffectModifier {
AbstractCharacter ac = (AbstractCharacter) awo;
if (ac.isSit())
damage *= 2.5f; // increase damage if sitting
if(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && source.equals(ac) == false && ZergManager.getReducedZergMultiplier(source,ac) != 0.0f){
damage *= ZergManager.getReducedZergMultiplier(source,ac);
if(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter) && !source.equals(ac)){
damage *= ((PlayerCharacter)source).ZergMultiplier;
}
}

50
src/engine/workthreads/ZergMechanicThread.java

@ -47,12 +47,10 @@ public boolean isMine = false; @@ -47,12 +47,10 @@ public boolean isMine = false;
@Override
public void run() {
if(mine != null)
while(mine.isActive)
while(mine != null && mine.isActive)
RunMineMechanic();
if(bane != null)
while(bane.getSiegePhase().equals(Enum.SiegePhase.WAR))
while(bane != null && bane.getSiegePhase().equals(Enum.SiegePhase.WAR))
RunBaneMechanic();
}
@ -103,42 +101,68 @@ public boolean isMine = false; @@ -103,42 +101,68 @@ public boolean isMine = false;
if(mine.dividedPlayers.containsKey(player.getGuild().getNation())){
int count = mine.dividedPlayers.get(player.getGuild().getNation()).size();
switch(mine.capSize){
case 3:
player.ZergMultiplier = ZergManager.getMultiplier3Man(count);
break;
case 5:
player.ZergMultiplier = ZergManager.getMultiplier5Man(count,player);
player.ZergMultiplier = ZergManager.getMultiplier5Man(count);
break;
case 10:
player.ZergMultiplier = ZergManager.getMultiplier10Man(count,player);
player.ZergMultiplier = ZergManager.getMultiplier10Man(count);
break;
case 20:
player.ZergMultiplier = ZergManager.getMultiplier20Man(count,player);
player.ZergMultiplier = ZergManager.getMultiplier20Man(count);
break;
}
player.mineAppliedID = mine.getObjectUUID();
} else{
player.ZergMultiplier = 1.0f;
player.mineAppliedID = 0;
}
}
}
public void RunBaneMechanic(){
HashSet<AbstractWorldObject> currentPlayers;
PlayerCharacter player;
currentPlayers = WorldGrid.getObjectsInRangePartial(bane.getCity().loc, Enum.CityBoundsType.GRID.extents * 2.0f, MBServerStatics.MASK_PLAYER);
Guild attacker = bane.getStone().getGuild().getNation();
Guild defender = bane.getCity().getGuild().getNation();
int attackers = 0;
int defenders = 0;
ArrayList<PlayerCharacter> attackers = new ArrayList<>();
ArrayList<PlayerCharacter> defenders = new ArrayList<>();
for(AbstractWorldObject awo : currentPlayers){
PlayerCharacter pc = (PlayerCharacter) awo;
if(pc.getGuild().getNation().equals(attacker) == false && pc.getGuild().getNation().equals(defender) == false)
if(!pc.getGuild().getNation().equals(attacker) && !pc.getGuild().getNation().equals(defender)) {
pc.teleport(pc.bindLoc);
pc.ZergMultiplier = 1.0f;
}
if(pc.getGuild().getNation().equals(attacker))
attackers++;
attackers.add(pc);
if(pc.getGuild().getNation().equals(defender))
defenders++;
defenders.add(pc);
}
int treeRank = bane.getCity().getTOL().getRank();
for(PlayerCharacter pc : attackers){
if(treeRank == 8){
pc.ZergMultiplier = ZergManager.getMultiplier40Man(attackers.size());
}else{
pc.ZergMultiplier = ZergManager.getMultiplier20Man(attackers.size());
}
}
for(PlayerCharacter pc : defenders){
if(treeRank == 8){
pc.ZergMultiplier = ZergManager.getMultiplier40Man(defenders.size());
}else{
pc.ZergMultiplier = ZergManager.getMultiplier20Man(defenders.size());
}
}
}

Loading…
Cancel
Save