Browse Source

FIRST AFTER ROLLBACK: reintroduce mines

lakebane-master
FatBoy-DOTC 5 months ago
parent
commit
8b03fbc15b
  1. 6
      src/engine/devcmd/cmds/MineActiveCmd.java
  2. 245
      src/engine/objects/Mine.java
  3. 38
      src/engine/server/world/WorldServer.java
  4. 138
      src/engine/workthreads/MineThread.java

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

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

245
src/engine/objects/Mine.java

@ -11,20 +11,26 @@ package engine.objects; @@ -11,20 +11,26 @@ package engine.objects;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
import engine.gameManager.*;
import engine.net.ByteBufferWriter;
import engine.net.DispatchMessage;
import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.server.MBServerStatics;
import engine.workthreads.ZergMechanicThread;
import org.joda.time.DateTime;
import org.pmw.tinylog.Logger;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import static engine.gameManager.DbManager.MineQueries;
import static engine.gameManager.DbManager.getObject;
@ -58,8 +64,7 @@ public class Mine extends AbstractGameObject { @@ -58,8 +64,7 @@ public class Mine extends AbstractGameObject {
public boolean hasProduced = false;
public int liveHour;
public int liveMinute;
public int liveTime;
public Boolean firstThirty = true;
public static ArrayList<Mine> ChinaMines = new ArrayList<>();
@ -67,6 +72,9 @@ public class Mine extends AbstractGameObject { @@ -67,6 +72,9 @@ public class Mine extends AbstractGameObject {
public static ArrayList<Mine> AmericaMines = new ArrayList<>();
public boolean wasOpened = false;
public int liveHour;
public int liveMinute;
/**
* ResultSet Constructor
*/
@ -117,17 +125,8 @@ public class Mine extends AbstractGameObject { @@ -117,17 +125,8 @@ public class Mine extends AbstractGameObject {
this.liveHour = rs.getInt("mineLiveHour");
this.liveMinute = rs.getInt("mineLiveMinute");
this.capSize = rs.getInt("capSize");
if(BuildingManager.getBuilding(this.buildingID) != null) {
Building mineTower = BuildingManager.getBuilding(this.buildingID);
if (mineTower != null) {
mineTower.setMaxHitPoints(5000 * this.capSize);
mineTower.setCurrentHitPoints((float) 5000 * this.capSize);
}
}
}
}
public static void releaseMineClaims(PlayerCharacter playerCharacter) {
if (playerCharacter == null)
@ -169,8 +168,6 @@ public class Mine extends AbstractGameObject { @@ -169,8 +168,6 @@ public class Mine extends AbstractGameObject {
public static void loadAllMines() {
try {
//Load mine resources
MineProduction.addResources();
@ -182,10 +179,6 @@ public class Mine extends AbstractGameObject { @@ -182,10 +179,6 @@ public class Mine extends AbstractGameObject {
Mine.towerMap.put(mine.buildingID, mine);
//mine.mineType = MineProduction.LUMBER;
}
}catch(Exception e) {
}
}
/*
@ -196,30 +189,20 @@ public class Mine extends AbstractGameObject { @@ -196,30 +189,20 @@ public class Mine extends AbstractGameObject {
return Mine.towerMap.get(towerID);
}
public static String getMineNationality(int time){
switch(time){
case 7:
case 8:
case 9:
return "CN";
case 14:
case 15:
case 16:
return "EU";
case 20:
case 21:
case 22:
return "NA";
default:
return "Unknown";
}
}
public static void serializeForClientMsg(Mine mine, ByteBufferWriter writer) {
writer.putInt(mine.getObjectType().ordinal());
writer.putInt(mine.getObjectUUID());
writer.putInt(mine.getObjectUUID()); //actually a hash of mine
writer.putString(mine.mineType.name);
writer.putString(Mine.getMineNationality(mine.liveHour) + " " + mine.capSize + " Man ");
if(ChinaMines.contains((mine))) {
writer.putString("Chinese" + " {" + mine.capSize + " Man}");
} else if(AmericaMines.contains(mine)){
writer.putString("American" + " {" + mine.capSize + " Man}");
} else if(EuroMines.contains(mine)){
writer.putString("European" + " {" + mine.capSize + " Man}");
}else{
writer.putString("Unknown" + " {" + mine.capSize + " Man}");
}
writer.putInt(mine.production.hash);
writer.putInt(mine.getModifiedProductionAmount());
writer.putInt(mine.getModifiedProductionAmount()); //TODO calculate range penalty here
@ -227,16 +210,21 @@ public class Mine extends AbstractGameObject { @@ -227,16 +210,21 @@ public class Mine extends AbstractGameObject {
// Errant mines are currently open. Set time to now.
LocalDateTime mineOpenTime = LocalDateTime.now().withHour(mine.liveHour).withMinute(mine.liveMinute);
LocalDateTime mineOpenTime;// = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
if(mine.firstThirty == true){
mineOpenTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(0).withSecond(0).withNano(0);
}
else{
mineOpenTime = LocalDateTime.now().withHour(mine.liveTime).withMinute(30).withSecond(0).withNano(0);
}
LocalDateTime mineCloseTime = mineOpenTime.plusMinutes(30);
if(LocalDateTime.now().isAfter(mineCloseTime) && mine.isActive == false){
if(LocalDateTime.now().isAfter(mineCloseTime)){
mineOpenTime = mineOpenTime.plusDays(1);
mineCloseTime = mineCloseTime.plusDays(1);
}
writer.putLocalDateTime(mineOpenTime);
writer.putLocalDateTime(mineCloseTime);
writer.put(mine.isActive ? (byte) 0x01 : (byte) 0x00);
Building mineTower = BuildingManager.getBuilding(mine.buildingID);
@ -246,51 +234,9 @@ public class Mine extends AbstractGameObject { @@ -246,51 +234,9 @@ public class Mine extends AbstractGameObject {
writer.putInt(mine.isExpansion() ? mine.mineType.xpacHash : mine.mineType.hash);
writer.putString(mine.nationName);
writer.putString(mine.guildName);
GuildTag._serializeForDisplay(mine.guildTag, writer);
boolean isPM = false;
if(mineOpenTime.getHour() > 11)
isPM = true;
int hourOpen = mineOpenTime.getHour();
int minuteOpen = mineOpenTime.getMinute();
int hourClose = mineCloseTime.getHour();
int minuteClose = mineCloseTime.getMinute();
if(isPM){
hourOpen -= 12;
hourClose -= 12;
}
String timeString = hourOpen + ":";
if(minuteOpen == 0){
timeString += "00 ";
}else{
timeString += "30 ";
}
if(isPM){
timeString += "PM ";
}else{
timeString += "AM ";
}
timeString += " to ";
timeString += hourClose + ":";
if(minuteClose == 0){
timeString += "00 ";
}else{
timeString += "30 ";
}
if(isPM){
timeString += "PM CST";
}else{
timeString += "AM CST";
}
writer.putString(timeString);
writer.putString(mine.nationName);
GuildTag._serializeForDisplay(mine.nationTag, writer);
}
@ -326,6 +272,8 @@ public class Mine extends AbstractGameObject { @@ -326,6 +272,8 @@ public class Mine extends AbstractGameObject {
// all the requirements to claim; landed
// guild with a warehouse, etc.
Guild playerGuild;
//verify the player exists
if (playerCharacter == null)
@ -333,7 +281,7 @@ public class Mine extends AbstractGameObject { @@ -333,7 +281,7 @@ public class Mine extends AbstractGameObject {
//verify the player is in valid guild
Guild playerGuild = playerCharacter.getGuild();
playerGuild = playerCharacter.getGuild();
// Can't claim something if you don't have a guild!
@ -355,9 +303,40 @@ public class Mine extends AbstractGameObject { @@ -355,9 +303,40 @@ public class Mine extends AbstractGameObject {
return false;
}
// Number of mines is based on the rank of the nation's tree.
City nationCapitol = playerGuild.getNation().getOwnedCity();
Building nationCapitolTOL = nationCapitol.getTOL();
if (nationCapitolTOL == null)
return false;
//int treeRank = nationCapitolTOL.getRank();
//if (treeRank < 1)
// return false;
//if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false) {
// ErrorPopupMsg.sendErrorMsg(playerCharacter, "Your nation cannot support another mine.");
// return false;
//}
return true;
}
private static boolean guildUnderMineLimit(Guild playerGuild, int tolRank) {
int mineCnt = 0;
mineCnt += Mine.getMinesForGuild(playerGuild.getObjectUUID()).size();
for (Guild guild : playerGuild.getSubGuildList())
mineCnt += Mine.getMinesForGuild(guild.getObjectUUID()).size();
return mineCnt <= tolRank;
}
public boolean changeProductionType(Resource resource) {
//if (!this.validForMine(resource))
// return false;
@ -614,9 +593,10 @@ public class Mine extends AbstractGameObject { @@ -614,9 +593,10 @@ public class Mine extends AbstractGameObject {
amount = 12000000;
break;
}
if(this.production.UUID != 7)
if(this.production.UUID == 7)
amount *= 0.5f;
else
amount = amount / value;
return (int) amount;
}
public Boolean onExit(HashSet<AbstractWorldObject> currentPlayers){
@ -643,4 +623,95 @@ public class Mine extends AbstractGameObject { @@ -643,4 +623,95 @@ public class Mine extends AbstractGameObject {
}
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.");
}
}
}
}
}

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

@ -23,6 +23,7 @@ import engine.gameManager.*; @@ -23,6 +23,7 @@ import engine.gameManager.*;
import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.LogoutCharacterJob;
import engine.math.Vector3fImmutable;
import engine.mobileAI.Threads.MobAIThread;
import engine.mobileAI.Threads.MobRespawnThread;
import engine.net.Dispatch;
@ -209,7 +210,7 @@ public class WorldServer { @@ -209,7 +210,7 @@ public class WorldServer {
LocalDateTime nextHourlyJobTime = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(0);
LocalDateTime nextWareHousePushTime = LocalDateTime.now();
LocalDateTime nextDiscSpawn = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(1);
LocalDateTime nextMinePulse = LocalDateTime.now().withMinute(0).withSecond(0);
LocalDateTime minePulse = LocalDateTime.now().withMinute(0).withSecond(0).plusHours(0);
// Begin execution of main game loop
@ -251,11 +252,11 @@ public class WorldServer { @@ -251,11 +252,11 @@ public class WorldServer {
if(LocalDateTime.now().isAfter(nextDiscSpawn)) {
switch (LocalDateTime.now().getHour()) {
case 0:
case 3:
case 7:
case 11:
case 15:
case 19:
case 4:
case 8:
case 12:
case 16:
case 20:
for (Mob dropper : Mob.disciplineDroppers) {
if (!dropper.isAlive()) {
Zone.respawnQue.add(dropper);
@ -266,12 +267,9 @@ public class WorldServer { @@ -266,12 +267,9 @@ public class WorldServer {
}
nextDiscSpawn = nextDiscSpawn.plusHours(1);
}
if (LocalDateTime.now().isAfter(nextMinePulse)) {
Thread mineThread = new Thread(new MineThread());
mineThread.setName("mineThread");
mineThread.start();
nextMinePulse = nextMinePulse.plusMinutes(30);
if(LocalDateTime.now().isAfter(minePulse)) {
Mine.processMineWindows();
minePulse = minePulse.plusMinutes(30);
}
ThreadUtils.sleep(50);
}
@ -552,18 +550,6 @@ public class WorldServer { @@ -552,18 +550,6 @@ public class WorldServer {
Logger.info("Running garbage collection...");
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();
//Logger.info("Starting Box Flag Thread");
//BoxFlagThread.startBoxFlagThread();
return true;
}
@ -843,9 +829,9 @@ public class WorldServer { @@ -843,9 +829,9 @@ public class WorldServer {
loadedMob.playerAgroMap.remove(player.getObjectUUID());
}
player.getTimestamps().put("logout", System.currentTimeMillis());
player.enteredWorld = false;
player.setEnteredWorld(false);
// remove from simulation and zero current loc
// remove from simulation and zero current loc
WorldGrid.RemoveWorldObject(player);

138
src/engine/workthreads/MineThread.java

@ -1,138 +0,0 @@ @@ -1,138 +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() {
processMineWindows();
}
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.");
}
}
}
}
}
Loading…
Cancel
Save