Search in sources :

Example 16 with IQuest

use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.

the class QuestCommandDelete method runCommand.

@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
    if (args[1].equalsIgnoreCase("all")) {
        QuestDatabase.INSTANCE.reset();
        QuestLineDatabase.INSTANCE.reset();
        PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
        PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
        sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.delete.all"));
    } else {
        try {
            int id = Integer.parseInt(args[1].trim());
            IQuest quest = QuestDatabase.INSTANCE.getValue(id);
            QuestDatabase.INSTANCE.removeKey(id);
            PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
            sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.delete.single", new TextComponentTranslation(quest.getUnlocalisedName())));
        } catch (Exception e) {
            throw getException(command);
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IQuest(betterquesting.api.questing.IQuest) CommandException(net.minecraft.command.CommandException)

Example 17 with IQuest

use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.

the class QuestCommandReset method runCommand.

@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
    String action = args[1];
    UUID uuid = null;
    if (args.length == 3) {
        uuid = this.findPlayerID(server, sender, args[2]);
        if (uuid == null) {
            throw this.getException(command);
        }
    }
    String pName = uuid == null ? "NULL" : NameCache.INSTANCE.getName(uuid);
    if (action.equalsIgnoreCase("all")) {
        for (IQuest quest : QuestDatabase.INSTANCE.getAllValues()) {
            if (uuid != null) {
                // Clear progress and state
                quest.resetUser(uuid, true);
            } else {
                quest.resetAll(true);
            }
        }
        if (uuid != null) {
            sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_all", pName));
        } else {
            sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_all"));
        }
    } else {
        try {
            int id = Integer.parseInt(action.trim());
            IQuest quest = QuestDatabase.INSTANCE.getValue(id);
            if (uuid != null) {
                // Clear progress and state
                quest.resetUser(uuid, true);
                sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_single", new TextComponentTranslation(quest.getUnlocalisedName()), pName));
            } else {
                quest.resetAll(true);
                sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_single", new TextComponentTranslation(quest.getUnlocalisedName())));
            }
        } catch (Exception e) {
            throw getException(command);
        }
    }
    PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IQuest(betterquesting.api.questing.IQuest) UUID(java.util.UUID) CommandException(net.minecraft.command.CommandException)

Example 18 with IQuest

use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.

the class ToolboxToolCopy method onMouseClick.

@Override
public void onMouseClick(int mx, int my, int click) {
    if (click == 1 && btnQuest != null) {
        btnQuest = null;
    } else if (click != 0) {
        return;
    }
    int snap = ToolboxGuiMain.getSnapValue();
    int modX = ((mx % snap) + snap) % snap;
    int modY = ((my % snap) + snap) % snap;
    mx -= modX;
    my -= modY;
    if (btnQuest == null) {
        GuiButtonQuestInstance tmpBtn = gui.getQuestLine().getButtonAt(mx, my);
        if (tmpBtn != null) {
            // Unregistered but setup
            QuestInstance tmpQ = new QuestInstance();
            tmpQ.readFromNBT(tmpBtn.getQuest().writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG), EnumSaveType.CONFIG);
            btnQuest = new GuiButtonQuestInstance(0, mx, my, tmpBtn.width, tmpBtn.height, tmpQ);
        }
    } else {
        // Pre-sync
        IQuest quest = btnQuest.getQuest();
        IQuestLine qLine = gui.getQuestLine().getQuestLine();
        int qID = QuestDatabase.INSTANCE.nextKey();
        int lID = QuestLineDatabase.INSTANCE.getKey(qLine);
        QuestLineEntry qe = new QuestLineEntry(mx, my, Math.max(btnQuest.width, btnQuest.height));
        qLine.add(qe, qID);
        btnQuest = null;
        // Sync Quest
        NBTTagCompound tag1 = new NBTTagCompound();
        NBTTagCompound base1 = new NBTTagCompound();
        base1.setTag("config", quest.writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG));
        tag1.setTag("data", base1);
        tag1.setInteger("action", EnumPacketAction.ADD.ordinal());
        tag1.setInteger("questID", qID);
        PacketSender.INSTANCE.sendToServer(new QuestingPacket(PacketTypeNative.QUEST_EDIT.GetLocation(), tag1));
        // Sync Line
        NBTTagCompound tag2 = new NBTTagCompound();
        NBTTagCompound base2 = new NBTTagCompound();
        base2.setTag("line", qLine.writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG));
        tag2.setTag("data", base2);
        tag2.setInteger("action", EnumPacketAction.EDIT.ordinal());
        tag2.setInteger("lineID", lID);
        PacketSender.INSTANCE.sendToServer(new QuestingPacket(PacketTypeNative.LINE_EDIT.GetLocation(), tag2));
    }
}
Also used : GuiButtonQuestInstance(betterquesting.api.client.gui.controls.GuiButtonQuestInstance) IQuest(betterquesting.api.questing.IQuest) GuiButtonQuestInstance(betterquesting.api.client.gui.controls.GuiButtonQuestInstance) QuestInstance(betterquesting.questing.QuestInstance) IQuestLine(betterquesting.api.questing.IQuestLine) QuestLineEntry(betterquesting.questing.QuestLineEntry) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) QuestingPacket(betterquesting.api.network.QuestingPacket)

