private boolean checkAbilityStillExists( Ability ability, ContinuousEffect effect, GameEvent event, Game game) { switch (effect .getDuration()) { // effects with fixed duration don't need an object with the source // ability (e.g. a silence cast with isochronic Scepter has no more a card // object case EndOfCombat: case EndOfGame: case EndOfStep: case EndOfTurn: case OneUse: case Custom: // custom duration means the effect ends itself if needed return true; } if (ability.getSourceId() == null) { // commander replacement effect return true; } MageObject object; if (event.getType().equals(EventType.ZONE_CHANGE) && ((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD) && event.getTargetId().equals(ability.getSourceId())) { object = ((ZoneChangeEvent) event).getTarget(); } else { object = game.getObject(ability.getSourceId()); } if (object == null) { return false; } boolean exists = true; if (!object.getAbilities().contains(ability)) { exists = false; if (object instanceof PermanentCard) { PermanentCard permanent = (PermanentCard) object; if (permanent.canTransform() && event.getType() == GameEvent.EventType.TRANSFORMED) { exists = permanent.getCard().getAbilities().contains(ability); } } } else { if (object instanceof PermanentCard) { PermanentCard permanent = (PermanentCard) object; if (permanent.isFaceDown(game) && !ability.getWorksFaceDown()) { return false; } } else if (object instanceof Spell) { Spell spell = (Spell) object; if (spell.isFaceDown(game) && !ability.getWorksFaceDown()) { return false; } } } return exists; }
private boolean checkAbilityStillExists( TriggeredAbility ability, GameEvent event, MageObject object) { boolean exists = true; if (!object.getAbilities().contains(ability)) { exists = false; if (object instanceof PermanentCard) { PermanentCard permanent = (PermanentCard) object; if (permanent.canTransform() && event.getType() == GameEvent.EventType.TRANSFORMED) { exists = permanent.getCard().getAbilities().contains(ability); } } } return exists; }
private void parseLine(String line) { if (parserState.equals(ParserState.EXPECTED)) { expectedResults.add(line); // just remember for future use return; } Matcher m = pattern.matcher(line); if (m.matches()) { String zone = m.group(1); String nickname = m.group(2); if (nickname.equals("ComputerA") || nickname.equals("ComputerB")) { List<Card> cards = null; List<PermanentCard> perms = null; Zone gameZone; if ("hand".equalsIgnoreCase(zone)) { gameZone = Zone.HAND; cards = nickname.equals("ComputerA") ? handCardsA : handCardsB; } else if ("battlefield".equalsIgnoreCase(zone)) { gameZone = Zone.BATTLEFIELD; perms = nickname.equals("ComputerA") ? battlefieldCardsA : battlefieldCardsB; } else if ("graveyard".equalsIgnoreCase(zone)) { gameZone = Zone.GRAVEYARD; cards = nickname.equals("ComputerA") ? graveyardCardsA : graveyardCardsB; } else if ("library".equalsIgnoreCase(zone)) { gameZone = Zone.LIBRARY; cards = nickname.equals("ComputerA") ? libraryCardsA : libraryCardsB; } else if ("player".equalsIgnoreCase(zone)) { String command = m.group(3); if ("life".equals(command)) { if (nickname.equals("ComputerA")) { commandsA.put(Zone.OUTSIDE, "life:" + m.group(4)); } else { commandsB.put(Zone.OUTSIDE, "life:" + m.group(4)); } } return; } else { return; // go parse next line } String cardName = m.group(3); Integer amount = Integer.parseInt(m.group(4)); boolean tapped = m.group(5) != null && m.group(5).equals(":{tapped}"); if (cardName.equals("clear")) { if (nickname.equals("ComputerA")) { commandsA.put(gameZone, "clear"); } else { commandsB.put(gameZone, "clear"); } } else { for (int i = 0; i < amount; i++) { CardInfo cardInfo = CardRepository.instance.findCard(cardName); Card card = cardInfo != null ? cardInfo.getCard() : null; if (card != null) { if (gameZone.equals(Zone.BATTLEFIELD)) { PermanentCard p = new PermanentCard(card, null); p.setTapped(tapped); perms.add(p); } else { cards.add(card); } } else { logger.fatal("Couldn't find a card: " + cardName); logger.fatal("line: " + line); } } } } else { logger.warn("Unknown player: " + nickname); } } else { logger.warn("Init string wasn't parsed: " + line); } }