Search in sources :

Example 1 with Team

use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.

the class PotionEffectEditorMenu method init.

@Override
public void init(Player player, InventoryContents contents) {
    addBackItem(contents, e -> menus.getTeamMenus().openPotionEffectsMenu(player, arena, team));
    contents.set(0, 3, ClickableItem.from(nameItem(Material.REDSTONE, "&eDuration", "||&eCurrent value: &3" + potionEffect.getDuration()), e -> openAnvilMenu(player, arena, team, potionEffect, String.valueOf(potionEffect.getDuration()), (p, text) -> {
        if (Utils.isInt(text)) {
            team.getLoadout().getEffects().remove(potionEffect);
            potionEffect = new PotionEffectBuilder(potionEffect).duration(Integer.parseInt(text)).build();
            team.getLoadout().getEffects().add(potionEffect);
            arena.write();
            Tasks.wait(1, () -> {
                // Since potion effects don't have setters, pass-by-reference is broken, so we
                // have to do some hacky waits to get the menu to open with the correct object
                player.closeInventory();
                Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
            });
            return AnvilGUI.Response.text(text);
        } else {
            PlayerUtils.send(player, PREFIX + "You must use an integer for the duration.");
            return AnvilGUI.Response.close();
        }
    })));
    contents.set(0, 5, ClickableItem.from(nameItem(Material.GLOWSTONE_DUST, "&eAmplifier", "||&eCurrent value: &3" + (potionEffect.getAmplifier() + 1)), e -> openAnvilMenu(player, arena, team, potionEffect, String.valueOf(potionEffect.getAmplifier()), (p, text) -> {
        if (Utils.isInt(text)) {
            team.getLoadout().getEffects().remove(potionEffect);
            potionEffect = new PotionEffectBuilder(potionEffect).amplifier(Integer.parseInt(text) - 1).build();
            team.getLoadout().getEffects().add(potionEffect);
            arena.write();
            Tasks.wait(1, () -> {
                player.closeInventory();
                Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
            });
            return AnvilGUI.Response.text(text);
        } else {
            PlayerUtils.send(player, PREFIX + "You must use an integer for the amplifier.");
            return AnvilGUI.Response.close();
        }
    })));
    contents.set(0, 8, ClickableItem.from(nameItem(Material.END_CRYSTAL, "&eSave"), e -> arena.write()));
    int row = 2;
    int column = 0;
    for (PotionEffectType effect : PotionEffectType.values()) {
        if (effect == null)
            continue;
        ItemStack potionItem = new ItemBuilder(Material.POTION).name("&e" + StringUtils.camelCase(effect.getName().replace("_", " "))).potionEffect(new PotionEffectBuilder(effect).duration(5).amplifier(0)).potionEffectColor(effect.getColor()).build();
        if (effect == potionEffect.getType())
            potionItem.setType(Material.SPLASH_POTION);
        contents.set(row, column, ClickableItem.from(potionItem, e -> {
            team.getLoadout().getEffects().remove(potionEffect);
            potionEffect = new PotionEffectBuilder(potionEffect).type(effect).build();
            team.getLoadout().getEffects().add(potionEffect);
            arena.write();
            Tasks.wait(1, () -> {
                player.closeInventory();
                Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
            });
        }));
        if (column == 8) {
            column = 0;
            row++;
        } else {
            column++;
        }
    }
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) StringUtils(gg.projecteden.nexus.utils.StringUtils) Minigames.menus(gg.projecteden.nexus.features.minigames.Minigames.menus) NonNull(lombok.NonNull) BiFunction(java.util.function.BiFunction) Tasks(gg.projecteden.nexus.utils.Tasks) Player(org.bukkit.entity.Player) Arena(gg.projecteden.nexus.features.minigames.models.Arena) Utils(gg.projecteden.nexus.utils.Utils) ItemStack(org.bukkit.inventory.ItemStack) PotionEffect(org.bukkit.potion.PotionEffect) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) MenuUtils(gg.projecteden.nexus.features.menus.MenuUtils) PotionEffectBuilder(gg.projecteden.nexus.utils.PotionEffectBuilder) AnvilGUI(net.wesjd.anvilgui.AnvilGUI) PREFIX(gg.projecteden.nexus.features.minigames.Minigames.PREFIX) Team(gg.projecteden.nexus.features.minigames.models.Team) Material(org.bukkit.Material) PotionEffectType(org.bukkit.potion.PotionEffectType) ClickableItem(fr.minuskube.inv.ClickableItem) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) PotionEffectType(org.bukkit.potion.PotionEffectType) ItemStack(org.bukkit.inventory.ItemStack) PotionEffectBuilder(gg.projecteden.nexus.utils.PotionEffectBuilder)

