Refactored bank logic
Removed some unnecessary complexity from bank logic Improved handling of banking actions Now correctly tracks the active bank tab
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
package content.global.handlers.iface.bank
|
||||
|
||||
import content.global.dialogue.BankDepositDialogue
|
||||
import content.global.dialogue.BankHelpDialogue
|
||||
import core.ServerConstants
|
||||
import core.api.*
|
||||
import core.game.component.Component
|
||||
import core.game.container.Container
|
||||
import core.game.interaction.InterfaceListener
|
||||
import core.game.node.entity.player.Player
|
||||
import org.rs09.consts.Components
|
||||
import org.rs09.consts.Items
|
||||
import core.ServerConstants
|
||||
import content.global.dialogue.BankDepositDialogue
|
||||
import content.global.dialogue.BankHelpDialogue
|
||||
import core.game.interaction.InterfaceListener
|
||||
|
||||
/**
|
||||
* Allows the user to interact with the Bank Interface.
|
||||
@@ -58,8 +58,6 @@ class BankInterface : InterfaceListener {
|
||||
}
|
||||
|
||||
private fun onBankInterfaceOpen(player: Player, component: Component): Boolean {
|
||||
player.bank.sendBankSpace()
|
||||
|
||||
val settings = IfaceSettingsBuilder()
|
||||
.enableAllOptions()
|
||||
.enableSlotSwitch()
|
||||
@@ -74,14 +72,12 @@ class BankInterface : InterfaceListener {
|
||||
ServerConstants.BANK_SIZE
|
||||
)
|
||||
|
||||
resetSearch(player)
|
||||
return false
|
||||
}
|
||||
|
||||
private fun handleTabInteraction(player: Player, component: Component, opcode: Int, buttonID: Int, slot: Int, itemID: Int): Boolean {
|
||||
if (getAttribute(player, "search", false)) {
|
||||
player.bank.reopen()
|
||||
}
|
||||
|
||||
resetSearch(player)
|
||||
val clickedTabIndex = -((buttonID - 41) / 2)
|
||||
|
||||
when (opcode) {
|
||||
@@ -102,36 +98,16 @@ class BankInterface : InterfaceListener {
|
||||
private fun handleBankMenu(player: Player, component: Component, opcode: Int, buttonID: Int, slot: Int, itemID: Int): Boolean {
|
||||
val item = player.bank.get(slot)
|
||||
?: return true
|
||||
resetSearch(player)
|
||||
|
||||
when (opcode) {
|
||||
OP_AMOUNT_ONE -> runWorldTask { player.bank.takeItem(slot, 1) }
|
||||
OP_AMOUNT_FIVE -> runWorldTask { player.bank.takeItem(slot, 5) }
|
||||
OP_AMOUNT_TEN -> runWorldTask { player.bank.takeItem(slot, 10) }
|
||||
OP_AMOUNT_LAST_X -> runWorldTask {
|
||||
player.bank.takeItem(
|
||||
slot,
|
||||
player.bank.lastAmountX
|
||||
)
|
||||
}
|
||||
OP_AMOUNT_X -> runWorldTask {
|
||||
BankUtils.transferX(
|
||||
player,
|
||||
slot,
|
||||
true
|
||||
)
|
||||
}
|
||||
OP_AMOUNT_ALL -> runWorldTask {
|
||||
player.bank.takeItem(
|
||||
slot,
|
||||
player.bank.getAmount(item)
|
||||
)
|
||||
}
|
||||
OP_AMOUNT_ALL_BUT_ONE -> runWorldTask {
|
||||
player.bank.takeItem(
|
||||
slot,
|
||||
player.bank.getAmount(item) - 1
|
||||
)
|
||||
}
|
||||
OP_AMOUNT_ONE -> player.bank.takeItem(slot, 1)
|
||||
OP_AMOUNT_FIVE -> player.bank.takeItem(slot, 5)
|
||||
OP_AMOUNT_TEN -> player.bank.takeItem(slot, 10)
|
||||
OP_AMOUNT_LAST_X -> player.bank.takeItem(slot, player.bank.lastAmountX)
|
||||
OP_AMOUNT_X -> BankUtils.transferX(player, slot, true)
|
||||
OP_AMOUNT_ALL -> player.bank.takeItem(slot, player.bank.getAmount(item))
|
||||
OP_AMOUNT_ALL_BUT_ONE -> player.bank.takeItem(slot, player.bank.getAmount(item) - 1)
|
||||
OP_EXAMINE -> {
|
||||
var examineText = item.definition.examine
|
||||
val id = item.definition.id
|
||||
@@ -150,6 +126,7 @@ class BankInterface : InterfaceListener {
|
||||
private fun handleInventoryMenu(player: Player, component: Component, opcode: Int, buttonID: Int, slot: Int, itemID: Int): Boolean {
|
||||
val item = player.inventory.get(slot)
|
||||
?: return true
|
||||
resetSearch(player)
|
||||
|
||||
when (opcode) {
|
||||
OP_AMOUNT_ONE -> player.bank.addItem(slot, 1)
|
||||
@@ -211,4 +188,11 @@ class BankInterface : InterfaceListener {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun resetSearch (player: Player)
|
||||
{
|
||||
val lastTab = getAttribute(player, "bank:lasttab", 0)
|
||||
player.bank.tabIndex = lastTab
|
||||
setVarc(player, 190, 1) //re-enable "Search" right-click option on search button.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,61 @@
|
||||
package core.api
|
||||
|
||||
import com.moandjiezana.toml.Toml
|
||||
import content.data.consumables.*
|
||||
import content.data.skill.SkillingTool
|
||||
import content.global.handlers.iface.ge.StockMarket
|
||||
import content.global.skill.slayer.SlayerManager
|
||||
import content.global.skill.slayer.Tasks
|
||||
import content.global.skill.summoning.familiar.BurdenBeast
|
||||
import core.ServerConstants
|
||||
import core.api.utils.GlobalKillCounter
|
||||
import core.api.utils.Vector
|
||||
import core.cache.def.impl.AnimationDefinition
|
||||
import core.cache.def.impl.ItemDefinition
|
||||
import core.cache.def.impl.SceneryDefinition
|
||||
import core.cache.def.impl.VarbitDefinition
|
||||
import core.game.activity.Cutscene
|
||||
import core.game.component.Component
|
||||
import core.game.consumable.*
|
||||
import core.game.container.impl.EquipmentContainer
|
||||
import core.game.dialogue.DialogueFile
|
||||
import core.game.dialogue.SkillDialogueHandler
|
||||
import core.game.ge.GrandExchangeRecords
|
||||
import core.game.interaction.*
|
||||
import core.game.node.Node
|
||||
import core.game.node.entity.Entity
|
||||
import core.game.node.entity.combat.CombatSwingHandler
|
||||
import core.game.node.entity.combat.ImpactHandler
|
||||
import core.game.node.entity.impl.Animator
|
||||
import core.game.node.entity.impl.ForceMovement
|
||||
import core.game.node.entity.impl.Projectile
|
||||
import core.game.node.entity.npc.NPC
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.entity.player.info.LogType
|
||||
import core.game.node.entity.player.info.PlayerMonitor
|
||||
import core.game.node.entity.player.link.HintIconManager
|
||||
import core.game.node.entity.player.link.IronmanMode
|
||||
import core.game.node.entity.player.link.TeleportManager
|
||||
import core.game.node.entity.player.link.audio.Audio
|
||||
import core.game.node.entity.player.link.emote.Emotes
|
||||
import core.game.node.entity.player.link.quest.QuestRepository
|
||||
import core.game.node.entity.player.link.prayer.PrayerType
|
||||
import core.game.node.entity.player.link.quest.Quest
|
||||
import core.game.node.entity.player.link.quest.QuestRepository
|
||||
import core.game.node.entity.skill.Skills
|
||||
import content.data.skill.SkillingTool
|
||||
import content.global.skill.slayer.Tasks
|
||||
import content.global.skill.summoning.familiar.BurdenBeast
|
||||
import core.game.node.item.GroundItem
|
||||
import core.game.node.item.GroundItemManager
|
||||
import core.game.node.item.Item
|
||||
import core.game.node.scenery.Scenery
|
||||
import core.game.node.scenery.SceneryBuilder
|
||||
import core.game.requirement.*
|
||||
import core.game.shops.Shops
|
||||
import core.game.system.config.ItemConfigParser
|
||||
import core.game.system.config.ServerConfigParser
|
||||
import core.game.system.task.Pulse
|
||||
import core.game.system.timer.*
|
||||
import core.game.system.timer.impl.*
|
||||
import core.game.world.GameWorld
|
||||
import core.game.world.GameWorld.Pulser
|
||||
import core.game.world.map.Direction
|
||||
import core.game.world.map.Location
|
||||
import core.game.world.map.RegionManager
|
||||
@@ -39,48 +64,21 @@ import core.game.world.map.path.Pathfinder
|
||||
import core.game.world.map.zone.MapZone
|
||||
import core.game.world.map.zone.ZoneBorders
|
||||
import core.game.world.map.zone.ZoneBuilder
|
||||
import core.game.world.repository.Repository
|
||||
import core.game.world.update.flag.*
|
||||
import core.game.world.update.flag.chunk.AnimateObjectUpdateFlag
|
||||
import core.game.world.update.flag.context.*
|
||||
import core.net.packet.PacketRepository
|
||||
import core.net.packet.context.DefaultContext
|
||||
import core.net.packet.context.MusicContext
|
||||
import core.net.packet.out.AudioPacket
|
||||
import core.net.packet.out.MusicPacket
|
||||
import core.tools.*
|
||||
import org.rs09.consts.Items
|
||||
import org.rs09.consts.NPCs
|
||||
import core.game.dialogue.DialogueFile
|
||||
import core.game.dialogue.SkillDialogueHandler
|
||||
import core.api.utils.GlobalKillCounter
|
||||
import core.game.shops.Shops
|
||||
import core.game.ge.GrandExchangeRecords
|
||||
import core.game.interaction.InteractionListeners
|
||||
import content.global.handlers.iface.ge.StockMarket
|
||||
import content.global.skill.slayer.SlayerManager
|
||||
import content.data.consumables.*
|
||||
import core.game.activity.Cutscene
|
||||
import core.game.interaction.*
|
||||
import core.game.node.entity.player.info.LogType
|
||||
import core.game.node.entity.player.info.PlayerMonitor
|
||||
import core.tools.SystemLogger
|
||||
import core.game.system.config.ItemConfigParser
|
||||
import core.game.system.config.ServerConfigParser
|
||||
import core.game.world.GameWorld
|
||||
import core.game.world.GameWorld.Pulser
|
||||
import core.game.world.repository.Repository
|
||||
import core.game.consumable.*
|
||||
import core.ServerConstants
|
||||
import core.api.utils.Vector
|
||||
import core.cache.def.impl.AnimationDefinition
|
||||
import core.game.node.entity.player.link.quest.Quest
|
||||
import core.tools.*
|
||||
import core.game.world.update.flag.*
|
||||
import core.game.world.update.flag.context.*
|
||||
import core.game.requirement.*
|
||||
import core.net.packet.PacketRepository
|
||||
import core.net.packet.context.MusicContext
|
||||
import core.net.packet.out.MusicPacket
|
||||
import core.game.system.timer.*
|
||||
import core.game.system.timer.impl.*
|
||||
import core.game.node.entity.combat.CombatSwingHandler
|
||||
import core.net.packet.context.DefaultContext
|
||||
import core.net.packet.out.AudioPacket
|
||||
import org.rs09.consts.Sounds
|
||||
import java.util.regex.*
|
||||
import java.io.*
|
||||
import java.util.regex.*
|
||||
import kotlin.math.*
|
||||
|
||||
/**
|
||||
@@ -1271,6 +1269,11 @@ fun setVarbit (player: Player, varbitId: Int, value: Int, save: Boolean = false)
|
||||
setVarbit (player, def, value, save)
|
||||
}
|
||||
|
||||
fun setVarc (player: Player, varc: Int, value: Int)
|
||||
{
|
||||
player.packetDispatch.sendVarcUpdate(varc.toShort(), value)
|
||||
}
|
||||
|
||||
fun reinitVarps (player: Player) {
|
||||
for ((index, value) in player.varpMap) {
|
||||
setVarp(player, index, value, player.saveVarp[index] ?: false)
|
||||
@@ -2068,7 +2071,7 @@ fun dumpContainer(player: Player, container: core.game.container.Container): Int
|
||||
}
|
||||
|
||||
container.remove(item)
|
||||
bank.add(unnote(item))
|
||||
bank.add(unnote(item), false)
|
||||
dumpedCount++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,13 +131,10 @@ public final class BankContainer extends Container {
|
||||
super.refresh();
|
||||
player.getInventory().getListeners().add(listener);
|
||||
player.getInventory().refresh();
|
||||
setVarp(player, 1249, lastAmountX);
|
||||
setVarp(player, 1249, lastAmountX);
|
||||
int settings = new IfaceSettingsBuilder().enableOptions(new IntRange(0, 5)).enableExamine().enableSlotSwitch().build();
|
||||
player.getPacketDispatch().sendIfaceSettings(settings, 0, 763, 0, 27);
|
||||
player.getPacketDispatch().sendRunScript(1451, "");
|
||||
open = true;
|
||||
setTabConfigurations();
|
||||
sendBankSpace();
|
||||
}
|
||||
|
||||
public void open(Player player) {
|
||||
@@ -165,8 +162,7 @@ public final class BankContainer extends Container {
|
||||
player.getPacketDispatch().sendIfaceSettings(settings, 0, 763, 0, 27);
|
||||
player.getPacketDispatch().sendRunScript(1451, "");
|
||||
open = true;
|
||||
this.player.getBank().setTabConfigurations(player);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,21 +246,8 @@ public final class BankContainer extends Container {
|
||||
increaseTabStartSlots(tabIndex);
|
||||
}
|
||||
super.add(add, true, preferredSlot);
|
||||
setTabConfigurations();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-opens the bank interface.
|
||||
*/
|
||||
public void reopen() {
|
||||
if (!open) {
|
||||
return;
|
||||
}
|
||||
player.getInterfaceManager().close();
|
||||
open();
|
||||
refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a item from the bank container and adds one to the inventory
|
||||
@@ -302,15 +285,11 @@ public final class BankContainer extends Container {
|
||||
if (super.remove(item, slot, false)) {
|
||||
player.getInventory().add(add);
|
||||
}
|
||||
int tabId = getTabByItemSlot(slot);
|
||||
if (get(slot) == null) {
|
||||
int tabId = getTabByItemSlot(slot);
|
||||
decreaseTabStartSlots(tabId);
|
||||
}
|
||||
setTabConfigurations();
|
||||
shift();
|
||||
if (player.getAttribute("search", false)) {
|
||||
reopen();
|
||||
}
|
||||
shift();
|
||||
} else update();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,8 +365,7 @@ public final class BankContainer extends Container {
|
||||
* Sends the bank space values on the interface.
|
||||
*/
|
||||
public void sendBankSpace() {
|
||||
player.getPacketDispatch().sendString(Integer.toString(capacity() - freeSlots()), 762, 97);
|
||||
player.getPacketDispatch().sendString(Integer.toString(capacity()), 762, 98);
|
||||
setVarc(player, 192, capacity() - freeSlots());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,47 +389,17 @@ public final class BankContainer extends Container {
|
||||
replace(tempTabItems[i], slot, false);
|
||||
}
|
||||
refresh(); //We only refresh once.
|
||||
setTabConfigurations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tab configs.
|
||||
*/
|
||||
public void setTabConfigurations() {
|
||||
int value = getItemsInTab(1);
|
||||
value += getItemsInTab(2) << 10;
|
||||
value += getItemsInTab(3) << 20;
|
||||
setVarp(player, 1246, value);
|
||||
value = getItemsInTab(4);
|
||||
value += getItemsInTab(5) << 10;
|
||||
value += getItemsInTab(6) << 20;
|
||||
setVarp(player, 1247, value);
|
||||
value = -2013265920;
|
||||
value += (134217728 * (tabIndex == 10 ? 0 : tabIndex));
|
||||
value += getItemsInTab(7);
|
||||
value += getItemsInTab(8) << 10;
|
||||
setVarp(player, 1248, value);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
setVarbit(player, 4885 + i, getItemsInTab(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tab configs.
|
||||
*/
|
||||
public void setTabConfigurations(Player player) {
|
||||
int value = getItemsInTab(1);
|
||||
value += getItemsInTab(2) << 10;
|
||||
value += getItemsInTab(3) << 20;
|
||||
setVarp(player, 1246, value);
|
||||
value = getItemsInTab(4);
|
||||
value += getItemsInTab(5) << 10;
|
||||
value += getItemsInTab(6) << 20;
|
||||
setVarp(player, 1247, value);
|
||||
value = -2013265920;
|
||||
value += (134217728 * (tabIndex == 10 ? 0 : tabIndex));
|
||||
value += getItemsInTab(7);
|
||||
value += getItemsInTab(8) << 10;
|
||||
setVarp(player, 1248, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the amount of items in one tab.
|
||||
* @param tabId The tab index.
|
||||
@@ -515,14 +463,9 @@ public final class BankContainer extends Container {
|
||||
* @param tabIndex The tabIndex to set.
|
||||
*/
|
||||
public void setTabIndex(int tabIndex) {
|
||||
this.tabIndex = tabIndex;
|
||||
|
||||
/*
|
||||
* Kludge to update the interface
|
||||
* after dumping all to prevent
|
||||
* "invisible" items in slots.
|
||||
*/
|
||||
update(true);
|
||||
this.tabIndex = tabIndex == 0 ? 10 : tabIndex;
|
||||
setVarbit(player, 4893, tabIndex + 1);
|
||||
setAttribute(player, "bank:lasttab", tabIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user