Browse Source

More itembase refactor work

combat-2
MagicBot 8 months ago
parent
commit
f78baf229d
  1. 114
      src/engine/net/client/ClientMessagePump.java
  2. 2
      src/engine/net/client/Protocol.java
  3. 156
      src/engine/net/client/handlers/RepairMsgHandler.java

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

@ -9,7 +9,10 @@ @@ -9,7 +9,10 @@
package engine.net.client;
import engine.Enum.*;
import engine.Enum.DispatchChannel;
import engine.Enum.GameObjectType;
import engine.Enum.ItemContainerType;
import engine.Enum.ProtectionState;
import engine.InterestManagement.WorldGrid;
import engine.exception.MsgSendException;
import engine.gameManager.*;
@ -1215,112 +1218,6 @@ public class ClientMessagePump implements NetMsgHandler { @@ -1215,112 +1218,6 @@ public class ClientMessagePump implements NetMsgHandler {
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
private static void Repair(RepairMsg msg, ClientConnection origin) {
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
Dispatch dispatch;
if (player == null)
return;
NPC npc = NPC.getFromCache(msg.getNPCID());
if (npc == null)
return;
if (msg.getMsgType() == 1) { //Open RepairObject Window
if (player.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
ErrorPopupMsg.sendErrorPopup(player, 14);
return;
}
//send open repair window response
msg.setRepairWindowAck(npc);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
} else if (msg.getMsgType() == 0) { //Request RepairObject
CharacterItemManager itemMan = player.getCharItemManager();
if (itemMan == null)
return;
Item gold = itemMan.getGoldInventory();
if (gold == null)
return;
Item toRepair = Item.getFromCache(msg.getItemID());
if (toRepair == null)
return;
if (toRepair.getItemBase().isGlass())
return;
//make sure item is in player's inventory or equipment
if (!itemMan.inventoryContains(toRepair) && !itemMan.equippedContains(toRepair))
return;
//make sure item is damaged and not destroyed
short dur = (short) toRepair.durabilityCurrent;
short max = (short) toRepair.template.item_health_full;
//account for durability modifications
float durMod = toRepair.getBonusPercent(ModType.Durability, SourceType.NONE);
max *= (1 + (durMod * 0.01f));
if (dur >= max || dur < 1) {
//redundancy message to clear item from window in client
toRepair.setDurabilityCurrent(max);
msg.setupRepairAck(max - dur);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return;
}
//TODO get cost to repair
int cost = (int) ((max - dur) * 80.1);
Building b = (!npc.isStatic()) ? npc.getBuilding() : null;
if (b != null)
if (b.getProtectionState().equals(ProtectionState.NPC))
b = null;
if (b != null && (b.getStrongboxValue() + cost) > b.getMaxGold()) {
ErrorPopupMsg.sendErrorPopup(player, 206);
return;
}
if (player.getCharItemManager().getGoldInventory().getNumOfItems() - cost < 0)
return;
if (player.getCharItemManager().getGoldInventory().getNumOfItems() - cost > MBServerStatics.PLAYER_GOLD_LIMIT)
return;
if (!itemMan.buyFromNPC(b, cost, cost)) {
ErrorPopupMsg.sendErrorPopup(player, 128);
return;
}
//update player's goldItem count
UpdateGoldMsg ugm = new UpdateGoldMsg(player);
ugm.configure();
dispatch = Dispatch.borrow(player, ugm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
//update durability to database
if (!DbManager.ItemQueries.SET_DURABILITY(toRepair, max))
return;
//repair the item
toRepair.setDurabilityCurrent(max);
//send repair msg
msg.setupRepairAck(max - dur);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
}
protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException {
PlayerCharacter pc = SessionManager.getPlayerCharacter(conn);
@ -1633,9 +1530,6 @@ public class ClientMessagePump implements NetMsgHandler { @@ -1633,9 +1530,6 @@ public class ClientMessagePump implements NetMsgHandler {
case SELLOBJECT:
sellToNPC((SellToNPCMsg) msg, origin);
break;
case REPAIROBJECT:
Repair((RepairMsg) msg, origin);
break;
case TRAINERLIST:
WorldServer.trainerInfo((TrainerInfoMsg) msg, origin);
break;

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

@ -169,7 +169,7 @@ public enum Protocol { @@ -169,7 +169,7 @@ public enum Protocol {
REMOVECHAR(0x5D3F9739, DeleteCharacterMsg.class, null), // Delete Character
REMOVEFRIEND(0xE0D5DB42, RemoveFriendMessage.class, RemoveFriendHandler.class),
REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class),
REPAIROBJECT(0x782219CE, RepairMsg.class, null), //Repair Window Req/Ack, RepairObject item Req/Ack
REPAIROBJECT(0x782219CE, RepairMsg.class, RepairMsgHandler.class), //Repair Window Req/Ack, RepairObject item Req/Ack
REQUESTCONTENTS(0xA786B0A2, LootWindowRequestMsg.class, null), // MoveObjectToContainer Window Request
REQUESTGUILDLIST(0x85DCC6D7, ReqGuildListMsg.class, RequestGuildListHandler.class),
REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, AttackCmdMsgHandler.class), // Attack

156
src/engine/net/client/handlers/RepairMsgHandler.java

@ -0,0 +1,156 @@ @@ -0,0 +1,156 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.Enum;
import engine.Enum.DispatchChannel;
import engine.exception.MsgSendException;
import engine.gameManager.DbManager;
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.RepairMsg;
import engine.net.client.msg.UpdateGoldMsg;
import engine.objects.*;
import engine.server.MBServerStatics;
public class RepairMsgHandler extends AbstractClientMsgHandler {
public RepairMsgHandler() {
super(RepairMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
Dispatch dispatch;
RepairMsg repairMsg = (RepairMsg) baseMsg;
if (player == null)
return true;
NPC npc = NPC.getFromCache(repairMsg.getNPCID());
if (npc == null)
return true;
if (repairMsg.getMsgType() == 1) { //Open RepairObject Window
if (player.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
ErrorPopupMsg.sendErrorPopup(player, 14);
return true;
}
//send open repair window response
repairMsg.setRepairWindowAck(npc);
dispatch = Dispatch.borrow(player, repairMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
} else if (repairMsg.getMsgType() == 0) { //Request RepairObject
CharacterItemManager itemMan = player.getCharItemManager();
if (itemMan == null)
return true;
Item gold = itemMan.getGoldInventory();
if (gold == null)
return true;
Item toRepair = Item.getFromCache(repairMsg.getItemID());
if (toRepair == null)
return true;
if (toRepair.name.toUpperCase().contains("GLASS"))
return true;
//make sure item is in player's inventory or equipment
if (!itemMan.inventoryContains(toRepair) && !itemMan.equippedContains(toRepair))
return true;
//make sure item is damaged and not destroyed
short dur = (short) toRepair.durabilityCurrent;
short max = (short) toRepair.template.item_health_full;
//account for durability modifications
float durMod = toRepair.getBonusPercent(Enum.ModType.Durability, Enum.SourceType.NONE);
max *= (1 + (durMod * 0.01f));
if (dur >= max || dur < 1) {
//redundancy message to clear item from window in client
toRepair.setDurabilityCurrent(max);
repairMsg.setupRepairAck(max - dur);
dispatch = Dispatch.borrow(player, repairMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
}
//TODO get cost to repair
int cost = (int) ((max - dur) * 80.1);
Building building = (!npc.isStatic()) ? npc.getBuilding() : null;
if (building != null)
if (building.getProtectionState().equals(Enum.ProtectionState.NPC))
building = null;
if (building != null && (building.getStrongboxValue() + cost) > building.getMaxGold()) {
ErrorPopupMsg.sendErrorPopup(player, 206);
return true;
}
if (player.getCharItemManager().getGoldInventory().getNumOfItems() - cost < 0)
return true;
if (player.getCharItemManager().getGoldInventory().getNumOfItems() - cost > MBServerStatics.PLAYER_GOLD_LIMIT)
return true;
if (!itemMan.buyFromNPC(building, cost, cost)) {
ErrorPopupMsg.sendErrorPopup(player, 128);
return true;
}
//update player's goldItem count
UpdateGoldMsg ugm = new UpdateGoldMsg(player);
ugm.configure();
dispatch = Dispatch.borrow(player, ugm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
//update durability to database
if (!DbManager.ItemQueries.SET_DURABILITY(toRepair, max))
return true;
//repair the item
toRepair.setDurabilityCurrent(max);
//send repair msg
repairMsg.setupRepairAck(max - dur);
dispatch = Dispatch.borrow(player, repairMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
return true;
}
}
Loading…
Cancel
Save