From c5f47ffcd447876b4f3f7a3c7a8c5be509f28212 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 28 Dec 2024 07:39:15 -0600 Subject: [PATCH] bane commander NPC --- src/engine/db/handlers/dbBaneHandler.java | 103 ++++++++++++++++++++++ src/engine/objects/Bane.java | 10 +++ src/engine/objects/Contract.java | 53 +++++++++-- 3 files changed, 160 insertions(+), 6 deletions(-) diff --git a/src/engine/db/handlers/dbBaneHandler.java b/src/engine/db/handlers/dbBaneHandler.java index a076e321..23a6bc0b 100644 --- a/src/engine/db/handlers/dbBaneHandler.java +++ b/src/engine/db/handlers/dbBaneHandler.java @@ -88,6 +88,109 @@ public class dbBaneHandler extends dbHandlerBase { return true; } + public boolean SET_BANE_TIME_NEW(int hour, int cityUUID, DateTime placementDate) { + + DateTime toSet = placementDate.withHourOfDay(12 + hour).withMinuteOfHour(0).withSecondOfMinute(0); + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `liveDate`=? WHERE `cityUUID`=?")) { + + preparedStatement.setTimestamp(1, new java.sql.Timestamp(toSet.getMillis())); + preparedStatement.setLong(2, cityUUID); + + preparedStatement.execute(); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `time_set`=? WHERE `cityUUID`=?")) { + + preparedStatement.setInt(1, 1); + preparedStatement.setLong(2, cityUUID); + + preparedStatement.execute(); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + return true; + } + + public boolean SET_BANE_DAY_NEW(int day, int cityUUID, DateTime placementDate) { + + DateTime toSet = placementDate.plusDays(day); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `liveDate`=? WHERE `cityUUID`=?")) { + + preparedStatement.setTimestamp(1, new java.sql.Timestamp(toSet.getMillis())); + preparedStatement.setLong(2, cityUUID); + + preparedStatement.execute(); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `day_set`=? WHERE `cityUUID`=?")) { + + preparedStatement.setInt(1, 1); + preparedStatement.setLong(2, cityUUID); + + preparedStatement.execute(); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + return true; + } + + public boolean SET_BANE_CAP_NEW(int count, int cityUUID) { + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `cap_size`=? WHERE `cityUUID`=?")) { + + preparedStatement.setInt(1, count); + preparedStatement.setLong(2, cityUUID); + + preparedStatement.execute(); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `cap_set`=? WHERE `cityUUID`=?")) { + + preparedStatement.setInt(1, 1); + preparedStatement.setLong(2, cityUUID); + + preparedStatement.execute(); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `cap_size`=? WHERE `cityUUID`=?")) { + + preparedStatement.setInt(1, count); + preparedStatement.setLong(2, cityUUID); + + preparedStatement.execute(); + + } catch (SQLException e) { + Logger.error(e); + return false; + } + return true; + } + public boolean REMOVE_BANE(Bane bane) { if (bane == null) diff --git a/src/engine/objects/Bane.java b/src/engine/objects/Bane.java index 1bc5888c..9d0afdce 100644 --- a/src/engine/objects/Bane.java +++ b/src/engine/objects/Bane.java @@ -46,6 +46,10 @@ public final class Bane { private DateTime placementDate = null; private DateTime liveDate = null; private BaneDefaultTimeJob defaultTimeJob; + public boolean timeSet = false; + public boolean daySet = false; + public boolean capSet = false; + public int capSize = 10; // Internal cache for banes private ActivateBaneJob activateBaneJob; @@ -62,6 +66,12 @@ public final class Bane { this.ownerUUID = rs.getInt("ownerUUID"); this.stoneUUID = rs.getInt("stoneUUID"); + this.timeSet = rs.getInt("time_set") == 1; + this.daySet = rs.getInt("day_set") == 1; + this.capSet = rs.getInt("cap_set") == 1; + this.capSize = rs.getInt("cap_size"); + + sqlDateTime = rs.getTimestamp("placementDate"); if (sqlDateTime != null) diff --git a/src/engine/objects/Contract.java b/src/engine/objects/Contract.java index 09d27f97..9d29e9ad 100644 --- a/src/engine/objects/Contract.java +++ b/src/engine/objects/Contract.java @@ -199,6 +199,9 @@ public class Contract extends AbstractGameObject { vd.getOptions().clear(); Building building = npc.building; Bane bane = null; + int updateBaneTime = 0; + int updateBaneDay = 0; + int updateBaneCap = 0; if(building != null) { City city = ZoneManager.getCityAtLocation(npc.loc); @@ -212,12 +215,18 @@ public class Contract extends AbstractGameObject { DateTime placement = bane.getPlacementDate(); switch(optionId){ default: - MenuOption option1 = new MenuOption(796, "Set Bane Day", 796); - vd.getOptions().add(option1); - MenuOption option2 = new MenuOption(797, "Set Bane Time", 797); - vd.getOptions().add(option2); - MenuOption option3 = new MenuOption(797, "Set Bane Cap", 798); - vd.getOptions().add(option3); + if(!bane.daySet) { + MenuOption option1 = new MenuOption(796, "Set Bane Day", 796); + vd.getOptions().add(option1); + } + if(!bane.timeSet) { + MenuOption option2 = new MenuOption(797, "Set Bane Time", 797); + vd.getOptions().add(option2); + } + if(!bane.capSet) { + MenuOption option3 = new MenuOption(797, "Set Bane Cap", 798); + vd.getOptions().add(option3); + } break; case 796: // set bane day DateTime dayOption1Date = placement.plusDays(3); @@ -276,50 +285,82 @@ public class Contract extends AbstractGameObject { case 7961: //3 days after placement ErrorPopupMsg.sendErrorMsg(pc, "Bane Set 3 Days From Placement Date"); + updateBaneDay = 3; break; case 7962: //4 days after placement ErrorPopupMsg.sendErrorMsg(pc, "Bane Set 4 Days From Placement Date"); + updateBaneDay = 4; break; case 7963: //5 days after placement ErrorPopupMsg.sendErrorMsg(pc, "Bane Set 5 Days From Placement Date"); + updateBaneDay = 5; break; case 7964: //6 days after placement ErrorPopupMsg.sendErrorMsg(pc, "Bane Set 6 Days From Placement Date"); + updateBaneDay = 6; break; case 7965: //7 days after placement ErrorPopupMsg.sendErrorMsg(pc, "Bane Set 7 Days From Placement Date"); + updateBaneDay = 7; break; case 7971: //6:00pm CST ErrorPopupMsg.sendErrorMsg(pc, "Bane Set For 6:00 pm CST"); + updateBaneTime = 6; break; case 7972: //7:00pm CST ErrorPopupMsg.sendErrorMsg(pc, "Bane Set For 7:00 pm CST"); + updateBaneTime = 7; break; case 7973: //8:00pm CST ErrorPopupMsg.sendErrorMsg(pc, "Bane Set For 8:00 pm CST"); + updateBaneTime = 8; break; case 7974: //9:00pm CST ErrorPopupMsg.sendErrorMsg(pc, "Bane Set For 9:00 pm CST"); + updateBaneTime = 9; break; case 7975: //10:00pm CST ErrorPopupMsg.sendErrorMsg(pc, "Bane Set For 10:00 pm CST"); + updateBaneTime = 10; break; case 7981: //cap = 10 ErrorPopupMsg.sendErrorMsg(pc, "Bane Cap Set To 10 Players On Each Side"); + updateBaneCap = 10; break; case 7982: //cap = 20 ErrorPopupMsg.sendErrorMsg(pc, "Bane Cap Set To 20 Players On Each Side"); + updateBaneCap = 20; break; case 7983: //cap = 30 ErrorPopupMsg.sendErrorMsg(pc, "Bane Cap Set To 30 Players On Each Side"); + updateBaneCap = 30; break; case 7984: //cap = 40 ErrorPopupMsg.sendErrorMsg(pc, "Bane Cap Set To 40 Players On Each Side"); + updateBaneCap = 40; break; case 7985: //cap = Unlimited ErrorPopupMsg.sendErrorMsg(pc, "Bane Cap Set To Unlimited Players On Each Side"); + updateBaneCap = 9999; break; } + if (updateBaneDay > 0) { + if(DbManager.BaneQueries.SET_BANE_DAY_NEW(updateBaneDay,bane.getCityUUID(), bane.getPlacementDate())){ + bane.daySet = true; + } + } + if (updateBaneTime > 0) { + if(DbManager.BaneQueries.SET_BANE_TIME_NEW(updateBaneDay,bane.getCityUUID(), bane.getPlacementDate())){ + bane.timeSet = true; + } + } + if (updateBaneCap > 0) { + if(DbManager.BaneQueries.SET_BANE_CAP_NEW(updateBaneCap,bane.getCityUUID())){ + bane.capSet = true; + bane.capSize = updateBaneCap; + } + } + return vd; }