Example 19 with IQuest

use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.

the class QuestLineButtonTree method RebuildTree.

public void RebuildTree() {
    buttonTree.clear();
    treeW = 0;
    treeH = 0;
    if (line == null) {
        return;
    }
    for (int id : line.getAllKeys()) {
        IQuest quest = QuestingAPI.getAPI(ApiReference.QUEST_DB).getValue(id);
        IQuestLineEntry entry = line.getValue(id);
        if (quest != null && entry != null) {
            buttonTree.add(new GuiButtonQuestInstance(0, entry.getPosX(), entry.getPosY(), entry.getSize(), entry.getSize(), quest));
        }
    }
    // Offset origin to 0,0 and establish bounds
    for (GuiButtonQuestInstance btn : buttonTree) {
        if (btn == null) {
            continue;
        }
        treeW = Math.max(btn.x + btn.width, treeW);
        treeH = Math.max(btn.y + btn.height, treeH);
        for (GuiButtonQuestInstance b2 : buttonTree) {
            if (b2 == null || btn == b2 || btn.getQuest() == null) {
                continue;
            }
            if (btn.getQuest().getPrerequisites().contains(b2.getQuest())) {
                btn.addParent(b2);
            }
        }
    }
}
Also used : GuiButtonQuestInstance(betterquesting.api.client.gui.controls.GuiButtonQuestInstance) IQuest(betterquesting.api.questing.IQuest) IQuestLineEntry(betterquesting.api.questing.IQuestLineEntry)

Example 20 with IQuest

use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.

the class QuestLineButtonTree method getButtonAt.

public GuiButtonQuestInstance getButtonAt(int x, int y) {
    if (line == null) {
        return null;
    }
    int id = line.getQuestAt(x, y);
    IQuest quest = QuestingAPI.getAPI(ApiReference.QUEST_DB).getValue(id);
    if (quest == null) {
        return null;
    }
    for (GuiButtonQuestInstance btn : buttonTree) {
        if (btn.getQuest() == quest) {
            return btn;
        }
    }
    return null;
}
Also used : GuiButtonQuestInstance(betterquesting.api.client.gui.controls.GuiButtonQuestInstance) IQuest(betterquesting.api.questing.IQuest)

Aggregations

IQuest (betterquesting.api.questing.IQuest)44 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 ITask (betterquesting.api.questing.tasks.ITask)9 UUID (java.util.UUID)9 QuestInstance (betterquesting.questing.QuestInstance)8 ArrayList (java.util.ArrayList)6 GuiButtonQuestInstance (betterquesting.api.client.gui.controls.GuiButtonQuestInstance)5 QuestingPacket (betterquesting.api.network.QuestingPacket)4 IQuestLine (betterquesting.api.questing.IQuestLine)4 HashMap (java.util.HashMap)4 NBTBase (net.minecraft.nbt.NBTBase)4 GuiButtonThemed (betterquesting.api.client.gui.controls.GuiButtonThemed)3 IQuestLineEntry (betterquesting.api.questing.IQuestLineEntry)3 PanelButtonStorage (betterquesting.api2.client.gui.controls.PanelButtonStorage)3 QuestLineEntry (betterquesting.questing.QuestLineEntry)3 List (java.util.List)3 Minecraft (net.minecraft.client.Minecraft)3 CommandException (net.minecraft.command.CommandException)3 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)3 IPanelButton (betterquesting.api2.client.gui.controls.IPanelButton)2