/**
   * Sets the locked flag on a PC
   *
   * @param pc
   */
  public static void applyDomain(PlayerCharacter pc, Domain d) {
    ClassSource source = pc.getDomainSource(d);
    PCClass aClass = pc.getClassKeyed(source.getPcclass().getKeyName());
    if (aClass != null) {
      int maxLevel;

      for (maxLevel = 0; maxLevel < 10; maxLevel++) {
        if (pc.getSpellSupport(aClass).getCastForLevel(maxLevel, pc) == 0) {
          break;
        }
      }

      if (maxLevel > 0) {
        addSpellsToClassForLevels(pc, d, aClass, 0, maxLevel - 1);
      }

      if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
        DomainSpellList domainSpellList = d.get(ObjectKey.DOMAIN_SPELLLIST);
        final List<Spell> aList =
            pc.getAllSpellsInLists(Collections.singletonList(domainSpellList));

        for (Spell gcs : aList) {
          if (SpellLevel.getFirstLvlForKey(gcs, domainSpellList, pc) < maxLevel) {
            pc.setDomainSpellCount(aClass, 1);
            break;
          }
        }
      }
    }

    Collection<CDOMReference<Spell>> mods = d.getSafeListMods(Spell.SPELLS);
    for (CDOMReference<Spell> ref : mods) {
      Collection<Spell> spells = ref.getContainedObjects();
      Collection<AssociatedPrereqObject> assoc = d.getListAssociations(Spell.SPELLS, ref);
      for (AssociatedPrereqObject apo : assoc) {
        if (!PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, d)) {
          continue;
        }
        for (Spell s : spells) {
          String book = apo.getAssociation(AssociationKey.SPELLBOOK);
          List<CharacterSpell> aList = pc.getCharacterSpells(aClass, s, book, -1);

          if (aList.isEmpty()) {
            Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
            CharacterSpell cs = new CharacterSpell(d, s);
            int resolvedTimes = times.resolve(pc, d.getQualifiedKey()).intValue();
            cs.addInfo(1, resolvedTimes, book);
            pc.addCharacterSpell(aClass, cs);
          }
        }
      }
    }
  }
Example #2
0
  /*
   * REFACTOR There is potentially redundant information here - level and PC...
   * is this ever out of sync or can this method be removed/made private??
   */
  public double getBonusTo(
      final String argType, final String argMname, final int asLevel, final PlayerCharacter aPC) {
    double i = 0;

    List<BonusObj> rawBonusList = getRawBonusList(aPC);

    for (int lvl = 1; lvl < asLevel; lvl++) {
      rawBonusList.addAll(aPC.getActiveClassLevel(this, lvl).getRawBonusList(aPC));
    }
    if ((asLevel == 0) || rawBonusList.isEmpty()) {
      return 0;
    }

    final String type = argType.toUpperCase();
    final String mname = argMname.toUpperCase();

    for (final BonusObj bonus : rawBonusList) {
      final StringTokenizer breakOnPipes =
          new StringTokenizer(bonus.toString().toUpperCase(), Constants.PIPE, false);
      final String theType = breakOnPipes.nextToken();

      if (!theType.equals(type)) {
        continue;
      }

      final String str = breakOnPipes.nextToken();
      final StringTokenizer breakOnCommas = new StringTokenizer(str, Constants.COMMA, false);

      while (breakOnCommas.hasMoreTokens()) {
        final String theName = breakOnCommas.nextToken();

        if (theName.equals(mname)) {
          final String aString = breakOnPipes.nextToken();
          final List<Prerequisite> localPreReqList = new ArrayList<>();
          if (bonus.hasPrerequisites()) {
            localPreReqList.addAll(bonus.getPrerequisiteList());
          }

          // TODO: This code should be removed after the 5.8 release
          // as the prereqs are processed by the bonus loading code.
          while (breakOnPipes.hasMoreTokens()) {
            final String bString = breakOnPipes.nextToken();

            if (PreParserFactory.isPreReqString(bString)) {
              Logging.debugPrint(
                  "Why is this prerequisite '"
                      + bString
                      + "' parsed in '"
                      + getClass().getName()
                      + ".getBonusTo(String,String,int)' rather than in the persistence layer?"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
              try {
                final PreParserFactory factory = PreParserFactory.getInstance();
                localPreReqList.add(factory.parse(bString));
              } catch (PersistenceLayerException ple) {
                Logging.errorPrint(ple.getMessage(), ple);
              }
            }
          }

          // must meet criteria for bonuses before adding them in
          // TODO: This is a hack to avoid VARs etc in class defs
          // being qualified for when Bypass class prereqs is
          // selected.
          // Should we be passing in the BonusObj here to allow it to
          // be referenced in Qualifies statements?
          if (PrereqHandler.passesAll(localPreReqList, aPC, null)) {
            final double j = aPC.getVariableValue(aString, getQualifiedKey()).doubleValue();
            i += j;
          }
        }
      }
    }

    return i;
  }