Search in sources :

Example 6 with QuestContext

use of com.playmonumenta.scriptedquests.quests.QuestContext in project scripted-quests by TeamMonumenta.

the class QuestActions method serializeForClientAPI.

public Optional<JsonElement> serializeForClientAPI(QuestContext context) {
    if (mDelayTicks <= 0) {
        JsonArray a = new JsonArray();
        mActions.stream().map(v -> v.serializeForClientAPI(context)).forEach(a::add);
        return Optional.of(a);
    }
    return Optional.empty();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) ActionInteractNpc(com.playmonumenta.scriptedquests.quests.components.actions.ActionInteractNpc) Iterator(java.util.Iterator) ActionBase(com.playmonumenta.scriptedquests.quests.components.actions.ActionBase) ActionCommand(com.playmonumenta.scriptedquests.quests.components.actions.ActionCommand) Set(java.util.Set) ActionGiveLoot(com.playmonumenta.scriptedquests.quests.components.actions.ActionGiveLoot) EntityType(org.bukkit.entity.EntityType) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) JsonArray(com.google.gson.JsonArray) ActionDialog(com.playmonumenta.scriptedquests.quests.components.actions.ActionDialog) ActionFunction(com.playmonumenta.scriptedquests.quests.components.actions.ActionFunction) ActionRerunComponents(com.playmonumenta.scriptedquests.quests.components.actions.ActionRerunComponents) ActionVoiceOver(com.playmonumenta.scriptedquests.quests.components.actions.ActionVoiceOver) Entry(java.util.Map.Entry) Optional(java.util.Optional) ActionSetScore(com.playmonumenta.scriptedquests.quests.components.actions.ActionSetScore) QuestContext(com.playmonumenta.scriptedquests.quests.QuestContext) Bukkit(org.bukkit.Bukkit)

Example 7 with QuestContext

use of com.playmonumenta.scriptedquests.quests.QuestContext in project scripted-quests by TeamMonumenta.

the class Race method win.

public void win(int endTime) {
    end();
    /* Set score on player */
    if (mScoreboard != null) {
        Score score = mScoreboard.getScore(mPlayer.getName());
        if (!score.isScoreSet() || score.getScore() == 0 || endTime < score.getScore()) {
            score.setScore(endTime);
            /* If the RedisSync plugin is also present, update the score in the leaderboard cache */
            if (Bukkit.getServer().getPluginManager().getPlugin("MonumentaRedisSync") != null) {
                MonumentaRedisSyncAPI.updateLeaderboardAsync(mScoreboard.getName(), mPlayer.getName(), endTime);
            }
            // handle new world record
            if (mWRTime > endTime) {
                String cmdStr = "broadcastcommand tellraw @a [\"\",{\"text\":\"" + mPlayer.getName() + "\",\"color\":\"blue\"},{\"text\":\" has set a new world record for \",\"color\":\"dark_aqua\"},{\"text\":\"" + mName + "\",\"color\":\"blue\"},{\"text\":\"\\nNew time: \",\"color\":\"dark_aqua\"},{\"text\":\"" + RaceUtils.msToTimeString(endTime) + "\",\"color\":\"blue\"}]";
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmdStr);
            }
        }
    }
    // header
    if (mShowStats) {
        mPlayer.sendMessage("" + ChatColor.DARK_AQUA + ChatColor.BOLD + "----====----       " + ChatColor.AQUA + ChatColor.BOLD + "Speedruns" + ChatColor.DARK_AQUA + ChatColor.BOLD + "       ----====----\n");
        mPlayer.sendMessage(" " + String.format("%s - %s", "" + ChatColor.AQUA + "Race Recap", " " + ChatColor.YELLOW + mName));
        mPlayer.sendMessage(" ");
    }
    // TODO: World record time first
    mPlayer.sendMessage(String.format("  %sWorld Record - %16s  | %s %s", "" + ChatColor.AQUA + ChatColor.BOLD, "" + RaceUtils.msToTimeString(mWRTime), "" + ((endTime <= mWRTime) ? ("" + ChatColor.AQUA + ChatColor.BOLD + "\u272A") : ("" + ChatColor.GRAY + ChatColor.BOLD + "\u272A")), "" + ((endTime <= mWRTime) ? ("" + ChatColor.BLUE + ChatColor.BOLD + "( -" + RaceUtils.msToTimeString(mWRTime - endTime) + ")") : ("" + ChatColor.RED + ChatColor.BOLD + "( +" + RaceUtils.msToTimeString(endTime - mWRTime) + ")"))));
    int bestMedalTime = Integer.MAX_VALUE;
    String bestMedalColor = null;
    for (RaceTime time : mTimes) {
        int medalTime = time.getTime();
        if (mShowStats) {
            mPlayer.sendMessage(String.format("  %s   %s      - %16s  | %s %s", "" + time.getColor(), "" + time.getLabel(), "" + RaceUtils.msToTimeString(medalTime), "" + ((endTime <= medalTime) ? ("" + time.getColor() + "\u272A") : ("" + ChatColor.GRAY + ChatColor.BOLD + "\u272A")), "" + ((endTime <= medalTime) ? ("" + ChatColor.BLUE + ChatColor.BOLD + "( -" + RaceUtils.msToTimeString(medalTime - endTime) + ")") : ("" + ChatColor.RED + ChatColor.BOLD + "( +" + RaceUtils.msToTimeString(endTime - medalTime) + ")"))));
        }
        if (endTime <= medalTime) {
            if (medalTime < bestMedalTime) {
                bestMedalTime = medalTime;
                bestMedalColor = time.getColor();
            }
        }
    }
    if (mShowStats) {
        mPlayer.sendMessage(" ");
    }
    if (mScoreboard != null && mShowStats) {
        int personalBest = mScoreboard.getScore(mPlayer.getName()).getScore();
        mPlayer.sendMessage(String.format("  %s Personal Best - %16s  | %s", "" + ChatColor.BLUE + ChatColor.BOLD, "" + RaceUtils.msToTimeString(personalBest), "" + ((endTime <= personalBest) ? ("" + ChatColor.BLUE + ChatColor.BOLD + "( -" + RaceUtils.msToTimeString(personalBest - endTime) + ")") : ("" + ChatColor.RED + ChatColor.BOLD + "( +" + RaceUtils.msToTimeString(endTime - personalBest) + ")"))));
    }
    if (mShowStats) {
        mPlayer.sendMessage(String.format("  %s  Your Time   - %16s", "" + ChatColor.BLUE + ChatColor.BOLD, "" + ChatColor.ITALIC + bestMedalColor + RaceUtils.msToTimeString(endTime)));
    }
    /* Last thing is to do any actions associated with the race */
    for (RaceTime time : mTimes) {
        if (endTime <= time.getTime()) {
            time.doActions(new QuestContext(mPlugin, mPlayer, null));
        }
    }
}
Also used : Score(org.bukkit.scoreboard.Score) QuestContext(com.playmonumenta.scriptedquests.quests.QuestContext)

