Search in sources :

Example 1 with QuestInstance

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

the class EventHandler method onLivingUpdate.

@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
    if (event.getEntityLiving().world.isRemote) {
        return;
    }
    if (event.getEntityLiving() instanceof EntityPlayer) {
        if (QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) {
            return;
        }
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        UUID uuid = QuestingAPI.getQuestingUUID(player);
        List<IQuest> syncList = new ArrayList<IQuest>();
        List<QuestInstance> updateList = new ArrayList<QuestInstance>();
        for (Entry<ITask, IQuest> entry : QuestCache.INSTANCE.getActiveTasks(uuid).entrySet()) {
            ITask task = entry.getKey();
            IQuest quest = entry.getValue();
            if (!task.isComplete(uuid)) {
                if (task instanceof ITickableTask) {
                    ((ITickableTask) task).updateTask(player, quest);
                }
                if (task.isComplete(uuid)) {
                    if (!syncList.contains(quest)) {
                        syncList.add(quest);
                    }
                    if (!updateList.contains(quest) && quest instanceof QuestInstance) {
                        updateList.add((QuestInstance) quest);
                    }
                }
            }
        }
        if (player.ticksExisted % 20 == 0) {
            for (IQuest quest : QuestCache.INSTANCE.getActiveQuests(uuid)) {
                quest.update(player);
                if (quest.isComplete(uuid) && !syncList.contains(quest)) {
                    syncList.add(quest);
                    updateList.remove(quest);
                }
            }
            QuestCache.INSTANCE.updateCache(player);
        } else {
            Iterator<IQuest> iterator = syncList.iterator();
            while (iterator.hasNext()) {
                IQuest quest = iterator.next();
                quest.update(player);
                if (quest.isComplete(uuid) && !quest.canSubmit(player)) {
                    iterator.remove();
                    updateList.remove(quest);
                }
            }
        }
        for (IQuest quest : syncList) {
            PacketSender.INSTANCE.sendToAll(quest.getSyncPacket());
        }
        for (QuestInstance quest : updateList) {
            quest.postPresetNotice(player, 1);
        }
    }
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IQuest(betterquesting.api.questing.IQuest) QuestInstance(betterquesting.questing.QuestInstance) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ITickableTask(betterquesting.api.questing.tasks.ITickableTask) UUID(java.util.UUID) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with QuestInstance

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

the class LegacyLoader_v0 method readQuest.

