Untitled

 avatar
unknown
plain_text
2 months ago
3.2 kB
6
Indexable
package com.zenyte.plugins.item;

import com.zenyte.game.item.Item;
import com.zenyte.game.model.item.pluginextensions.ItemPlugin;
import com.zenyte.game.world.entity.masks.Animation;
import com.zenyte.game.world.entity.player.Player;
import com.zenyte.game.world.entity.player.dialogue.Dialogue;
import com.zenyte.plugins.dialogue.ItemChat;

/**
 * Item plugin for the Barrelchest unlock scroll
 * This scroll unlocks the ability to fight the Barrelchest boss
 */
public class BarrelchestUnlockScrollOption extends ItemPlugin {
    // Animation for reading the scroll
    private static final Animation READ_ANIM = new Animation(7403);

    // Use the exact same values as in the command
    private static final String ATTRIBUTE_KEY = "barrelchest_unlocked";
    private static final int VARBIT_ID = 10042;

    @Override
    public void handle() {
        bind("Claim", (player, item, slotId) -> {
            // Check access using the same approach as the command
            boolean hasAccess = player.getBooleanAttribute(ATTRIBUTE_KEY);

            if (hasAccess) {
                player.sendMessage("You've already unlocked the ability to fight the Barrelchest.");
                return;
            }

            player.getDialogueManager().start(new Dialogue(player) {
                @Override
                public void buildDialogue() {
                    item(item, "Claiming this scroll will unlock the ability to fight the fearsome Barrelchest.");
                    options("This will consume the scroll!",
                            "Claim",
                            "Cancel")
                            .onOptionOne(() -> {
                                // Check again inside the dialogue option
                                if (player.getBooleanAttribute(ATTRIBUTE_KEY)) {
                                    player.sendMessage("You've already unlocked the ability to fight the Barrelchest.");
                                    return;
                                }

                                // Remove the scroll
                                player.getInventory().deleteItem(slotId, item);

                                // Lock the player during animation
                                player.lock(5);
                                player.setAnimation(READ_ANIM);

                                // Use EXACTLY the same code as the test command
                                player.putBooleanAttribute(ATTRIBUTE_KEY, true);
                                player.getVarManager().sendBit(VARBIT_ID, 1);

                                // Log the action for debugging
                                player.sendMessage("DEBUG: Barrelchest access granted - Attribute set to true");

                                player.getDialogueManager().start(new ItemChat(player, item,
                                        "You claim the scroll, unlocking the ability to fight the Barrelchest."));
                            });
                }
            });
        });
    }

    @Override
    public int[] getItems() {
        return new int[]{26500};
    }
}
Editor is loading...
Leave a Comment