Greatly improved examine text handling and authenticity for various coin quantities on ground, in bank and in inventory

Fixed clue scroll examine text crashing the client in some situations
This commit is contained in:
Byte 2022-09-15 01:51:05 +00:00 committed by Ryan
parent 854b8cdc6b
commit c8f1fd1253
4 changed files with 386 additions and 365 deletions

File diff suppressed because it is too large Load diff

View file

@ -1696,4 +1696,17 @@ public class ItemDefinition extends Definition<Item> {
public void setMaleWornModelId4(int maleWornModelId4) { public void setMaleWornModelId4(int maleWornModelId4) {
this.maleWornModelId4 = maleWornModelId4; this.maleWornModelId4 = maleWornModelId4;
} }
/**
* Gets the examine.
* @return The examine.
*/
@Override
public String getExamine() {
examine = super.getExamine();
if (!isUnnoted()) {
examine = "Swap this note at any bank for the equivalent item.";
}
return examine;
}
} }

View file

@ -43,7 +43,8 @@ public final class ExaminePacket implements IncomingPacket {
if (id < 0 || id > Cache.getItemDefinitionsSize()) { if (id < 0 || id > Cache.getItemDefinitionsSize()) {
break; break;
} }
player.getPacketDispatch().sendMessage(getItemExamine(id)); ItemDefinition itemDef = ItemDefinition.forId(id);
player.getPacketDispatch().sendMessage(itemDef.getExamine());
break; break;
case 72: // NPC examine case 72: // NPC examine
id = buffer.getShort(); id = buffer.getShort();
@ -59,30 +60,4 @@ public final class ExaminePacket implements IncomingPacket {
break; break;
} }
} }
}
/**
* Gets the item examine.
* @param id the item id.
* @return the item examine.
*/
public static String getItemExamine(int id) {
// Coins examine override
if (id == Items.COINS_995) {
return "Lovely money!";
}
// Clue scroll examine override
if (ItemDefinition.forId(id).getExamine().length() == 255) {
return "A set of instructions to be followed.";
}
// Noted item examine override
if (!ItemDefinition.forId(id).isUnnoted()) {
return "Swap this note at any bank for the equivalent item.";
}
// Return the examine string for the given item ID
return ItemDefinition.forId(id).getExamine();
}
}

View file

@ -2,8 +2,12 @@ package rs09.game.interaction.inter.bank
import api.* import api.*
import core.game.component.Component import core.game.component.Component
import core.game.container.Container
import core.game.node.entity.player.Player import core.game.node.entity.player.Player
import core.game.node.item.Item
import core.tools.StringUtils
import org.rs09.consts.Components import org.rs09.consts.Components
import org.rs09.consts.Items
import rs09.ServerConstants import rs09.ServerConstants
import rs09.game.content.dialogue.region.worldwide.bank.BankDepositDialogue import rs09.game.content.dialogue.region.worldwide.bank.BankDepositDialogue
import rs09.game.content.dialogue.region.worldwide.bank.BankHelpDialogue import rs09.game.content.dialogue.region.worldwide.bank.BankHelpDialogue
@ -52,6 +56,8 @@ class BankInterface : InterfaceListener {
private const val OP_SET_TAB = 155 private const val OP_SET_TAB = 155
private const val OP_COLLAPSE_TAB = 196 private const val OP_COLLAPSE_TAB = 196
private const val THRESHOLD_TO_DISPLAY_EXACT_QUANTITY_ON_EXAMINE = 100000;
} }
private fun onBankInterfaceOpen(player: Player, component: Component): Boolean { private fun onBankInterfaceOpen(player: Player, component: Component): Boolean {
@ -129,7 +135,15 @@ class BankInterface : InterfaceListener {
player.bank.getAmount(item) - 1 player.bank.getAmount(item) - 1
) )
} }
OP_EXAMINE -> sendMessage(player, item.definition.examine) OP_EXAMINE -> {
var examineText = item.definition.examine
val id = item.definition.id
val bank = player.bank
if (isCoinOverrideNeeded(id, bank)) {
examineText = "" + bank.getAmount(id) + " x " + item.definition.name + "."
}
sendMessage(player, examineText)
}
else -> player.debug("Unknown bank menu opcode $opcode") else -> player.debug("Unknown bank menu opcode $opcode")
} }
@ -147,7 +161,15 @@ class BankInterface : InterfaceListener {
OP_AMOUNT_LAST_X -> player.bank.addItem(slot, player.bank.lastAmountX) OP_AMOUNT_LAST_X -> player.bank.addItem(slot, player.bank.lastAmountX)
OP_AMOUNT_X -> BankUtils.transferX(player, slot, false) OP_AMOUNT_X -> BankUtils.transferX(player, slot, false)
OP_AMOUNT_ALL -> player.bank.addItem(slot, player.inventory.getAmount(item)) OP_AMOUNT_ALL -> player.bank.addItem(slot, player.inventory.getAmount(item))
OP_EXAMINE -> sendMessage(player, item.definition.examine) OP_EXAMINE -> {
var examineText = item.definition.examine
val id = item.definition.id
val inventory = player.inventory
if (isCoinOverrideNeeded(id, inventory)) {
examineText = "" + inventory.getAmount(id) + " x " + item.definition.name + "."
}
sendMessage(player, examineText)
}
else -> player.debug("Unknown inventory menu opcode $opcode") else -> player.debug("Unknown inventory menu opcode $opcode")
} }
@ -181,4 +203,15 @@ class BankInterface : InterfaceListener {
on(Components.BANK_V2_SIDE_763, ::handleInventoryMenu) on(Components.BANK_V2_SIDE_763, ::handleInventoryMenu)
} }
}
private fun isCoinOverrideNeeded(id: Int, container: Container): Boolean {
val amount = container.getAmount(id)
// Only COINS_995 are obtainable and bankable by player
if (id == Items.COINS_995 && amount >= THRESHOLD_TO_DISPLAY_EXACT_QUANTITY_ON_EXAMINE) {
return true
}
return false
}
}