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

114 lines
4.1 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.Enum;
import engine.Enum.GameObjectType;
import engine.Enum.GuildState;
import engine.exception.MsgSendException;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.gameManager.SessionManager;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
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() {
super(AcceptSubInviteMsg.class);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
AcceptSubInviteMsg msg = (AcceptSubInviteMsg) baseMsg;
2026-05-07 15:20:24 -04:00
PlayerCharacter playerCharacter;
Guild protectorate;
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
2026-05-07 15:20:24 -04:00
playerCharacter = SessionManager.getPlayerCharacter(origin);
2022-04-30 09:41:17 -04:00
2026-05-07 15:20:24 -04:00
if (playerCharacter == null)
2023-07-15 09:23:48 -04:00
return true;
2022-04-30 09:41:17 -04:00
2026-05-07 15:20:24 -04:00
protectorate = playerCharacter.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-07 15:20:24 -04:00
if (nation == null) {
ErrorPopupMsg.sendErrorPopup(playerCharacter, 45); // Failure to swear guild
2023-07-15 09:23:48 -04:00
return true;
}
2026-05-07 15:20:24 -04:00
if (protectorate == null) {
ErrorPopupMsg.sendErrorPopup(playerCharacter, 45); // Failure to swear guild
2023-07-15 09:23:48 -04:00
return true;
}
2022-04-30 09:41:17 -04:00
2026-05-07 15:20:24 -04:00
if (protectorate.equals(nation))
2023-07-15 09:23:48 -04:00
return true;
2022-04-30 09:41:17 -04:00
2026-05-07 15:20:24 -04:00
if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus()) == false) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "Only a guild leader can accept fealty!");
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
//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-07 15:20:24 -04:00
if (!nation.canSubAGuild(protectorate)) {
ErrorPopupMsg.sendErrorPopup(playerCharacter, 45); // Failure to swear guild
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
//all tests passed, let's Handle code
2026-05-07 15:20:24 -04:00
// Update database
if (!DbManager.GuildQueries.UPDATE_PARENT(protectorate.getObjectUUID(), nation.getObjectUUID())) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "A Serious error has occured. Please post details for to ensure transaction integrity");
return true;
}
2023-07-15 09:23:48 -04:00
//Update Target Guild State.
2022-04-30 09:41:17 -04:00
2026-05-07 15:20:24 -04:00
protectorate.upgradeGuildState(false);
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-07 15:20:24 -04:00
ArrayList<Guild> subs = nation.getSubGuildList();
subs.add(protectorate);
2022-04-30 09:41:17 -04:00
2026-05-07 15:20:24 -04:00
nation.setGuildState(GuildState.Nation);
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-07 15:20:24 -04:00
msg.setResponse("Your guild is now a " + protectorate.getGuildState().name() + '.');
dispatch = Dispatch.borrow(playerCharacter, msg);
2023-07-15 09:23:48 -04:00
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
2026-05-07 15:20:24 -04:00
ChatManager.chatSystemInfo(playerCharacter, "Your guild is now a " + protectorate.getGuildState().name() + '.');
2023-07-15 09:23:48 -04:00
return true;
}
2022-04-30 09:41:17 -04:00
}