Search in sources :

Example 1 with ITask

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

the class QuestInstance method canSubmit.

@Override
public boolean canSubmit(EntityPlayer player) {
    if (player == null) {
        return false;
    }
    UUID playerID = QuestingAPI.getQuestingUUID(player);
    UserEntry entry = this.GetUserEntry(playerID);
    if (// Incomplete
    entry == null) {
        return true;
    } else if (// Complete but repeatable
    !entry.hasClaimed() && getProperties().getProperty(NativeProps.REPEAT_TIME).intValue() >= 0) {
        int done = 0;
        for (ITask tsk : tasks.getAllValues()) {
            if (tsk.isComplete(playerID)) {
                done += 1;
            }
        }
        return !qInfo.getProperty(NativeProps.LOGIC_TASK).getResult(done, tasks.size());
    } else {
        return false;
    }
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) UserEntry(betterquesting.misc.UserEntry) UUID(java.util.UUID)

Example 2 with ITask

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

the class QuestInstance method getStandardTooltip.

@SideOnly(Side.CLIENT)
private List<String> getStandardTooltip(EntityPlayer player) {
    ArrayList<String> list = new ArrayList<String>();
    list.add(I18n.format(getUnlocalisedName()) + (!Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? "" : (" #" + parentDB.getKey(this))));
    UUID playerID = QuestingAPI.getQuestingUUID(player);
    if (isComplete(playerID)) {
        list.add(TextFormatting.GREEN + I18n.format("betterquesting.tooltip.complete"));
        if (!hasClaimed(playerID)) {
            list.add(TextFormatting.GRAY + I18n.format("betterquesting.tooltip.rewards_pending"));
        } else if (qInfo.getProperty(NativeProps.REPEAT_TIME).intValue() > 0) {
            long time = getRepeatSeconds(player);
            DecimalFormat df = new DecimalFormat("00");
            String timeTxt = "";
            if (time >= 3600) {
                timeTxt += (time / 3600) + "h " + df.format((time % 3600) / 60) + "m ";
            } else if (time >= 60) {
                timeTxt += (time / 60) + "m ";
            }
            timeTxt += df.format(time % 60) + "s";
            list.add(TextFormatting.GRAY + I18n.format("betterquesting.tooltip.repeat", timeTxt));
        }
    } else if (!isUnlocked(playerID)) {
        list.add(TextFormatting.RED + "" + TextFormatting.UNDERLINE + I18n.format("betterquesting.tooltip.requires") + " (" + qInfo.getProperty(NativeProps.LOGIC_QUEST).toString().toUpperCase() + ")");
        for (IQuest req : preRequisites) {
            if (!req.isComplete(playerID)) {
                list.add(TextFormatting.RED + "- " + I18n.format(req.getUnlocalisedName()));
            }
        }
    } else {
        int n = 0;
        for (ITask task : tasks.getAllValues()) {
            if (task.isComplete(playerID)) {
                n++;
            }
        }
        list.add(TextFormatting.GRAY + I18n.format("betterquesting.tooltip.tasks_complete", n, tasks.size()));
    }
    return list;
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IQuest(betterquesting.api.questing.IQuest) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) UUID(java.util.UUID) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with ITask

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

the class QuestInstance method detect.

/**
 * Fired when someone clicks the detect button for this quest
 */
@Override
public void detect(EntityPlayer player) {
    UUID playerID = QuestingAPI.getQuestingUUID(player);
    if (isComplete(playerID) && (qInfo.getProperty(NativeProps.REPEAT_TIME).intValue() < 0 || rewards.size() <= 0)) {
        return;
    } else if (!canSubmit(player)) {
        return;
    }
    if (isUnlocked(playerID) || QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) {
        int done = 0;
        boolean update = false;
        for (ITask tsk : tasks.getAllValues()) {
            if (!tsk.isComplete(playerID)) {
                tsk.detect(player, this);
                if (tsk.isComplete(playerID)) {
                    IParty party = PartyManager.INSTANCE.getUserParty(playerID);
                    if (// Ensures task is marked as complete for all team members
                    party != null) {
                        for (UUID mem : party.getMembers()) {
                            tsk.setComplete(mem);
                        }
                    }
                    done += 1;
                    update = true;
                }
            } else {
                done += 1;
            }
        }
        if ((tasks.size() > 0 || !QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) && qInfo.getProperty(NativeProps.LOGIC_TASK).getResult(done, tasks.size())) {
            setComplete(playerID, player.world.getTotalWorldTime());
            if (!QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE) && !qInfo.getProperty(NativeProps.SILENT)) {
                postPresetNotice(player, 2);
            }
        } else if (update && qInfo.getProperty(NativeProps.SIMULTANEOUS)) {
            resetUser(playerID, false);
            PacketSender.INSTANCE.sendToAll(getSyncPacket());
        } else if (update) {
            if (!QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE) && !qInfo.getProperty(NativeProps.SILENT)) {
                postPresetNotice(player, 1);
            }
        }
        PacketSender.INSTANCE.sendToAll(getSyncPacket());
    }
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IParty(betterquesting.api.questing.party.IParty) UUID(java.util.UUID)

Example 4 with ITask

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

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

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