예제 #1
0
  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();
    }
  }
예제 #2
0
 /**
  * @param location The location to search
  * @param needForCancel If true, excludes noCancel spells
  * @return A list of ALL breakable spells (currently Combat,Day,Permanent) that are in the
  *     clearing.
  */
 public ArrayList getAllSpellsInClearing(TileLocation location, boolean needForCancel) {
   ArrayList ret = new ArrayList();
   for (Iterator i = getSpells(null).iterator(); i.hasNext(); ) {
     SpellWrapper spell = (SpellWrapper) i.next();
     if (!needForCancel || !spell.isNoCancelSpell()) {
       TileLocation test = spell.getCurrentLocation();
       if (test
           != null) { // test might be null if the spell is targeting a treasure that hasn't yet
                      // been seen
         if (test.equals(location)) {
           ret.add(spell);
         } else if (test.isTileOnly()) {
           ret.add(spell);
         }
       }
     }
   }
   return ret;
 }
예제 #3
0
  /** Calculates spell locations, and figures out the colors (infinite sources only here) */
  public void energizePermanentSpells(JFrame frame, GameWrapper game) {
    HashLists conflicts = new HashLists();
    for (SpellWrapper spell : getSpells(PERMANENT_SPELLS)) {
      if (spell.isInert()) { // no point energizing non-inert spells!
        TileLocation loc = spell.getCurrentLocation();
        if (loc == null) {
          // This means the spell was lost somehow
          spell.expireSpell();
        } else {
          if (spellCanEnergize(game, loc, spell, true)) {
            if (spell.canConflict()) {
              // Before we can add this, need to make sure that the affected target isn't already
              // afflicted with a STRONGER spell
              boolean addSpell = true;

              int str = spell.getConflictStrength();
              GameObject at = spell.getAffectedTarget().getGameObject();
              ArrayList<SpellWrapper> affSpells = getAffectingSpells(at);
              for (SpellWrapper affSpell : affSpells) {
                if (!affSpell.isInert() && affSpell.canConflict() && !affSpell.equals(spell)) {
                  int aStr = affSpell.getConflictStrength();
                  if (aStr >= str) {
                    // The active spell gets priority because it is equal to or greater in strength
                    // than this spell
                    addSpell = false;
                    break;
                  }
                }
              }

              if (addSpell) {
                conflicts.put(at, spell);
              }
            } else {
              spell.affectTargets(frame, game, false);
            }
          }
        }
      }
    }

    // Resolve conflicts per target (if any)
    for (Iterator i = conflicts.keySet().iterator(); i.hasNext(); ) {
      GameObject target = (GameObject) i.next();
      SpellWrapper strongest = null;
      ArrayList list = conflicts.getList(target);
      if (list.size() == 1) {
        // No conflict!
        strongest = (SpellWrapper) list.get(0);
      } else {
        // Multiple spells affecting target - find the strongest one
        ArrayList<SpellWrapper> strongGroup = new ArrayList<SpellWrapper>();
        int bestStrength = 0;
        for (Iterator n = list.iterator(); n.hasNext(); ) {
          SpellWrapper spell = (SpellWrapper) n.next();
          int strength = spell.getConflictStrength();
          if (strength > bestStrength) {
            strongGroup.clear();
            bestStrength = strength;
          }
          if (strength == bestStrength) {
            strongGroup.add(spell);
          }
        }
        if (strongGroup.size() == 1) {
          // Found the strongest spell
          strongest = strongGroup.get(0);
        } else {
          // uh-oh, this means there are two spells with equal strength affecting the same target
          // In this case, it is up to the spellcaster to decide which spell goes into effect

          // Make sure its all the same caster
          CharacterWrapper commonCaster = null;
          for (SpellWrapper spell : strongGroup) {
            CharacterWrapper caster = spell.getCaster();
            if (commonCaster == null) {
              commonCaster = caster;
            }
            if (!commonCaster.equals(caster)) {
              commonCaster = null;
              break;
            }
          }
          if (commonCaster != null) {
            // Found a common caster
            commonCaster.setSpellConflicts(strongGroup);
          } else {
            // No common caster?  No choice here, but to pick one at random!
            int r = RandomNumber.getRandom(strongGroup.size());
            strongest = strongGroup.get(r);
          }
        }
      }
      if (strongest != null) {
        strongest.affectTargets(frame, game, false);
      }
    }
  }