Files
prestonbane/src/engine/net/client/handlers/RecommendNationMsgHandler.java
T

88 lines
2.6 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
package engine.net.client.handlers;
import engine.exception.MsgSendException;
import engine.gameManager.ChatManager;
import engine.gameManager.SessionManager;
import engine.mbEnums.AllianceType;
2022-04-30 09:41:17 -04:00
import engine.net.Dispatch;
import engine.net.client.ClientConnection;
import engine.net.client.msg.AllianceChangeMsg;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.RecommendNationMsg;
import engine.objects.Guild;
import engine.objects.PlayerCharacter;
/*
* @Author:
* @Summary: Processes application protocol message which handles
* protecting and unprotecting city assets
*/
public class RecommendNationMsgHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public RecommendNationMsgHandler() {
super(RecommendNationMsg.class);
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
private static void RecommendNation(Guild fromGuild, Guild toGuild, RecommendNationMsg msg, ClientConnection origin) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Member variable declaration
Dispatch dispatch;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Member variable assignment
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (fromGuild == null)
return;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (toGuild == null)
return;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
AllianceType allianceType;
if (msg.getAlly() == 1)
allianceType = AllianceType.RecommendedAlly;
else
allianceType = AllianceType.RecommendedEnemy;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (!fromGuild.addGuildToAlliance(new AllianceChangeMsg(origin.getPlayerCharacter(), fromGuild.getObjectUUID(), toGuild.getObjectUUID(), (byte) 0, 0), allianceType, toGuild, origin.getPlayerCharacter()))
return;
String alliance = msg.getAlly() == 1 ? "ally" : "enemy";
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
ChatManager.chatGuildInfo(fromGuild, origin.getPlayerCharacter().getFirstName() + " has recommended " + toGuild.getName() + " as an " + alliance);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
2022-04-30 09:41:17 -04:00
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
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
// Member variable declaration
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
PlayerCharacter player;
RecommendNationMsg msg;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Member variable assignment
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
msg = (RecommendNationMsg) baseMsg;
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
2023-07-15 09:23:48 -04:00
RecommendNationMsgHandler.RecommendNation(player.getGuild(), Guild.getGuild(msg.getGuildID()), msg, origin);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// dispatch = Dispatch.borrow(player, baseMsg);
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
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
}