RuneHive-Game
Loading...
Searching...
No Matches
BankPin.java
Go to the documentation of this file.
1package com.runehive.game.world.items.containers.bank;
2
3import com.runehive.content.dialogue.DialogueFactory;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.net.packet.out.SendInputMessage;
6import com.runehive.net.packet.out.SendMessage;
7import com.runehive.util.MessageColor;
8
9/**
10 * Handles the bank pin system.
11 *
12 * @author Daniel
13 * @since 13-1-2017.
14 */
15public class BankPin {
16
17 /** The player instance. */
18 private final Player player;
19
20 /** The player's bank pin. */
21 public String pin;
22
23 /** If the player has unlocked the bank for this session. */
24 public boolean entered = false;
25
26 /** Constructs a new <code>BankPin</code>. */
28 this.player = player;
29 }
30
31 /** Handles opening the bank pin dialogue. */
32 public void open() {
33 DialogueFactory factory = player.dialogueFactory;
34 factory.sendOption("Set Bank Pin", () -> set(factory), "Remove Bank Pin", () -> remove(factory), "Nevermind", factory::clear);
35 factory.execute();
36 }
37
38 private void set(DialogueFactory factory) {
39 factory.sendStatement("Enter a 4-5 digit pin for your bank.", "Make sure to write it down!").onAction(() -> {
40 player.send(new SendInputMessage("Enter the pin you would like to assign your bank:", 5, input -> {
41 if (input.length() < 4 || input.length() > 5) {
42 player.send(new SendMessage("Your pin must have 4-5 digits.", MessageColor.RED));
43 return;
44 }
45
46 pin = input;
47 entered = true;
48 player.send(new SendMessage("Your new bank pin is now: " + pin + ". Write it down!", MessageColor.BLUE));
49 factory.clear();
50 }));
51 }).execute();
52 }
53
54 private void remove(DialogueFactory factory) {
55 factory.onAction(() -> {
56 if (!hasPin()) {
57 player.send(new SendMessage("You don't have a pin set!"));
58 factory.clear();
59 return;
60 }
61 player.send(new SendInputMessage("Enter your bank pin:", 5, input -> {
62 if (!pin.equalsIgnoreCase(input)) {
63 player.send(new SendMessage("You have entered an invalid bank pin!", MessageColor.RED));
64 factory.clear();
65 return;
66 }
67
68 pin = null;
69 player.send(new SendMessage("You have successfully removed your bank pin.", MessageColor.BLUE));
70 factory.clear();
71 }));
72 });
73
74 }
75
76 /** Handles entering the bank pin. */
77 public void enter() {
78 player.send(new SendInputMessage("Enter your bank pin:", 5, input -> {
79
80 if (!pin.equalsIgnoreCase(input)) {
81 player.dialogueFactory.sendStatement("You have entered an invalid bank pin!").execute();
82 return;
83 }
84
85 entered = true;
86 player.send(new SendMessage("You have successfully entered your bank pin. You can access your bank for this session.", MessageColor.BLUE));
87 player.bank.open();
88 }));
89 }
90
91 /** Checks if player has a bank pin. */
92 public boolean hasPin() {
93 return pin != null;
94 }
95}
Represents a factory class that contains important functions for building dialogues.
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
This class represents a character controlled by a player.
Definition Player.java:125
BankPin(Player player)
Constructs a new BankPin.
Definition BankPin.java:27
boolean entered
If the player has unlocked the bank for this session.
Definition BankPin.java:24
void open()
Handles opening the bank pin dialogue.
Definition BankPin.java:32
void enter()
Handles entering the bank pin.
Definition BankPin.java:77
boolean hasPin()
Checks if player has a bank pin.
Definition BankPin.java:92
final Player player
The player instance.
Definition BankPin.java:18
Sends a chatbox input prompt that accepts full text with spaces.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Holds an enum of colors for ease.