private int getMoveModifier() { int mod = 0; GameObject go = getGameObject().getHeldBy(); if (go != null && go.hasThisAttribute(CHARACTER)) { CharacterWrapper character = new CharacterWrapper(go); ArrayList<GameObject> list = character.getAllActiveInventoryThisKeyAndValue(Constants.HORSE_MOD, null); for (GameObject item : list) { mod += item.getThisInt( Constants.HORSE_MOD); // cumulative... though there's really only the Horse Trainer // (Traveler) at this time } } alteredMoveSpeed = mod != 0; return mod; }
/** 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); } } }