@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); MageObject sourceObject = source.getSourceObject(game); Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Player newController = game.getPlayer(getTargetPointer().getFirst(game, source)); if (newController != null && controller != null && sourceObject != null && sourceObject.equals(sourcePermanent)) { // remove old control effects of the same player for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) { if (effect instanceof GainControlTargetEffect) { UUID checkId = (UUID) effect.getValue("RiskyMoveSourceId"); UUID controllerId = (UUID) effect.getValue("RiskyMoveControllerId"); if (source.getSourceId().equals(checkId) && newController.getId().equals(controllerId)) { effect.discard(); } } } ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, newController.getId()); effect.setValue("RiskyMoveSourceId", source.getSourceId()); effect.setValue("RiskyMoveControllerId", newController.getId()); effect.setTargetPointer(new FixedTarget(sourcePermanent.getId())); effect.setText("and gains control of it"); game.addEffect(effect, source); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); MageObject sourceObject = source.getSourceObject(game); Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Player newController = game.getPlayer(getTargetPointer().getFirst(game, source)); if (newController != null && controller != null && sourceObject != null && sourceObject.equals(sourcePermanent)) { sourcePermanent.untap(game); game.informPlayers(newController.getLogName() + " untaps " + sourceObject.getIdName()); // remove old control effects of the same player for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) { if (effect instanceof GainControlTargetEffect) { UUID checkId = (UUID) effect.getValue("KaronaFalseGodSourceId"); UUID controllerId = (UUID) effect.getValue("KaronaFalseGodControllerId"); if (source.getSourceId().equals(checkId) && newController.getId().equals(controllerId)) { effect.discard(); } } } ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, newController.getId()); effect.setValue("KaronaFalseGodSourceId", source.getSourceId()); effect.setValue("KaronaFalseGodControllerId", newController.getId()); effect.setTargetPointer(new FixedTarget(sourcePermanent.getId())); effect.setText("and gains control of it"); game.addEffect(effect, source); return true; } return false; } }