2022-04-30 09:41:17 -04:00
|
|
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
|
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
|
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
|
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
|
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
|
|
|
// Magicbane Emulator Project © 2013 - 2022
|
|
|
|
|
// www.magicbane.com
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package engine.net.client.handlers;
|
|
|
|
|
|
2024-05-12 13:14:42 -04:00
|
|
|
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 09:32:07 -04:00
|
|
|
if (!nation.getSubGuildList().contains(protectorate)) {
|
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 (!Guild.canSwearIn(protectorate)) {
|
|
|
|
|
ErrorPopupMsg.sendErrorMsg(player, protectorate.getGuildState().name() + "cannot be sworn in");
|
2022-04-30 09:41:17 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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 09:32:07 -04:00
|
|
|
//shouldn't get here.
|
|
|
|
|
if (protectorate.getGuildState().equals(GuildState.Petitioner))
|
|
|
|
|
GuildManager.updateAllGuildBinds(protectorate, nation.getOwnedCity());
|
2022-04-30 09:41:17 -04:00
|
|
|
|
|
|
|
|
//update Guild state.
|
2026-05-10 09:32:07 -04:00
|
|
|
|
|
|
|
|
if (protectorate.getNation().isEmptyGuild())
|
|
|
|
|
protectorate.setGuildState(GuildState.Sworn);
|
|
|
|
|
else
|
|
|
|
|
protectorate.setGuildState(GuildState.Protectorate);
|
|
|
|
|
|
|
|
|
|
protectorate.setNation(nation);
|
|
|
|
|
GuildManager.updateAllGuildTags(protectorate);
|
|
|
|
|
|
2026-05-10 10:18:15 -04:00
|
|
|
if (nation.getGuildState() == GuildState.Sovereign &&
|
|
|
|
|
protectorate.getGuildState().equals(GuildState.Protectorate))
|
2026-05-10 09:32:07 -04:00
|
|
|
nation.setGuildState(GuildState.Nation);
|
2022-04-30 09:41:17 -04:00
|
|
|
|
|
|
|
|
SendGuildEntryMsg msg = new SendGuildEntryMsg(player);
|
|
|
|
|
dispatch = Dispatch.borrow(player, msg);
|
2024-05-12 13:14:42 -04:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|