More itembase refactor work

This commit is contained in:
2024-03-15 13:13:22 -04:00
parent 22f498a6f8
commit f78baf229d
3 changed files with 161 additions and 111 deletions
+4 -110
View File
@@ -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 {
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 {
case SELLOBJECT:
sellToNPC((SellToNPCMsg) msg, origin);
break;
case REPAIROBJECT:
Repair((RepairMsg) msg, origin);
break;
case TRAINERLIST:
WorldServer.trainerInfo((TrainerInfoMsg) msg, origin);
break;