private boolean spellCanEnergize( GameWrapper game, TileLocation loc, SpellWrapper spell, boolean includeCalendar) { RealmCalendar cal = RealmCalendar.getCalendar(game.getGameObject().getGameData()); ArrayList infiniteSources = new ArrayList(); if (loc.isInClearing()) { infiniteSources.addAll(loc.clearing.getAllSourcesOfColor(true)); } else if (loc.isBetweenClearings()) { infiniteSources.addAll(loc.clearing.getAllSourcesOfColor(true)); infiniteSources.addAll(loc.getOther().clearing.getAllSourcesOfColor(true)); } else if (loc.isTileOnly()) { infiniteSources.addAll(loc.tile.getAllSourcesOfColor()); } else if (loc.isBetweenTiles()) { infiniteSources.addAll(loc.tile.getAllSourcesOfColor()); infiniteSources.addAll(loc.getOther().tile.getAllSourcesOfColor()); } if (includeCalendar) { // 7th day color magic! infiniteSources.addAll(cal.getColorMagic(game.getMonth(), game.getDay())); } if (infiniteSources.size() > 0) { ColorMagic spellColor = spell.getRequiredColorMagic(); if (spellColor == null || infiniteSources.contains(spellColor)) { // We got it! return true; // spell.affectTargets(frame,game,false); } } return false; }
public void deenergizePermanentSpells() { // Make each permanent spell "inert", one at a time boolean didDeenergize = false; for (SpellWrapper spell : getSpells(PERMANENT_SPELLS)) { if (!spell.isInert()) { // If spell is already inert, then don't deenergize it! // Don't deenergize spells that have an automatic supply of color magic if (spellCanEnergize( GameWrapper.findGame(spell.getGameData()), spell.getCurrentLocation(), spell, false)) { continue; } if (!spell.isAlwaysActive()) { spell.unaffectTargets(); spell.makeInert(); didDeenergize = true; } } } if (didDeenergize) { // Yes, this is a dangerous recursion, but necessary I think. If you Absorb Essence, and then // activate a Transform // spell, you end up two layers deep in spell wizardry, and this is the only way to guarantee // that both are deenergized. deenergizePermanentSpells(); } }