Browse Source

bane commander NPC

lakebane2
FatBoy-DOTC 3 weeks ago
parent
commit
d94de771bf
  1. 92
      src/engine/db/handlers/dbBaneHandler.java
  2. 8
      src/engine/objects/Contract.java

92
src/engine/db/handlers/dbBaneHandler.java

@ -88,67 +88,65 @@ public class dbBaneHandler extends dbHandlerBase {
return true; return true;
} }
public boolean SET_BANE_TIME_NEW(int hour, int cityUUID, DateTime placementDate) { public boolean SET_BANE_TIME_NEW(int hour, int cityUUID) {
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(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `time_set`=? WHERE `cityUUID`=?")) { PreparedStatement getStatement = connection.prepareStatement("SELECT `liveDate` FROM `dyn_banes` WHERE `cityUUID`=?");
PreparedStatement updateStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `liveDate`=?, `time_set`=? WHERE `cityUUID`=?")) {
preparedStatement.setInt(1, 1);
preparedStatement.setLong(2, cityUUID); // Retrieve the existing liveDate
getStatement.setInt(1, cityUUID);
preparedStatement.execute(); try (ResultSet rs = getStatement.executeQuery()) {
if (rs.next()) {
DateTime existingDate = new DateTime(rs.getTimestamp("liveDate").getTime());
// Update only the time
DateTime updatedDate = existingDate.withHourOfDay(hour).withMinuteOfHour(0).withSecondOfMinute(0);
// Update liveDate and time_set flag
updateStatement.setTimestamp(1, new java.sql.Timestamp(updatedDate.getMillis()));
updateStatement.setInt(2, 1); // time_set flag
updateStatement.setInt(3, cityUUID);
updateStatement.execute();
return true;
}
}
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
return false;
} }
return true; return false;
} }
public boolean SET_BANE_DAY_NEW(int day, int cityUUID, DateTime placementDate) { public boolean SET_BANE_DAY_NEW(int dayOffset, int cityUUID) {
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(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `day_set`=? WHERE `cityUUID`=?")) { PreparedStatement getStatement = connection.prepareStatement("SELECT `liveDate` FROM `dyn_banes` WHERE `cityUUID`=?");
PreparedStatement updateStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `liveDate`=?, `day_set`=? WHERE `cityUUID`=?")) {
preparedStatement.setInt(1, 1);
preparedStatement.setLong(2, cityUUID); // Retrieve the existing liveDate
getStatement.setInt(1, cityUUID);
preparedStatement.execute(); try (ResultSet rs = getStatement.executeQuery()) {
if (rs.next()) {
DateTime existingDate = new DateTime(rs.getTimestamp("liveDate").getTime());
// Update only the day
DateTime updatedDate = existingDate.plusDays(dayOffset);
// Update liveDate and day_set flag
updateStatement.setTimestamp(1, new java.sql.Timestamp(updatedDate.getMillis()));
updateStatement.setInt(2, 1); // day_set flag
updateStatement.setInt(3, cityUUID);
updateStatement.execute();
return true;
}
}
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
return false;
} }
return true; return false;
} }
public boolean SET_BANE_CAP_NEW(int count, int cityUUID) { public boolean SET_BANE_CAP_NEW(int count, int cityUUID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();

8
src/engine/objects/Contract.java

@ -212,6 +212,10 @@ public class Contract extends AbstractGameObject {
if(bane == null){ if(bane == null){
return VendorDialog.getHostileVendorDialog(); return VendorDialog.getHostileVendorDialog();
} }
if(bane.timeSet && bane.capSet && bane.daySet){
vd.getOptions().clear();
return vd;
}
DateTime placement = bane.getPlacementDate(); DateTime placement = bane.getPlacementDate();
switch(optionId){ switch(optionId){
default: default:
@ -345,12 +349,12 @@ public class Contract extends AbstractGameObject {
break; break;
} }
if (updateBaneDay > 0) { if (updateBaneDay > 0) {
if(DbManager.BaneQueries.SET_BANE_DAY_NEW(updateBaneDay,bane.getCityUUID(), bane.getPlacementDate())){ if(DbManager.BaneQueries.SET_BANE_DAY_NEW(updateBaneDay,bane.getCityUUID())){
bane.daySet = true; bane.daySet = true;
} }
} }
if (updateBaneTime > 0) { if (updateBaneTime > 0) {
if(DbManager.BaneQueries.SET_BANE_TIME_NEW(updateBaneDay,bane.getCityUUID(), bane.getPlacementDate())){ if(DbManager.BaneQueries.SET_BANE_TIME_NEW(updateBaneDay,bane.getCityUUID())){
bane.timeSet = true; bane.timeSet = true;
} }
} }

Loading…
Cancel
Save