Search in sources :

Example 1 with Participator

use of pl.themolka.arcade.game.Participator in project Arcade2 by ShootGame.

the class NobodyStrategy method getDominators.

@Override
public Multimap<Participator, GamePlayer> getDominators(Multimap<Participator, GamePlayer> competitors) {
    Multimap<Participator, GamePlayer> dominators = ArrayListMultimap.create();
    for (Map.Entry<Participator, Collection<GamePlayer>> entry : competitors.asMap().entrySet()) {
        Participator competitor = entry.getKey();
        Collection<GamePlayer> players = entry.getValue();
        int playerCount = players.size();
        int dominatorCount = 0;
        for (Map.Entry<Participator, Collection<GamePlayer>> dominator : dominators.asMap().entrySet()) {
            // All competitors have same player counts - break the loop.
            dominatorCount = dominator.getValue().size();
            break;
        }
        if (playerCount < dominatorCount) {
            continue;
        } else if (playerCount > dominatorCount) {
            // Do not clear the map when player counts are equal.
            dominators.clear();
        }
        dominators.putAll(competitor, players);
    }
    return dominators;
}
Also used : Participator(pl.themolka.arcade.game.Participator) GamePlayer(pl.themolka.arcade.game.GamePlayer) Collection(java.util.Collection) Map(java.util.Map)

Example 2 with Participator

use of pl.themolka.arcade.game.Participator in project Arcade2 by ShootGame.

the class CapturedState method heartbeat.

