From 1825035739ead38dac04033cdf484892814a0a2b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:04:46 -0400 Subject: [PATCH] Handler created for RefineMsg --- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/RefineMsgHandler.java | 157 ++++++++++++++++++ src/engine/net/client/msg/RefineMsg.java | 133 +-------------- 4 files changed, 164 insertions(+), 131 deletions(-) create mode 100644 src/engine/net/client/handlers/RefineMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 7fca0893..c814fe52 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -129,9 +129,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCUNTRAINLIST: WorldServer.refinerScreen((RefinerScreenMsg) msg, origin); break; - case ARCUNTRAINABILITY: - RefineMsg.refine((RefineMsg) msg, origin); - break; case POWERTARGNAME: PowersManager.summon((SendSummonsRequestMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 4109a450..2aa3324d 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -47,7 +47,7 @@ public enum Protocol { ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, null), //Request/Send Track window ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow - ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, null), //Refine + ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, RefineMsgHandler.class), //Refine ARCUNTRAINLIST(0x38879E90, RefinerScreenMsg.class, null), //Refiner screen ARCVIEWASSETTRANSACTIONS(0xBFA476E4, ArcViewAssetTransactionsMsg.class, ArcViewAssetTransactionsMsgHandler.class), ASSETSUPPORT(0xc481f89D, AssetSupportMsg.class, AssetSupportMsgHandler.class), diff --git a/src/engine/net/client/handlers/RefineMsgHandler.java b/src/engine/net/client/handlers/RefineMsgHandler.java new file mode 100644 index 00000000..b53e90fe --- /dev/null +++ b/src/engine/net/client/handlers/RefineMsgHandler.java @@ -0,0 +1,157 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.RefineMsg; +import engine.net.client.msg.RefinerScreenMsg; +import engine.objects.*; +import engine.server.MBServerStatics; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; + +public class RefineMsgHandler extends AbstractClientMsgHandler { + + public RefineMsgHandler() { + super(RefineMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + RefineMsg msg; + + // Member variable assignment + + msg = (RefineMsg) baseMsg; + + NPC npc = NPC.getFromCache(msg.npcID); + + if (npc == null) + return true; + + int type = msg.type; + int token = msg.token; + boolean worked = false; + boolean skillPower = true; + + if (type == 0) { //refine skill + worked = refineSkill(origin, playerCharacter, token, msg); + } else if (type == 1) { //refine power + worked = refinePower(origin, playerCharacter, token, msg); + } else if (type == 2) { //refine stat + worked = refineStat(origin, playerCharacter, token, msg); + skillPower = false; + } + + if (worked) { + + //update player + playerCharacter.applyBonuses(); + playerCharacter.charItemManager.RemoveEquipmentFromLackOfSkill(playerCharacter, true); + + //echo refine message back + + Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + + // if (type == 0 && token == 1488335491){ + // dispatch = Dispatch.borrow(pc, msg); + // DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + // } + + //resend refine screen + + RefinerScreenMsg refinerScreenMsg = new RefinerScreenMsg(skillPower, npc.getSellPercent(playerCharacter)); //TODO set npc cost + dispatch = Dispatch.borrow(playerCharacter, refinerScreenMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + playerCharacter.recalculate(); + } + return true; + } + + public static boolean refineSkill(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + CharacterSkill skill = null; + ConcurrentHashMap skills = pc.getSkills(); + for (CharacterSkill sk : skills.values()) { + if (sk == null) + continue; + SkillsBase sb = sk.getSkillsBase(); + if (sb == null) + continue; + if (sb.getToken() == token) + skill = sk; + } + //check if player has skill to refine + if (skill == null) + return false; + //check there's a train to refine + if (skill.getNumTrains() < 1) + return false; + + //TODO verify if any skills have this as prereq + + //TODO verify if any powers have this as a prereq + //get all players powers + for (CharacterPower power : pc.getPowers().values()) { + ArrayList reqs = PowerReq.getPowerReqsForRune(power.getPowerID()); + for (PowerReq req : reqs) { + ConcurrentHashMap playerSkills = pc.getSkills(); + CharacterSkill playerSkill = playerSkills.get(token); + int currentSkillLevel = playerSkill.getTotalSkillPercet(); + if (token == req.getToken() && req.getLevel() == currentSkillLevel) { + return false; + } + } + } + + //refine skill + return skill.refine(pc); + } + + public static boolean refinePower(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + CharacterPower power = null; + ConcurrentHashMap powers = pc.getPowers(); + if (!powers.containsKey(token)) + return false; + power = powers.get(token); + if (power == null) + return false; + if (power.getTrains() < 1) + return false; + + //TODO verify if any powers have this as a prereq + + return power.refine(pc); + } + + public static boolean refineStat(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + if (token == MBServerStatics.STAT_STR_ID) + return pc.refineStr(); + if (token == MBServerStatics.STAT_DEX_ID) + return pc.refineDex(); + if (token == MBServerStatics.STAT_CON_ID) + return pc.refineCon(); + if (token == MBServerStatics.STAT_INT_ID) + return pc.refineInt(msg); + if (token == MBServerStatics.STAT_SPI_ID) + return pc.refineSpi(); + return false; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/msg/RefineMsg.java b/src/engine/net/client/msg/RefineMsg.java index bf1e5791..1e6e6eba 100644 --- a/src/engine/net/client/msg/RefineMsg.java +++ b/src/engine/net/client/msg/RefineMsg.java @@ -10,23 +10,18 @@ package engine.net.client.msg; -import engine.gameManager.SessionManager; -import engine.net.*; -import engine.net.client.ClientConnection; +import engine.net.AbstractConnection; +import engine.net.ByteBufferReader; +import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -import engine.objects.*; -import engine.server.MBServerStatics; - -import java.util.ArrayList; -import java.util.concurrent.ConcurrentHashMap; public class RefineMsg extends ClientNetMsg { private int npcType; - private int npcID; + public int npcID; private int unknown01; - private int type; - private int token; + public int type; + public int token; private int unknown02; /** @@ -56,122 +51,6 @@ public class RefineMsg extends ClientNetMsg { super(Protocol.ARCUNTRAINABILITY, origin, reader); } - public static void refine(RefineMsg msg, ClientConnection origin) { - if (origin == null) - return; - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - NPC npc = NPC.getFromCache(msg.npcID); - if (npc == null) - return; - int type = msg.type; - int token = msg.token; - boolean worked = false; - boolean skillPower = true; - if (type == 0) { //refine skill - worked = refineSkill(origin, pc, token, msg); - } else if (type == 1) { //refine power - worked = refinePower(origin, pc, token, msg); - } else if (type == 2) { //refine stat - worked = refineStat(origin, pc, token, msg); - skillPower = false; - } - - if (worked) { - - //update player - pc.applyBonuses(); - pc.charItemManager.RemoveEquipmentFromLackOfSkill(pc, true); - - //echo refine message back - - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - - // if (type == 0 && token == 1488335491){ - // dispatch = Dispatch.borrow(pc, msg); - // DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - // } - - //resend refine screen - - RefinerScreenMsg refinerScreenMsg = new RefinerScreenMsg(skillPower, npc.getSellPercent(pc)); //TODO set npc cost - dispatch = Dispatch.borrow(pc, refinerScreenMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - pc.recalculate(); - } - } - - private static boolean refineSkill(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - CharacterSkill skill = null; - ConcurrentHashMap skills = pc.getSkills(); - for (CharacterSkill sk : skills.values()) { - if (sk == null) - continue; - SkillsBase sb = sk.getSkillsBase(); - if (sb == null) - continue; - if (sb.getToken() == token) - skill = sk; - } - //check if player has skill to refine - if (skill == null) - return false; - //check there's a train to refine - if (skill.getNumTrains() < 1) - return false; - - //TODO verify if any skills have this as prereq - - //TODO verify if any powers have this as a prereq - //get all players powers - for (CharacterPower power : pc.getPowers().values()) { - ArrayList reqs = PowerReq.getPowerReqsForRune(power.getPowerID()); - for (PowerReq req : reqs) { - ConcurrentHashMap playerSkills = pc.getSkills(); - CharacterSkill playerSkill = playerSkills.get(token); - int currentSkillLevel = playerSkill.getTotalSkillPercet(); - if (token == req.getToken() && req.getLevel() == currentSkillLevel) { - return false; - } - } - } - - //refine skill - return skill.refine(pc); - } - - private static boolean refinePower(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - CharacterPower power = null; - ConcurrentHashMap powers = pc.getPowers(); - if (!powers.containsKey(token)) - return false; - power = powers.get(token); - if (power == null) - return false; - if (power.getTrains() < 1) - return false; - - //TODO verify if any powers have this as a prereq - - return power.refine(pc); - } - - private static boolean refineStat(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - if (token == MBServerStatics.STAT_STR_ID) - return pc.refineStr(); - if (token == MBServerStatics.STAT_DEX_ID) - return pc.refineDex(); - if (token == MBServerStatics.STAT_CON_ID) - return pc.refineCon(); - if (token == MBServerStatics.STAT_INT_ID) - return pc.refineInt(msg); - if (token == MBServerStatics.STAT_SPI_ID) - return pc.refineSpi(); - return false; - } - /** * Serializes the subclass specific items to the supplied NetMsgWriter. */