Public Repository for the Magicbane Shadowbane Emulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
5.9 KiB

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.workthreads;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.gameManager.*;
import engine.objects.*;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
11 months ago
public class ZergMechanicThread implements Runnable {
private final Mine mine;
private final Bane bane;
private final HashSet<PlayerCharacter> affectedPlayers = new HashSet<>();
11 months ago
public ZergMechanicThread(Bane b, Mine m) {
this.mine = m;
this.bane = b;
}
11 months ago
@Override
public void run() {
12 months ago
if (mine != null)
RunMineMechanic();
12 months ago
if (bane != null)
RunBaneMechanic();
11 months ago
}
11 months ago
private void RunMineMechanic() {
12 months ago
Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID());
11 months ago
float zoneBounds = Enum.CityBoundsType.GRID.extents * 0.5f;
11 months ago
while (mine.isActive) {
HashSet<AbstractWorldObject> currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, zoneBounds, MBServerStatics.MASK_PLAYER);
11 months ago
for (AbstractWorldObject playerObject : currentPlayers) {
PlayerCharacter player = (PlayerCharacter) playerObject;
11 months ago
affectedPlayers.add(player);
12 months ago
12 months ago
mine._recentMemory.remove(player.getObjectUUID());
11 months ago
mine._playerMemory.add(player.getObjectUUID());
}
11 months ago
try {
mine.onExit(currentPlayers);
} catch (Exception e) {
Logger.error(e.getMessage());
}
12 months ago
11 months ago
mine.dividedPlayers = new HashMap<>();
for (Integer playerID : mine._playerMemory) {
PlayerCharacter player = PlayerCharacter.getFromCache(playerID);
Guild nation = player.getGuild().getNation();
mine.dividedPlayers.computeIfAbsent(nation, k -> new ArrayList<>()).add(playerID);
12 months ago
}
11 months ago
for (Integer playerID : mine._playerMemory) {
PlayerCharacter player = PlayerCharacter.getFromCache(playerID);
Guild nation = player.getGuild().getNation();
if (mine.dividedPlayers.containsKey(nation)) {
int count = mine.dividedPlayers.get(nation).size();
player.ZergMultiplier = ZergManager.getCurrentMultiplier(count, mine.capSize);
player.mineAppliedID = mine.getObjectUUID();
} else {
player.ZergMultiplier = 1.0f;
player.mineAppliedID = 0;
12 months ago
}
}
}
12 months ago
11 months ago
resetZergMultiplier();
}
11 months ago
private void RunBaneMechanic() {
while (bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) {
HashSet<AbstractWorldObject> 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();
ArrayList<PlayerCharacter> attackers = new ArrayList<>();
ArrayList<PlayerCharacter> defenders = new ArrayList<>();
for (AbstractWorldObject awo : currentPlayers) {
PlayerCharacter pc = (PlayerCharacter) awo;
affectedPlayers.add(pc);
if (!pc.getGuild().getNation().equals(attacker) && !pc.getGuild().getNation().equals(defender)) {
pc.teleport(pc.bindLoc);
pc.ZergMultiplier = 1.0f;
}
12 months ago
11 months ago
if (pc.getGuild().getNation().equals(attacker))
attackers.add(pc);
12 months ago
11 months ago
if (pc.getGuild().getNation().equals(defender))
defenders.add(pc);
12 months ago
}
11 months ago
for (PlayerCharacter pc : attackers) {
pc.ZergMultiplier = ZergManager.getCurrentMultiplier(attackers.size(), bane.capSize);
12 months ago
}
11 months ago
for (PlayerCharacter pc : defenders) {
pc.ZergMultiplier = ZergManager.getCurrentMultiplier(defenders.size(), bane.capSize);
12 months ago
}
}
11 months ago
resetZergMultiplier();
}
12 months ago
11 months ago
private void resetZergMultiplier() {
for (PlayerCharacter player : affectedPlayers)
player.ZergMultiplier = 1.0f;
}
12 months ago
11 months ago
public static void startZergThreadMine(Mine mine) {
Thread zergMechanicThread = new Thread(new ZergMechanicThread(null, mine));
zergMechanicThread.setName(mine.getParentZone().getName() + "Mine");
zergMechanicThread.start();
}
12 months ago
11 months ago
public static void startZergThreadBane(Bane bane) {
Thread zergMechanicThread = new Thread(new ZergMechanicThread(bane, null));
zergMechanicThread.setName(bane.getCity().getGuild().getName() + "Bane");
zergMechanicThread.start();
}
12 months ago
}