From 7b5ac708dc515f9fd39967c798555d203efaff47 Mon Sep 17 00:00:00 2001 From: randy Date: Fri, 7 Feb 2025 16:40:10 -0700 Subject: [PATCH] Implemented shared banks aka clan banks Players can talk to a banker to enable clan banks. When enabled, any banking function will use the primary bank of the owner of the clan chat the player is in. This only works while the bank owner is online; if they are offline the player will fallback to their own bank. --- .../content/global/dialogue/BankerDialogue.kt | 60 +++++++++++++++---- .../game/container/impl/BankContainer.java | 20 +++++++ .../core/game/node/entity/player/Player.java | 11 +++- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/Server/src/main/content/global/dialogue/BankerDialogue.kt b/Server/src/main/content/global/dialogue/BankerDialogue.kt index e913ce4f0..7b857da7d 100644 --- a/Server/src/main/content/global/dialogue/BankerDialogue.kt +++ b/Server/src/main/content/global/dialogue/BankerDialogue.kt @@ -45,18 +45,7 @@ class BankerDialogue(player: Player? = null) : core.game.dialogue.DialoguePlugin 2 -> showTopics( Topic(core.game.dialogue.FacialExpression.FRIENDLY, "I'd like to access my bank account, please.", 10), - IfTopic( - core.game.dialogue.FacialExpression.FRIENDLY, - "I'd like to switch to my ${getBankAccountName(player, true)} bank account.", - 13, - hasActivatedSecondaryBankAccount(player) - ), - IfTopic( - core.game.dialogue.FacialExpression.FRIENDLY, - "I'd like to open a secondary bank account.", - 20, - !hasActivatedSecondaryBankAccount(player) - ), + Topic(core.game.dialogue.FacialExpression.FRIENDLY, "I'd like to switch my default bank account.", 7), Topic(core.game.dialogue.FacialExpression.FRIENDLY, "I'd like to check my PIN settings.", 11), Topic(core.game.dialogue.FacialExpression.FRIENDLY, "I'd like to collect items.", 12), Topic(core.game.dialogue.FacialExpression.ASKING, "What is this place?", 3), @@ -78,6 +67,53 @@ class BankerDialogue(player: Player? = null) : core.game.dialogue.DialoguePlugin "Leave your valuables with us if you want to keep them safe." ).also { stage = END_DIALOGUE } + 7 -> showTopics( + IfTopic( + core.game.dialogue.FacialExpression.FRIENDLY, + "I'd like to turn on the Clan bank, please.", + 8, + !(player.getAttribute("clanbank:enabled",false)) + ), + IfTopic( + core.game.dialogue.FacialExpression.FRIENDLY, + "I'd like to turn off the Clan bank, please.", + 9, + player.getAttribute("clanbank:enabled",false) + ), + IfTopic( + core.game.dialogue.FacialExpression.FRIENDLY, + "I'd like to switch to my ${getBankAccountName(player, true)} bank account.", + 13, + hasActivatedSecondaryBankAccount(player) + ), + IfTopic( + core.game.dialogue.FacialExpression.FRIENDLY, + "I'd like to open a secondary bank account.", + 20, + !hasActivatedSecondaryBankAccount(player) + ), + ) + + 8 -> { + player.setAttribute("/save:clanbank:enabled", true) + + npcl( + core.game.dialogue.FacialExpression.FRIENDLY, + "The Clan bank has been enabled. " + + "If the Clan owner is online, you will access their primary bank account instead of your own." + ).also { stage = 2 } + } + + 9 -> { + player.removeAttribute("clanbank:enabled") + + npcl( + core.game.dialogue.FacialExpression.FRIENDLY, + "The Clan bank has been disabled. " + + "You will now always open your personal bank account." + ).also { stage = 2 } + } + 10 -> { openBankAccount(player) end() diff --git a/Server/src/main/core/game/container/impl/BankContainer.java b/Server/src/main/core/game/container/impl/BankContainer.java index f8f994d4d..42421e0eb 100644 --- a/Server/src/main/core/game/container/impl/BankContainer.java +++ b/Server/src/main/core/game/container/impl/BankContainer.java @@ -43,6 +43,11 @@ public final class BankContainer extends Container { */ private Player player; + /** + * Snowscape. The player reference. + */ + private Player owner; + /** * The bank listener. */ @@ -76,6 +81,7 @@ public final class BankContainer extends Container { super(SIZE, ContainerType.ALWAYS_STACK, SortType.HASH); super.register(listener = new BankListener(player)); this.player = player; + this.owner = player; } /** @@ -110,6 +116,18 @@ public final class BankContainer extends Container { ); } + /** + * Snowscape custom. Sets the current player. Used for clan banks. + * @param newplayer The new player assigned to the bank. + */ + public void setPlayer(Player newPlayer) { + // Only modify if the bank is not open, otherwise the player who is accessing it will suddenly be unable to deposit/withdraw + if (!isOpen()) { + this.player = newPlayer; + this.listener.player = newPlayer; + } + } + /** * Open the bank. */ @@ -195,6 +213,8 @@ public final class BankContainer extends Container { player.getInterfaceManager().closeSingleTab(); player.removeAttribute("search"); player.getPacketDispatch().sendRunScript(571, ""); + //Snowscape. Set the player back to the owner of the account. + setPlayer(this.owner); } /** diff --git a/Server/src/main/core/game/node/entity/player/Player.java b/Server/src/main/core/game/node/entity/player/Player.java index a23d472c7..8a09b46ac 100644 --- a/Server/src/main/core/game/node/entity/player/Player.java +++ b/Server/src/main/core/game/node/entity/player/Player.java @@ -1048,11 +1048,20 @@ public class Player extends Entity { return equipment; } - /** + /** Snowscape modifications: Added check for clan bank * Gets the current active bank. * @return Current active bank. */ public BankContainer getBank() { + if (getAttribute("clanbank:enabled",false)) { + Player target = Repository.getPlayerByName(this.getCommunication().getCurrentClan()); + if (target != null) { + target.getBankPrimary().setPlayer(this); + return target.getBankPrimary(); + } + } + //The primary bank.player is changed back to the owner when a player closes it, but if something else, like dialogue, runs a getbank() function then it's never changed back. So this manually changes it when checking our own bank. + bank.setPlayer(this); return useSecondaryBank ? bankSecondary : bank; }