forked from MagicBane/Server
Handlers created for vendor buy/sell windows
This commit is contained in:
@@ -774,73 +774,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
|||||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void openSellToNPCWindow(SellToNPCWindowMsg msg, ClientConnection origin) {
|
|
||||||
|
|
||||||
PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin);
|
|
||||||
Dispatch dispatch;
|
|
||||||
|
|
||||||
if (sourcePlayer == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
NPC npc = NPC.getFromCache(msg.getNPCID());
|
|
||||||
|
|
||||||
if (npc == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// test within talking range
|
|
||||||
|
|
||||||
if (sourcePlayer.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
|
|
||||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 14);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Contract con = npc.getContract();
|
|
||||||
|
|
||||||
if (con == null)
|
|
||||||
return;
|
|
||||||
float bargain = sourcePlayer.getBargain();
|
|
||||||
|
|
||||||
float profit = npc.getBuyPercent(sourcePlayer) + bargain;
|
|
||||||
|
|
||||||
if (profit > 1)
|
|
||||||
profit = 1;
|
|
||||||
|
|
||||||
msg.setupOutput();
|
|
||||||
|
|
||||||
msg.setUnknown05(profit);
|
|
||||||
msg.setUnknown06(500000); //TODO set goldItem on npc later
|
|
||||||
msg.setItemType(con.getBuyItemType());
|
|
||||||
msg.setSkillTokens(con.getBuySkillToken());
|
|
||||||
msg.setUnknownArray(con.getBuyUnknownToken());
|
|
||||||
|
|
||||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
|
||||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void openBuyFromNPCWindow(BuyFromNPCWindowMsg msg, ClientConnection origin) {
|
|
||||||
|
|
||||||
PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin);
|
|
||||||
Dispatch dispatch;
|
|
||||||
|
|
||||||
if (sourcePlayer == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
NPC npc = NPC.getFromCache(msg.getNpcID());
|
|
||||||
|
|
||||||
if (npc == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// test within talking range
|
|
||||||
|
|
||||||
if (sourcePlayer.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
|
|
||||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 14);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
|
||||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException {
|
protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException {
|
||||||
|
|
||||||
PlayerCharacter pc = SessionManager.getPlayerCharacter(conn);
|
PlayerCharacter pc = SessionManager.getPlayerCharacter(conn);
|
||||||
@@ -1141,12 +1074,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
|||||||
case VENDORDIALOG:
|
case VENDORDIALOG:
|
||||||
VendorDialogMsg.replyDialog((VendorDialogMsg) msg, origin);
|
VendorDialogMsg.replyDialog((VendorDialogMsg) msg, origin);
|
||||||
break;
|
break;
|
||||||
case SHOPLIST:
|
|
||||||
openBuyFromNPCWindow((BuyFromNPCWindowMsg) msg, origin);
|
|
||||||
break;
|
|
||||||
case SHOPINFO:
|
|
||||||
openSellToNPCWindow((SellToNPCWindowMsg) msg, origin);
|
|
||||||
break;
|
|
||||||
case TRAINERLIST:
|
case TRAINERLIST:
|
||||||
WorldServer.trainerInfo((TrainerInfoMsg) msg, origin);
|
WorldServer.trainerInfo((TrainerInfoMsg) msg, origin);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -196,8 +196,6 @@ public enum Protocol {
|
|||||||
SETOBJVAL(0x08A50FD1, null, null),
|
SETOBJVAL(0x08A50FD1, null, null),
|
||||||
SETRUNE(0x888E7C64, ApplyRuneMsg.class, null), //Apply Promotion, Stat Rune (maybe disc also)
|
SETRUNE(0x888E7C64, ApplyRuneMsg.class, null), //Apply Promotion, Stat Rune (maybe disc also)
|
||||||
SETSELECTEDOBECT(0x64E10938, TargetObjectMsg.class, null), // Target an object
|
SETSELECTEDOBECT(0x64E10938, TargetObjectMsg.class, null), // Target an object
|
||||||
SHOPINFO(0x267DAB90, SellToNPCWindowMsg.class, null), //open Sell to NPC Window
|
|
||||||
SHOPLIST(0x682DAB4D, BuyFromNPCWindowMsg.class, null), // Open Buy From NPC Window
|
|
||||||
SHOWCOMBATINFO(0x9BF1E5EA, ShowMsg.class, null), // Request/Response /show
|
SHOWCOMBATINFO(0x9BF1E5EA, ShowMsg.class, null), // Request/Response /show
|
||||||
SHOWVAULTINVENTORY(0xD1FB4842, null, null), // Show Vault Inventory
|
SHOWVAULTINVENTORY(0xD1FB4842, null, null), // Show Vault Inventory
|
||||||
SOCIALCHANNEL(0x2BF58FA6, SocialMsg.class, null), // Socials
|
SOCIALCHANNEL(0x2BF58FA6, SocialMsg.class, null), // Socials
|
||||||
@@ -240,6 +238,8 @@ public enum Protocol {
|
|||||||
UPDATETRADEWINDOW(0x406EBDE6, UpdateTradeWindowMsg.class, null), // Trade Complete
|
UPDATETRADEWINDOW(0x406EBDE6, UpdateTradeWindowMsg.class, null), // Trade Complete
|
||||||
UPGRADEASSET(0x2B85A865, UpgradeAssetMessage.class, UpgradeAssetMsgHandler.class),
|
UPGRADEASSET(0x2B85A865, UpgradeAssetMessage.class, UpgradeAssetMsgHandler.class),
|
||||||
VENDORDIALOG(0x98ACD594, VendorDialogMsg.class, null), // Send/Recv Vendor Dialog
|
VENDORDIALOG(0x98ACD594, VendorDialogMsg.class, null), // Send/Recv Vendor Dialog
|
||||||
|
VENDORSELLWINDOW(0x267DAB90, VendorSellWindowMsg.class, VendorSellWindowMsgHandler.class), //open Sell to NPC Window
|
||||||
|
VENDORBUYWINDOW(0x682DAB4D, VendorBuyWindowMsg.class, VendorBuyWindowMsgHandler.class), // Open Buy From NPC Window
|
||||||
VERSIONINFO(0x4B7EE463, VersionInfoMsg.class, null), // Version Information
|
VERSIONINFO(0x4B7EE463, VersionInfoMsg.class, null), // Version Information
|
||||||
VIEWRESOURCES(0xCEFD0346, ViewResourcesMessage.class, null),
|
VIEWRESOURCES(0xCEFD0346, ViewResourcesMessage.class, null),
|
||||||
VISUALUPDATE(0x33402fd2, null, null),
|
VISUALUPDATE(0x33402fd2, null, null),
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// Magicbane Emulator Project © 2013 - 2022
|
||||||
|
// www.magicbane.com
|
||||||
|
|
||||||
|
package engine.net.client.handlers;
|
||||||
|
|
||||||
|
import engine.Enum.DispatchChannel;
|
||||||
|
import engine.exception.MsgSendException;
|
||||||
|
import engine.gameManager.SessionManager;
|
||||||
|
import engine.net.Dispatch;
|
||||||
|
import engine.net.DispatchMessage;
|
||||||
|
import engine.net.client.ClientConnection;
|
||||||
|
import engine.net.client.msg.ClientNetMsg;
|
||||||
|
import engine.net.client.msg.ErrorPopupMsg;
|
||||||
|
import engine.net.client.msg.VendorBuyWindowMsg;
|
||||||
|
import engine.objects.NPC;
|
||||||
|
import engine.objects.PlayerCharacter;
|
||||||
|
import engine.server.MBServerStatics;
|
||||||
|
|
||||||
|
public class VendorBuyWindowMsgHandler extends AbstractClientMsgHandler {
|
||||||
|
|
||||||
|
public VendorBuyWindowMsgHandler() {
|
||||||
|
super(VendorBuyWindowMsg.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||||
|
|
||||||
|
PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin);
|
||||||
|
Dispatch dispatch;
|
||||||
|
|
||||||
|
VendorBuyWindowMsg msg = (VendorBuyWindowMsg) baseMsg;
|
||||||
|
|
||||||
|
if (sourcePlayer == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
NPC npc = NPC.getFromCache(msg.getNpcID());
|
||||||
|
|
||||||
|
if (npc == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// test within talking range
|
||||||
|
|
||||||
|
if (sourcePlayer.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
|
||||||
|
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 14);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
||||||
|
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// Magicbane Emulator Project © 2013 - 2022
|
||||||
|
// www.magicbane.com
|
||||||
|
|
||||||
|
package engine.net.client.handlers;
|
||||||
|
|
||||||
|
import engine.Enum.DispatchChannel;
|
||||||
|
import engine.exception.MsgSendException;
|
||||||
|
import engine.gameManager.SessionManager;
|
||||||
|
import engine.net.Dispatch;
|
||||||
|
import engine.net.DispatchMessage;
|
||||||
|
import engine.net.client.ClientConnection;
|
||||||
|
import engine.net.client.msg.ClientNetMsg;
|
||||||
|
import engine.net.client.msg.ErrorPopupMsg;
|
||||||
|
import engine.net.client.msg.VendorSellWindowMsg;
|
||||||
|
import engine.objects.Contract;
|
||||||
|
import engine.objects.NPC;
|
||||||
|
import engine.objects.PlayerCharacter;
|
||||||
|
import engine.server.MBServerStatics;
|
||||||
|
|
||||||
|
public class VendorSellWindowMsgHandler extends AbstractClientMsgHandler {
|
||||||
|
|
||||||
|
public VendorSellWindowMsgHandler() {
|
||||||
|
super(VendorSellWindowMsg.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||||
|
|
||||||
|
PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin);
|
||||||
|
Dispatch dispatch;
|
||||||
|
|
||||||
|
VendorSellWindowMsg msg = (VendorSellWindowMsg) baseMsg;
|
||||||
|
|
||||||
|
if (playerCharacter == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
NPC npc = NPC.getFromCache(msg.getNPCID());
|
||||||
|
|
||||||
|
if (npc == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// test within talking range
|
||||||
|
|
||||||
|
if (playerCharacter.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
|
||||||
|
ErrorPopupMsg.sendErrorPopup(playerCharacter, 14);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Contract contract = npc.getContract();
|
||||||
|
|
||||||
|
if (contract == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
float bargain = playerCharacter.getBargain();
|
||||||
|
|
||||||
|
float profit = npc.getBuyPercent(playerCharacter) + bargain;
|
||||||
|
|
||||||
|
if (profit > 1)
|
||||||
|
profit = 1;
|
||||||
|
|
||||||
|
msg.setupOutput();
|
||||||
|
|
||||||
|
msg.setUnknown05(profit);
|
||||||
|
msg.setUnknown06(500000); //TODO set goldItem on npc later
|
||||||
|
msg.setItemType(contract.getBuyItemType());
|
||||||
|
msg.setSkillTokens(contract.getBuySkillToken());
|
||||||
|
msg.setUnknownArray(contract.getBuyUnknownToken());
|
||||||
|
|
||||||
|
dispatch = Dispatch.borrow(playerCharacter, msg);
|
||||||
|
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
-5
@@ -21,7 +21,7 @@ import engine.objects.*;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class BuyFromNPCWindowMsg extends ClientNetMsg {
|
public class VendorBuyWindowMsg extends ClientNetMsg {
|
||||||
|
|
||||||
private int unknown01;
|
private int unknown01;
|
||||||
private int npcType;
|
private int npcType;
|
||||||
@@ -33,9 +33,9 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg {
|
|||||||
/**
|
/**
|
||||||
* This is the general purpose constructor
|
* This is the general purpose constructor
|
||||||
*/
|
*/
|
||||||
public BuyFromNPCWindowMsg(int unknown01, int npcType, int npcID,
|
public VendorBuyWindowMsg(int unknown01, int npcType, int npcID,
|
||||||
float unknown02, byte unknown03, int unknown04) {
|
float unknown02, byte unknown03, int unknown04) {
|
||||||
super(Protocol.SHOPLIST);
|
super(Protocol.VENDORBUYWINDOW);
|
||||||
this.unknown01 = unknown01;
|
this.unknown01 = unknown01;
|
||||||
this.npcType = npcType;
|
this.npcType = npcType;
|
||||||
this.npcID = npcID;
|
this.npcID = npcID;
|
||||||
@@ -50,8 +50,8 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg {
|
|||||||
* past the limit) then this constructor Throws that Exception to the
|
* past the limit) then this constructor Throws that Exception to the
|
||||||
* caller.
|
* caller.
|
||||||
*/
|
*/
|
||||||
public BuyFromNPCWindowMsg(AbstractConnection origin, ByteBufferReader reader) {
|
public VendorBuyWindowMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||||
super(Protocol.SHOPLIST, origin, reader);
|
super(Protocol.VENDORBUYWINDOW, origin, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+5
-5
@@ -24,7 +24,7 @@ import java.util.ArrayList;
|
|||||||
*
|
*
|
||||||
* @author Eighty
|
* @author Eighty
|
||||||
*/
|
*/
|
||||||
public class SellToNPCWindowMsg extends ClientNetMsg {
|
public class VendorSellWindowMsg extends ClientNetMsg {
|
||||||
|
|
||||||
//Item Types:
|
//Item Types:
|
||||||
//1: weapon
|
//1: weapon
|
||||||
@@ -53,10 +53,10 @@ public class SellToNPCWindowMsg extends ClientNetMsg {
|
|||||||
/**
|
/**
|
||||||
* This is the general purpose constructor
|
* This is the general purpose constructor
|
||||||
*/
|
*/
|
||||||
public SellToNPCWindowMsg(int npcType, int npcID, byte unknownByte02,
|
public VendorSellWindowMsg(int npcType, int npcID, byte unknownByte02,
|
||||||
ArrayList<Integer> itemTypes, ArrayList<Integer> skillTokens,
|
ArrayList<Integer> itemTypes, ArrayList<Integer> skillTokens,
|
||||||
ArrayList<Integer> unknownArray02, float unknown05, int unknown06) {
|
ArrayList<Integer> unknownArray02, float unknown05, int unknown06) {
|
||||||
super(Protocol.SHOPINFO);
|
super(Protocol.VENDORSELLWINDOW);
|
||||||
this.npcType = npcType;
|
this.npcType = npcType;
|
||||||
this.npcID = npcID;
|
this.npcID = npcID;
|
||||||
this.unknownByte01 = (byte) 0;
|
this.unknownByte01 = (byte) 0;
|
||||||
@@ -75,8 +75,8 @@ public class SellToNPCWindowMsg extends ClientNetMsg {
|
|||||||
/**
|
/**
|
||||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller.
|
* This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller.
|
||||||
*/
|
*/
|
||||||
public SellToNPCWindowMsg(AbstractConnection origin, ByteBufferReader reader) {
|
public VendorSellWindowMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||||
super(Protocol.SHOPINFO, origin, reader);
|
super(Protocol.VENDORSELLWINDOW, origin, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reference in New Issue
Block a user