Files
BattleBane/src/engine/net/client/handlers/SwearInGuildHandler.java
T

135 lines
5.2 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.gameManager.*;
2024-05-12 11:55:12 -04:00
import engine.mbEnums;
import engine.mbEnums.GameObjectType;
import engine.mbEnums.GuildState;
2022-04-30 09:41:17 -04:00
import engine.net.Dispatch;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.guild.SendGuildEntryMsg;
import engine.net.client.msg.guild.SwearInGuildMsg;
import engine.objects.City;
import engine.objects.Guild;
import engine.objects.GuildStatusController;
import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
public class SwearInGuildHandler extends AbstractClientMsgHandler {
public SwearInGuildHandler() {
2024-05-12 11:55:12 -04:00
super();
2022-04-30 09:41:17 -04:00
}
@Override
2024-05-12 13:42:11 -04:00
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {
2022-04-30 09:41:17 -04:00
PlayerCharacter player;
SwearInGuildMsg swearInMsg;
2026-05-10 09:32:07 -04:00
Guild protectorate;
2022-04-30 09:41:17 -04:00
Guild nation;
Dispatch dispatch;
swearInMsg = (SwearInGuildMsg) baseMsg;
player = SessionManager.getPlayerCharacter(origin);
if (player == null)
return true;
2026-05-10 09:32:07 -04:00
protectorate = (Guild) DbManager.getObject(GameObjectType.Guild, swearInMsg.getGuildUUID());
2022-04-30 09:41:17 -04:00
2026-05-10 09:32:07 -04:00
if (protectorate == null) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
2022-04-30 09:41:17 -04:00
return true;
}
nation = player.getGuild();
if (nation == null) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!");
2022-04-30 09:41:17 -04:00
return true;
}
try {
if (!nation.isNation()) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "Your guild is not a nation!");
2022-04-30 09:41:17 -04:00
return true;
}
2026-05-10 11:03:07 -04:00
2026-05-10 09:32:07 -04:00
if (!nation.getSubGuildList().contains(protectorate)) {
2026-05-10 18:45:37 -04:00
ErrorPopupMsg.sendErrorMsg(player, "Guild is not a petitioner!");
2022-04-30 09:41:17 -04:00
return true;
}
2026-05-10 18:45:37 -04:00
if (protectorate.guildState.equals(GuildState.Petitioner) == false) {
ErrorPopupMsg.sendErrorMsg(player, "Guild is not a petitioner!");
2026-05-10 11:03:07 -04:00
return true;
2026-05-10 18:45:37 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) {
2022-04-30 09:41:17 -04:00
ErrorPopupMsg.sendErrorMsg(player, "Your do not have such authority!");
return true;
}
2026-05-10 09:32:07 -04:00
if (!DbManager.GuildQueries.UPDATE_PARENT(protectorate.getObjectUUID(), nation.getObjectUUID())) {
2022-04-30 09:41:17 -04:00
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
return true;
}
2026-05-10 18:45:37 -04:00
// update Guild state.
// R8 is a province
2026-05-10 09:32:07 -04:00
if (protectorate.getNation().isEmptyGuild())
2026-05-10 10:36:27 -04:00
protectorate.guildState = GuildState.Sworn;
2026-05-10 09:32:07 -04:00
else
2026-05-10 18:45:37 -04:00
protectorate.guildState = (protectorate.getOwnedCity().getTOL().getRank() == 8)
? GuildState.Province
: GuildState.Protectorate;
2026-05-10 09:32:07 -04:00
protectorate.setNation(nation);
GuildManager.updateAllGuildTags(protectorate);
2026-05-11 03:59:22 -04:00
// Upgrade to a nation if new sub is a landed guild
2026-05-10 18:36:43 -04:00
if (nation.guildState == GuildState.Sovereign)
2026-05-11 03:58:31 -04:00
if (protectorate.guildState.equals(GuildState.Protectorate) ||
protectorate.guildState.equals(GuildState.Province))
2026-05-10 10:36:27 -04:00
nation.guildState = GuildState.Nation;
2022-04-30 09:41:17 -04:00
SendGuildEntryMsg msg = new SendGuildEntryMsg(player);
dispatch = Dispatch.borrow(player, msg);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
City.lastCityUpdate = System.currentTimeMillis();
2022-04-30 09:41:17 -04:00
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(nation.getObjectUUID());
2026-05-10 09:51:30 -04:00
for (PlayerCharacter member : guildMembers)
2026-05-10 10:12:13 -04:00
ChatManager.chatGuildInfo(member, protectorate.getName() + " has sworn fealty to you.");
2022-04-30 09:41:17 -04:00
2026-05-10 09:32:07 -04:00
ArrayList<PlayerCharacter> swornMembers = SessionManager.getActivePCsInGuildID(protectorate.getObjectUUID());
2022-04-30 09:41:17 -04:00
2026-05-10 09:51:30 -04:00
for (PlayerCharacter member : swornMembers)
ChatManager.chatGuildInfo(member, "Your Guild has sworn fealty to " + nation.getName() + '.');
2022-04-30 09:41:17 -04:00
} catch (Exception e) {
2023-07-15 09:23:48 -04:00
Logger.error(e.getMessage());
2022-04-30 09:41:17 -04:00
return true;
}
return true;
}
}