RuneHive-Game
Loading...
Searching...
No Matches
TriviaBot.java
Go to the documentation of this file.
1package com.runehive.content.triviabot;
2
3import com.runehive.Config;
4import com.runehive.content.achievement.AchievementHandler;
5import com.runehive.content.achievement.AchievementKey;
6import com.runehive.game.world.World;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.entity.mob.player.PlayerRight;
9import com.runehive.net.packet.out.SendMessage;
10import com.runehive.util.Utility;
11
12import java.util.Arrays;
13import java.util.Collections;
14import java.util.HashSet;
15import java.util.Set;
16
17import static com.runehive.game.world.items.containers.bank.VaultCurrency.BLOOD_MONEY;
18import static com.runehive.game.world.items.containers.bank.VaultCurrency.COINS;
19
20/**
21 * Manages the trivia bot system.
22 *
23 * @author Daniel
24 */
25public class TriviaBot {
26
27 /**
28 * Holds all the bot data.
29 */
30 private final static Set<TriviaBotData> DATA = new HashSet<>();
31
32 /**
33 * The current question/answer set.
34 */
35 private static TriviaBotData CURRENT = null;
36
37 /**
38 * Color of the TriviaBot messages.
39 */
40 private static final String COLOR = "<col=354CE6>";
41
42 public static int answeredTotal = 0;
43 /**
44 * Declares the TriviaBot data.
45 */
46 public static void declare() {
47 Collections.addAll(DATA, TriviaBotData.values());
48 }
49
50 /**
51 * Assigns a new question
52 */
53 public static void assign() {
54 // DISABLED
55 // CURRENT = Utility.randomElement(DATA);
56 // World.sendMessage(COLOR + "<icon=21> TriviaBot: </col>" + CURRENT.getQuestion(), player -> player.settings.triviaBot);
57 }
58
59 /**
60 * Handles player answering the question
61 */
62 public static void answer(Player player, String answer) {
63 if (!player.settings.triviaBot) {
64 return;
65 }
66 if (CURRENT == null) {
67 player.send(new SendMessage(COLOR + "<icon=21> TriviaBot: </col>There is no question currently assigned!"));
68 return;
69 }
70 if (Arrays.stream(Config.BAD_STRINGS).anyMatch(answer::contains)) {
71 player.send(new SendMessage(COLOR + "<icon=21> TriviaBot: </col>You think you're funny, don't you? Guess what? You ain't."));
72 return;
73 }
74 if (Arrays.stream(CURRENT.getAnswers()).anyMatch(a -> a.equalsIgnoreCase(answer))) {
75 answered(player, answer);
76 return;
77 }
78 if (Utility.random(3) == 0) {
79 player.speak("Golly gee! I just entered a wrong trivia answer!");
80 }
81 player.send(new SendMessage(COLOR + "<icon=21> TriviaBot: </col>Sorry, the answer you have entered is incorrect! Try again!"));
82 }
83
84 /**
85 * Handles player answering the question successfully
86 */
87 private static void answered(Player player, String answer) {
88 String color = player.right.getColor();
89 int reward = Utility.random(50, 150);
90 if (PlayerRight.isIronman(player)) {
91 player.bankVault.add(COINS, reward);
93 player.answeredTrivias += 1;
94 player.send(new SendMessage(Utility.formatDigits(reward) + " coins were added into your bank vault."));
95 } else {
96 player.bankVault.add(BLOOD_MONEY, reward);
97 player.answeredTrivias += 1;
99 player.send(new SendMessage(Utility.formatDigits(reward) + " blood money were added into your bank vault."));
100 }
101 // DISABLED
102 // World.sendMessage(COLOR + "<icon=21> TriviaBot: <col=" + color + ">" + player.getName() + "</col> has answered the question correctly!");
103 CURRENT = null;
104 }
105}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final String[] BAD_STRINGS
Strings that are classified as bad.
Definition Config.java:216
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
Manages the trivia bot system.
static void declare()
Declares the TriviaBot data.
static final Set< TriviaBotData > DATA
Holds all the bot data.
static void assign()
Assigns a new question.
static TriviaBotData CURRENT
The current question/answer set.
static final String COLOR
Color of the TriviaBot messages.
static void answer(Player player, String answer)
Handles player answering the question.
static void answered(Player player, String answer)
Handles player answering the question successfully.
void speak(String forceChat)
Sets the mob's forced chat.
Definition Mob.java:127
This class represents a character controlled by a player.
Definition Player.java:125
boolean add(VaultCurrency currency, long amount)
Adds an amount into the player's bank vault with no checks.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
static boolean isIronman(Player player)
Checks if the player is an ironman.