Exemplo n.º 1
0
 @Override
 public boolean triggerAbility(TriggeredAbility source, Game game) {
   if (source != null && source.canChooseTarget(game)) {
     Ability ability;
     List<Ability> options = getPlayableOptions(source, game);
     if (options.isEmpty()) {
       ability = source;
     } else {
       if (options.size() == 1) ability = options.get(0);
       else ability = options.get(rnd.nextInt(options.size()));
     }
     if (ability.isUsesStack()) {
       game.getStack().push(new StackAbility(ability, playerId));
       if (ability.activate(game, false)) {
         actionCount++;
         return true;
       }
     } else {
       if (ability.activate(game, false)) {
         ability.resolve(game);
         actionCount++;
         return true;
       }
     }
   }
   return false;
 }
Exemplo n.º 2
0
 private Ability getAction(Game game) {
   List<Ability> playables = getPlayableAbilities(game);
   Ability ability;
   while (true) {
     if (playables.size() == 1) ability = playables.get(0);
     else ability = playables.get(rnd.nextInt(playables.size()));
     List<Ability> options = getPlayableOptions(ability, game);
     if (!options.isEmpty()) {
       if (options.size() == 1) ability = options.get(0);
       else ability = options.get(rnd.nextInt(options.size()));
     }
     if (ability.getManaCosts().getVariableCosts().size() > 0) {
       int amount =
           getAvailableManaProducers(game).size() - ability.getManaCosts().convertedManaCost();
       if (amount > 0) {
         ability = ability.copy();
         ability.getManaCostsToPay().add(new GenericManaCost(rnd.nextInt(amount)));
       }
     }
     // check if ability kills player, if not then it's ok to play
     //            if (ability.isUsesStack()) {
     //                Game testSim = game.copy();
     //                activateAbility((ActivatedAbility) ability, testSim);
     //                StackObject testAbility = testSim.getStack().pop();
     //                testAbility.resolve(testSim);
     //                testSim.applyEffects();
     //                testSim.checkStateAndTriggered();
     //                if (!testSim.getPlayer(playerId).hasLost()) {
     //                    break;
     //                }
     //            }
     //            else {
     break;
     //            }
   }
   return ability;
 }