RuneHive-Game
Loading...
Searching...
No Matches
VoteDialogue.java
Go to the documentation of this file.
1package com.runehive.content.dialogue.impl;
2
3import com.runehive.content.dialogue.Dialogue;
4import com.runehive.content.dialogue.DialogueFactory;
5import com.runehive.content.dialogue.Expression;
6import com.runehive.content.store.Store;
7import com.runehive.game.world.World;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.net.packet.out.SendInputAmount;
10import com.runehive.net.packet.out.SendURL;
11import com.runehive.util.Utility;
12
13/**
14 * Handles the vote dialogue.
15 *
16 * @author Daniel
17 */
18public class VoteDialogue extends Dialogue {
19
20 @Override
21 public void sendDialogues(DialogueFactory factory) {
22 Player player = factory.getPlayer();
23 factory.sendNpcChat(7481, Expression.HAPPY, "Hello " + player.getName() + "!", "What can I do for you today?");
24
25 factory.sendOption("Would you want to know what are some of the benefits of voting are?", () -> {
26 factory.sendPlayerChat(Expression.HAPPY, "Yes I would!");
27 factory.sendNpcChat(7481, "Voting results in attracting new players!", "In return, you'll receive", "vote points that you can use to buy", "items from the vote store.");
28 }, "Exchange vote token", () -> {
29 World.schedule(1, () -> player.send(new SendInputAmount("How many vote tokens would you like to exchange?", 10, input -> exchange(factory, Integer.parseInt(input)))));
30 }, "Show me your voting store!", () -> {
31 Store.STORES.get("osroyale Vote Store").open(player);
32 }, "I would like to vote to support this great server!", () -> {
33 player.send(new SendURL("https://runehive.com"));
34 factory.sendNpcChat(7481, "Thank you for voting!");
35 }, "Nevermind, I don't want to do anything for this server.", () -> {
36 factory.clear();
37 });
38 factory.execute();
39 }
40
41 /** Handles redeeming vote tokens. */
42 private void exchange(DialogueFactory factory, int amount) {
43 Player player = factory.getPlayer();
44 if (amount > 10000) {
45 factory.sendNpcChat(7481, Expression.SAD, "Sorry but you can only exchange", " 10,000 tokens at a time!").execute();
46 return;
47 }
48
49 int tokenAmount = player.inventory.computeAmountForId(7478);
50
51 if (amount > tokenAmount)
52 amount = tokenAmount;
53
54 if (amount == 0) {
55 factory.sendNpcChat(7481, Expression.SAD, "Sorry but you do not have enough", "vote tokens to do this!").execute();
56 return;
57 }
58
59 player.votePoints += amount;
60 player.inventory.remove(7478, amount);
61 factory.sendNpcChat(7481, Expression.SAD, "I've exchanged " + amount + " vote tokens for you!", "You now have " + Utility.formatDigits(player.votePoints) + " vote points!").execute();
62 }
63}
Represents a factory class that contains important functions for building dialogues.
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
void clear()
Clears the current dialogue chain.
final DialogueFactory sendPlayerChat(String... lines)
Appends a PlayerDialogue to the current dialogue chain.
Player getPlayer()
The player that owns this factory.
final DialogueFactory sendNpcChat(int id, String... lines)
Appends an NpcDialogue to the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
Represents an abstract dialogue, in which extending classes will be able to construct and send dialog...
Definition Dialogue.java:11
void exchange(DialogueFactory factory, int amount)
Handles redeeming vote tokens.
void sendDialogues(DialogueFactory factory)
Sends a player a dialogue.
The class which holds support for further abstraction for shops.
Definition Store.java:20
static Map< String, Store > STORES
A mapping of each shop by it's name.
Definition Store.java:23
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
This class represents a character controlled by a player.
Definition Player.java:125
String getName()
Gets the name of this entity.
Definition Player.java:774
final int computeAmountForId(int id)
Computes the total quantity of the Items in this container with id.
boolean remove(Item item)
Attempts to withdraw item from this container.
The OutgoingPacket that opens a URL from client.
Definition SendURL.java:12
Handles miscellaneous methods.
Definition Utility.java:27
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
Represents the expressions of entities for dialogue.