/** Causes all combat spells to expire */ public void expireCombatSpells() { // Expire the spells, one at a time for (SpellWrapper spell : getSpells(COMBAT_SPELLS)) { spell.expireSpell(); } // Clear the combat spell list setBoolean(COMBAT_SPELLS, false); }
/** Causes all day spells to expire */ public void expireDaySpells() { // Expire the spells, one at a time for (SpellWrapper spell : getSpells(DAY_SPELLS)) { spell.expireSpell(); } // Clear the day spell list setBoolean(DAY_SPELLS, false); }
/** * Causes all phase spells to expire * * @return true when spells were expired */ public boolean expirePhaseSpells() { boolean ret = false; // Expire the spells, one at a time for (SpellWrapper spell : getSpells(PHASE_SPELLS)) { spell.expireSpell(); ret = true; } // Clear the phase spell list setBoolean(PHASE_SPELLS, false); return ret; }
public void expireAllSpells() { // Expire the spells, one at a time for (SpellWrapper spell : getSpells(null)) { spell.expireSpell(); } // Clear all spell lists setBoolean(DAY_SPELLS, false); setBoolean(COMBAT_SPELLS, false); setBoolean(PERMANENT_SPELLS, false); setBoolean(PHASE_SPELLS, false); setBoolean(MOVE_SPELLS, false); }
private void expireBewitchingSpells(GameObject target, SpellWrapper exclude, boolean nullify) { for (SpellWrapper spell : getAffectingSpells(target)) { if (exclude != null && exclude.getGameObject().equals(spell.getGameObject())) continue; if (!nullify) { spell.removeTarget(target); if (spell.getTargetCount() == 0) { spell.expireSpell(); // System.err.println(spell.getGameObject().getName()+" is expired"); } } else { spell.nullifySpell(); // System.err.println(spell.getGameObject().getName()+" is nullified"); } } }
public void expireIncantationSpell(GameObject incantation) { SpellWrapper spell = getIncantedSpell(incantation); if (spell != null) { spell.expireSpell(); } }
/** 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); } } }