public void readQuest(IQuest quest, JsonObject json) {
    IPropertyContainer props = quest.getProperties();
    props.setProperty(NativeProps.NAME, JsonHelper.GetString(json, "name", "New Quest"));
    props.setProperty(NativeProps.DESC, JsonHelper.GetString(json, "description", "No Description"));
    props.setProperty(NativeProps.MAIN, JsonHelper.GetBoolean(json, "isMain", false));
    props.setProperty(NativeProps.SILENT, JsonHelper.GetBoolean(json, "isSilent", false));
    props.setProperty(NativeProps.LOCKED_PROGRESS, JsonHelper.GetBoolean(json, "lockedProgress", false));
    props.setProperty(NativeProps.SIMULTANEOUS, JsonHelper.GetBoolean(json, "simultaneous", false));
    props.setProperty(NativeProps.GLOBAL, JsonHelper.GetBoolean(json, "globalQuest", false));
    props.setProperty(NativeProps.GLOBAL_SHARE, JsonHelper.GetBoolean(json, "globalShare", false));
    props.setProperty(NativeProps.AUTO_CLAIM, JsonHelper.GetBoolean(json, "autoClaim", false));
    props.setProperty(NativeProps.REPEAT_TIME, JsonHelper.GetNumber(json, "repeatTime", 2000).intValue());
    props.setProperty(NativeProps.LOGIC_QUEST, EnumLogic.valueOf(JsonHelper.GetString(json, "logic", "AND")));
    props.setProperty(NativeProps.LOGIC_TASK, EnumLogic.valueOf(JsonHelper.GetString(json, "taskLogic", "AND")));
    props.setProperty(NativeProps.ICON, JsonHelper.JsonToItemStack(NBTConverter.JSONtoNBT_Object(JsonHelper.GetObject(json, "icon"), new NBTTagCompound())));
    for (JsonElement je : JsonHelper.GetArray(json, "preRequisites")) {
        if (je == null || !je.isJsonPrimitive() || !je.getAsJsonPrimitive().isNumber()) {
            continue;
        }
        int qID = je.getAsInt();
        IQuest prq = QuestDatabase.INSTANCE.getValue(qID);
        if (prq == null) {
            prq = new QuestInstance();
            QuestDatabase.INSTANCE.add(prq, qID);
        }
        quest.getPrerequisites().add(prq);
    }
    IRegStorageBase<Integer, ITask> taskDB = quest.getTasks();
    ArrayList<ITask> uaTasks = new ArrayList<ITask>();
    for (JsonElement entry : JsonHelper.GetArray(json, "tasks")) {
        if (entry == null || !entry.isJsonObject()) {
            continue;
        }
        JsonObject jsonTask = entry.getAsJsonObject();
        ResourceLocation loc = new ResourceLocation(JsonHelper.GetString(jsonTask, "taskID", ""));
        int index = JsonHelper.GetNumber(jsonTask, "index", -1).intValue();
        ITask task = TaskRegistry.INSTANCE.createTask(loc);
        if (task instanceof TaskPlaceholder) {
            JsonObject jt2 = JsonHelper.GetObject(jsonTask, "orig_data");
            ResourceLocation loc2 = new ResourceLocation(JsonHelper.GetString(jt2, "taskID", ""));
            ITask t2 = TaskRegistry.INSTANCE.createTask(loc2);
            if (// Restored original task
            t2 != null) {
                jsonTask = jt2;
                task = t2;
            }
        }
        NBTTagCompound nbtTask = NBTConverter.JSONtoNBT_Object(jsonTask, new NBTTagCompound());
        if (task != null) {
            task.readFromNBT(nbtTask, EnumSaveType.CONFIG);
            if (index >= 0) {
                taskDB.add(task, index);
            } else {
                uaTasks.add(task);
            }
        } else {
            TaskPlaceholder tph = new TaskPlaceholder();
            tph.setTaskData(nbtTask, EnumSaveType.CONFIG);
            if (index >= 0) {
                taskDB.add(tph, index);
            } else {
                uaTasks.add(tph);
            }
        }
    }
    for (ITask t : uaTasks) {
        taskDB.add(t, taskDB.nextKey());
    }
    IRegStorageBase<Integer, IReward> rewardDB = quest.getRewards();
    ArrayList<IReward> unassigned = new ArrayList<IReward>();
    for (JsonElement entry : JsonHelper.GetArray(json, "rewards")) {
        if (entry == null || !entry.isJsonObject()) {
            continue;
        }
        JsonObject jsonReward = entry.getAsJsonObject();
        ResourceLocation loc = new ResourceLocation(JsonHelper.GetString(jsonReward, "rewardID", ""));
        int index = JsonHelper.GetNumber(jsonReward, "index", -1).intValue();
        IReward reward = RewardRegistry.INSTANCE.createReward(loc);
        if (reward instanceof RewardPlaceholder) {
            JsonObject jr2 = JsonHelper.GetObject(jsonReward, "orig_data");
            ResourceLocation loc2 = new ResourceLocation(JsonHelper.GetString(jr2, "rewardID", ""));
            IReward r2 = RewardRegistry.INSTANCE.createReward(loc2);
            if (r2 != null) {
                jsonReward = jr2;
                reward = r2;
            }
        }
        NBTTagCompound nbtReward = NBTConverter.JSONtoNBT_Object(jsonReward, new NBTTagCompound());
        if (reward != null) {
            reward.readFromNBT(nbtReward, EnumSaveType.CONFIG);
            if (index >= 0) {
                rewardDB.add(reward, index);
            } else {
                unassigned.add(reward);
            }
        } else {
            RewardPlaceholder rph = new RewardPlaceholder();
            rph.setRewardData(nbtReward, EnumSaveType.CONFIG);
            if (index >= 0) {
                rewardDB.add(rph, index);
            } else {
                unassigned.add(rph);
            }
        }
    }
    for (IReward r : unassigned) {
        rewardDB.add(r, rewardDB.nextKey());
    }
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IReward(betterquesting.api.questing.rewards.IReward) IPropertyContainer(betterquesting.api.properties.IPropertyContainer) IQuest(betterquesting.api.questing.IQuest) QuestInstance(betterquesting.questing.QuestInstance) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) RewardPlaceholder(betterquesting.api.placeholders.rewards.RewardPlaceholder) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) TaskPlaceholder(betterquesting.api.placeholders.tasks.TaskPlaceholder)

Example 3 with QuestInstance

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

the class LegacyLoader_v0 method readQuestDatabase.

public void readQuestDatabase(JsonArray jAry) {
    QuestDatabase.INSTANCE.reset();
    for (JsonElement je : jAry) {
        if (je == null || !je.isJsonObject()) {
            continue;
        }
        JsonObject json = je.getAsJsonObject();
        int qID = JsonHelper.GetNumber(json, "questID", -1).intValue();
        IQuest quest = QuestDatabase.INSTANCE.getValue(qID);
        boolean flag = quest == null;
        quest = quest != null ? quest : new QuestInstance();
        readQuest(quest, json);
        if (quest != null && flag) {
            QuestDatabase.INSTANCE.add(quest, qID);
        }
    }
}
Also used : IQuest(betterquesting.api.questing.IQuest) JsonElement(com.google.gson.JsonElement) QuestInstance(betterquesting.questing.QuestInstance) JsonObject(com.google.gson.JsonObject)

Example 4 with QuestInstance

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

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

the class ToolboxToolNew method initTool.

@Override
public void initTool(IGuiQuestLine gui) {
    this.gui = gui;
    nQuest = new GuiButtonQuestInstance(0, 0, 0, 24, 24, new QuestInstance());
}
Also used : GuiButtonQuestInstance(betterquesting.api.client.gui.controls.GuiButtonQuestInstance) GuiButtonQuestInstance(betterquesting.api.client.gui.controls.GuiButtonQuestInstance) QuestInstance(betterquesting.questing.QuestInstance)

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