Search in sources :

Example 6 with QuestInstance

use of betterquesting.questing.QuestInstance in project BetterQuesting by Funwayguy.

the class ImportedQuests method createNew.

@Override
public IQuest createNew() {
    IQuest q = new QuestInstance();
    q.setParentDatabase(this);
    return q;
}
Also used : IQuest(betterquesting.api.questing.IQuest) QuestInstance(betterquesting.questing.QuestInstance)

Example 7 with QuestInstance

use of betterquesting.questing.QuestInstance 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 8 with QuestInstance

use of betterquesting.questing.QuestInstance 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 9 with QuestInstance

use of betterquesting.questing.QuestInstance 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

QuestInstance (betterquesting.questing.QuestInstance)9 IQuest (betterquesting.api.questing.IQuest)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 GuiButtonQuestInstance (betterquesting.api.client.gui.controls.GuiButtonQuestInstance)3 ITask (betterquesting.api.questing.tasks.ITask)3 QuestingPacket (betterquesting.api.network.QuestingPacket)2 IQuestLine (betterquesting.api.questing.IQuestLine)2 QuestLineEntry (betterquesting.questing.QuestLineEntry)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 EnumPacketAction (betterquesting.api.enums.EnumPacketAction)1 DatabaseEvent (betterquesting.api.events.DatabaseEvent)1 RewardPlaceholder (betterquesting.api.placeholders.rewards.RewardPlaceholder)1 TaskPlaceholder (betterquesting.api.placeholders.tasks.TaskPlaceholder)1 IPropertyContainer (betterquesting.api.properties.IPropertyContainer)1 IReward (betterquesting.api.questing.rewards.IReward)1 ITickableTask (betterquesting.api.questing.tasks.ITickableTask)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1