@Override
public void heartbeat(long ticks, Match match, Multimap<Participator, GamePlayer> competitors, Multimap<Participator, GamePlayer> dominators, List<Participator> canCapture, Participator owner) {
    if (dominators.isEmpty()) {
        // nobody on the point
        return;
    }
    if (!canCapture.contains(owner)) {
        // The owner is not dominating the point, begin losing it, or
        // start capturing if the capturing captured mode is enabled.
        // If there are more than one enemies on the point and
        // capturing captured mode is enabled - start losing it.
        List<Participator> enemies = new ArrayList<>();
        for (Participator enemy : canCapture) {
            if (!enemy.equals(owner)) {
                enemies.add(enemy);
            }
        }
        Participator enemy = null;
        if (enemies.size() == 1) {
            enemy = enemies.get(0);
        }
        if (this.point.isCapturingCapturedEnabled() && enemy != null) {
            this.point.startCapturingCaptured(enemy, Progress.ZERO);
        } else {
            this.point.startLosing(owner, Progress.DONE);
        }
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) ArrayList(java.util.ArrayList)

Example 3 with Participator

use of pl.themolka.arcade.game.Participator in project Arcade2 by ShootGame.

the class WoolPickupTracker method pickup.

public void pickup(GamePlayer picker, ItemStack item) {
    Participator competitor = this.game.getMatch().findWinnerByPlayer(picker);
    if (competitor == null || this.wool.isCompleted() || !this.wool.isCompletableBy(competitor)) {
        return;
    }
    boolean firstPickup = !this.pickups.containsValue(picker);
    boolean firstCompetitorPickup = !this.pickups.containsKey(competitor);
    double oldProgress = this.wool.getProgress();
    WoolPickupEvent event = new WoolPickupEvent(this.game.getPlugin(), this.wool, competitor, firstPickup, firstCompetitorPickup, item, picker);
    this.game.getPlugin().getEventBus().publish(event);
    if (!event.isCanceled() && !this.pickups.containsValue(picker)) {
        this.wool.getContributions().addContributor(picker);
        competitor.sendGoalMessage(this.wool.getPickupMessage(picker.getDisplayName()));
        this.pickups.put(competitor, picker);
        GoalProgressEvent.call(this.game.getPlugin(), this.wool, picker, oldProgress);
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator)

Example 4 with Participator

use of pl.themolka.arcade.game.Participator in project Arcade2 by ShootGame.

the class CapturingState method heartbeat.

@Override
public void heartbeat(long ticks, Match match, Multimap<Participator, GamePlayer> competitors, Multimap<Participator, GamePlayer> dominators, List<Participator> canCapture, Participator owner) {
    if (!dominators.isEmpty()) {
        if (!canCapture.contains(this.capturer)) {
            // The dominator has changed.
            this.startLosing(this.point, this.capturer, dominators, this.getProgress());
            return;
        }
        if (canCapture.size() == 1) {
            // Progress the state if there is only one dominator who can dominate the point.
            this.progress();
        }
    }
    if (this.getProgress() >= CAPTURED) {
        // The point is captured at 100%.
        if (owner != null && owner.equals(this.capturer)) {
            return;
        }
        CapturedState capturedState = this.point.createCapturedState(this);
        PointCapturedEvent event = new PointCapturedEvent(this.game.getPlugin(), this.point, this, capturedState, owner, this.capturer);
        this.game.getPlugin().getEventBus().publish(event);
        if (event.isCanceled()) {
            return;
        }
        PointState newState = event.getNewState();
        this.point.setState(newState);
        if (newState instanceof CapturedState) {
            Participator oldOwner = event.getOldOwner();
            Participator newOwner = event.getNewOwner();
            if (newOwner != null && (oldOwner == null || !oldOwner.equals(newOwner))) {
                this.point.capture(newOwner, null);
            }
        }
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) PointCapturedEvent(pl.themolka.arcade.capture.point.PointCapturedEvent)

Example 5 with Participator

use of pl.themolka.arcade.game.Participator in project Arcade2 by ShootGame.

the class Wool method onWoolPlace.

@Handler(priority = Priority.HIGHER)
public void onWoolPlace(BlockTransformEvent event) {
    Block block = event.getBlock();
    if (!WoolUtils.isWool(block) || !this.getMonument().contains(block)) {
        return;
    }
    GamePlayer player = event.getGamePlayer();
    if (player == null) {
        // Endermans, TNTs and other entities are not permitted to place wools.
        event.setCanceled(true);
        return;
    }
    if (!WoolUtils.isWool(block, this.getColor())) {
        for (Capturable otherCapturable : this.game.getCapturables()) {
            if (otherCapturable instanceof Wool) {
                Wool otherWool = (Wool) otherCapturable;
                if (WoolUtils.isWool(block, otherWool.getColor()) && otherWool.getMonument().contains(block)) {
                    // This will be handled in its correct listener, return.
                    return;
                }
            }
        }
        event.setCanceled(true);
        player.sendError("Only " + this.getColoredName() + Messageable.ERROR_COLOR + " may be placed here!");
        return;
    }
    event.setCanceled(true);
    if (this.isCompleted()) {
        player.sendError(ChatColor.GOLD + this.getColoredName() + Messageable.ERROR_COLOR + " has already been captured!");
    } else if (this.hasOwner() && this.getOwner().contains(player)) {
        player.sendError("You may not capture your own " + ChatColor.GOLD + this.getColoredName() + Messageable.ERROR_COLOR + "!");
    } else {
        Participator competitor = this.game.getMatch().findWinnerByPlayer(player);
        if (competitor == null) {
            return;
        }
        WoolPlaceEvent placeEvent = new WoolPlaceEvent(this.game.getPlugin(), this, competitor, player);
        this.game.getPlugin().getEventBus().publish(placeEvent);
        if (placeEvent.isCanceled()) {
            return;
        }
        event.setCanceled(false);
        this.capture(placeEvent.getCompleter(), player);
    }
}
Also used : Capturable(pl.themolka.arcade.capture.Capturable) Participator(pl.themolka.arcade.game.Participator) GamePlayer(pl.themolka.arcade.game.GamePlayer) Block(org.bukkit.block.Block) Handler(net.engio.mbassy.listener.Handler) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Participator (pl.themolka.arcade.game.Participator)14 GamePlayer (pl.themolka.arcade.game.GamePlayer)5 MatchWinner (pl.themolka.arcade.match.MatchWinner)4 Map (java.util.Map)3 Handler (net.engio.mbassy.listener.Handler)3 Element (org.jdom2.Element)3 JDOMException (org.jdom2.JDOMException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Block (org.bukkit.block.Block)2 EventHandler (org.bukkit.event.EventHandler)2 MatchGame (pl.themolka.arcade.match.MatchGame)2 MatchModule (pl.themolka.arcade.match.MatchModule)2 Collection (java.util.Collection)1 Capturable (pl.themolka.arcade.capture.Capturable)1 PointCapturedEvent (pl.themolka.arcade.capture.point.PointCapturedEvent)1 Match (pl.themolka.arcade.match.Match)1