Files
Server/src/engine/net/client/handlers/ArcSiegeSpireMsgHandler.java
T

121 lines
3.6 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
package engine.net.client.handlers;
import engine.Enum.GameObjectType;
import engine.exception.MsgSendException;
import engine.gameManager.DbManager;
import engine.gameManager.SessionManager;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ArcSiegeSpireMsg;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ErrorPopupMsg;
import engine.objects.Building;
import engine.objects.GuildStatusController;
import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
/*
* @Author:
* @Summary: Processes application protocol message which requests that
* siege spires be toggled on or off.
*/
public class ArcSiegeSpireMsgHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public ArcSiegeSpireMsgHandler() {
super(ArcSiegeSpireMsg.class);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
PlayerCharacter player;
Building spire;
ArcSiegeSpireMsg msg;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
msg = (ArcSiegeSpireMsg) baseMsg;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
player = SessionManager.getPlayerCharacter(origin);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (player == null)
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
spire = (Building) DbManager.getObject(GameObjectType.Building, msg.getBuildingUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (spire == null)
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (spire.getCity() == null)
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
spire.getCity().transactionLock.writeLock().lock();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
try {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//can't activate a spire that's not rank 1.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (spire.getRank() < 1)
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// can't activate a spire without a city
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (spire.getCity() == null)
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Must have management authority for the spire
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ((player.getGuild().equals(spire.getGuild()) == false)
|| (GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false))
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Handle case where spire is sabotaged
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (spire.getTimeStamp("DISABLED") > System.currentTimeMillis()) {
ErrorPopupMsg.sendErrorPopup(player, 174); //This siege spire cannot be toggled yet.
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Handle case where spire's toggle delay hasn't yet passed
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (spire.getTimeStamp("TOGGLEDELAY") > System.currentTimeMillis()) {
ErrorPopupMsg.sendErrorPopup(player, 174); //This siege spire cannot be toggled yet.
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// This protocol message is a toggle. If it's currently active then disable
// the spire.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (spire.isSpireIsActive()) {
spire.disableSpire(false);
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Must be enough gold on the spire to turn it on
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (!spire.hasFunds(5000)) {
ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox
return true;
}
if (spire.getStrongboxValue() < 5000) {
ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox
return true;
}
spire.transferGold(-5000, false);
spire.enableSpire();
// Spire is now enabled. Reset the toggle delay
spire.setTimeStamp("TOGGLEDELAY", System.currentTimeMillis() + (long) 10 * 60 * 1000);
} catch (Exception e) {
Logger.error(e);
} finally {
spire.getCity().transactionLock.writeLock().unlock();
}
return true;
}
2022-04-30 09:41:17 -04:00
}