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-04-05 07:59:44 -04:00
|
|
|
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.InviteToSubMsg;
|
|
|
|
|
import engine.objects.Guild;
|
|
|
|
|
import engine.objects.GuildStatusController;
|
|
|
|
|
import engine.objects.PlayerCharacter;
|
|
|
|
|
|
|
|
|
|
public class InviteToSubHandler extends AbstractClientMsgHandler {
|
|
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
public InviteToSubHandler() {
|
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
|
|
|
private static void sendChat(PlayerCharacter source, String msg) {
|
|
|
|
|
ChatManager.chatGuildError(source, msg);
|
|
|
|
|
}
|
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
|
|
|
PlayerCharacter source;
|
|
|
|
|
PlayerCharacter target;
|
2026-05-10 21:38:38 -04:00
|
|
|
Guild nation;
|
|
|
|
|
Guild protectorate;
|
2023-07-15 09:23:48 -04:00
|
|
|
InviteToSubMsg msg = (InviteToSubMsg) baseMsg;
|
|
|
|
|
Dispatch dispatch;
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
source = SessionManager.getPlayerCharacter(origin);
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
if (source == null)
|
|
|
|
|
return true;
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
target = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, msg.getTargetUUID());
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
if (target == null) {
|
|
|
|
|
ErrorPopupMsg.sendErrorMsg(source, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
//Ignore invites to sub if ignoring player
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
if (target.isIgnoringPlayer(source))
|
|
|
|
|
return true;
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2026-05-10 21:38:38 -04:00
|
|
|
nation = source.getGuild();
|
|
|
|
|
protectorate = target.getGuild();
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
//source must be in guild
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2026-05-10 21:38:38 -04:00
|
|
|
if (nation == null) {
|
2023-07-15 09:23:48 -04:00
|
|
|
sendChat(source, "You must be in a guild to invite to sub.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2026-05-10 21:38:38 -04:00
|
|
|
if (nation.isEmptyGuild()) {
|
2023-07-15 09:23:48 -04:00
|
|
|
sendChat(source, "You must be in a guild to invite to sub.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
//source must be GL or IC
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
if (GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) {
|
|
|
|
|
sendChat(source, "Only guild leadership can invite to sub.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2026-05-10 21:38:38 -04:00
|
|
|
if (nation.getNation().isEmptyGuild())
|
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
|
|
|
//target must be in a guild
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2026-05-10 21:38:38 -04:00
|
|
|
if (protectorate == null)
|
2023-07-15 09:23:48 -04:00
|
|
|
return true;
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2026-05-10 21:38:38 -04:00
|
|
|
if (nation.equals(protectorate))
|
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
|
|
|
//target must be GL or IC
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
if (GuildStatusController.isInnerCouncil(target.getGuildStatus()) == false && GuildStatusController.isGuildLeader(target.getGuildStatus()) == false) {
|
|
|
|
|
sendChat(source, "Target player is not guild leadership.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2024-07-21 19:36:17 -05:00
|
|
|
//cannot be subbed into a nation if you already have your own sub guilds
|
2026-05-10 21:38:38 -04:00
|
|
|
if (protectorate.getSubGuildList() != null && protectorate.getSubGuildList().size() > 0) {
|
|
|
|
|
sendChat(source, "This Guild is already a nation!");
|
2024-07-21 19:36:17 -05:00
|
|
|
return true;
|
2026-05-10 21:38:38 -04:00
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2026-05-10 21:38:38 -04:00
|
|
|
if (!nation.canSubAGuild(protectorate)) {
|
2023-07-15 09:23:48 -04:00
|
|
|
sendChat(source, "This Guild can't be subbed.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-05-10 21:38:38 -04:00
|
|
|
|
|
|
|
|
if (nation.getSubGuildList().size() >= nation.getOwnedCity().getRank()) {
|
|
|
|
|
sendChat(source, "Your TOL cannot support another subguild!");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-04-28 11:58:55 -05:00
|
|
|
if (ConfigManager.MB_RULESET.getValue().equals("LORE")) {
|
2024-03-24 09:42:27 -04:00
|
|
|
if (source.guild.getGuildType().equals(target.guild.getGuildType()) == false) {
|
2024-02-15 19:46:41 -06:00
|
|
|
sendChat(source, "You Must Be The Same Charter To Form A Nation.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-15 09:23:48 -04:00
|
|
|
//all tests passed, let's send invite.
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
if (target.getClientConnection() != null) {
|
2026-05-10 21:38:38 -04:00
|
|
|
msg.setGuildTag(nation.getGuildTag());
|
|
|
|
|
msg.setGuildName(nation.getName());
|
|
|
|
|
msg.setGuildUUID(nation.getObjectUUID());
|
2023-07-15 09:23:48 -04:00
|
|
|
msg.setUnknown02(1);
|
2022-04-30 09:41:17 -04:00
|
|
|
|
2023-07-15 09:23:48 -04:00
|
|
|
dispatch = Dispatch.borrow(target, 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
|
|
|
} else {
|
|
|
|
|
sendChat(source, "Failed to send sub invite to target.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-04-30 09:41:17 -04:00
|
|
|
}
|