Esempio n. 1
0
 private MageObject getMageObject(GameEvent event, Game game, TriggeredAbility ability) {
   MageObject object = game.getPermanent(ability.getSourceId());
   if (object == null) {
     object = game.getLastKnownInformation(ability.getSourceId(), event.getZone());
     if (object == null) {
       object = game.getObject(ability.getSourceId());
     }
   }
   return object;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 private String getKey(TriggeredAbility ability, MageObject target) {
   String key = ability.getId() + "_";
   if (target != null) {
     key += target.getId();
   }
   return key;
 }
Esempio n. 4
0
 public void checkTriggers(GameEvent event, Game game) {
   for (TriggeredAbility ability : this.values()) {
     if (ability.isInUseableZone(game, null, true)) {
       MageObject object = getMageObject(event, game, ability);
       if (object != null) {
         if (checkAbilityStillExists(ability, event, object)) {
           if (object instanceof Permanent) {
             ability.setControllerId(((Permanent) object).getControllerId());
           }
           if (ability.checkTrigger(event, game)) {
             UUID controllerId = ability.getControllerId();
             ability.trigger(game, controllerId);
           }
         }
       }
     }
   }
 }