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

192 lines
7.4 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.*;
import engine.mbEnums;
import engine.mbEnums.GameObjectType;
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.BreakFealtyMsg;
import engine.net.client.msg.guild.SendGuildEntryMsg;
import engine.objects.*;
2023-06-07 13:37:43 -04:00
import engine.server.world.WorldServer;
2022-04-30 09:41:17 -04:00
import engine.session.Session;
import java.util.ArrayList;
public class BreakFealtyHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public BreakFealtyHandler() {
2024-05-12 11:55:12 -04:00
super();
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
2024-05-12 13:42:11 -04:00
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
BreakFealtyMsg bfm;
PlayerCharacter player;
2026-05-10 11:49:51 -04:00
Guild nation;
Guild protectorate;
2023-07-15 09:23:48 -04:00
Dispatch dispatch;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
bfm = (BreakFealtyMsg) baseMsg;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// get PlayerCharacter of person accepting invite
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
2026-05-10 11:49:51 -04:00
nation = (Guild) DbManager.getObject(GameObjectType.Guild, bfm.getGuildUUID());
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
if (nation == 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");
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
protectorate = player.getGuild();
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
if (protectorate == null) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!");
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
if (nation.isNPCGuild()) {
if (!GuildStatusController.isGuildLeader(player.getGuildStatus())) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!");
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
if (!DbManager.GuildQueries.UPDATE_PARENT(protectorate.getObjectUUID(), WorldServer.worldUUID)) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
switch (protectorate.guildState) {
2023-07-15 09:23:48 -04:00
case Sworn:
2026-05-10 11:49:51 -04:00
protectorate.setNation(Guild.getErrantNation());
GuildManager.updateAllGuildTags(protectorate);
GuildManager.updateAllGuildBinds(protectorate, null);
protectorate.guildState = mbEnums.GuildState.Errant;
2023-07-15 09:23:48 -04:00
break;
case Province:
case Protectorate:
2026-05-10 11:49:51 -04:00
protectorate.setNation(protectorate);
GuildManager.updateAllGuildTags(protectorate);
GuildManager.updateAllGuildBinds(protectorate, protectorate.getOwnedCity());
boolean isNation = false;
2026-05-10 11:49:51 -04:00
for (Guild subGuild : protectorate.getSubGuildList())
if (subGuild.getOwnedCity() != null)
isNation = true;
if (isNation)
2026-05-10 11:49:51 -04:00
protectorate.guildState = mbEnums.GuildState.Nation;
else
2026-05-10 11:49:51 -04:00
protectorate.guildState = mbEnums.GuildState.Sovereign;
2023-07-15 09:23:48 -04:00
break;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -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
//Update Map.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
final Session s = SessionManager.getSession(player);
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
2026-05-10 11:49:51 -04:00
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(protectorate.getObjectUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (PlayerCharacter member : guildMembers) {
2026-05-10 11:49:51 -04:00
ChatManager.chatGuildInfo(member, protectorate.getName() + " has broke fealty from " + nation.getName() + '!');
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
ArrayList<PlayerCharacter> breakFealtyMembers = SessionManager.getActivePCsInGuildID(nation.getObjectUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (PlayerCharacter member : breakFealtyMembers) {
2026-05-10 11:49:51 -04:00
ChatManager.chatGuildInfo(member, protectorate.getName() + " has broken fealty from " + nation.getName() + '!');
2023-07-15 09:23:48 -04:00
}
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
2026-05-10 11:49:51 -04:00
if (!nation.getSubGuildList().contains(protectorate)) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "Failure to break fealty!");
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
if (!GuildStatusController.isGuildLeader(player.getGuildStatus())) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!");
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
if (Bane.getBaneByAttackerGuild(protectorate) != null) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "You may break fealty with active bane!");
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
if (!DbManager.GuildQueries.UPDATE_PARENT(protectorate.getObjectUUID(), WorldServer.worldUUID)) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
switch (protectorate.guildState) {
2023-07-15 09:23:48 -04:00
case Sworn:
2026-05-10 11:49:51 -04:00
protectorate.setNation(null);
GuildManager.updateAllGuildTags(protectorate);
GuildManager.updateAllGuildBinds(protectorate, null);
2023-07-15 09:23:48 -04:00
break;
case Province:
2026-05-10 11:49:51 -04:00
protectorate.setNation(protectorate);
GuildManager.updateAllGuildTags(protectorate);
GuildManager.updateAllGuildBinds(protectorate, protectorate.getOwnedCity());
2023-07-15 09:23:48 -04:00
break;
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
nation.getSubGuildList().remove(protectorate);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -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
//Update Map.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
final Session s = SessionManager.getSession(player);
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
2026-05-10 11:49:51 -04:00
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(protectorate.getObjectUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (PlayerCharacter member : guildMembers) {
2026-05-10 11:49:51 -04:00
ChatManager.chatGuildInfo(member, protectorate.getName() + " has broke fealty from " + nation.getName() + '!');
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2026-05-10 11:49:51 -04:00
ArrayList<PlayerCharacter> breakFealtyMembers = SessionManager.getActivePCsInGuildID(nation.getObjectUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (PlayerCharacter member : breakFealtyMembers) {
2026-05-10 11:49:51 -04:00
ChatManager.chatGuildInfo(member, protectorate.getName() + " has broken fealty from " + nation.getName() + '!');
2023-07-15 09:23:48 -04:00
}
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
}