1package com.runehive.content.ai;
3import com.runehive.content.dialogue.Expression;
4import com.runehive.game.world.entity.mob.npc.Npc;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.position.Position;
7import org.slf4j.Logger;
8import org.slf4j.LoggerFactory;
10import com.runehive.game.task.Task;
11import com.runehive.game.world.World;
12import java.util.concurrent.atomic.AtomicBoolean;
15import java.util.concurrent.ConcurrentHashMap;
36 player.
move(playerTarget);
40 player.dialogueCamNpc = npc;
41 player.dialogueCamMode = com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.Mode.BEHIND_PLAYER;
57 player.dialogueFactory
58 .sendPlayerChat(
"Hey, Wise Old Man!")
59 .onAction(() -> player.
dialogueCamMode = com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.Mode.BEHIND_NPC)
62 "I am Gandalf GPT4o. I can connect to the OpenAI",
63 "mystical networks to provide you with advanced",
66 "Would you like me to establish this connection?")
68 "Yes, connect to OpenAI", () -> {
70 logger.info(
"Player {} consented to OpenAI connection for this session", player.
getUsername());
73 String timestamp =
new java.text.SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss").format(
new java.util.Date());
74 player.
message(
"<col=0000FF>[OpenAI Service] Initialized at " + timestamp +
". Conversation History = 10.</col>");
78 "No, maybe later", () -> {
79 player.dialogueFactory
81 "Very well. I shall remain here if you change",
82 "your mind. The mystical networks await when",
95 player.dialogueFactory
97 "Alas! The mystical networks are unreachable.",
98 "Please ensure the OpenAI key scroll is present",
99 "and try again later.")
110 logger.info(
"Player accepted OpenAI connection - initializing OpenAI services...");
115 logger.info(
"Official OpenAI Service initialized with GPT-4o-mini model");
117 logger.info(
"OpenAI services fully initialized and ready for interactions!");
120 }
catch (Exception e) {
121 logger.error(
"Failed to initialize OpenAI services", e);
138 npc.
animate(
new com.runehive.game.Animation(858));
139 npc.
speak(
"GPT 4o at your service!");
140 player.dialogueFactory
141 .sendPlayerChat(
"Hello again, Wise Old Man!")
142 .onAction(() -> player.
dialogueCamMode = com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.Mode.BEHIND_NPC)
144 "To send a message, type:",
145 "<col=0000FF>::gpt <your message></col>")
148 com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.requestReset(player);
155 player.dialogueFactory
156 .sendPlayerChat(
"Hello again, Wise Old Man!")
157 .onAction(() -> player.
dialogueCamMode = com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.Mode.BEHIND_NPC)
159 "To send a message, type:",
160 "<col=0000FF>::gpt <your message></col>")
163 com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.requestReset(player);
176 int warningsSent = 0;
179 public void execute() {
185 if (warningsSent == 0) {
186 player.dialogueFactory
188 "Hey " + player.
getUsername() +
", I'm still here!",
189 "If I don't hear back from you within 1 minute,",
190 "I shall close the OpenAI realms. Your message",
191 "history would be reset in this event.")
195 player.dialogueFactory
218 logger.info(
"Cleared OpenAI consent for player: {}", username);
222 String timestamp =
new java.text.SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss").format(
new java.util.Date());
223 player.message(
"<col=0000FF>[OpenAI Service] Terminated at " + timestamp +
". Conversation History flushed.</col>");
236 logger.info(
"Shutting down OpenAI services...");
static OpenAIService getOpenAIService()
static void showGptInstructions(Player player, Npc npc)
static final Logger logger
static void initializeOpenAIAndProcess(Player player, Npc npc)
static final Map< String, Task > inactivityTimers
static void clearPlayerConsent(String username)
static volatile OpenAIService openAIService
static void markInstructionsReceived(String username)
static void showOpenAIConnectionOffer(Player player, Npc npc)
static final int GANDALF_AI_ID
static void showGptInstructionsWithGreeting(Player player, Npc npc)
static boolean isInitialized()
static final AtomicBoolean openAIInitialized
static synchronized boolean initializeOpenAIServices()
static final Set< String > sessionConsents
static boolean handleGandalfAIClick(Player player, Npc npc)
static void startInactivityTimer(Player player, Npc npc)
static void cancelInactivityTimer(String username)
static OpenAIService getInstance()
A game representing a cyclic unit of work.
synchronized final void cancel()
Cancels all subsequent executions.
Represents the game world.
static void schedule(Task task)
Submits a new event.
static Optional< Player > getPlayerByName(String username)
final boolean isRegistered()
void speak(String forceChat)
Sets the mob's forced chat.
void animate(int animation)
void move(Position position)
Moves the mob to a set position.
void face(GameObject object)
Sets the client update flag to face a certain direction.
Represents a non-player character in the in-game world.
void close(int interfaceId)
This class represents a character controlled by a player.
void message(String message)
transient com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.Mode dialogueCamMode
Dialogue camera system.
final InterfaceManager interfaceManager
Represents a single tile on the game world.
int getHeight()
Gets the height coordinate, or height.
int getY()
Gets the absolute y coordinate.
int getX()
Gets the absolute x coordinate.
Represents the expressions of entities for dialogue.