Browse Source

FIRST AFTER ROLLBACK: reintroduce mines

lakebane-master
FatBoy-DOTC 6 months ago
parent
commit
cf6f684f5e
  1. 6
      src/engine/devcmd/cmds/MineActiveCmd.java
  2. 322
      src/engine/objects/Mine.java
  3. 15
      src/engine/server/world/WorldServer.java
  4. 140
      src/engine/workthreads/MineThread.java

6
src/engine/devcmd/cmds/MineActiveCmd.java

@ -12,12 +12,10 @@ package engine.devcmd.cmds;
import engine.devcmd.AbstractDevCmd; import engine.devcmd.AbstractDevCmd;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.SimulationManager;
import engine.objects.AbstractGameObject; import engine.objects.AbstractGameObject;
import engine.objects.Building; import engine.objects.Building;
import engine.objects.Mine; import engine.objects.Mine;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import engine.workthreads.MineThread;
/** /**
* *
@ -42,10 +40,10 @@ public class MineActiveCmd extends AbstractDevCmd {
String trigger = args[0]; String trigger = args[0];
switch (trigger) { switch (trigger) {
case "true": case "true":
MineThread.mineWindowOpen(mine); Mine.mineWindowOpen(mine);
break; break;
case "false": case "false":
MineThread.mineWindowClose(mine); Mine.mineWindowClose(mine);
break; break;
default: default:
this.sendUsage(pcSender); this.sendUsage(pcSender);

322
src/engine/objects/Mine.java

@ -11,9 +11,13 @@ package engine.objects;
import engine.Enum; import engine.Enum;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
import engine.gameManager.*; import engine.gameManager.*;
import engine.net.ByteBufferWriter; import engine.net.ByteBufferWriter;
import engine.net.DispatchMessage;
import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import engine.workthreads.ZergMechanicThread; import engine.workthreads.ZergMechanicThread;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -68,6 +72,9 @@ public class Mine extends AbstractGameObject {
public static ArrayList<Mine> AmericaMines = new ArrayList<>(); public static ArrayList<Mine> AmericaMines = new ArrayList<>();
public boolean wasOpened = false; public boolean wasOpened = false;
public int liveHour;
public int liveMinute;
/** /**
* ResultSet Constructor * ResultSet Constructor
*/ */
@ -115,140 +122,9 @@ public class Mine extends AbstractGameObject {
this.production = Resource.valueOf(rs.getString("mine_resource")); this.production = Resource.valueOf(rs.getString("mine_resource"));
this.lastClaimer = null; this.lastClaimer = null;
} this.liveHour = rs.getInt("mineLiveHour");
} this.liveMinute = rs.getInt("mineLiveMinute");
this.capSize = rs.getInt("capSize");
public static void SetTimes(){
try {
EuroMines.get(0).liveTime = 16;
EuroMines.get(1).liveTime = 16;
EuroMines.get(2).liveTime = 16;
EuroMines.get(3).liveTime = 16;
EuroMines.get(4).liveTime = 16;
EuroMines.get(5).liveTime = 16;
EuroMines.get(6).liveTime = 16;
}catch(Exception e){
}
try{
ChinaMines.get(0).liveTime = 11;
ChinaMines.get(1).liveTime = 11;
ChinaMines.get(2).liveTime = 11;
ChinaMines.get(3).liveTime = 12;
ChinaMines.get(4).liveTime = 12;
ChinaMines.get(5).liveTime = 12;
ChinaMines.get(6).liveTime = 12;
ChinaMines.get(7).liveTime = 12;
ChinaMines.get(8).liveTime = 12;
ChinaMines.get(9).liveTime = 12;
ChinaMines.get(10).liveTime = 13;
ChinaMines.get(11).liveTime = 13;
ChinaMines.get(12).liveTime = 13;
ChinaMines.get(13).liveTime = 13;
}catch(Exception e){
}
try{
AmericaMines.get(0).liveTime = 1;
AmericaMines.get(1).liveTime = 1;
AmericaMines.get(2).liveTime = 1;
AmericaMines.get(3).liveTime = 2;
AmericaMines.get(4).liveTime = 2;
AmericaMines.get(5).liveTime = 2;
AmericaMines.get(6).liveTime = 2;
AmericaMines.get(7).liveTime = 2;
AmericaMines.get(8).liveTime = 2;
AmericaMines.get(9).liveTime = 2;
AmericaMines.get(10).liveTime = 3;
AmericaMines.get(11).liveTime = 3;
AmericaMines.get(12).liveTime = 3;
AmericaMines.get(13).liveTime = 3;
}catch(Exception e){
}
int count = 1;
for(Mine mine : EuroMines){
switch(count){
case 1:
mine.capSize = 3;
break;
case 2:
mine.capSize = 5;
break;
case 3:
mine.capSize = 10;
break;
case 4:
mine.capSize = 3;
break;
}
count ++;
if(count == 5)
count = 1;
if(BuildingManager.getBuilding(mine.buildingID) != null) {
Building mineTower = BuildingManager.getBuilding(mine.buildingID);
if (mineTower != null) {
mineTower.setMaxHitPoints(5000 * mine.capSize);
mineTower.setCurrentHitPoints((float) 5000 * mine.capSize);
}
}
}
for(Mine mine : ChinaMines){
switch(count){
case 1:
mine.capSize = 3;
break;
case 2:
mine.capSize = 5;
break;
case 3:
mine.capSize = 10;
break;
case 4:
mine.capSize = 3;
break;
}
count ++;
if(count == 5)
count = 1;
if(BuildingManager.getBuilding(mine.buildingID) != null) {
Building mineTower = BuildingManager.getBuilding(mine.buildingID);
if (mineTower != null) {
mineTower.setMaxHitPoints(5000 * mine.capSize);
mineTower.setCurrentHitPoints((float) 5000 * mine.capSize);
}
}
}
for(Mine mine : AmericaMines){
switch(count){
case 1:
mine.capSize = 3;
break;
case 2:
mine.capSize = 5;
break;
case 3:
mine.capSize = 10;
break;
case 4:
mine.capSize = 3;
break;
}
count ++;
if(count == 5)
count = 1;
if(BuildingManager.getBuilding(mine.buildingID) != null) {
Building mineTower = BuildingManager.getBuilding(mine.buildingID);
if (mineTower != null) {
mineTower.setMaxHitPoints(5000 * mine.capSize);
mineTower.setCurrentHitPoints((float) 5000 * mine.capSize);
}
}
} }
} }
public static void releaseMineClaims(PlayerCharacter playerCharacter) { public static void releaseMineClaims(PlayerCharacter playerCharacter) {
@ -292,8 +168,6 @@ public class Mine extends AbstractGameObject {
public static void loadAllMines() { public static void loadAllMines() {
try {
//Load mine resources //Load mine resources
MineProduction.addResources(); MineProduction.addResources();
@ -305,91 +179,6 @@ public class Mine extends AbstractGameObject {
Mine.towerMap.put(mine.buildingID, mine); Mine.towerMap.put(mine.buildingID, mine);
//mine.mineType = MineProduction.LUMBER; //mine.mineType = MineProduction.LUMBER;
} }
try {
ChinaMines.add(serverMines.get(0));
ChinaMines.add(serverMines.get(3));
ChinaMines.add(serverMines.get(6));
ChinaMines.add(serverMines.get(9));
ChinaMines.add(serverMines.get(12));
ChinaMines.add(serverMines.get(15));
ChinaMines.add(serverMines.get(18));
ChinaMines.add(serverMines.get(21));
ChinaMines.add(serverMines.get(23));
ChinaMines.add(serverMines.get(25));
ChinaMines.add(serverMines.get(27));
ChinaMines.add(serverMines.get(29));
ChinaMines.add(serverMines.get(31));
ChinaMines.add(serverMines.get(33));
}catch(Exception e){
}
try{
AmericaMines.add(serverMines.get(1));
AmericaMines.add(serverMines.get(4));
AmericaMines.add(serverMines.get(7));
AmericaMines.add(serverMines.get(10));
AmericaMines.add(serverMines.get(13));
AmericaMines.add(serverMines.get(16));
AmericaMines.add(serverMines.get(19));
AmericaMines.add(serverMines.get(22));
AmericaMines.add(serverMines.get(24));
AmericaMines.add(serverMines.get(26));
AmericaMines.add(serverMines.get(28));
AmericaMines.add(serverMines.get(30));
AmericaMines.add(serverMines.get(32));
AmericaMines.add(serverMines.get(34));
}catch(Exception e){
}
try{
EuroMines.add(serverMines.get(2));
EuroMines.add(serverMines.get(5));
EuroMines.add(serverMines.get(8));
EuroMines.add(serverMines.get(11));
EuroMines.add(serverMines.get(14));
EuroMines.add(serverMines.get(17));
EuroMines.add(serverMines.get(20));
}catch(Exception e){
}
SetTimes();
for(Mine mine : EuroMines){
if(EuroMines.indexOf(mine) %2 == 0 ){
mine.firstThirty = true;
} else{
mine.firstThirty = false;
}
}
for(Mine mine : AmericaMines){
if(AmericaMines.indexOf(mine) %2 == 0 ){
mine.firstThirty = true;
} else{
mine.firstThirty = false;
}
}
for(Mine mine : ChinaMines){
if(ChinaMines.indexOf(mine) %2 == 0 ){
mine.firstThirty = true;
} else{
mine.firstThirty = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
for(Mine mine : Mine.getMines()){
int minute = 0;
if (mine.firstThirty == false)
minute = 30;
LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0);
LocalDateTime closeTime = openTime.plusMinutes(30);
if(LocalDateTime.now().isAfter(closeTime))
mine.wasOpened = true;
}
} }
/* /*
@ -834,4 +623,95 @@ public class Mine extends AbstractGameObject {
} }
return true; return true;
} }
public static void mineWindowOpen(Mine mine) {
mine.setActive(true);
Logger.info(mine.getParentZone().getName() + "'s Mine is now Active!");
}
public static boolean mineWindowClose(Mine mine) {
// No need to end the window of a mine which never opened.
if (mine.isActive == false)
return false;
Building mineBuilding = BuildingManager.getBuildingFromCache(mine.getBuildingID());
if (mineBuilding == null) {
Logger.debug("Null mine building for Mine " + mine.getObjectUUID() + " Building " + mine.getBuildingID());
return false;
}
for(Integer id : mine._playerMemory ){
PlayerCharacter.getPlayerCharacter(id).ZergMultiplier = 1.0f;
}
for(Integer id : mine._recentMemory.keySet()){
PlayerCharacter.getPlayerCharacter(id).ZergMultiplier = 1.0f;
}
// Mine building still stands; nothing to do.
// We can early exit here.
if (mineBuilding.getRank() > 0) {
mine.setActive(false);
mine.lastClaimer = null;
return true;
}
// This mine does not have a valid claimer
// we will therefore set it to errant
// and keep the window open.
if (!Mine.validateClaimer(mine.lastClaimer)) {
mine.lastClaimer = null;
mine.updateGuildOwner(null);
mine.setActive(true);
return false;
}
//Update ownership to map
mine.guildName = mine.getOwningGuild().getName();
mine.guildTag = mine.getOwningGuild().getGuildTag();
Guild nation = mine.getOwningGuild().getNation();
mine.nationName = nation.getName();
mine.nationTag = nation.getGuildTag();
mineBuilding.rebuildMine(mine.capSize * 5000);
WorldGrid.updateObject(mineBuilding);
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mine.lastClaimer.getName() + " has claimed the mine in " + mine.getParentZone().getName() + " for " + mine.getOwningGuild().getName() + ". The mine is no longer active.");
chatMsg.setMessageType(10);
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
DispatchMessage.dispatchMsgToAll(chatMsg);
// Warehouse this claim event
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
DataWarehouse.pushToWarehouse(mineRecord);
mineBuilding.setRank(mineBuilding.getRank());
mine.lastClaimer = null;
mine.setActive(false);
mine.wasClaimed = true;
return true;
}
public static void processMineWindows(){
LocalDateTime currentTime = LocalDateTime.now();
for (Mine mine : Mine.getMines()) {
Building tower = BuildingManager.getBuildingFromCache(mine.getBuildingID());
//if the tower comes back null, skip this mine
if(tower == null)
continue;
//check if this mine needs to open
LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(mine.liveMinute).withSecond(0).withNano(0);
if(currentTime.isAfter(openTime) && currentTime.isBefore(openTime.plusMinutes(30)) && !mine.wasOpened){
mineWindowOpen(mine); //hour and minute match, time to open the window
ChatManager.chatSystemChannel(mine.getParentZone().getName() + " " + mine.getMineType() + "MINE is now vulnerable to attack!");
continue;
}
//check to see if the window shoul dbe closing now
if(currentTime.isAfter(openTime.plusMinutes(29)) && mine.isActive) {
//check to see if the tower was destoryed
boolean towerDestroyed = tower.getRank() < 1;
if(towerDestroyed){
//check if a valid claimer exists to close the window and claim the mine since the tower was destroyed
if(mine.lastClaimer != null) {
mineWindowClose(mine);
ChatManager.chatSystemChannel("The fight for " + mine.getParentZone().getName() + " " + mine.getMineType() + " MINE has concluded. " + mine.lastClaimer.getName() + " has seized it in the name of " + mine.lastClaimer.getGuild().getNation());
}else{
ChatManager.chatSystemChannel("The " + mine.getParentZone().getName() + " " + mine.getMineType() + " MINE is still unclaimed. The battle continues.");
}
}else{
//tower was not destroyed, mine window closes
mineWindowClose(mine);
ChatManager.chatSystemChannel(tower.getGuild().getNation().getName() + " has successfully defended the " + mine.getParentZone().getName() + " " + mine.getMineType() + " MINE, and retains their claim.");
}
}
}
}
} }

15
src/engine/server/world/WorldServer.java

@ -210,6 +210,7 @@ public class WorldServer {
LocalDateTime nextHourlyJobTime = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(0); LocalDateTime nextHourlyJobTime = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(0);
LocalDateTime nextWareHousePushTime = LocalDateTime.now(); LocalDateTime nextWareHousePushTime = LocalDateTime.now();
LocalDateTime nextDiscSpawn = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(1); LocalDateTime nextDiscSpawn = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(1);
LocalDateTime minePulse = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(0);
// Begin execution of main game loop // Begin execution of main game loop
@ -266,6 +267,10 @@ public class WorldServer {
} }
nextDiscSpawn = nextDiscSpawn.plusHours(1); nextDiscSpawn = nextDiscSpawn.plusHours(1);
} }
if(LocalDateTime.now().isAfter(minePulse)) {
Mine.processMineWindows();
minePulse = minePulse.plusMinutes(30);
}
ThreadUtils.sleep(50); ThreadUtils.sleep(50);
} }
} }
@ -545,16 +550,6 @@ public class WorldServer {
Logger.info("Running garbage collection..."); Logger.info("Running garbage collection...");
System.gc(); System.gc();
Logger.info("Starting Mine Thread...");
Thread mineThread = new Thread(new MineThread());
mineThread.setName("mine thread");
mineThread.start();
//Logger.info("Starting Power Thread...");
//Thread powerThread = new Thread(new PowersThread());
//powerThread.setName("power thread");
//powerThread.start();
return true; return true;
} }

140
src/engine/workthreads/MineThread.java

@ -1,140 +0,0 @@
package engine.workthreads;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager;
import engine.net.DispatchMessage;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.objects.Building;
import engine.objects.Guild;
import engine.objects.Mine;
import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
import java.time.LocalDateTime;
public class MineThread implements Runnable {
public MineThread(){
}
@Override
public void run() {
LocalDateTime nextPulse = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
while (true){
if(LocalDateTime.now().isAfter(nextPulse)) {
for (Mine mine : Mine.getMines()) {
if(nextPulse.getHour() == 2 && nextPulse.getMinute() == 0){
mine.wasClaimed = false;
mine.hasProduced = false;
}
Building mineTower = BuildingManager.getBuilding(mine.getBuildingID());
if (mineTower == null)
continue;
int minute = 0;
if (mine.firstThirty == false)
minute = 30;
LocalDateTime openTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(minute).withSecond(0);
LocalDateTime closeTime = openTime.plusMinutes(29);
//current time is after start time and before close time, open mine window
if (LocalDateTime.now().isAfter(openTime.minusMinutes(1)) && !mine.wasClaimed && !mine.wasOpened) {
mineWindowOpen(mine);
continue;
}
if (mine.isActive) {
if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() > 0)
mineWindowClose(mine); //mine was never knocked down, close window
if (LocalDateTime.now().isAfter(closeTime) && mineTower.getRank() < 1 && mine.lastClaimer != null)
mineWindowClose(mine); //mine was knocked down and was claimed, close window
}
}
nextPulse = nextPulse.plusMinutes(30);
}
}
}
public static void mineWindowOpen(Mine mine) {
mine.setActive(true);
ChatManager.chatSystemChannel(mine.getParentZone().getName() + "'s Mine is now Active!");
Logger.info(mine.getParentZone().getName() + "'s Mine is now Active!");
}
public static boolean mineWindowClose(Mine mine) {
// No need to end the window of a mine which never opened.
if (mine.isActive == false)
return false;
Building mineBuilding = BuildingManager.getBuildingFromCache(mine.getBuildingID());
if (mineBuilding == null) {
Logger.debug("Null mine building for Mine " + mine.getObjectUUID() + " Building " + mine.getBuildingID());
return false;
}
for(Integer id : mine._playerMemory ){
PlayerCharacter.getPlayerCharacter(id).ZergMultiplier = 1.0f;
}
for(Integer id : mine._recentMemory.keySet()){
PlayerCharacter.getPlayerCharacter(id).ZergMultiplier = 1.0f;
}
// Mine building still stands; nothing to do.
// We can early exit here.
if (mineBuilding.getRank() > 0) {
mine.setActive(false);
mine.lastClaimer = null;
return true;
}
// This mine does not have a valid claimer
// we will therefore set it to errant
// and keep the window open.
if (!Mine.validateClaimer(mine.lastClaimer)) {
mine.lastClaimer = null;
mine.updateGuildOwner(null);
mine.setActive(true);
return false;
}
//Update ownership to map
mine.guildName = mine.getOwningGuild().getName();
mine.guildTag = mine.getOwningGuild().getGuildTag();
Guild nation = mine.getOwningGuild().getNation();
mine.nationName = nation.getName();
mine.nationTag = nation.getGuildTag();
mineBuilding.rebuildMine(mine.capSize * 5000);
WorldGrid.updateObject(mineBuilding);
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mine.lastClaimer.getName() + " has claimed the mine in " + mine.getParentZone().getName() + " for " + mine.getOwningGuild().getName() + ". The mine is no longer active.");
chatMsg.setMessageType(10);
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
DispatchMessage.dispatchMsgToAll(chatMsg);
// Warehouse this claim event
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
DataWarehouse.pushToWarehouse(mineRecord);
mineBuilding.setRank(mineBuilding.getRank());
mine.lastClaimer = null;
mine.setActive(false);
mine.wasClaimed = true;
return true;
}
}
Loading…
Cancel
Save