Files
prestonbane/src/engine/net/client/msg/CityAssetMsg.java
T

219 lines
6.0 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.msg;
import engine.Enum;
import engine.Enum.GameObjectType;
import engine.Enum.ProtectionState;
import engine.exception.SerializationException;
import engine.gameManager.BuildingManager;
import engine.net.AbstractConnection;
import engine.net.ByteBufferReader;
import engine.net.ByteBufferWriter;
import engine.net.client.Protocol;
import engine.objects.Building;
import engine.objects.City;
import engine.objects.Zone;
import org.pmw.tinylog.Logger;
import java.util.HashSet;
import java.util.Set;
public class CityAssetMsg extends ClientNetMsg {
2023-07-15 09:23:48 -04:00
Set<Building> allCityAssets;
Set<Building> canProtectAssets;
private int type;
private int buildingID;
private int size;
private int pad = 0;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
/**
* 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 CityAssetMsg(AbstractConnection origin, ByteBufferReader reader) {
super(Protocol.CITYASSET, origin, reader);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public CityAssetMsg() {
super(Protocol.CITYASSET);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
/**
* Deserializes the subclass specific items from the supplied NetMsgReader.
*/
@Override
protected void _deserialize(ByteBufferReader reader) {
this.type = reader.getInt();
reader.getInt();
this.buildingID = reader.getInt();
reader.getInt();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
protected int getPowerOfTwoBufferSize() {
// Larger size for historically larger opcodes
return (12);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Precache and configure this message before we serialize it
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void configure() {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Building tol;
Zone zone;
City city;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
canProtectAssets = new HashSet<>();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
tol = BuildingManager.getBuildingFromCache(this.buildingID);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (tol == null) {
Logger.debug("TOL is null");
return;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
zone = tol.getParentZone();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (zone == null) {
Logger.debug("Zone is null");
return;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
city = City.getCity(zone.getPlayerCityUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (city == null) {
Logger.debug("Failed to load city data for Tree of life.");
return;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
allCityAssets = zone.zoneBuildingSet;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (Building building : allCityAssets) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (building.getBlueprint() == null)
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Protected assets do not show up on list
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (building.assetIsProtected() == true)
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (building.getProtectionState() == ProtectionState.PENDING)
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Shouldn't need this but just in case
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (building.getBlueprint().isWallPiece())
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.TOL))
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.BANESTONE))
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.SHRINE))
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (!city.isLocationOnCityGrid(building.getLoc()))
continue;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
canProtectAssets.add(building);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
/**
* Serializes the subclass specific items to the supplied NetMsgWriter.
*/
@Override
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
String buildingName;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
writer.putInt(0);
writer.putInt(0);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
writer.putInt(GameObjectType.Building.ordinal());
writer.putInt(this.buildingID);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
writer.putInt(canProtectAssets.size());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (Building cityBuilding : canProtectAssets) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
buildingName = cityBuilding.getName();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (buildingName.isEmpty() && cityBuilding.getBlueprint() != null) {
buildingName = cityBuilding.getBlueprint().getName();
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
writer.putInt(cityBuilding.getObjectType().ordinal());
writer.putInt(cityBuilding.getObjectUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
writer.putString(buildingName);
writer.putString(cityBuilding.getGuild().getName());
writer.putInt(20);// \/ Temp \/
writer.putInt(cityBuilding.getRank());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (cityBuilding.getBlueprint() != null) {
writer.putInt(cityBuilding.getBlueprint().getIcon());
} else {
writer.putInt(0);
}
writer.putInt(7); //TODO identify these Guild tags??
writer.putInt(17);
writer.putInt(14);
writer.putInt(14);
writer.putInt(98);// /\ Temp /\
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getPad() {
return pad;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void setPad(int value) {
this.pad = value;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getType() {
return type;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void setType(int type) {
this.type = type;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getSize() {
return size;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void setSize(int size) {
this.size = size;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getBuildingID() {
return buildingID;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void setBuildingID(int buildingID) {
this.buildingID = buildingID;
}
2022-04-30 09:41:17 -04:00
}