diff --git a/src/engine/gameManager/MovementManager.java b/src/engine/gameManager/MovementManager.java index 061335da..c8c2f657 100644 --- a/src/engine/gameManager/MovementManager.java +++ b/src/engine/gameManager/MovementManager.java @@ -14,12 +14,16 @@ import engine.Enum.ModType; import engine.Enum.SourceType; import engine.InterestManagement.InterestManager; import engine.exception.MsgSendException; +import engine.job.JobContainer; +import engine.job.JobScheduler; +import engine.jobs.StuckJob; import engine.math.Bounds; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.MoveToPointMsg; +import engine.net.client.msg.PromptRecallMsg; import engine.net.client.msg.TeleportToPointMsg; import engine.net.client.msg.UpdateStateMsg; import engine.objects.*; @@ -27,6 +31,7 @@ import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import static engine.math.FastMath.sqr; @@ -483,4 +488,77 @@ public enum MovementManager { private static void syncLoc(AbstractCharacter ac, Vector3fImmutable clientLoc, boolean useClientLoc) { ac.teleport(ac.getLoc()); } + + public static void HandlePromptRecall(PromptRecallMsg msg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = SessionManager.getPlayerCharacter(origin); + boolean recallAccepted; + + if (player == null) + return; + + boolean confirmed = msg.getConfirmed(); + + if (confirmed == true) { + long timeElapsed = System.currentTimeMillis() - player.getTimeStamp("PromptRecall"); + //send fail message + recallAccepted = timeElapsed < 15000; + } else + recallAccepted = false; + + if (recallAccepted == true) { + //handle recall + long type = player.getTimeStamp("LastRecallType"); + + if (type == 1) { //recall to bind + player.teleport(player.getBindLoc()); + player.setSafeMode(); + } else { //recall to rg + float dist = 9999999999f; + Building rg = null; + Vector3fImmutable rgLoc; + + for (Runegate runegate : Runegate._runegates.values()) { + + rgLoc = runegate.gateBuilding.getLoc(); + + float distanceSquaredToRunegate = player.getLoc().distanceSquared2D(rgLoc); + + if (distanceSquaredToRunegate < sqr(dist)) + rg = runegate.gateBuilding; + + } + + //nearest runegate found. teleport characterTarget + + if (rg != null) { + player.teleport(rg.getLoc()); + player.setSafeMode(); + } + } + } + } + + public static void stuck(ClientConnection origin) { + + PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); + + if (sourcePlayer == null) + return; + + if (sourcePlayer.getTimers().containsKey("Stuck")) + return; + + StuckJob sj = new StuckJob(sourcePlayer); + JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert + ConcurrentHashMap timers = sourcePlayer.getTimers(); + + if (timers != null) { + if (timers.containsKey("Stuck")) { + timers.get("Stuck").cancelJob(); + timers.remove("Stuck"); + } + timers.put("Stuck", jc); + } + } } diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 3df19668..57e1e0e1 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -14,11 +14,8 @@ import engine.Enum.GameObjectType; import engine.InterestManagement.WorldGrid; import engine.exception.MsgSendException; import engine.gameManager.*; -import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.RefreshGroupJob; -import engine.jobs.StuckJob; -import engine.math.Vector3fImmutable; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.NetMsgHandler; @@ -34,7 +31,6 @@ import engine.util.StringUtils; import org.pmw.tinylog.Logger; import java.sql.SQLException; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; import static engine.math.FastMath.sqr; @@ -155,38 +151,6 @@ public class ClientMessagePump implements NetMsgHandler { DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, true); } - //call this if the transfer fails server side to kick the item back to inventory from vault - public static void forceTransferFromInventoryToVault(ItemFromVaultMsg msg, ClientConnection origin, String reason) { - - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; - - if (player == null) - return; - - ItemToVaultMsg back = new ItemToVaultMsg(msg); - dispatch = Dispatch.borrow(player, back); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - ChatManager.chatInfoError(player, "Can't transfer to inventory: " + reason); - } - - //call this if the transfer fails server side to kick the item back to vault from inventory - public static void forceTransferFromVaultToInventory(ItemToVaultMsg msg, ClientConnection origin, String reason) { - - PlayerCharacter player = origin.getPlayerCharacter(); - Dispatch dispatch; - - if (player == null) - return; - - ItemFromVaultMsg back = new ItemFromVaultMsg(msg); - dispatch = Dispatch.borrow(player, back); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - ChatManager.chatInfoError(player, "Can't transfer to vault: " + reason); - } - private static void DeleteItem(DeleteItemMsg msg, ClientConnection origin) { CharacterItemManager itemManager = origin.getPlayerCharacter().charItemManager; @@ -727,29 +691,6 @@ public class ClientMessagePump implements NetMsgHandler { //returns true if looted item is goldItem and is split. Otherwise returns false - private static void stuck(ClientConnection origin) { - - PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); - - if (sourcePlayer == null) - return; - - if (sourcePlayer.getTimers().containsKey("Stuck")) - return; - - StuckJob sj = new StuckJob(sourcePlayer); - JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert - ConcurrentHashMap timers = sourcePlayer.getTimers(); - - if (timers != null) { - if (timers.containsKey("Stuck")) { - timers.get("Stuck").cancelJob(); - timers.remove("Stuck"); - } - timers.put("Stuck", jc); - } - } - private static void GuildTreeStatusMsg(GuildTreeStatusMsg msg, ClientConnection origin) throws SQLException { PlayerCharacter player = SessionManager.getPlayerCharacter(origin); @@ -861,56 +802,6 @@ public class ClientMessagePump implements NetMsgHandler { //Handle RepairObject Window and RepairObject Requests - protected static void HandlePromptRecall(PromptRecallMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - boolean recallAccepted; - - if (player == null) - return; - - boolean confirmed = msg.getConfirmed(); - - if (confirmed == true) { - long timeElapsed = System.currentTimeMillis() - player.getTimeStamp("PromptRecall"); - //send fail message - recallAccepted = timeElapsed < 15000; - } else - recallAccepted = false; - - if (recallAccepted == true) { - //handle recall - long type = player.getTimeStamp("LastRecallType"); - - if (type == 1) { //recall to bind - player.teleport(player.getBindLoc()); - player.setSafeMode(); - } else { //recall to rg - float dist = 9999999999f; - Building rg = null; - Vector3fImmutable rgLoc; - - for (Runegate runegate : Runegate._runegates.values()) { - - rgLoc = runegate.gateBuilding.getLoc(); - - float distanceSquaredToRunegate = player.getLoc().distanceSquared2D(rgLoc); - - if (distanceSquaredToRunegate < sqr(dist)) - rg = runegate.gateBuilding; - - } - - //nearest runegate found. teleport characterTarget - - if (rg != null) { - player.teleport(rg.getLoc()); - player.setSafeMode(); - } - } - } - } - @Override public boolean handleClientMsg(ClientNetMsg msg) { @@ -1093,7 +984,7 @@ public class ClientMessagePump implements NetMsgHandler { PowersManager.trackWindow((TrackWindowMsg) msg, origin); break; case STUCK: - stuck(origin); + MovementManager.stuck(origin); break; case RANDOM: ClientMessagePump.randomRoll((RandomMsg) msg, origin); @@ -1108,7 +999,7 @@ public class ClientMessagePump implements NetMsgHandler { ManageNPCCmd((ManageNPCMsg) msg, origin); break; case ARCPROMPTRECALL: - HandlePromptRecall((PromptRecallMsg) msg, origin); + MovementManager.HandlePromptRecall((PromptRecallMsg) msg, origin); break; case CHANNELMUTE: break; diff --git a/src/engine/net/client/handlers/ItemFromVaultMsgHandler.java b/src/engine/net/client/handlers/ItemFromVaultMsgHandler.java index 9d1a7d0d..ccbfa3a2 100644 --- a/src/engine/net/client/handlers/ItemFromVaultMsgHandler.java +++ b/src/engine/net/client/handlers/ItemFromVaultMsgHandler.java @@ -8,10 +8,15 @@ package engine.net.client.handlers; +import engine.Enum; import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ItemFromVaultMsg; +import engine.net.client.msg.ItemToVaultMsg; import engine.objects.PlayerCharacter; public class ItemFromVaultMsgHandler extends AbstractClientMsgHandler { @@ -20,6 +25,22 @@ public class ItemFromVaultMsgHandler extends AbstractClientMsgHandler { super(ItemFromVaultMsg.class); } + //call this if the transfer fails server side to kick the item back to inventory from vault + public static void forceTransferFromInventoryToVault(ItemFromVaultMsg msg, ClientConnection origin, String reason) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + ItemToVaultMsg back = new ItemToVaultMsg(msg); + dispatch = Dispatch.borrow(player, back); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + ChatManager.chatInfoError(player, "Can't transfer to inventory: " + reason); + } + @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { diff --git a/src/engine/net/client/handlers/ItemToVaultMsgHandler.java b/src/engine/net/client/handlers/ItemToVaultMsgHandler.java index e6686541..e7e70d1d 100644 --- a/src/engine/net/client/handlers/ItemToVaultMsgHandler.java +++ b/src/engine/net/client/handlers/ItemToVaultMsgHandler.java @@ -8,9 +8,14 @@ package engine.net.client.handlers; +import engine.Enum; import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.ItemFromVaultMsg; import engine.net.client.msg.ItemToVaultMsg; import engine.objects.PlayerCharacter; @@ -20,6 +25,22 @@ public class ItemToVaultMsgHandler extends AbstractClientMsgHandler { super(ItemToVaultMsg.class); } + //call this if the transfer fails server side to kick the item back to vault from inventory + public static void forceTransferFromVaultToInventory(ItemToVaultMsg msg, ClientConnection origin, String reason) { + + PlayerCharacter player = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (player == null) + return; + + ItemFromVaultMsg back = new ItemFromVaultMsg(msg); + dispatch = Dispatch.borrow(player, back); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + ChatManager.chatInfoError(player, "Can't transfer to vault: " + reason); + } + @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { diff --git a/src/engine/objects/Account.java b/src/engine/objects/Account.java index 5695ed8f..7e676fae 100644 --- a/src/engine/objects/Account.java +++ b/src/engine/objects/Account.java @@ -19,7 +19,8 @@ import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; -import engine.net.client.ClientMessagePump; +import engine.net.client.handlers.ItemFromVaultMsgHandler; +import engine.net.client.handlers.ItemToVaultMsgHandler; import engine.net.client.msg.*; import engine.util.ByteUtils; import org.pmw.tinylog.Logger; @@ -202,7 +203,7 @@ public class Account extends AbstractGameObject { return; if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "vault")) { - ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "You are out of range of the vault."); + ItemToVaultMsgHandler.forceTransferFromVaultToInventory(msg, origin, "You are out of range of the vault."); return; } @@ -210,7 +211,7 @@ public class Account extends AbstractGameObject { Item item = Item.getFromCache(uuid); if (item == null) { - ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "Can't find the item."); + ItemToVaultMsgHandler.forceTransferFromVaultToInventory(msg, origin, "Can't find the item."); return; } @@ -220,7 +221,7 @@ public class Account extends AbstractGameObject { if (item.containerType == Enum.ItemContainerType.INVENTORY && player.charItemManager.isVaultOpen()) { if (!player.charItemManager.hasRoomVault(item.template.item_wt)) { - ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "There is no room in your vault."); + ItemToVaultMsgHandler.forceTransferFromVaultToInventory(msg, origin, "There is no room in your vault."); return; } @@ -229,7 +230,7 @@ public class Account extends AbstractGameObject { dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); } else - ClientMessagePump.forceTransferFromVaultToInventory(msg, origin, "Failed to transfer item."); + ItemToVaultMsgHandler.forceTransferFromVaultToInventory(msg, origin, "Failed to transfer item."); } } @@ -242,21 +243,21 @@ public class Account extends AbstractGameObject { return; if (!NPCManager.NPCVaultBankRangeCheck(player, origin, "vault")) { - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "You are out of range of the vault."); + ItemFromVaultMsgHandler.forceTransferFromInventoryToVault(msg, origin, "You are out of range of the vault."); return; } CharacterItemManager itemManager = player.charItemManager; if (itemManager == null) { - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Can't find your item manager."); + ItemFromVaultMsgHandler.forceTransferFromInventoryToVault(msg, origin, "Can't find your item manager."); return; } Item item = Item.getFromCache(msg.getUUID()); if (item == null) { - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Can't find the item."); + ItemFromVaultMsgHandler.forceTransferFromInventoryToVault(msg, origin, "Can't find the item."); return; } @@ -266,7 +267,7 @@ public class Account extends AbstractGameObject { if (item.containerType == Enum.ItemContainerType.VAULT && itemManager.isVaultOpen()) { if (!itemManager.hasRoomInventory(item.template.item_wt)) { - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "There is no room in your inventory."); + ItemFromVaultMsgHandler.forceTransferFromInventoryToVault(msg, origin, "There is no room in your inventory."); return; } if (itemManager.moveItemToInventory(item)) { @@ -276,7 +277,7 @@ public class Account extends AbstractGameObject { DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); } else - ClientMessagePump.forceTransferFromInventoryToVault(msg, origin, "Failed to transfer item."); + ItemFromVaultMsgHandler.forceTransferFromInventoryToVault(msg, origin, "Failed to transfer item."); } }