2026-09-27 12:35:14 -05:00
|
|
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
|
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
|
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
|
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
|
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
|
|
|
// Magicbane Emulator Project © 2013 - 2022
|
|
|
|
|
// www.magicbane.com
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package engine.net.client.msg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import engine.exception.SerializationException;
|
|
|
|
|
import engine.net.AbstractConnection;
|
|
|
|
|
import engine.net.ByteBufferReader;
|
|
|
|
|
import engine.net.ByteBufferWriter;
|
|
|
|
|
import engine.net.client.Protocol;
|
|
|
|
|
import engine.objects.Building;
|
|
|
|
|
import engine.objects.Guild;
|
|
|
|
|
import engine.server.MBServerStatics;
|
2026-10-01 22:35:35 -05:00
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.temporal.ChronoField;
|
2026-09-27 12:35:14 -05:00
|
|
|
|
|
|
|
|
public class ArcMineWindowAvailableTimeMsg extends ClientNetMsg {
|
|
|
|
|
|
|
|
|
|
private int buildingUUID;
|
|
|
|
|
private Building treeOfLife;
|
|
|
|
|
|
|
|
|
|
private int currentMineHour;
|
2026-10-01 22:35:35 -05:00
|
|
|
private Duration secondsLeft;
|
|
|
|
|
private Instant lateTime;
|
2026-09-27 12:35:14 -05:00
|
|
|
private int late;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 ArcMineWindowAvailableTimeMsg(AbstractConnection origin, ByteBufferReader reader) {
|
|
|
|
|
super(Protocol.ARCMINEWINDOWAVAILABLETIME, origin, reader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ArcMineWindowAvailableTimeMsg(Building treeOfLife, int timeLeft) {
|
|
|
|
|
super(Protocol.ARCMINEWINDOWAVAILABLETIME);
|
|
|
|
|
this.treeOfLife = treeOfLife;
|
|
|
|
|
this.buildingUUID = treeOfLife.getObjectUUID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void _deserialize(ByteBufferReader reader) {
|
|
|
|
|
reader.getInt();
|
|
|
|
|
reader.getInt();
|
|
|
|
|
reader.getInt();
|
|
|
|
|
reader.getInt(); // Object type padding (We know it's a building)
|
|
|
|
|
this.buildingUUID = reader.getInt();
|
|
|
|
|
reader.getInt();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configures and pre-caches values for this message
|
|
|
|
|
// so everything is already available during serialisation.
|
|
|
|
|
|
|
|
|
|
public void configure() {
|
|
|
|
|
|
|
|
|
|
Guild guild;
|
|
|
|
|
guild = this.treeOfLife.getGuild();
|
|
|
|
|
|
|
|
|
|
if (guild != null)
|
|
|
|
|
currentMineHour = guild.getMineTime();
|
|
|
|
|
|
|
|
|
|
late = MBServerStatics.MINE_LATE_WINDOW;
|
2026-10-01 22:35:35 -05:00
|
|
|
lateTime = Instant.now();
|
2026-09-27 12:35:14 -05:00
|
|
|
|
|
|
|
|
if (late == 0)
|
2026-10-01 22:35:35 -05:00
|
|
|
lateTime = lateTime.plus(Duration.ofDays(1));
|
2026-09-27 12:35:14 -05:00
|
|
|
|
2026-10-01 22:35:35 -05:00
|
|
|
lateTime = lateTime.with(ChronoField.HOUR_OF_DAY, late);
|
2026-09-27 12:35:14 -05:00
|
|
|
|
|
|
|
|
late = ((late > 23) ? (late - 24) : late);
|
2026-10-01 22:35:35 -05:00
|
|
|
secondsLeft = Duration.between(Instant.now(), lateTime);
|
2026-09-27 12:35:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
|
|
|
|
|
|
|
|
|
writer.putInt(MBServerStatics.MINE_EARLY_WINDOW); //15);
|
|
|
|
|
writer.putInt(late);
|
|
|
|
|
writer.putInt(currentMineHour);
|
|
|
|
|
|
|
|
|
|
writer.putInt(this.treeOfLife.getObjectType().ordinal());
|
|
|
|
|
writer.putInt(this.treeOfLife.getObjectUUID());
|
|
|
|
|
|
|
|
|
|
writer.putInt((int) secondsLeft.getSeconds());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getBuildingUUID() {
|
|
|
|
|
return buildingUUID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setBuildingUUID(int buildingUUID) {
|
|
|
|
|
this.buildingUUID = buildingUUID;
|
|
|
|
|
}
|
2026-10-01 22:35:35 -05:00
|
|
|
}
|