Example 8 with QuestContext

use of com.playmonumenta.scriptedquests.quests.QuestContext in project scripted-quests by TeamMonumenta.

the class Race method restart.

public void restart() {
    if (mCountdownActive) {
        // Refuse this restart request if still starting
        return;
    }
    if (mTimeBar != null) {
        mTimeBar.cancel();
    }
    if (mStartActions != null) {
        mStartActions.doActions(new QuestContext(mPlugin, mPlayer, null));
    }
    mPlayer.addScoreboardTag(RaceManager.PLAYER_RACE_TAG);
    mStartTime = System.currentTimeMillis();
    mMaxTime = mTimes.get(mTimes.size() - 1).getTime();
    // Copy the waypoints to something local to work with
    mRemainingWaypoints = new ArrayDeque<RaceWaypoint>(mWaypoints);
    mNextWaypoint = mRemainingWaypoints.removeFirst();
    // Create the timetracking bar
    mTimeBar = new TimeBar(mPlayer, mTimes);
    countdownStart();
}
Also used : QuestContext(com.playmonumenta.scriptedquests.quests.QuestContext)

Aggregations

QuestContext (com.playmonumenta.scriptedquests.quests.QuestContext)8 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 NpcTrade (com.playmonumenta.scriptedquests.trades.NpcTrade)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 IStandardByteReader (com.floweytf.utils.stdstreams.IStandardByteReader)1 StandardByteReader (com.floweytf.utils.stdstreams.StandardByteReader)1 StandardByteWriter (com.floweytf.utils.stdstreams.StandardByteWriter)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 Constants (com.playmonumenta.scriptedquests.Constants)1 Plugin (com.playmonumenta.scriptedquests.Plugin)1 InteractableEntry (com.playmonumenta.scriptedquests.quests.InteractableEntry)1 QuestComponent (com.playmonumenta.scriptedquests.quests.components.QuestComponent)1 QuestPrerequisites (com.playmonumenta.scriptedquests.quests.components.QuestPrerequisites)1 ActionBase (com.playmonumenta.scriptedquests.quests.components.actions.ActionBase)1 ActionCommand (com.playmonumenta.scriptedquests.quests.components.actions.ActionCommand)1 ActionDialog (com.playmonumenta.scriptedquests.quests.components.actions.ActionDialog)1