BankController - jimdroberts/FishMMO GitHub Wiki
Controls the player's bank inventory, handling currency and item slots. Manages client-server synchronization and broadcast handling for bank operations.
-
public long LastInteractableID { get; set; }
The ID of the last interactable bank object used by the player. Used for tracking which bank was accessed most recently.
-
public long Currency { get; set; }
The amount of currency stored in the bank.
-
public override void OnAwake()
Called when the bank controller is initialized. Resets currency and adds 100 item slots.
-
public override void ResetState(bool asServer)
Resets the state of the bank controller, clearing all items and calling base reset logic. asServer (bool): True if called on the server.
-
public override void OnStartCharacter()
Called when the character starts. Registers client broadcast handlers for bank operations if the local player owns this bank. Disables the controller for non-owners.
-
public override void OnStopCharacter()
Called when the character stops. Unregisters client broadcast handlers for bank operations if the local player owns this bank.
-
private void OnClientBankSetItemBroadcastReceived(BankSetItemBroadcast msg, Channel channel)
Handles a broadcast from the server to set a single item in the bank. Updates the specified slot with the received item details. msg (BankSetItemBroadcast): The broadcast message containing item data. channel (Channel): The network channel used for the broadcast.
-
private void OnClientBankSetMultipleItemsBroadcastReceived(BankSetMultipleItemsBroadcast msg, Channel channel)
Handles a broadcast from the server to set multiple items in the bank. Updates each specified slot with the received item details. msg (BankSetMultipleItemsBroadcast): The broadcast message containing multiple items. channel (Channel): The network channel used for the broadcast.
-
private void OnClientBankRemoveItemBroadcastReceived(BankRemoveItemBroadcast msg, Channel channel)
Handles a broadcast from the server to remove an item from a bank slot. Removes the item from the specified slot with server authority. msg (BankRemoveItemBroadcast): The broadcast message containing the slot to remove. channel (Channel): The network channel used for the broadcast.
-
private void OnClientBankSwapItemSlotsBroadcastReceived(BankSwapItemSlotsBroadcast msg, Channel channel)
Handles a broadcast from the server to swap item slots in the bank or between inventories. Performs the swap operation based on the source inventory type. msg (BankSwapItemSlotsBroadcast): The broadcast message containing swap details. channel (Channel): The network channel used for the broadcast.
-
public override bool CanManipulate()
Determines if the bank can be manipulated (e.g., items moved or swapped). Always returns true unless base logic restricts manipulation. Returns: True if manipulation is allowed, false otherwise.
-
public bool CanSwapItemSlots(int from, int to, InventoryType fromInventory)
Determines if two item slots can be swapped, preventing swaps within the same bank slot. from (int): The source slot index. to (int): The destination slot index. fromInventory (InventoryType): The inventory type of the source slot. Returns: True if the slots can be swapped, false otherwise.
- Attach BankController to the player or character GameObject.
- The bank will be initialized with 100 item slots and zero currency.
- Use the provided methods and broadcasts to synchronize bank state between client and server.
// Example 1: Initializing the bank controller
bankController.OnAwake();
// Example 2: Handling a bank item broadcast
// (Called automatically by the network system)
// Example 3: Checking if slots can be swapped
bool canSwap = bankController.CanSwapItemSlots(0, 1, InventoryType.Bank);
- Always use the provided methods to manipulate bank items and currency.
- Register and unregister broadcast handlers to keep the client and server in sync.
- Prevent swapping the same slot within the bank to avoid unnecessary operations.
- Extend BankController for custom bank logic or additional features as needed.