Search in sources :

Example 1 with TimerSkipAbleMarker

use of com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker in project Warlords by ebicep.

the class PowerupOption method register.

@Override
public void register(Game game) {
    this.game = game;
    game.registerGameMarker(DebugLocationMarker.class, DebugLocationMarker.create(() -> type.getDebugMaterial(), () -> type.getDebugData(), this::getClass, () -> this.getClass().getSimpleName() + ": " + this.type.name(), this::getLocation, () -> Arrays.asList("Type: " + this.getType(), "Cooldown: " + this.getCooldown(), "Duration: " + this.getDuration(), "Max cooldown: " + this.getMaxCooldown(), "Entity: " + this.getEntity())));
    game.registerGameMarker(TimerSkipAbleMarker.class, new TimerSkipAbleMarker() {

        @Override
        public void skipTimer(int delayInTicks) {
            cooldown = Math.max(cooldown - delayInTicks / 20, 0);
            if (cooldown == 0) {
                spawn();
            }
        }

        @Override
        public int getDelay() {
            return cooldown * 20;
        }
    });
}
Also used : TimerSkipAbleMarker(com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker)

Example 2 with TimerSkipAbleMarker

use of com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker in project Warlords by ebicep.

the class WinAfterTimeoutOption method register.

@Override
public void register(Game game) {
    new TimerSkipAbleMarker() {

        @Override
        public int getDelay() {
            return timeRemaining * 20;
        }

        @Override
        public void skipTimer(int delay) {
            timeRemaining -= delay / 20;
        }
    }.register(game);
    game.registerGameMarker(ScoreboardHandler.class, scoreboard = new SimpleScoreboardHandler(SCOREBOARD_PRIORITY, "timeout") {

        @Override
        public List<String> computeLines(@Nullable WarlordsPlayer player) {
            final EnumSet<Team> teams = TeamMarker.getTeams(game);
            Team winner = null;
            if (teams.size() > 1) {
                List<PointPredicterMarker> predictionMarkers = game.getMarkers(PointPredicterMarker.class);
                int scoreNeededToEndGame = game.getOptions().stream().filter(e -> e instanceof WinByPointsOption).mapToInt(e -> ((WinByPointsOption) e).getPointLimit()).sorted().findFirst().orElse(Integer.MAX_VALUE);
                int highestScore = Integer.MIN_VALUE;
                int highestWinInSeconds = Integer.MAX_VALUE;
                for (Team team : teams) {
                    int points = game.getPoints(team);
                    int winInSeconds;
                    if (predictionMarkers.isEmpty()) {
                        winInSeconds = Integer.MAX_VALUE;
                    } else {
                        double pointsPerMinute = predictionMarkers.stream().mapToDouble(e -> e.predictPointsNextMinute(team)).sum();
                        int pointsRemaining = scoreNeededToEndGame - points;
                        int winInSecondsCalculated = pointsPerMinute <= 0 ? Integer.MAX_VALUE : (int) (pointsRemaining / pointsPerMinute * 60);
                        int pointsAfterTimeIsOver = (int) (points + timeRemaining * pointsPerMinute / 60);
                        if (winInSecondsCalculated >= 0 && winInSecondsCalculated < timeRemaining) {
                            // This teamis going to win before the timer is over
                            winInSeconds = winInSecondsCalculated;
                            points = scoreNeededToEndGame;
                        } else {
                            winInSeconds = timeRemaining;
                            points = pointsAfterTimeIsOver;
                        }
                    }
                    if (points > highestScore) {
                        highestScore = points;
                        highestWinInSeconds = winInSeconds;
                        winner = team;
                    } else if (points == highestScore) {
                        if (winInSeconds < highestWinInSeconds) {
                            highestWinInSeconds = winInSeconds;
                            winner = team;
                        } else if (winInSeconds == highestWinInSeconds) {
                            winner = null;
                        }
                    }
                }
            }
            StringBuilder message = new StringBuilder(64);
            if (winner != null) {
                message.append(winner.coloredPrefix()).append(ChatColor.GOLD).append(" Wins in: ");
            } else {
                message.append(ChatColor.WHITE).append("Time Left: ");
            }
            message.append(ChatColor.GREEN);
            Utils.formatTimeLeft(message, timeRemaining);
            return Collections.singletonList(message.toString());
        }
    });
}
Also used : Utils(com.ebicep.warlords.util.warlords.Utils) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Team(com.ebicep.warlords.game.Team) PointPredicterMarker(com.ebicep.warlords.game.option.marker.PointPredicterMarker) OptionalInt(java.util.OptionalInt) SimpleScoreboardHandler(com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler) WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) SECOND(com.ebicep.warlords.util.warlords.GameRunnable.SECOND) List(java.util.List) Game(com.ebicep.warlords.game.Game) ScoreboardHandler(com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) BukkitTask(org.bukkit.scheduler.BukkitTask) ChatColor(org.bukkit.ChatColor) TeamMarker(com.ebicep.warlords.game.option.marker.TeamMarker) TimerSkipAbleMarker(com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) EnumSet(java.util.EnumSet) Bukkit(org.bukkit.Bukkit) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) TimerSkipAbleMarker(com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker) SimpleScoreboardHandler(com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler) Team(com.ebicep.warlords.game.Team) Nullable(javax.annotation.Nullable) PointPredicterMarker(com.ebicep.warlords.game.option.marker.PointPredicterMarker)

Aggregations

TimerSkipAbleMarker (com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker)2 WarlordsGameTriggerWinEvent (com.ebicep.warlords.events.WarlordsGameTriggerWinEvent)1 Game (com.ebicep.warlords.game.Game)1 Team (com.ebicep.warlords.game.Team)1 PointPredicterMarker (com.ebicep.warlords.game.option.marker.PointPredicterMarker)1 TeamMarker (com.ebicep.warlords.game.option.marker.TeamMarker)1 ScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler)1 SimpleScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler)1 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)1 GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)1 SECOND (com.ebicep.warlords.util.warlords.GameRunnable.SECOND)1 Utils (com.ebicep.warlords.util.warlords.Utils)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 OptionalInt (java.util.OptionalInt)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Bukkit (org.bukkit.Bukkit)1 ChatColor (org.bukkit.ChatColor)1