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;
}
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);
}
}
}
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);
}
}
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);
}
}
}
}
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);
}
}
Aggregations