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

147 lines
4.5 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
package engine.net.client.handlers;
import engine.Enum;
import engine.InterestManagement.RealmMap;
import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.TaxCityMsg;
import engine.net.client.msg.ViewResourcesMessage;
import engine.objects.*;
/*
* @Author:
* @Summary: Processes application protocol message which handles
* protecting and unprotecting city assets
*/
public class TaxCityMsgHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public TaxCityMsgHandler() {
super(TaxCityMsg.class);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
private static boolean ViewTaxes(TaxCityMsg 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.getGuildID());
Guild playerGuild = player.getGuild();
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
if (city.getWarehouse() == null) {
ErrorPopupMsg.sendErrorMsg(player, "This city does not have a warehouse!");
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (playerGuild == null || playerGuild.isEmptyGuild()) {
ErrorPopupMsg.sendErrorMsg(player, "You must belong to a guild to do that!");
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (playerGuild.getOwnedCity() == null) {
ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a city!");
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (playerGuild.getOwnedCity().getWarehouse() == null) {
ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a warehouse!");
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (playerGuild.getOwnedCity().getTOL() == null) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot find Tree of Life for your city!");
return true;
}
2022-04-30 09:41:17 -04:00
// if (playerGuild.getOwnedCity().getTOL().getRank() != 8){
// ErrorPopupMsg.sendErrorMsg(player, "Your City needs to Own a realm!");
// return true;
// }
2023-07-15 09:23:48 -04:00
if (playerGuild.getOwnedCity().getRealm() == null) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!");
return true;
}
Realm targetRealm = RealmMap.getRealmForCity(city);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (targetRealm == null) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for city you are attempting to tax!");
return true;
}
2022-04-30 09:41:17 -04:00
// if (targetRealm.getRulingCity() == null){
// ErrorPopupMsg.sendErrorMsg(player, "Realm Does not have a ruling city!");
// return true;
// }
// if (targetRealm.getRulingCity().getObjectUUID() != playerGuild.getOwnedCity().getObjectUUID()){
// ErrorPopupMsg.sendErrorMsg(player, "Your guild does not rule this realm!");
// return true;
// }
// if (playerGuild.getOwnedCity().getObjectUUID() == city.getObjectUUID()){
// ErrorPopupMsg.sendErrorMsg(player, "You cannot tax your own city!");
// return true;
// }
2023-07-15 09:23:48 -04:00
if (!GuildStatusController.isTaxCollector(player.getGuildStatus())) {
ErrorPopupMsg.sendErrorMsg(player, "You Must be a tax Collector!");
return true;
}
2022-04-30 09:41:17 -04:00
// if (!city.isAfterTaxPeriod(DateTime.now(), player))
// return true;
2023-07-15 09:23:48 -04:00
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
vrm.setGuild(building.getGuild());
vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().getBuildingUID()));
vrm.configure();
Dispatch dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
dispatch = Dispatch.borrow(player, vrm);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return true;
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
// Member variable declaration
PlayerCharacter player;
TaxCityMsg msg;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
player = origin.getPlayerCharacter();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
msg = (TaxCityMsg) baseMsg;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ViewTaxes(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
}