Browse Source

Handler created for RefineMsg

combat-2
MagicBot 8 months ago
parent
commit
1825035739
  1. 3
      src/engine/net/client/ClientMessagePump.java
  2. 2
      src/engine/net/client/Protocol.java
  3. 157
      src/engine/net/client/handlers/RefineMsgHandler.java
  4. 133
      src/engine/net/client/msg/RefineMsg.java

3
src/engine/net/client/ClientMessagePump.java

@ -129,9 +129,6 @@ public class ClientMessagePump implements NetMsgHandler {
case ARCUNTRAINLIST: case ARCUNTRAINLIST:
WorldServer.refinerScreen((RefinerScreenMsg) msg, origin); WorldServer.refinerScreen((RefinerScreenMsg) msg, origin);
break; break;
case ARCUNTRAINABILITY:
RefineMsg.refine((RefineMsg) msg, origin);
break;
case POWERTARGNAME: case POWERTARGNAME:
PowersManager.summon((SendSummonsRequestMsg) msg, origin); PowersManager.summon((SendSummonsRequestMsg) msg, origin);
break; break;

2
src/engine/net/client/Protocol.java

@ -47,7 +47,7 @@ public enum Protocol {
ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request
ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, null), //Request/Send Track window ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, null), //Request/Send Track window
ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow 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 ARCUNTRAINLIST(0x38879E90, RefinerScreenMsg.class, null), //Refiner screen
ARCVIEWASSETTRANSACTIONS(0xBFA476E4, ArcViewAssetTransactionsMsg.class, ArcViewAssetTransactionsMsgHandler.class), ARCVIEWASSETTRANSACTIONS(0xBFA476E4, ArcViewAssetTransactionsMsg.class, ArcViewAssetTransactionsMsgHandler.class),
ASSETSUPPORT(0xc481f89D, AssetSupportMsg.class, AssetSupportMsgHandler.class), ASSETSUPPORT(0xc481f89D, AssetSupportMsg.class, AssetSupportMsgHandler.class),

157
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<String, CharacterSkill> 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<PowerReq> reqs = PowerReq.getPowerReqsForRune(power.getPowerID());
for (PowerReq req : reqs) {
ConcurrentHashMap<String, CharacterSkill> 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<Integer, CharacterPower> 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;
}
}

133
src/engine/net/client/msg/RefineMsg.java

@ -10,23 +10,18 @@
package engine.net.client.msg; package engine.net.client.msg;
import engine.gameManager.SessionManager; import engine.net.AbstractConnection;
import engine.net.*; import engine.net.ByteBufferReader;
import engine.net.client.ClientConnection; import engine.net.ByteBufferWriter;
import engine.net.client.Protocol; 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 { public class RefineMsg extends ClientNetMsg {
private int npcType; private int npcType;
private int npcID; public int npcID;
private int unknown01; private int unknown01;
private int type; public int type;
private int token; public int token;
private int unknown02; private int unknown02;
/** /**
@ -56,122 +51,6 @@ public class RefineMsg extends ClientNetMsg {
super(Protocol.ARCUNTRAINABILITY, origin, reader); 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<String, CharacterSkill> 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<PowerReq> reqs = PowerReq.getPowerReqsForRune(power.getPowerID());
for (PowerReq req : reqs) {
ConcurrentHashMap<String, CharacterSkill> 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<Integer, CharacterPower> 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. * Serializes the subclass specific items to the supplied NetMsgWriter.
*/ */

Loading…
Cancel
Save