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.

198 lines
7.8 KiB

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.workthreads;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
import engine.gameManager.*;
12 months ago
import engine.mobileAI.Threads.MobAIThread;
import engine.net.DispatchMessage;
import engine.net.MessageDispatcher;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.*;
import engine.server.MBServerStatics;
import engine.server.world.WorldServer;
import org.pmw.tinylog.Logger;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import static engine.server.MBServerStatics.MINE_LATE_WINDOW;
public class ZergMechanicThread implements Runnable {
public Bane bane = null;
public Mine mine = null;
12 months ago
public ArrayList<PlayerCharacter> affectedPlayers = new ArrayList<>();
public ZergMechanicThread(Bane b, Mine m) {
12 months ago
this.mine = m;
this.bane = b;
}
@Override
public void run() {
12 months ago
if (mine != null)
RunMineMechanic();
12 months ago
if (bane != null)
RunBaneMechanic();
}
public void RunMineMechanic(){
12 months ago
while(mine.isActive) {
HashSet<AbstractWorldObject> currentPlayers;
PlayerCharacter player;
12 months ago
// Gather current list of players within the zone bounds
Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID());
currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents * 0.5f, MBServerStatics.MASK_PLAYER);
12 months ago
for (AbstractWorldObject playerObject : currentPlayers) {
12 months ago
if (playerObject == null)
continue;
12 months ago
player = (PlayerCharacter) playerObject;
12 months ago
if(!this.affectedPlayers.contains(player))
this.affectedPlayers.add(player);
12 months ago
//ChatManager.chatSystemInfo(player, "TESTING ZERG MECHANIC");
12 months ago
if (mine._recentMemory.containsKey(player.getObjectUUID()))
mine._recentMemory.remove(player.getObjectUUID());
12 months ago
if (mine._playerMemory.contains(player.getObjectUUID()))
continue;
12 months ago
mine._playerMemory.add(player.getObjectUUID());
12 months ago
}
12 months ago
boolean updated = false;
try {
mine.onExit(currentPlayers);
} catch (Exception e) {
Logger.error(e.getMessage());
}
mine.dividedPlayers = new HashMap<>();
for (Integer playerID : mine._playerMemory) {
player = PlayerCharacter.getFromCache(playerID);
Guild nation = player.getGuild().getNation();
Guild entry;
if (mine.dividedPlayers.containsKey(nation)) {
mine.dividedPlayers.get(nation).add(playerID);
} else {
ArrayList<Integer> newEntry = new ArrayList<>();
newEntry.add(playerID);
mine.dividedPlayers.put(nation, newEntry);
}
}
for (Integer playerID : mine._playerMemory) {
player = PlayerCharacter.getFromCache(playerID);
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);
break;
case 10:
player.ZergMultiplier = ZergManager.getMultiplier10Man(count);
break;
case 20:
player.ZergMultiplier = ZergManager.getMultiplier20Man(count);
break;
}
player.mineAppliedID = mine.getObjectUUID();
} else {
player.ZergMultiplier = 1.0f;
player.mineAppliedID = 0;
}
}
}
12 months ago
for(PlayerCharacter player : this.affectedPlayers)
player.ZergMultiplier = 1.0f;
}
public void RunBaneMechanic(){
12 months ago
while(bane.getSiegePhase().equals(Enum.SiegePhase.WAR)) {
HashSet<AbstractWorldObject> currentPlayers;
12 months ago
currentPlayers = WorldGrid.getObjectsInRangePartial(bane.getCity().loc, Enum.CityBoundsType.GRID.extents * 2.0f, MBServerStatics.MASK_PLAYER);
12 months ago
Guild attacker = bane.getStone().getGuild().getNation();
Guild defender = bane.getCity().getGuild().getNation();
12 months ago
ArrayList<PlayerCharacter> attackers = new ArrayList<>();
ArrayList<PlayerCharacter> defenders = new ArrayList<>();
12 months ago
for (AbstractWorldObject awo : currentPlayers) {
12 months ago
if(!this.affectedPlayers.contains((PlayerCharacter)awo))
this.affectedPlayers.add((PlayerCharacter)awo);
12 months ago
PlayerCharacter pc = (PlayerCharacter) awo;
if (!pc.getGuild().getNation().equals(attacker) && !pc.getGuild().getNation().equals(defender)) {
pc.teleport(pc.bindLoc);
pc.ZergMultiplier = 1.0f;
}
12 months ago
if (pc.getGuild().getNation().equals(attacker))
attackers.add(pc);
12 months ago
if (pc.getGuild().getNation().equals(defender))
defenders.add(pc);
}
12 months ago
int treeRank = bane.getCity().getTOL().getRank();
12 months ago
for (PlayerCharacter pc : attackers) {
if (treeRank == 8) {
pc.ZergMultiplier = ZergManager.getMultiplier40Man(attackers.size());
} else {
pc.ZergMultiplier = ZergManager.getMultiplier20Man(attackers.size());
}
}
12 months ago
for (PlayerCharacter pc : defenders) {
if (treeRank == 8) {
pc.ZergMultiplier = ZergManager.getMultiplier40Man(defenders.size());
} else {
pc.ZergMultiplier = ZergManager.getMultiplier20Man(defenders.size());
}
}
}
12 months ago
for(PlayerCharacter player : this.affectedPlayers)
player.ZergMultiplier = 1.0f;
}
12 months ago
public static void startZergThreadMine(Mine mine) {
Thread zergMechanicThread;
zergMechanicThread = new Thread(new ZergMechanicThread(null, mine));
zergMechanicThread.setName(mine.getParentZone().getName() + "Mine");
zergMechanicThread.start();
}
public static void startZergThreadBane(Bane bane) {
Thread zergMechanicThread;
zergMechanicThread = new Thread(new ZergMechanicThread(bane, null));
zergMechanicThread.setName(bane.getCity().getGuild().getName() + "Bane");
zergMechanicThread.start();
}
}