Files
prestonbane/src/engine/net/client/handlers/TaxResourcesMsgHandler.java
T

73 lines
1.7 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
package engine.net.client.handlers;
import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.TaxResourcesMsg;
import engine.objects.Building;
import engine.objects.City;
import engine.objects.PlayerCharacter;
/*
* @Author:
* @Summary: Processes application protocol message which handles
* protecting and unprotecting city assets
*/
public class TaxResourcesMsgHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public TaxResourcesMsgHandler() {
super(TaxResourcesMsg.class);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
private static boolean TaxWarehouse(TaxResourcesMsg msg, PlayerCharacter player) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Member variable declaration
Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (building == null) {
ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!");
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
City city = building.getCity();
if (city == null) {
ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city.");
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
city.TaxWarehouse(msg, player);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
return true;
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 boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Member variable declaration
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
PlayerCharacter player;
TaxResourcesMsg msg;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
player = origin.getPlayerCharacter();
if (player == null)
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
msg = (TaxResourcesMsg) baseMsg;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
TaxWarehouse(msg, player);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
}