Search in sources :

Example 41 with IQuest

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

the class QuestCache method updateCache.

public void updateCache(EntityPlayer player) {
    if (player == null) {
        return;
    }
    UUID uuid = QuestingAPI.getQuestingUUID(player);
    HashMap<Integer, List<Integer>> pCache = new HashMap<Integer, List<Integer>>();
    IQuestDatabase questDB = QuestingAPI.getAPI(ApiReference.QUEST_DB);
    List<Integer> idList = questDB.getAllKeys();
    for (int qID : idList) {
        IQuest quest = questDB.getValue(qID);
        if (quest == null || (!quest.isUnlocked(uuid) && !quest.getProperties().getProperty(NativeProps.LOCKED_PROGRESS))) {
            // Invalid or locked
            continue;
        } else if (quest.canSubmit(player) || quest.getProperties().getProperty(NativeProps.REPEAT_TIME).intValue() >= 0) {
        // Active quest or pending repeat reset
        } else if (quest.getProperties().getProperty(NativeProps.AUTO_CLAIM) && !quest.hasClaimed(uuid)) {
        // Pending auto-claim
        } else {
            continue;
        }
        List<Integer> tList = new ArrayList<Integer>();
        for (int tID : quest.getTasks().getAllKeys()) {
            ITask task = quest.getTasks().getValue(tID);
            if (task != null && !task.isComplete(uuid)) {
                tList.add(tID);
            }
        }
        pCache.put(qID, tList);
    }
    rawCache.put(uuid, pCache);
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IQuest(betterquesting.api.questing.IQuest) HashMap(java.util.HashMap) IQuestDatabase(betterquesting.api.questing.IQuestDatabase) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Example 42 with IQuest

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

the class QuestCache method getActiveQuests.

/**
 * Returns a cached list of active quests
 */
public List<IQuest> getActiveQuests(UUID uuid) {
    List<IQuest> list = new ArrayList<IQuest>();
    HashMap<Integer, List<Integer>> pCache = rawCache.get(uuid);
    pCache = pCache != null ? pCache : new HashMap<Integer, List<Integer>>();
    for (int id : pCache.keySet()) {
        IQuest quest = QuestingAPI.getAPI(ApiReference.QUEST_DB).getValue(id);
        if (quest != null) {
            list.add(quest);
        }
    }
    return list;
}
Also used : IQuest(betterquesting.api.questing.IQuest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 43 with IQuest

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

the class TileSubmitStation method fill.

@Override
public int fill(FluidStack fluid, boolean doFill) {
    IQuest q = getQuest();
    IFluidTask t = getFluidTask();
    if (q == null || t == null || fluid == null) {
        return 0;
    }
    FluidStack remainder = null;
    int amount = fluid.amount;
    if (doFill) {
        remainder = t.submitFluid(owner, fluid);
        if (((ITask) t).isComplete(owner)) {
            PacketSender.INSTANCE.sendToAll(q.getSyncPacket());
            reset();
            world.getMinecraftServer().getPlayerList().sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 128, world.provider.getDimension(), getUpdatePacket());
        } else {
            needsUpdate = true;
        }
    }
    return remainder != null ? amount - remainder.amount : amount;
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IFluidTask(betterquesting.api.questing.tasks.IFluidTask) IQuest(betterquesting.api.questing.IQuest) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 44 with IQuest

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

the class TileSubmitStation method update.

@Override
public void update() {
    if (world.isRemote || QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) {
        return;
    }
    IQuest q = getQuest();
    IItemTask t = getItemTask();
    if (world.getTotalWorldTime() % 10 == 0) {
        if (owner != null && q != null && t != null && owner != null && !itemStack.get(0).isEmpty() && itemStack.get(1).isEmpty()) {
            ItemStack inStack = itemStack.get(0).copy();
            if (t.canAcceptItem(owner, inStack)) {
                // Even if this returns an invalid item for submission it will be moved next pass
                itemStack.set(0, t.submitItem(owner, inStack));
                if (((ITask) t).isComplete(owner)) {
                    PacketSender.INSTANCE.sendToAll(q.getSyncPacket());
                    reset();
                    world.getMinecraftServer().getPlayerList().sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 128, world.provider.getDimension(), getUpdatePacket());
                } else {
                    needsUpdate = true;
                }
            } else {
                itemStack.set(1, inStack);
                itemStack.set(0, ItemStack.EMPTY);
            }
        }
        if (needsUpdate) {
            needsUpdate = false;
            if (q != null && !world.isRemote) {
                PacketSender.INSTANCE.sendToAll(q.getSyncPacket());
            }
        } else if (t != null && ((ITask) t).isComplete(owner)) {
            reset();
            world.getMinecraftServer().getPlayerList().sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 128, world.provider.getDimension(), getUpdatePacket());
        }
    }
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IQuest(betterquesting.api.questing.IQuest) IItemTask(betterquesting.api.questing.tasks.IItemTask) ItemStack(net.minecraft.item.ItemStack)

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