MagicBot
8 months ago
6 changed files with 153 additions and 88 deletions
@ -0,0 +1,58 @@
@@ -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 @@
@@ -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; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue