Search in sources :

Example 26 with IQuest

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

the class GuiRewardEditor method refreshGui.

@Override
public void refreshGui() {
    IQuest tmp = QuestDatabase.INSTANCE.getValue(qID);
    if (tmp == null) {
        mc.displayGuiScreen(parent);
        return;
    }
    this.quest = tmp;
    this.rewardIDs = quest.getRewards().getAllKeys();
    RefreshColumns();
}
Also used : IQuest(betterquesting.api.questing.IQuest)

Example 27 with IQuest

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

the class GuiTaskEditor method refreshGui.

@Override
public void refreshGui() {
    IQuest tmp = QuestDatabase.INSTANCE.getValue(qId);
    if (tmp == null) {
        mc.displayGuiScreen(parent);
        return;
    }
    this.quest = tmp;
    this.taskIDs = quest.getTasks().getAllKeys();
    RefreshColumns();
}
Also used : IQuest(betterquesting.api.questing.IQuest)

Example 28 with IQuest

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

the class ToolboxToolNew method onMouseClick.

@Override
public void onMouseClick(int mx, int my, int click) {
    if (click != 0) {
        return;
    }
    int snap = ToolboxGuiMain.getSnapValue();
    int modX = ((mx % snap) + snap) % snap;
    int modY = ((my % snap) + snap) % snap;
    mx -= modX;
    my -= modY;
    // Pre-sync
    IQuestLine qLine = gui.getQuestLine().getQuestLine();
    IQuest quest = new QuestInstance();
    int qID = QuestDatabase.INSTANCE.nextKey();
    int lID = QuestLineDatabase.INSTANCE.getKey(qLine);
    QuestLineEntry qe = new QuestLineEntry(mx, my, 24);
    qLine.add(qe, qID);
    // 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 : IQuest(betterquesting.api.questing.IQuest) IQuestLine(betterquesting.api.questing.IQuestLine) GuiButtonQuestInstance(betterquesting.api.client.gui.controls.GuiButtonQuestInstance) QuestInstance(betterquesting.questing.QuestInstance) QuestLineEntry(betterquesting.questing.QuestLineEntry) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) QuestingPacket(betterquesting.api.network.QuestingPacket)

Example 29 with IQuest

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

the class PktHandlerQuestEdit method handleServer.

@Override
public void handleServer(NBTTagCompound data, EntityPlayerMP sender) {
    if (sender == null) {
        return;
    }
    boolean isOP = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
    if (!isOP) {
        BetterQuesting.logger.log(Level.WARN, "Player " + sender.getName() + " (UUID:" + QuestingAPI.getQuestingUUID(sender) + ") tried to edit quest without OP permissions!");
        sender.sendStatusMessage(new TextComponentString(TextFormatting.RED + "You need to be OP to edit quests!"), false);
        // Player is not operator. Do nothing
        return;
    }
    int aID = !data.hasKey("action") ? -1 : data.getInteger("action");
    int qID = !data.hasKey("questID") ? -1 : data.getInteger("questID");
    IQuest quest = QuestDatabase.INSTANCE.getValue(qID);
    EnumPacketAction action = null;
    if (aID < 0 || aID >= EnumPacketAction.values().length) {
        return;
    }
    action = EnumPacketAction.values()[aID];
    if (action == EnumPacketAction.EDIT && quest != null) {
        quest.readPacket(data);
        PacketSender.INSTANCE.sendToAll(quest.getSyncPacket());
        return;
    } else if (action == EnumPacketAction.REMOVE) {
        if (quest == null || qID < 0) {
            BetterQuesting.logger.log(Level.ERROR, sender.getName() + " tried to delete non-existent quest with ID:" + qID);
            return;
        }
        BetterQuesting.logger.log(Level.INFO, "Player " + sender.getName() + " deleted quest " + quest.getUnlocalisedName());
        QuestDatabase.INSTANCE.removeKey(qID);
        PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
        return;
    } else if (// Force Complete/Reset
    action == EnumPacketAction.SET && quest != null) {
        if (data.getBoolean("state")) {
            UUID senderID = QuestingAPI.getQuestingUUID(sender);
            boolean com = quest.isComplete(senderID);
            if (com && quest instanceof QuestInstance) {
                ((QuestInstance) quest).setClaimed(senderID, 0);
            } else {
                quest.setComplete(senderID, 0);
                int done = 0;
                if (// Preliminary check
                !quest.getProperties().getProperty(NativeProps.LOGIC_TASK).getResult(done, quest.getTasks().size())) {
                    for (ITask task : quest.getTasks().getAllValues()) {
                        task.setComplete(senderID);
                        done += 1;
                        if (quest.getProperties().getProperty(NativeProps.LOGIC_TASK).getResult(done, quest.getTasks().size())) {
                            // Only complete enough quests to claim the reward
                            break;
                        }
                    }
                }
            }
        } else {
            quest.resetAll(true);
        }
        PacketSender.INSTANCE.sendToAll(quest.getSyncPacket());
        return;
    } else if (action == EnumPacketAction.ADD) {
        IQuest nq = new QuestInstance();
        int nID = QuestDatabase.INSTANCE.nextKey();
        if (data.hasKey("data") && data.hasKey("questID")) {
            nID = data.getInteger("questID");
            NBTTagCompound base = data.getCompoundTag("data");
            nq.readFromNBT(base.getCompoundTag("config"), EnumSaveType.CONFIG);
        }
        QuestDatabase.INSTANCE.add(nq, nID);
        PacketSender.INSTANCE.sendToAll(nq.getSyncPacket());
        return;
    }
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IQuest(betterquesting.api.questing.IQuest) EnumPacketAction(betterquesting.api.enums.EnumPacketAction) QuestInstance(betterquesting.questing.QuestInstance) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 30 with IQuest

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

the class PktHandlerQuestSync method handleClient.

@Override
public void handleClient(NBTTagCompound data) {
    int questID = !data.hasKey("questID") ? -1 : data.getInteger("questID");
    IQuest quest = QuestDatabase.INSTANCE.getValue(questID);
    if (quest == null) {
        quest = new QuestInstance();
        QuestDatabase.INSTANCE.add(quest, questID);
    }
    quest.readPacket(data);
    MinecraftForge.EVENT_BUS.post(new DatabaseEvent.Update());
}
Also used : IQuest(betterquesting.api.questing.IQuest) QuestInstance(betterquesting.questing.QuestInstance) DatabaseEvent(betterquesting.api.events.DatabaseEvent)

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