RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
DialogueScript.java
1package com.osroyale.content.dialogue.script;
2
3import com.osroyale.content.dialogue.DialogueFactory;
4import com.osroyale.content.dialogue.Expression;
5import com.osroyale.game.world.entity.mob.npc.Npc;
6import com.osroyale.game.world.entity.mob.player.Player;
7
8import java.util.ArrayList;
9import java.util.List;
10
33
34public class DialogueScript {
35
36 private final int[] npcIds;
37 private final List<DialogueAction> actions;
38
39 public DialogueScript(int[] npcIds) {
40 this.npcIds = npcIds;
41 this.actions = new ArrayList<>();
42 }
43
44 public void addAction(DialogueAction action) {
45 actions.add(action);
46 }
47
48 public void execute(Player player, Npc npc) {
49 if (actions.isEmpty()) {
50 return;
51 }
52
53 DialogueFactory factory = player.dialogueFactory;
54
55 for (DialogueAction action : actions) {
56 action.apply(factory, player, npc);
57 }
58
59 factory.execute();
60 }
61
62 public int[] getNpcIds() {
63 return npcIds;
64 }
65
66 public interface DialogueAction {
67 void apply(DialogueFactory factory, Player player, Npc npc);
68 }
69
70 public static class NpcDialogueAction implements DialogueAction {
71 private final String[] messages;
72 private final Expression expression;
73
74 public NpcDialogueAction(String[] messages, Expression expression) {
75 this.messages = messages;
76 this.expression = expression;
77 }
78
79 @Override
80 public void apply(DialogueFactory factory, Player player, Npc npc) {
81 factory.sendNpcChat(npc.id, expression, messages);
82 }
83 }
84
85 public static class PlayerDialogueAction implements DialogueAction {
86 private final String[] messages;
87 private final Expression expression;
88
89 public PlayerDialogueAction(String[] messages, Expression expression) {
90 this.messages = messages;
91 this.expression = expression;
92 }
93
94 @Override
95 public void apply(DialogueFactory factory, Player player, Npc npc) {
96 factory.sendPlayerChat(expression, messages);
97 }
98 }
99
100 public static class StatementAction implements DialogueAction {
101 private final String[] messages;
102
103 public StatementAction(String[] messages) {
104 this.messages = messages;
105 }
106
107 @Override
108 public void apply(DialogueFactory factory, Player player, Npc npc) {
109 factory.sendStatement(messages);
110 }
111 }
112
113 public static class OptionAction implements DialogueAction {
114 private final String title;
115 private final String[] options;
116 private final Runnable[] actions;
117
118 public OptionAction(String title, String[] options, Runnable[] actions) {
119 this.title = title;
120 this.options = options;
121 this.actions = actions;
122 }
123
124 @Override
125 public void apply(DialogueFactory factory, Player player, Npc npc) {
126 // Simple implementation: just display first 2 options with dummy actions
127 if (options.length >= 2) {
128 factory.sendOption(options[0], () -> {}, options[1], () -> {});
129 } else if (options.length == 1) {
130 factory.sendOption(options[0], () -> {}, "Nevermind", () -> {});
131 }
132 }
133 }
134}
final DialogueFactory sendStatement(String... lines)
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
final DialogueFactory sendPlayerChat(String... lines)
final DialogueFactory sendNpcChat(int id, String... lines)