Search in sources :

Example 16 with ITask

use of betterquesting.api.questing.tasks.ITask in project BetterQuesting by Funwayguy.

the class TaskStorage method writeToJson_Progress.

private NBTTagList writeToJson_Progress(NBTTagList json) {
    for (Entry<Integer, ITask> entry : database.entrySet()) {
        ResourceLocation taskID = entry.getValue().getFactoryID();
        NBTTagCompound qJson = entry.getValue().writeToNBT(new NBTTagCompound(), EnumSaveType.PROGRESS);
        qJson.setString("taskID", taskID.toString());
        qJson.setInteger("index", entry.getKey());
        json.appendTag(qJson);
    }
    return json;
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 17 with ITask

use of betterquesting.api.questing.tasks.ITask in project BetterQuesting by Funwayguy.

the class QuestCache method getActiveTasks.

/**
 * Returns a cached list of active tasks of the given type with references to their parent quest
 */
@SuppressWarnings("unchecked")
public <T extends ITask> Map<T, IQuest> getActiveTasks(UUID uuid, Class<T> type) {
    Map<T, IQuest> list = new HashMap<T, IQuest>();
    HashMap<Integer, List<Integer>> pCache = rawCache.get(uuid);
    pCache = pCache != null ? pCache : new HashMap<Integer, List<Integer>>();
    for (Entry<Integer, List<Integer>> entry : pCache.entrySet()) {
        IQuest quest = QuestingAPI.getAPI(ApiReference.QUEST_DB).getValue(entry.getKey());
        if (quest == null) {
            continue;
        }
        for (int tID : entry.getValue()) {
            ITask task = quest.getTasks().getValue(tID);
            if (task != null && type.isAssignableFrom(task.getClass())) {
                list.put((T) task, quest);
            }
        }
    }
    return list;
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IQuest(betterquesting.api.questing.IQuest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with ITask

use of betterquesting.api.questing.tasks.ITask 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 19 with ITask

use of betterquesting.api.questing.tasks.ITask 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 20 with ITask

use of betterquesting.api.questing.tasks.ITask 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

ITask (betterquesting.api.questing.tasks.ITask)20 IQuest (betterquesting.api.questing.IQuest)9 UUID (java.util.UUID)8 ArrayList (java.util.ArrayList)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 ResourceLocation (net.minecraft.util.ResourceLocation)5 TaskPlaceholder (betterquesting.api.placeholders.tasks.TaskPlaceholder)3 QuestInstance (betterquesting.questing.QuestInstance)3 FactoryTaskPlaceholder (betterquesting.api.placeholders.tasks.FactoryTaskPlaceholder)2 IParty (betterquesting.api.questing.party.IParty)2 UserEntry (betterquesting.misc.UserEntry)2 HashMap (java.util.HashMap)2 List (java.util.List)2 NBTBase (net.minecraft.nbt.NBTBase)2 EnumPacketAction (betterquesting.api.enums.EnumPacketAction)1 RewardPlaceholder (betterquesting.api.placeholders.rewards.RewardPlaceholder)1 IPropertyContainer (betterquesting.api.properties.IPropertyContainer)1 IQuestDatabase (betterquesting.api.questing.IQuestDatabase)1 IReward (betterquesting.api.questing.rewards.IReward)1 IFluidTask (betterquesting.api.questing.tasks.IFluidTask)1