Files
lakebane/src/engine/net/client/handlers/CityDataHandler.java
T

91 lines
3.2 KiB
Java
Raw Normal View History

2023-02-22 08:23:13 -05:00
package engine.net.client.handlers;
import engine.Enum;
import engine.Enum.DispatchChannel;
import engine.exception.MsgSendException;
import engine.gameManager.SessionManager;
import engine.gameManager.ZoneManager;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.*;
import engine.objects.City;
import engine.objects.Mine;
import engine.objects.PlayerCharacter;
import engine.server.world.WorldServer;
import engine.session.Session;
import java.time.ZoneId;
2023-02-22 08:23:13 -05:00
/*
* @Author:
* @Summary: Processes application protocol message which displays
2023-02-22 08:34:10 -05:00
* the map interface. (Zones, Cities, Realms, Hot-zones)
2023-02-22 08:23:13 -05:00
*/
public class CityDataHandler extends AbstractClientMsgHandler {
2023-02-22 08:34:10 -05:00
public CityDataHandler() {
super(KeepAliveServerClientMsg.class);
}
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
boolean updateMine = false;
boolean updateCity = false;
Session playerSession;
PlayerCharacter playerCharacter;
2023-02-22 08:38:18 -05:00
Dispatch dispatch;
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
playerCharacter = origin.getPlayerCharacter();
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
if (playerCharacter == null)
return true;
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
// Session is needed as param for worldObjectMsg.
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
playerSession = SessionManager.getSession(playerCharacter);
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
if (playerSession == null)
return true;
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
// No reason to serialize cities and mines everytime map is
// opened. Wait until something has changed.
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
if (playerCharacter.getTimeStamp("mineupdate") <= Mine.getLastChange()) {
playerCharacter.setTimeStamp("mineupdate", System.currentTimeMillis());
updateMine = true;
}
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate) {
playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis());
updateCity = true;
}
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
cityDataMsg cityDataMsg = new cityDataMsg(SessionManager.getSession(playerCharacter), false);
cityDataMsg.updateMines(updateMine);
cityDataMsg.updateCities(updateCity);
2023-02-22 08:23:13 -05:00
2023-02-22 08:38:18 -05:00
dispatch = Dispatch.borrow(playerCharacter, cityDataMsg);
2023-02-22 08:34:10 -05:00
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
2023-02-22 08:23:13 -05:00
2023-02-22 08:38:18 -05:00
// If the hotZone has changed then update the client's map accordingly.
2023-02-22 08:23:13 -05:00
if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.hotZoneLastUpdate.toEpochMilli() && ZoneManager.hotZone != null) {
HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID());
2023-02-22 08:34:10 -05:00
dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100);
}
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
// Serialize the realms for this map
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
WorldRealmMsg worldRealmMsg = new WorldRealmMsg();
dispatch = Dispatch.borrow(playerCharacter, worldRealmMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
return true;
}
2023-02-22 08:23:13 -05:00
}