Search in sources :

Example 1 with IReward

use of betterquesting.api.questing.rewards.IReward in project BetterQuesting by Funwayguy.

the class QuestInstance method claimReward.

@Override
public void claimReward(EntityPlayer player) {
    for (IReward rew : rewards.getAllValues()) {
        rew.claimReward(player, this);
    }
    UUID pID = QuestingAPI.getQuestingUUID(player);
    IParty party = PartyManager.INSTANCE.getUserParty(pID);
    if (party != null && this.qInfo.getProperty(NativeProps.PARTY_LOOT)) {
        for (UUID mem : party.getMembers()) {
            EnumPartyStatus pStat = party.getStatus(mem);
            if (pStat == null || pStat == EnumPartyStatus.INVITE) {
                continue;
            }
            UserEntry entry = GetUserEntry(mem);
            if (entry == null) {
                entry = new UserEntry(mem);
                this.completeUsers.add(entry);
            }
            entry.setClaimed(true, player.world.getTotalWorldTime());
        }
    } else {
        UserEntry entry = GetUserEntry(pID);
        if (entry == null) {
            entry = new UserEntry(pID);
            this.completeUsers.add(entry);
        }
        entry.setClaimed(true, player.world.getTotalWorldTime());
    }
    PacketSender.INSTANCE.sendToAll(getSyncPacket());
}
Also used : EnumPartyStatus(betterquesting.api.enums.EnumPartyStatus) IReward(betterquesting.api.questing.rewards.IReward) UserEntry(betterquesting.misc.UserEntry) IParty(betterquesting.api.questing.party.IParty) UUID(java.util.UUID)

Example 2 with IReward

use of betterquesting.api.questing.rewards.IReward 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 IReward

use of betterquesting.api.questing.rewards.IReward in project BetterQuesting by Funwayguy.

the class GuiQuest method refreshRewardPanel.

private void refreshRewardPanel() {
    if (pnReward != null) {
        cvInner.removePanel(pnReward);
    }
    if (rewardIndex < 0 || rewardIndex >= quest.getRewards().size()) {
        if (rectReward != null && quest.getRewards().size() == 0) {
            this.initPanel();
        } else {
            titleReward.setText("?");
            updateButtons();
        }
        return;
    } else if (rectReward == null) {
        this.initPanel();
        return;
    }
    IReward rew = quest.getRewards().getAllValues().get(rewardIndex);
    pnReward = new PanelLegacyEmbed<>(rectReward, rew.getRewardGui(rectReward.getX(), rectReward.getY(), rectReward.getWidth(), rectReward.getHeight(), quest));
    cvInner.addPanel(pnReward);
    titleReward.setText(I18n.format(rew.getUnlocalisedName()));
    updateButtons();
}
Also used : IReward(betterquesting.api.questing.rewards.IReward)

Example 4 with IReward

use of betterquesting.api.questing.rewards.IReward in project BetterQuesting by Funwayguy.

the class GuiRewardEditor method actionPerformed.

@Override
public void actionPerformed(GuiButton button) {
    super.actionPerformed(button);
    int column = button.id & 3;
    int id = (button.id >> 2) - 1;
    if (id < 0) {
        return;
    }
    if (// Edit reward
    column == 0) {
        IReward reward = quest.getRewards().getValue(id);
        if (reward != null) {
            GuiScreen editor = reward.getRewardEditor(this, quest);
            if (editor != null) {
                mc.displayGuiScreen(editor);
            } else {
                mc.displayGuiScreen(new GuiRewardEditDefault(this, quest, reward));
            }
        }
    } else if (// Delete reward
    column == 1) {
        quest.getRewards().removeKey(id);
        SendChanges();
    } else if (// Add reward
    column == 2) {
        if (id >= 0 && id < rewardTypes.size()) {
            quest.getRewards().add(RewardRegistry.INSTANCE.createReward(rewardTypes.get(id).getRegistryName()), quest.getRewards().nextKey());
            SendChanges();
        }
    }
}
Also used : IReward(betterquesting.api.questing.rewards.IReward) GuiScreen(net.minecraft.client.gui.GuiScreen)

Example 5 with IReward

use of betterquesting.api.questing.rewards.IReward in project BetterQuesting by Funwayguy.

the class GuiRewardEditDefault method initGui.

@Override
public void initGui() {
    super.initGui();
    if (!isDone) {
        this.isDone = true;
        IReward reward = quest.getRewards().getValue(rID);
        if (reward != null) {
            this.mc.displayGuiScreen(new GuiJsonEditor(this, json, reward.getDocumentation(), this));
        } else {
            this.mc.displayGuiScreen(parent);
        }
    } else {
        this.mc.displayGuiScreen(parent);
    }
}
Also used : IReward(betterquesting.api.questing.rewards.IReward) GuiJsonEditor(betterquesting.client.gui.editors.json.scrolling.GuiJsonEditor)

Aggregations

IReward (betterquesting.api.questing.rewards.IReward)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 RewardPlaceholder (betterquesting.api.placeholders.rewards.RewardPlaceholder)2 ArrayList (java.util.ArrayList)2 EnumPartyStatus (betterquesting.api.enums.EnumPartyStatus)1 TaskPlaceholder (betterquesting.api.placeholders.tasks.TaskPlaceholder)1 IPropertyContainer (betterquesting.api.properties.IPropertyContainer)1 IQuest (betterquesting.api.questing.IQuest)1 IParty (betterquesting.api.questing.party.IParty)1 ITask (betterquesting.api.questing.tasks.ITask)1 GuiJsonEditor (betterquesting.client.gui.editors.json.scrolling.GuiJsonEditor)1 UserEntry (betterquesting.misc.UserEntry)1 QuestInstance (betterquesting.questing.QuestInstance)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 UUID (java.util.UUID)1 GuiScreen (net.minecraft.client.gui.GuiScreen)1 NBTBase (net.minecraft.nbt.NBTBase)1