Example 2 with Team

use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.

the class TeamMechanic method nextTurn.

public void nextTurn(@NotNull Match match) {
    Arena arena = match.getArena();
    MatchData matchData = match.getMatchData();
    MatchTasks tasks = match.getTasks();
    if (match.isEnded() || matchData == null)
        return;
    if (matchData.getTurnTeam() != null) {
        onTurnEnd(match, matchData.getTurnTeam());
        matchData.setTurnTeam(null);
    }
    if (shouldBeOver(match)) {
        end(match);
        return;
    }
    if (matchData.getTurns() >= match.getArena().getMaxTurns()) {
        match.broadcast("Max turns reached, ending game");
        match.end();
        return;
    }
    if (matchData.getTurnTeamList().isEmpty()) {
        matchData.setTurnTeamList(new ArrayList<>(match.getAliveTeams()));
        if (shuffleTurnList())
            Collections.shuffle(matchData.getTurnTeamList());
    }
    tasks.cancel(MatchTaskType.TURN);
    Team team = matchData.getTurnTeamList().get(0);
    matchData.getTurnTeamList().remove(team);
    matchData.setTurnTeam(team);
    match.getScoreboard().update();
    onTurnStart(match, team);
    tasks.register(MatchTaskType.TURN, tasks.wait(arena.getTurnTime() * TickTime.SECOND.get(), () -> nextTurn(match)));
}
Also used : MatchTasks(gg.projecteden.nexus.features.minigames.models.Match.MatchTasks) Team(gg.projecteden.nexus.features.minigames.models.Team) MatchData(gg.projecteden.nexus.features.minigames.models.MatchData) Arena(gg.projecteden.nexus.features.minigames.models.Arena)

Example 3 with Team

use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.

the class TeamMechanic method announceWinners.

@Override
public void announceWinners(@NotNull Match match) {
    Arena arena = match.getArena();
    Map<Team, Integer> scores = match.getScores();
    int winningScore = getWinningScore(scores.values());
    List<Team> winners = getWinningTeams(winningScore, scores);
    String announcement = null;
    if (winningScore == 0)
        announcement = "No teams scored in ";
    else if (arena.getTeams().size() == winners.size())
        announcement = "All teams tied in ";
    JsonBuilder builder = new JsonBuilder();
    builder.next(announcement == null ? getWinnersComponent(winners) : Component.text(announcement));
    builder.next(arena);
    if (winningScore != 0)
        builder.next(" (" + winningScore + ")");
    Minigames.broadcast(builder);
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) Team(gg.projecteden.nexus.features.minigames.models.Team) Arena(gg.projecteden.nexus.features.minigames.models.Arena)

Example 4 with Team

use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.

the class TeamMechanic method getBalanceWrappers.

