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

69 lines
2.1 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.GuildManager;
import engine.mbEnums;
import engine.mbEnums.DispatchChannel;
2022-04-30 09:41:17 -04:00
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.CityChoiceMsg;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.TeleportRepledgeListMsg;
import engine.objects.City;
import engine.objects.Guild;
import engine.objects.PlayerCharacter;
/*
* @Author:
* @Summary: Processes application protocol message which keeps
* client's tcp connection open.
*/
public class CityChoiceMsgHandler extends AbstractClientMsgHandler {
2023-07-15 09:23:48 -04:00
public CityChoiceMsgHandler() {
super(CityChoiceMsg.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
PlayerCharacter player = origin.getPlayerCharacter();
Dispatch dispatch;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
CityChoiceMsg msg = (CityChoiceMsg) baseMsg;
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
switch (msg.getMsgType()) {
case 5:
TeleportRepledgeListMsg trlm = new TeleportRepledgeListMsg(player, false);
trlm.configure();
dispatch = Dispatch.borrow(player, trlm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
break;
case 3:
City city = City.getCity(msg.getCityID());
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (city == null)
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Guild cityGuild = city.getGuild();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (cityGuild == null)
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (player.getLevel() < cityGuild.getRepledgeMin() || player.getLevel() > cityGuild.getRepledgeMax())
return true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
//if repledge, reguild the player but set his building now.
2022-04-30 09:41:17 -04:00
GuildManager.joinGuild(player, cityGuild, city.getObjectUUID(), mbEnums.GuildHistoryType.JOIN);
2023-07-15 09:23:48 -04:00
break;
}
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
}