Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] Initial Astreaus Dialogue System Rip #631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions 2006Scape Server/plugins/plugin/buttons/DialogueOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package plugin.buttons;

import com.rs2.event.SubscribesTo;
import com.rs2.event.impl.ButtonActionEvent;
import com.rs2.game.dialog.Dialogue;
import com.rs2.game.players.Player;

@SubscribesTo(ButtonActionEvent.class)
public final class DialogueOptions extends ButtonClick {

@Override
protected void execute(Player player, ButtonActionEvent event) {
switch (event.getButton()) {

// First Option (Option Interfaces 2, 3, 4, and 5)
case 9157:
case 9167:
case 9178:
case 9190:
player.getDialogueFactory().executeOption(0, player.getOptionDialogue());
break;
// Second Option (Option Interfaces 2, 3, 4, and 5)
case 9158:
case 9168:
case 9179:
case 9191:
player.getDialogueFactory().executeOption(1, player.getOptionDialogue());
break;
// Third Option (Option Interfaces 3, 4, and 5)
case 9169:
case 9180:
case 9192:
player.getDialogueFactory().executeOption(2, player.getOptionDialogue());
break;
// Fourth Option (Option Interfaces 4 and 5)
case 9181:
case 9193:
player.getDialogueFactory().executeOption(3, player.getOptionDialogue());
break;
// Fifth Option (Option Interface 5)
case 9194:
player.getDialogueFactory().executeOption(4, player.getOptionDialogue());
break;

}
}

@Override
public boolean test(ButtonActionEvent event) {
return Dialogue.isDialogueButton(event.getButton());
}

}
28 changes: 28 additions & 0 deletions 2006Scape Server/plugins/plugin/npc/shopkeeper/FirstClick.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package plugin.npc.shopkeeper;

import com.rs2.event.EventContext;
import com.rs2.event.EventSubscriber;
import com.rs2.event.SubscribesTo;
import com.rs2.event.impl.NpcFirstClickEvent;
import com.rs2.game.players.Player;

import static com.rs2.game.content.StaticNpcList.SHOP_KEEPER_528;

@SubscribesTo(NpcFirstClickEvent.class)
public final class FirstClick implements EventSubscriber<NpcFirstClickEvent> {

@Override
public void subscribe(EventContext context, Player player, NpcFirstClickEvent event) {
if (player.playerRights == 3) {
player.getPacketSender().sendMessage("[click= npc], [type = first], [id= " + event.getNpc() + "], [Type= " + event.getNpc() + "]");
}

switch (event.getNpc()) {

case SHOP_KEEPER_528:
player.getDialogueFactory().sendDialogue(new GeneralStoreDialogue());
break;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package plugin.npc.shopkeeper;

import com.rs2.game.dialog.Dialogue;
import com.rs2.game.dialog.DialogueFactory;


public final class GeneralStoreDialogue extends Dialogue {
@Override
public void sendDialogues(DialogueFactory factory) {
factory.getPlayer().dialoguePlugin = true;
Copy link
Contributor

@ipkpjersi ipkpjersi Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name the variable here dialogue, not factory, since dialogue is a more descriptive name of what it is.

factory.sendNpcChat("Can I help you at all?")
.sendOption("Yes please. What are you selling?", () -> {
factory.onAction(() -> {
factory.getPlayer().getShopAssistant().openShop(88);
});
}, "No thanks.", () -> {
factory.sendPlayerChat("No thanks.");
}).execute();
}

}

13 changes: 13 additions & 0 deletions 2006Scape Server/src/main/java/com/rs2/game/dialog/Chainable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.rs2.game.dialog;

import java.util.function.Consumer;

/**
* The chain-able interface that allows implementing dialogue factories the ability to chain together.
*
* @author Vult-R
*/
public interface Chainable extends Consumer<DialogueFactory> {

}

45 changes: 45 additions & 0 deletions 2006Scape Server/src/main/java/com/rs2/game/dialog/Dialogue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.rs2.game.dialog;

import com.google.common.collect.ImmutableList;
import com.rs2.game.players.Player;

/**
* Represents an abstract dialogue, in which extending classes will be able to construct and send dialogues
* to a player.
*
* @author Vult-R
*/
public abstract class Dialogue {

private static Player player;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be static.


/**
* The action buttons responsible for dialogues.
*/
public static final ImmutableList<Integer> DIALOGUE_BUTTONS = ImmutableList.of(9157, 9167, 9178, 9190,
9158, 9168, 9179, 9191, 9169, 9180, 9192, 9181, 9193, 9194);

/**
* Sends a player a dialogue.
*
* @param factory
* The factory for this dialogue.
*/
public abstract void sendDialogues(DialogueFactory factory);

/**
* Checks if the button triggered is an optional dialogue button.
*
* @param button
* The index of the button being checked.
*
* @return The result of the operation.
*/
public static final boolean isDialogueButton(int button) {
if (player.dialoguePlugin) {
return DIALOGUE_BUTTONS.stream().anyMatch(search -> search == button);
} else {
return false;
}
}
}
Loading