RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
TriviaBot.java
1package com.osroyale.content.triviabot;
2
3import com.osroyale.Config;
4import com.osroyale.content.achievement.AchievementHandler;
5import com.osroyale.content.achievement.AchievementKey;
6import com.osroyale.game.world.World;
7import com.osroyale.game.world.entity.mob.player.Player;
8import com.osroyale.game.world.entity.mob.player.PlayerRight;
9import com.osroyale.net.packet.out.SendMessage;
10import com.osroyale.util.Utility;
11
12import java.util.Arrays;
13import java.util.Collections;
14import java.util.HashSet;
15import java.util.Set;
16
17import static com.osroyale.game.world.items.containers.bank.VaultCurrency.BLOOD_MONEY;
18import static com.osroyale.game.world.items.containers.bank.VaultCurrency.COINS;
19
56
57public class TriviaBot {
58
62 private final static Set<TriviaBotData> DATA = new HashSet<>();
63
67 private static TriviaBotData CURRENT = null;
68
72 private static final String COLOR = "<col=354CE6>";
73
74 public static int answeredTotal = 0;
78 public static void declare() {
79 Collections.addAll(DATA, TriviaBotData.values());
80 }
81
85 public static void assign() {
86 CURRENT = Utility.randomElement(DATA);
87 World.sendMessage(COLOR + "<icon=21> TriviaBot: </col>" + CURRENT.getQuestion(), player -> player.settings.triviaBot);
88 }
89
93 public static void answer(Player player, String answer) {
94 if (!player.settings.triviaBot) {
95 return;
96 }
97 if (CURRENT == null) {
98 player.send(new SendMessage(COLOR + "<icon=21> TriviaBot: </col>There is no question currently assigned!"));
99 return;
100 }
101 if (Arrays.stream(Config.BAD_STRINGS).anyMatch(answer::contains)) {
102 player.send(new SendMessage(COLOR + "<icon=21> TriviaBot: </col>You think you're funny, don't you? Guess what? You ain't."));
103 return;
104 }
105 if (Arrays.stream(CURRENT.getAnswers()).anyMatch(a -> a.equalsIgnoreCase(answer))) {
106 answered(player, answer);
107 return;
108 }
109 if (Utility.random(3) == 0) {
110 player.speak("Golly gee! I just entered a wrong trivia answer!");
111 }
112 player.send(new SendMessage(COLOR + "<icon=21> TriviaBot: </col>Sorry, the answer you have entered is incorrect! Try again!"));
113 }
114
118 private static void answered(Player player, String answer) {
119 String color = player.right.getColor();
120 int reward = Utility.random(50, 150);
121 if (PlayerRight.isIronman(player)) {
122 player.bankVault.add(COINS, reward);
123 AchievementHandler.activate(player, AchievementKey.TRIVIABOT, 1);
124 player.answeredTrivias += 1;
125 player.send(new SendMessage(Utility.formatDigits(reward) + " coins were added into your bank vault."));
126 } else {
127 player.bankVault.add(BLOOD_MONEY, reward);
128 player.answeredTrivias += 1;
129 AchievementHandler.activate(player, AchievementKey.TRIVIABOT, 1);
130 player.send(new SendMessage(Utility.formatDigits(reward) + " blood money were added into your bank vault."));
131 }
132 World.sendMessage(COLOR + "<icon=21> TriviaBot: <col=" + color + ">" + player.getName() + "</col> has answered the question correctly!");
133 CURRENT = null;
134 }
135}
static final String[] BAD_STRINGS
Definition Config.java:254
static void activate(Player player, AchievementKey achievement)
static void answer(Player player, String answer)
static void sendMessage(String... messages)
Definition World.java:433
void speak(String forceChat)
Definition Mob.java:164
boolean add(VaultCurrency currency, long amount)
static String formatDigits(final int amount)
Definition Utility.java:78
static< T > T randomElement(Collection< T > collection)
Definition Utility.java:285