Files
Server/src/engine/net/client/handlers/RepairMsgHandler.java
T
MagicBotandClaude Opus 5.5 6b4e9815e0 Switch Item.template and MobLoot to CObjectTemplate
Item.template is now the cache template from CObjectTemplate.lookup
instead of the legacy DB ItemTemplate, so item.template.cacheTemplate.X
becomes item.template.X. MobLoot, LootManager, ItemManager.isTwoHanded/
isShield and CombatManager.getSwingAnimation take a CObjectTemplate.

No value changes: every getter already read the cache template through
the bridge, and the lookup resolves the same 7586 ids as
static_item_templates with the same item_type (offline parity p17.py,
0 differences).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 07:55:28 -04:00

155 lines
5.5 KiB
Java

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
package engine.net.client.handlers;
import engine.gameManager.DbManager;
import engine.gameManager.DispatchManager;
import engine.gameManager.SessionManager;
import engine.mbEnums;
import engine.mbEnums.DispatchChannel;
import engine.net.Dispatch;
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();
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {
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);
DispatchManager.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
} else if (repairMsg.getMsgType() == 0) { //Request RepairObject
CharacterItemManager itemMan = player.charItemManager;
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.combat_health_current;
short max = (short) toRepair.template.getCombatHealthFull();
//account for durability modifications
float durMod = toRepair.getBonusPercent(mbEnums.ModType.Durability, mbEnums.SourceType.None);
max *= (1 + (durMod * 0.01f));
if (dur >= max || dur < 1) {
//redundancy message to clear item from window in client
toRepair.setCombat_health_current(max);
repairMsg.setupRepairAck(max - dur);
dispatch = Dispatch.borrow(player, repairMsg);
DispatchManager.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(mbEnums.ProtectionState.NPC))
building = null;
if (building != null && (building.getStrongboxValue() + cost) > building.getMaxGold()) {
ErrorPopupMsg.sendErrorPopup(player, 206);
return true;
}
if (player.charItemManager.getGoldInventory().getNumOfItems() - cost < 0)
return true;
if (player.charItemManager.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);
DispatchManager.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
//update durability to database
if (!DbManager.ItemQueries.SET_DURABILITY(toRepair, max))
return true;
//repair the item
toRepair.setCombat_health_current(max);
//send repair msg
repairMsg.setupRepairAck(max - dur);
dispatch = Dispatch.borrow(player, repairMsg);
DispatchManager.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
return true;
}
}