Refactor to remove abstraction
This commit is contained in:
@@ -9,12 +9,15 @@
|
|||||||
|
|
||||||
package engine.db.handlers;
|
package engine.db.handlers;
|
||||||
|
|
||||||
|
import engine.gameManager.DbManager;
|
||||||
import engine.objects.Mob;
|
import engine.objects.Mob;
|
||||||
import engine.objects.Zone;
|
import engine.objects.Zone;
|
||||||
import engine.server.MBServerStatics;
|
import engine.server.MBServerStatics;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -26,87 +29,106 @@ public class dbMobHandler extends dbHandlerBase {
|
|||||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mob ADD_MOB(Mob toAdd)
|
public Mob ADD_MOB(Mob toAdd) {
|
||||||
{
|
|
||||||
prepareCallable("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
|
Mob mobile = null;
|
||||||
setLong(1, toAdd.getParentZoneID());
|
|
||||||
setInt(2, toAdd.getMobBaseID());
|
try (Connection connection = DbManager.getConnection();
|
||||||
setInt(3, toAdd.getGuildUUID());
|
PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||||
setFloat(4, toAdd.getSpawnX());
|
|
||||||
setFloat(5, toAdd.getSpawnY());
|
preparedStatement.setLong(1, toAdd.getParentZoneID());
|
||||||
setFloat(6, toAdd.getSpawnZ());
|
preparedStatement.setInt(2, toAdd.getMobBaseID());
|
||||||
setInt(7, 0);
|
preparedStatement.setInt(3, toAdd.getGuildUUID());
|
||||||
setFloat(8, toAdd.getSpawnRadius());
|
preparedStatement.setFloat(4, toAdd.getSpawnX());
|
||||||
setInt(9, toAdd.getTrueSpawnTime());
|
preparedStatement.setFloat(5, toAdd.getSpawnY());
|
||||||
if (toAdd.getContract() != null)
|
preparedStatement.setFloat(6, toAdd.getSpawnZ());
|
||||||
setInt(10, toAdd.getContract().getContractID());
|
preparedStatement.setInt(7, 0);
|
||||||
else
|
preparedStatement.setFloat(8, toAdd.getSpawnRadius());
|
||||||
setInt(10, 0);
|
preparedStatement.setInt(9, toAdd.getTrueSpawnTime());
|
||||||
setInt(11, toAdd.getBuildingID());
|
|
||||||
setInt(12, toAdd.getLevel());
|
if (toAdd.getContract() != null)
|
||||||
setString(13, toAdd.getFirstName());
|
preparedStatement.setInt(10, toAdd.getContract().getContractID());
|
||||||
int objectUUID = (int) getUUID();
|
else
|
||||||
if (objectUUID > 0)
|
preparedStatement.setInt(10, 0);
|
||||||
return GET_MOB(objectUUID);
|
|
||||||
return null;
|
preparedStatement.setInt(11, toAdd.getBuildingID());
|
||||||
|
preparedStatement.setInt(12, toAdd.getLevel());
|
||||||
|
preparedStatement.setString(13, toAdd.getFirstName());
|
||||||
|
|
||||||
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
int objectUUID = (int) rs.getLong("UID");
|
||||||
|
|
||||||
|
if (objectUUID > 0)
|
||||||
|
mobile = GET_MOB(objectUUID);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return mobile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateUpgradeTime(Mob mob, DateTime upgradeDateTime) {
|
public boolean updateUpgradeTime(Mob mob, DateTime upgradeDateTime) {
|
||||||
|
|
||||||
try {
|
try (Connection connection = DbManager.getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_mob SET upgradeDate=? "
|
||||||
prepareCallable("UPDATE obj_mob SET upgradeDate=? "
|
+ "WHERE UID = ?")) {
|
||||||
+ "WHERE UID = ?");
|
|
||||||
|
|
||||||
if (upgradeDateTime == null)
|
if (upgradeDateTime == null)
|
||||||
setNULL(1, java.sql.Types.DATE);
|
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||||
else
|
else
|
||||||
setTimeStamp(1, upgradeDateTime.getMillis());
|
preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis()));
|
||||||
|
|
||||||
setInt(2, mob.getObjectUUID());
|
preparedStatement.setInt(2, mob.getObjectUUID());
|
||||||
executeUpdate();
|
|
||||||
} catch (Exception e) {
|
preparedStatement.execute();
|
||||||
Logger.error("Mob.updateUpgradeTime", "UUID: " + mob.getObjectUUID());
|
return true;
|
||||||
return false;
|
} catch (SQLException e) {
|
||||||
|
Logger.error(e);
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int DELETE_MOB(final Mob mob) {
|
public int DELETE_MOB(final Mob mob) {
|
||||||
prepareCallable("DELETE FROM `object` WHERE `UID` = ?");
|
|
||||||
setLong(1, mob.getDBID());
|
int row_count = 0;
|
||||||
return executeUpdate();
|
try (Connection connection = DbManager.getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||||
|
|
||||||
|
preparedStatement.setLong(1, mob.getDBID());
|
||||||
|
row_count = preparedStatement.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.error(e);
|
||||||
|
|
||||||
|
}
|
||||||
|
return row_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LOAD_PATROL_POINTS(Mob captain) {
|
public void LOAD_PATROL_POINTS(Mob captain) {
|
||||||
|
|
||||||
prepareCallable("SELECT * FROM `dyn_guards` WHERE `captainUID` = ?");
|
try (Connection connection = DbManager.getConnection();
|
||||||
setInt(1,captain.getObjectUUID());
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guards` WHERE `captainUID` = ?")) {
|
||||||
|
|
||||||
try {
|
preparedStatement.setInt(1, captain.getObjectUUID());
|
||||||
ResultSet rs = executeQuery();
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
|
||||||
//shrines cached in rs for easy cache on creation.
|
while (rs.next()) {
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
int mobBaseID = rs.getInt("mobBaseID");
|
|
||||||
String name = rs.getString("name");
|
String name = rs.getString("name");
|
||||||
Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(),name);
|
Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(), name);
|
||||||
|
|
||||||
if (toCreate == null)
|
if (toCreate == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (toCreate != null) {
|
if (toCreate != null) {
|
||||||
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
|
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
|
||||||
toCreate.setDeathTime(System.currentTimeMillis());
|
toCreate.setDeathTime(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Logger.error( e.toString());
|
Logger.error(e);
|
||||||
} finally {
|
|
||||||
closeCallable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) {
|
public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) {
|
||||||
@@ -122,7 +144,7 @@ public class dbMobHandler extends dbHandlerBase {
|
|||||||
prepareCallable("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?");
|
prepareCallable("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?");
|
||||||
setLong(1, captainUID);
|
setLong(1, captainUID);
|
||||||
setInt(2, mobBaseID);
|
setInt(2, mobBaseID);
|
||||||
setInt(3,slot);
|
setInt(3, slot);
|
||||||
return (executeUpdate() > 0);
|
return (executeUpdate() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user