@NotNull
protected List<BalanceWrapper> getBalanceWrappers(@NotNull Match match) {
    // ALL PERCENTAGES HERE RANGE FROM 0 to 1 !!
    List<Team> teams = match.getArena().getTeams();
    List<BalanceWrapper> wrappers = new ArrayList<>();
    // sum of all balance percentages
    double percentageSum = 0;
    // count of teams w/o balance percentages
    int noPercentage = 0;
    for (Team team : teams) {
        BalanceWrapper wrapper = new BalanceWrapper(team, match);
        wrappers.add(wrapper);
        if (wrapper.getPercentage() != null)
            percentageSum += wrapper.getPercentage();
        else
            noPercentage++;
    }
    if (noPercentage > 0 && percentageSum < 1) {
        // evenly split the balance of teams that don't have a balance percentage (if there is any unassigned %)
        double percentage = (1d / noPercentage) * (1d - percentageSum);
        wrappers.stream().filter(wrapper -> wrapper.getPercentage() == null).forEach(wrapper -> wrapper.setPercentage(percentage));
    }
    // ensure percentages add up to 100
    double totalPercentage = wrappers.stream().mapToDouble(BalanceWrapper::getPercentage).sum();
    wrappers.forEach(wrapper -> wrapper.setPercentage(wrapper.getPercentage() / totalPercentage));
    return wrappers;
}
Also used : MatchTasks(gg.projecteden.nexus.features.minigames.models.Match.MatchTasks) VoiceChannelCategory(gg.projecteden.utils.DiscordId.VoiceChannelCategory) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) LocalDateTime(java.time.LocalDateTime) OptionalPlayer(me.lexikiq.OptionalPlayer) HashMap(java.util.HashMap) Member(net.dv8tion.jda.api.entities.Member) Player(org.bukkit.entity.Player) MatchData(gg.projecteden.nexus.features.minigames.models.MatchData) Name(gg.projecteden.nexus.utils.Name) Match(gg.projecteden.nexus.features.minigames.models.Match) MinigamerQuitEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MinigamerQuitEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Guild(net.dv8tion.jda.api.entities.Guild) MatchEndEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MatchEndEvent) RandomUtils(gg.projecteden.nexus.utils.RandomUtils) Component(net.kyori.adventure.text.Component) Map(java.util.Map) Team(gg.projecteden.nexus.features.minigames.models.Team) Minigames(gg.projecteden.nexus.features.minigames.Minigames) ChatColor(net.md_5.bungee.api.ChatColor) Nexus(gg.projecteden.nexus.Nexus) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) Set(java.util.Set) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) Discord(gg.projecteden.nexus.features.discord.Discord) Arena(gg.projecteden.nexus.features.minigames.models.Arena) MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent) DiscordId(gg.projecteden.utils.DiscordId) MatchTaskType(gg.projecteden.nexus.features.minigames.models.Match.MatchTasks.MatchTaskType) TickTime(gg.projecteden.utils.TimeUtils.TickTime) Nullable(org.jetbrains.annotations.Nullable) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) List(java.util.List) Data(lombok.Data) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) MultiplayerMechanic(gg.projecteden.nexus.features.minigames.models.mechanics.multiplayer.MultiplayerMechanic) ArrayList(java.util.ArrayList) Team(gg.projecteden.nexus.features.minigames.models.Team) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Team

use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.

the class TeamMechanic method basicBalanceCheck.

public final boolean basicBalanceCheck(@NotNull List<Minigamer> minigamers) {
    if (minigamers.isEmpty())
        return false;
    Match match = minigamers.get(0).getMatch();
    Arena arena = match.getArena();
    List<Team> teams = new ArrayList<>(arena.getTeams());
    int required = 0;
    for (Team team : teams) required += team.getMinPlayers();
    if (match.getMinigamers().size() < required) {
        error("Not enough players to meet team requirements!", match);
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Team(gg.projecteden.nexus.features.minigames.models.Team) Arena(gg.projecteden.nexus.features.minigames.models.Arena) Match(gg.projecteden.nexus.features.minigames.models.Match)

Aggregations

Team (gg.projecteden.nexus.features.minigames.models.Team)31 Arena (gg.projecteden.nexus.features.minigames.models.Arena)17 ItemStack (org.bukkit.inventory.ItemStack)13 Match (gg.projecteden.nexus.features.minigames.models.Match)11 ArrayList (java.util.ArrayList)11 Player (org.bukkit.entity.Player)11 Minigamer (gg.projecteden.nexus.features.minigames.models.Minigamer)10 Material (org.bukkit.Material)10 ClickableItem (fr.minuskube.inv.ClickableItem)8 InventoryContents (fr.minuskube.inv.content.InventoryContents)8 InventoryProvider (fr.minuskube.inv.content.InventoryProvider)8 MenuUtils (gg.projecteden.nexus.features.menus.MenuUtils)8 NonNull (lombok.NonNull)8 Tasks (gg.projecteden.nexus.utils.Tasks)7 Map (java.util.Map)7 NotNull (org.jetbrains.annotations.NotNull)7 HashMap (java.util.HashMap)6 Minigames.menus (gg.projecteden.nexus.features.minigames.Minigames.menus)5 List (java.util.List)5 Optional (java.util.Optional)5