Search in sources :

Example 1 with MatchWinner

use of pl.themolka.arcade.match.MatchWinner 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 2 with MatchWinner

use of pl.themolka.arcade.match.MatchWinner 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 3 with MatchWinner

use of pl.themolka.arcade.match.MatchWinner in project Arcade2 by ShootGame.

the class KillEnemiesGame method getDynamicWinners.

@Override
public List<MatchWinner> getDynamicWinners() {
    double highestProgress = Goal.PROGRESS_UNTOUCHED;
    List<MatchWinner> results = new ArrayList<>();
    for (MatchWinner winner : this.getMatch().getWinnerList()) {
        if (winner.areGoalsCompleted()) {
            results.add(winner);
            continue;
        }
        KillEnemies objective = this.getObjective(winner);
        if (objective == null) {
            continue;
        }
        double progress = objective.getProgress();
        if (progress > highestProgress) {
            results.clear();
            highestProgress = progress;
        }
        if (!results.contains(winner) && progress >= highestProgress) {
            results.add(winner);
        }
    }
    if (highestProgress != Goal.PROGRESS_UNTOUCHED && !results.isEmpty()) {
        return results;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) MatchWinner(pl.themolka.arcade.match.MatchWinner)

Example 4 with MatchWinner

use of pl.themolka.arcade.match.MatchWinner in project Arcade2 by ShootGame.

the class KillEnemiesGame method onEnable.

@Override
public void onEnable() {
    MatchGame module = (MatchGame) this.getGame().getModule(MatchModule.class);
    this.match = module.getMatch();
    this.match.registerDynamicWinnable(this);
    for (Map.Entry<Participator, KillEnemies> entry : this.byOwner.entrySet()) {
        MatchWinner winner = this.match.findWinnerById(entry.getKey().getId());
        if (winner == null) {
            continue;
        }
        winner.addGoal(entry.getValue());
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) MatchGame(pl.themolka.arcade.match.MatchGame) MatchWinner(pl.themolka.arcade.match.MatchWinner) MatchModule(pl.themolka.arcade.match.MatchModule) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with MatchWinner

use of pl.themolka.arcade.match.MatchWinner in project Arcade2 by ShootGame.

the class ScoreGame method onEnable.

@Override
public void onEnable() {
    MatchGame module = (MatchGame) this.getGame().getModule(MatchModule.class);
    this.match = module.getMatch();
    this.match.registerDynamicWinnable(this);
    for (Map.Entry<Participator, Score> entry : this.byOwner.entrySet()) {
        MatchWinner winner = this.match.findWinnerById(entry.getKey().getId());
        if (winner == null) {
            continue;
        }
        Score score = entry.getValue();
        score.setMatch(this.match);
        winner.addGoal(score);
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) MatchGame(pl.themolka.arcade.match.MatchGame) MatchWinner(pl.themolka.arcade.match.MatchWinner) MatchModule(pl.themolka.arcade.match.MatchModule) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MatchWinner (pl.themolka.arcade.match.MatchWinner)6 Participator (pl.themolka.arcade.game.Participator)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Element (org.jdom2.Element)2 JDOMException (org.jdom2.JDOMException)2 MatchGame (pl.themolka.arcade.match.MatchGame)2 MatchModule (pl.themolka.arcade.match.MatchModule)2