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

103 lines
3.7 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.ChatManager;
import engine.gameManager.DbManager;
import engine.gameManager.DispatchManager;
2022-04-30 09:41:17 -04:00
import engine.gameManager.SessionManager;
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.AcceptSubInviteMsg;
import engine.objects.Guild;
import engine.objects.GuildStatusController;
import engine.objects.PlayerCharacter;
import java.util.ArrayList;
public class AcceptSubInviteHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public AcceptSubInviteHandler() {
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
AcceptSubInviteMsg msg = (AcceptSubInviteMsg) baseMsg;
PlayerCharacter sourcePlayer;
2026-05-10 09:32:07 -04:00
Guild swornGuild;
Guild nation;
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
// get PlayerCharacter of person sending sub invite
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
sourcePlayer = SessionManager.getPlayerCharacter(origin);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (sourcePlayer == null)
return true;
2022-04-30 09:41:17 -04:00
2026-05-10 09:32:07 -04:00
swornGuild = sourcePlayer.getGuild();
nation = (Guild) DbManager.getObject(GameObjectType.Guild, msg.guildUUID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//must be source guild to sub to
2022-04-30 09:41:17 -04:00
2026-05-10 09:32:07 -04:00
if (nation == null) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
return true;
}
2026-05-10 09:32:07 -04:00
if (swornGuild == null) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-10 09:32:07 -04:00
if (swornGuild.equals(nation))
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
if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()) == false) {
ErrorPopupMsg.sendErrorMsg(sourcePlayer, "Only a guild leader can accept fealty!");
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//source guild is limited to 7 subs
//TODO this should be based on TOL rank
2022-04-30 09:41:17 -04:00
2026-05-10 09:32:07 -04:00
if (!nation.canSubAGuild(swornGuild)) {
2023-07-15 09:23:48 -04:00
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
return true;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//all tests passed, let's Handle code
//Update Target Guild State.
2022-04-30 09:41:17 -04:00
2026-05-10 09:32:07 -04:00
swornGuild.setGuildState(GuildState.Petitioner);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//Add sub so GuildMaster can Swear in.
2022-04-30 09:41:17 -04:00
2026-05-10 09:32:07 -04:00
ArrayList<Guild> subGuildList = nation.getSubGuildList();
subGuildList.add(swornGuild);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//Let's send the message back.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
msg.setUnknown02(1);
2026-05-10 09:32:07 -04:00
msg.setResponse("Your guild is now a " + swornGuild.getGuildState().name() + '.');
2023-07-15 09:23:48 -04:00
dispatch = Dispatch.borrow(sourcePlayer, msg);
DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
2023-07-15 09:23:48 -04:00
2026-05-10 10:06:37 -04:00
ChatManager.chatGuildInfo(sourcePlayer, "Your guild is now a " + swornGuild.getGuildState().name() + '.');
2023-07-15 09:23:48 -04:00
return true;
}
2022-04-30 09:41:17 -04:00
}