forked from MagicBane/Server
Building handler added
This commit is contained in:
@@ -88,6 +88,23 @@ public class dbBuildingHandler extends dbHandlerBase {
|
|||||||
return removeFromBuildings(b);
|
return removeFromBuildings(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<Building> GET_ALL_BUILDINGS() {
|
||||||
|
|
||||||
|
ArrayList<Building> buildings = new ArrayList<>();
|
||||||
|
|
||||||
|
try (Connection connection = DbManager.getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` ORDER BY `object`.`UID` ASC;")) {
|
||||||
|
|
||||||
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
buildings = getObjectsFromRs(rs, 1000);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildings;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<Building> GET_ALL_BUILDINGS_FOR_ZONE(Zone zone) {
|
public ArrayList<Building> GET_ALL_BUILDINGS_FOR_ZONE(Zone zone) {
|
||||||
|
|
||||||
ArrayList<Building> buildings = new ArrayList<>();
|
ArrayList<Building> buildings = new ArrayList<>();
|
||||||
|
|||||||
@@ -1,151 +0,0 @@
|
|||||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
||||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
||||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
||||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
||||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
||||||
// Magicbane Emulator Project © 2013 - 2022
|
|
||||||
// www.magicbane.com
|
|
||||||
|
|
||||||
|
|
||||||
package engine.net.client.msg;
|
|
||||||
|
|
||||||
|
|
||||||
import engine.exception.SerializationException;
|
|
||||||
import engine.gameManager.BuildingManager;
|
|
||||||
import engine.gameManager.DbManager;
|
|
||||||
import engine.gameManager.ZoneManager;
|
|
||||||
import engine.net.AbstractConnection;
|
|
||||||
import engine.net.ByteBufferReader;
|
|
||||||
import engine.net.ByteBufferWriter;
|
|
||||||
import engine.net.client.Protocol;
|
|
||||||
import engine.objects.Building;
|
|
||||||
import engine.objects.Zone;
|
|
||||||
import org.pmw.tinylog.Logger;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class SyncMessage extends ClientNetMsg {
|
|
||||||
|
|
||||||
private int type;
|
|
||||||
private int size;
|
|
||||||
private int pad = 0;
|
|
||||||
private int objectType;
|
|
||||||
private int objectUUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
|
||||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
|
||||||
* past the limit) then this constructor Throws that Exception to the
|
|
||||||
* caller.
|
|
||||||
*/
|
|
||||||
public SyncMessage(AbstractConnection origin, ByteBufferReader reader) {
|
|
||||||
super(Protocol.CITYASSET, origin, reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SyncMessage() {
|
|
||||||
super(Protocol.CITYASSET);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void _deserialize(ByteBufferReader reader) {
|
|
||||||
//none yet
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
|
||||||
//lets do returns before writing so we don't send improper structures to the client
|
|
||||||
|
|
||||||
Building tol = BuildingManager.getBuilding(this.objectUUID);
|
|
||||||
|
|
||||||
if (tol == null) {
|
|
||||||
Logger.debug("TOL is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Zone zone = ZoneManager.findSmallestZone(tol.getLoc());
|
|
||||||
if (zone == null) {
|
|
||||||
Logger.debug("Zone is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<Building> allCityAssets = DbManager.BuildingQueries.GET_ALL_BUILDINGS_FOR_ZONE(zone);
|
|
||||||
|
|
||||||
// *** Refactor: collection created but never used?
|
|
||||||
|
|
||||||
ArrayList<Building> canProtectAssets = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Building b : allCityAssets) {
|
|
||||||
if (b.getBlueprintUUID() != 0)
|
|
||||||
canProtectAssets.add(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// *** Refactor : Not sure what this synch message does
|
|
||||||
// Get the feeling it should be looping over upgradable
|
|
||||||
// assets.
|
|
||||||
writer.putInt(0);
|
|
||||||
writer.putInt(0);
|
|
||||||
writer.putInt(this.objectType);
|
|
||||||
writer.putInt(this.objectUUID);
|
|
||||||
writer.putInt(allCityAssets.size());
|
|
||||||
for (Building b : allCityAssets) {
|
|
||||||
String name = b.getName();
|
|
||||||
// if (name.equals(""))
|
|
||||||
// name = b.getBuildingSet().getName();
|
|
||||||
writer.putInt(b.getObjectType().ordinal());
|
|
||||||
writer.putInt(b.getObjectUUID());
|
|
||||||
|
|
||||||
writer.putString(b.getName()); // Blueprint name?
|
|
||||||
writer.putString(b.getGuild().getName());
|
|
||||||
writer.putInt(20);// \/ Temp \/
|
|
||||||
writer.putInt(b.getRank());
|
|
||||||
writer.putInt(1); // symbol
|
|
||||||
writer.putInt(7); //TODO identify these Guild tags??
|
|
||||||
writer.putInt(17);
|
|
||||||
writer.putInt(14);
|
|
||||||
writer.putInt(14);
|
|
||||||
writer.putInt(98);// /\ Temp /\
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getObjectType() {
|
|
||||||
return objectType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setObjectType(int value) {
|
|
||||||
this.objectType = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getUUID() {
|
|
||||||
return objectUUID;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPad() {
|
|
||||||
return pad;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPad(int value) {
|
|
||||||
this.pad = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(int type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(int size) {
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -555,67 +555,6 @@ public class WorldServer {
|
|||||||
for (Zone zone : rootParent) {
|
for (Zone zone : rootParent) {
|
||||||
|
|
||||||
ZoneManager.addZone(zone.template, zone);
|
ZoneManager.addZone(zone.template, zone);
|
||||||
|
|
||||||
//Handle Buildings
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayList<Building> bList;
|
|
||||||
bList = DbManager.BuildingQueries.GET_ALL_BUILDINGS_FOR_ZONE(zone);
|
|
||||||
|
|
||||||
for (Building b : bList) {
|
|
||||||
|
|
||||||
b.setObjectTypeMask(MBServerStatics.MASK_BUILDING);
|
|
||||||
b.setLoc(b.getLoc());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.error(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Handle Mobs
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayList<Mob> mobs;
|
|
||||||
mobs = DbManager.MobQueries.GET_ALL_MOBS_FOR_ZONE(zone);
|
|
||||||
|
|
||||||
for (Mob m : mobs) {
|
|
||||||
m.setObjectTypeMask(MBServerStatics.MASK_MOB | m.getTypeMasks());
|
|
||||||
m.setLoc(m.getLoc());
|
|
||||||
|
|
||||||
// Load Minions for Guard Captains here.
|
|
||||||
|
|
||||||
if (m.building != null && m.building.getBlueprint() != null && m.building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BARRACK)
|
|
||||||
DbManager.MobQueries.LOAD_GUARD_MINIONS(m);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.error(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Handle NPCs
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayList<NPC> npcs;
|
|
||||||
|
|
||||||
// Ignore NPCs on the seafloor (npc guild leaders, etc)
|
|
||||||
|
|
||||||
if (zone.equals(seaFloor))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
npcs = DbManager.NPCQueries.GET_ALL_NPCS_FOR_ZONE(zone);
|
|
||||||
|
|
||||||
for (NPC n : npcs) {
|
|
||||||
n.setObjectTypeMask(MBServerStatics.MASK_NPC);
|
|
||||||
n.setLoc(n.getLoc());
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
Logger.error(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
//Handle cities
|
|
||||||
|
|
||||||
ZoneManager.loadCities(zone);
|
|
||||||
ZoneManager.populateWorldZones(zone);
|
ZoneManager.populateWorldZones(zone);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user