Search in sources :

Example 6 with Participator

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

the class DestroyGame method parseMapXml.

private void parseMapXml() {
    for (Element xml : this.getSettings().getChildren()) {
        try {
            // factory
            DestroyableFactory factory = this.getFactory(xml.getName());
            if (factory == null) {
                continue;
            }
            // id
            String id = xml.getAttributeValue("id");
            if (id == null || id.trim().isEmpty()) {
                continue;
            }
            // owner
            String ownerId = xml.getAttributeValue("owner");
            Participator owner = null;
            if (ownerId != null && !ownerId.trim().isEmpty()) {
                owner = this.getMatch().findWinnerById(ownerId.trim());
            }
            // name
            String name = XMLParser.parseMessage(xml.getAttributeValue("name"));
            // object
            Destroyable destroyable = factory.newDestroyable(this, owner, id.trim(), name, xml);
            if (destroyable == null) {
                continue;
            }
            destroyable.setName(name);
            this.addDestroyable(destroyable);
            // register
            if (destroyable.registerGoal()) {
                for (MatchWinner winner : this.getMatch().getWinnerList()) {
                    if (destroyable.isCompletableBy(winner)) {
                        winner.addGoal(destroyable);
                    }
                }
            }
            // register listeners
            destroyable.registerEventListeners(this, true);
        } catch (JDOMException ex) {
            ex.printStackTrace();
        }
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) Element(org.jdom2.Element) MatchWinner(pl.themolka.arcade.match.MatchWinner) JDOMException(org.jdom2.JDOMException)

Example 7 with Participator

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

the class LeakGame method parseMapXml.

private void parseMapXml() {
    for (Element xml : this.getSettings().getChildren()) {
        try {
            // factory
            LeakableFactory factory = this.getFactory(xml.getName());
            if (factory == null) {
                continue;
            }
            // id
            String id = xml.getAttributeValue("id");
            if (id == null || id.trim().isEmpty()) {
                continue;
            }
            // owner
            String ownerId = xml.getAttributeValue("owner");
            Participator owner = null;
            if (ownerId != null && !ownerId.trim().isEmpty()) {
                owner = this.getMatch().findWinnerById(ownerId.trim());
            }
            // name
            String name = XMLParser.parseMessage(xml.getAttributeValue("name"));
            // object
            Leakable leakable = factory.newLeakable(this, owner, id.trim(), name, xml);
            if (leakable == null) {
                continue;
            }
            leakable.setName(name);
            this.addLeakable(leakable);
            // register
            if (leakable.registerGoal()) {
                for (Participator completableBy : this.match.getWinnerList()) {
                    if (leakable.isCompletableBy(completableBy)) {
                        completableBy.addGoal(leakable);
                    }
                }
            }
            // register listeners
            leakable.registerEventListeners(this, true);
        } catch (JDOMException ex) {
            ex.printStackTrace();
        }
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) Element(org.jdom2.Element) JDOMException(org.jdom2.JDOMException)

Example 8 with Participator

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

the class Point method heartbeat.

public void heartbeat(long ticks) {
    if (this.isPermanent() && this.isCompleted()) {
        return;
    }
    Match match = this.game.getMatch();
    Multimap<Participator, GamePlayer> competitors = ArrayListMultimap.create();
    for (GamePlayer player : this.getPlayers()) {
        if (this.canCapture(player) && this.canDominate(player)) {
            Participator competitor = match.findWinnerByPlayer(player);
            if (competitor != null && (competitor.equals(player) || this.canCapture(competitor))) {
                competitors.put(competitor, player);
            }
        }
    }
    Multimap<Participator, GamePlayer> dominators = this.getDominatorStrategy().getDominators(competitors);
    if (dominators == null) {
        dominators = DominatorStrategy.EMPTY_DOMINATORS;
    }
    List<Participator> canCapture = new ArrayList<>();
    for (Participator competitor : dominators.keySet()) {
        if (this.canCapture(competitor)) {
            canCapture.add(competitor);
        }
    }
    // Heartbeat the current state.
    Participator oldOwner = this.getOwner();
    this.getState().heartbeat(ticks, match, competitors, dominators, canCapture, oldOwner);
    Participator newOwner = this.getOwner();
    double pointReward = this.getPointReward();
    if (oldOwner != null && newOwner != null && oldOwner.equals(newOwner) && pointReward != Score.ZERO) {
        // Give reward points for owning the point.
        this.heartbeatReward(oldOwner, pointReward);
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) GamePlayer(pl.themolka.arcade.game.GamePlayer) ArrayList(java.util.ArrayList) Match(pl.themolka.arcade.match.Match)

Example 9 with Participator

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

the class CaptureGame method parseMapXml.

private void parseMapXml() {
    for (Element xml : this.getSettings().getChildren()) {
        try {
            // factory
            CapturableFactory factory = this.getFactory(xml.getName());
            if (factory == null) {
                continue;
            }
            // id
            String id = xml.getAttributeValue("id");
            if (id == null || id.trim().isEmpty()) {
                continue;
            }
            // owner
            String ownerId = xml.getAttributeValue("owner");
            Participator owner = null;
            if (ownerId != null && !ownerId.trim().isEmpty()) {
                owner = this.getMatch().findWinnerById(ownerId.trim());
            }
            // name
            String name = XMLParser.parseMessage(xml.getAttributeValue("name"));
            // object
            Capturable capturable = factory.newCapturable(this, owner, id.trim(), name, xml);
            if (capturable == null) {
                continue;
            }
            capturable.setName(name);
            this.addCapturable(capturable);
            // register
            if (capturable.registerGoal()) {
                for (MatchWinner winner : this.getMatch().getWinnerList()) {
                    if (capturable.isCompletableBy(winner)) {
                        winner.addGoal(capturable);
                    }
                }
            }
            // register listeners
            capturable.registerEventListeners(this, true);
        } catch (JDOMException ex) {
            ex.printStackTrace();
        }
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) Element(org.jdom2.Element) MatchWinner(pl.themolka.arcade.match.MatchWinner) JDOMException(org.jdom2.JDOMException)

Example 10 with Participator

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

the class PointRegionRender method renderPoint.

public void renderPoint(Point point) {
    Participator owner = point.getOwner();
    this.renderPoint(point, owner != null ? owner.getColor() : point.getNeutralColor());
}
Also used : Participator(pl.themolka.arcade.game.Participator)

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