protected boolean chooseRandom(Target target, Game game) { Set<UUID> possibleTargets = target.possibleTargets(playerId, game); if (possibleTargets.isEmpty()) { return false; } if (possibleTargets.size() == 1) { target.add(possibleTargets.iterator().next(), game); return true; } Iterator<UUID> it = possibleTargets.iterator(); int targetNum = rnd.nextInt(possibleTargets.size()); UUID targetId = it.next(); for (int i = 0; i < targetNum; i++) { targetId = it.next(); } target.add(targetId, game); return true; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent.getCardType().contains(CardType.CREATURE) && (permanent.getControllerId().equals(this.controllerId))) { if (!this.getTargets().isEmpty()) { // remove previous target if (this.getTargets().get(0).getTargets().size() > 0) { this.getTargets().clear(); this.addTarget(new TargetCreaturePermanent()); } Target target = this.getTargets().get(0); if (target instanceof TargetCreaturePermanent) { target.add(event.getTargetId(), game); } } return true; } } return false; }