Esempio n. 1
0
 public String[] unparse(LoadContext context, PCClassLevel obj) {
   Changes<CDOMReference<Skill>> changes =
       context.getObjectContext().getListChanges(obj, ListKey.LOCALCCSKILL);
   List<String> list = new ArrayList<String>();
   Collection<CDOMReference<Skill>> removedItems = changes.getRemoved();
   if (removedItems != null && !removedItems.isEmpty()) {
     if (changes.includesGlobalClear()) {
       context.addWriteMessage(
           "Non-sensical relationship in "
               + getTokenName()
               + ": global .CLEAR and local .CLEAR. performed");
       return null;
     }
     list.add(
         Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
   }
   if (changes.includesGlobalClear()) {
     list.add(Constants.LST_DOT_CLEAR);
   }
   Collection<CDOMReference<Skill>> added = changes.getAdded();
   if (added != null && !added.isEmpty()) {
     list.add(ReferenceUtilities.joinLstFormat(added, Constants.PIPE));
   }
   if (list.isEmpty()) {
     return null;
   }
   return list.toArray(new String[list.size()]);
 }
Esempio n. 2
0
 public String[] unparse(LoadContext context, Race race) {
   Changes<RaceSubType> changes =
       context.getObjectContext().getListChanges(race, ListKey.RACESUBTYPE);
   if (changes == null || changes.isEmpty()) {
     return null;
   }
   List<String> list = new ArrayList<String>();
   Collection<RaceSubType> removedItems = changes.getRemoved();
   if (changes.includesGlobalClear()) {
     if (removedItems != null && !removedItems.isEmpty()) {
       context.addWriteMessage(
           "Non-sensical relationship in "
               + getTokenName()
               + ": global .CLEAR and local .CLEAR. performed");
       return null;
     }
     list.add(Constants.LST_DOT_CLEAR);
   } else if (removedItems != null && !removedItems.isEmpty()) {
     list.add(Constants.LST_DOT_CLEAR_DOT + StringUtil.join(removedItems, "|.CLEAR."));
   }
   Collection<RaceSubType> added = changes.getAdded();
   if (added != null && !added.isEmpty()) {
     list.add(StringUtil.join(added, Constants.PIPE));
   }
   if (list.isEmpty()) {
     return null;
   }
   return list.toArray(new String[list.size()]);
 }
Esempio n. 3
0
  @Override
  protected ParseResult parseTokenWithSeparator(
      LoadContext context, PCClassLevel obj, String value) {
    boolean first = true;
    boolean foundAny = false;
    boolean foundOther = false;

    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    while (tok.hasMoreTokens()) {
      String tokText = tok.nextToken();
      if (Constants.LST_DOT_CLEAR.equals(tokText)) {
        if (!first) {
          return new ParseResult.Fail(
              "  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item");
        }
        context.getObjectContext().removeList(obj, ListKey.LOCALCCSKILL);
      } else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
        String clearText = tokText.substring(7);
        if (Constants.LST_ALL.equals(clearText)) {
          context
              .getObjectContext()
              .removeFromList(
                  obj, ListKey.LOCALCCSKILL, context.ref.getCDOMAllReference(SKILL_CLASS));
        } else {
          CDOMReference<Skill> ref =
              TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, clearText);
          if (ref == null) {
            return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName());
          }
          context.getObjectContext().removeFromList(obj, ListKey.LOCALCCSKILL, ref);
        }
      } else {
        /*
         * Note this HAS to be done one-by-one, because the
         * .clearChildNodeOfClass method above does NOT recognize the
         * C/CC Skill object and therefore doesn't know how to search
         * the sublists
         */
        if (Constants.LST_ALL.equals(tokText)) {
          foundAny = true;
          context
              .getObjectContext()
              .addToList(obj, ListKey.LOCALCCSKILL, context.ref.getCDOMAllReference(SKILL_CLASS));
        } else {
          foundOther = true;
          CDOMReference<Skill> ref = getSkillReference(context, tokText);
          if (ref == null) {
            return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName());
          }
          context.getObjectContext().addToList(obj, ListKey.LOCALCCSKILL, ref);
        }
      }
      first = false;
    }
    if (foundAny && foundOther) {
      return new ParseResult.Fail(
          "Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value);
    }
    return ParseResult.SUCCESS;
  }
Esempio n. 4
0
 protected Kit getCDOMObject(LoadContext context, String name) {
   Kit obj = context.getReferenceContext().silentlyGetConstructedCDOMObject(targetClass, name);
   if (obj == null) {
     obj = context.getReferenceContext().constructCDOMObject(targetClass, name);
   }
   return obj;
 }
Esempio n. 5
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    boolean first = true;

    while (tok.hasMoreTokens()) {
      String tokString = tok.nextToken();
      if (Constants.LST_DOT_CLEAR.equals(tokString)) {
        if (!first) {
          return new ParseResult.Fail(
              "  Non-sensical "
                  + getTokenName()
                  + ": .CLEAR was not the first list item: "
                  + value);
        }
        context.obj.removeList(race, ListKey.RACESUBTYPE);
      } else if (tokString.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
        String clearText = tokString.substring(7);
        context
            .getObjectContext()
            .removeFromList(race, ListKey.RACESUBTYPE, RaceSubType.getConstant(clearText));
      } else {
        context
            .getObjectContext()
            .addToList(race, ListKey.RACESUBTYPE, RaceSubType.getConstant(tokString));
      }
      first = false;
    }
    return ParseResult.SUCCESS;
  }
Esempio n. 6
0
 @Override
 public String[] unparse(LoadContext context, T obj) {
   FactSetKey<F> fk = def.getFactSetKey();
   Changes<ObjectContainer<F>> changes = context.getObjectContext().getSetChanges(obj, fk);
   Collection<ObjectContainer<F>> removedItems = changes.getRemoved();
   List<String> results = new ArrayList<String>(2);
   if (changes.includesGlobalClear()) {
     results.add(Constants.LST_DOT_CLEAR_ALL);
   }
   if (removedItems != null && !removedItems.isEmpty()) {
     context.addWriteMessage(getTokenName() + " does not support " + Constants.LST_DOT_CLEAR_DOT);
     return null;
   }
   Collection<ObjectContainer<F>> added = changes.getAdded();
   if (added != null && added.size() > 0) {
     StringBuilder sb = new StringBuilder();
     boolean needsPipe = false;
     for (ObjectContainer<F> oc : added) {
       if (needsPipe) {
         sb.append(Constants.PIPE);
       }
       sb.append(oc.getLSTformat(false));
       needsPipe = true;
     }
     results.add(sb.toString());
   }
   return results.toArray(new String[results.size()]);
 }
Esempio n. 7
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, Spell spell, String value) {
    StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);

    boolean first = true;
    while (aTok.hasMoreTokens()) {
      String tok = aTok.nextToken();
      if (Constants.LST_DOT_CLEAR.equals(tok)) {
        if (!first) {
          return new ParseResult.Fail(
              "Non-sensical use of .CLEAR in " + getTokenName() + ": " + value, context);
        }
        context.getObjectContext().removeList(spell, ListKey.RANGE);
      } else {
        if (!StringUtil.hasBalancedParens(value)) {
          return new ParseResult.Fail(
              "Unbalanced parentheses in "
                  + getTokenName()
                  + " '"
                  + value
                  + "' used in spell "
                  + spell,
              context);
        }
        context.getObjectContext().addToList(spell, ListKey.RANGE, tok);
        Globals.addSpellRangesSet(tok);
      }
      first = false;
    }
    return ParseResult.SUCCESS;
  }
Esempio n. 8
0
 @Override
 public String[] unparse(LoadContext context, PCTemplate pct) {
   Changes<CDOMReference<Ability>> changes =
       context.getObjectContext().getListChanges(pct, ListKey.FEAT_TOKEN_LIST);
   Collection<CDOMReference<Ability>> added = changes.getAdded();
   Collection<CDOMReference<Ability>> removedItems = changes.getRemoved();
   String returnVal = null;
   if (changes.includesGlobalClear()) {
     if (removedItems != null && !removedItems.isEmpty()) {
       context.addWriteMessage(
           "Non-sensical relationship in "
               + getTokenName()
               + ": global .CLEAR and local .CLEAR. performed");
       return null;
     }
     returnVal = Constants.LST_DOT_CLEAR;
   } else if (removedItems != null && !removedItems.isEmpty()) {
     context.addWriteMessage(getTokenName() + " does not support " + Constants.LST_DOT_CLEAR_DOT);
     return null;
   }
   if (added != null && !added.isEmpty()) {
     returnVal = ReferenceUtilities.joinLstFormat(added, Constants.PIPE);
   }
   if (returnVal == null) {
     return null;
   }
   return new String[] {returnVal};
 }
Esempio n. 9
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, PCTemplate pct, String value) {
    context.getObjectContext().removeList(pct, ListKey.FEAT_TOKEN_LIST);

    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);

    boolean first = true;

    ReferenceManufacturer<Ability> rm =
        context.ref.getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT);
    while (tok.hasMoreTokens()) {
      String token = tok.nextToken();
      if (Constants.LST_DOT_CLEAR.equals(token)) {
        if (!first) {
          return new ParseResult.Fail(
              "  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item: " + value,
              context);
        }
      } else {
        CDOMReference<Ability> ability = TokenUtilities.getTypeOrPrimitive(rm, token);
        if (ability == null) {
          return ParseResult.INTERNAL_ERROR;
        }
        context.getObjectContext().addToList(pct, ListKey.FEAT_TOKEN_LIST, ability);
      }
      first = false;
    }
    return ParseResult.SUCCESS;
  }
Esempio n. 10
0
 @Override
 public String[] unparse(LoadContext context, CDOMObject cdo) {
   Changes<Type> changes = context.getObjectContext().getListChanges(cdo, ListKey.TYPE);
   if (changes == null || changes.isEmpty()) {
     return null;
   }
   StringBuilder sb = new StringBuilder();
   Collection<?> added = changes.getAdded();
   boolean globalClear = changes.includesGlobalClear();
   if (globalClear) {
     sb.append(Constants.LST_DOT_CLEAR);
   }
   if (added != null && !added.isEmpty()) {
     if (globalClear) {
       sb.append(Constants.DOT);
     }
     sb.append(StringUtil.join(added, Constants.DOT));
   }
   Collection<Type> removed = changes.getRemoved();
   if (removed != null && !removed.isEmpty()) {
     if (sb.length() > 0) {
       sb.append(Constants.DOT);
     }
     sb.append("REMOVE.");
     sb.append(StringUtil.join(removed, Constants.DOT));
   }
   if (sb.length() == 0) {
     context.addWriteMessage(
         getTokenName()
             + " was expecting non-empty changes to include "
             + "added items or global clear");
     return null;
   }
   return new String[] {sb.toString()};
 }
 @Override
 public String[] unparse(LoadContext context, CDOMObject cdo) {
   ChooseInformation<?> tc = context.getObjectContext().getObject(cdo, ObjectKey.CHOOSE_INFO);
   if (tc == null) {
     return null;
   }
   if (!tc.getName().equals(getTokenName())) {
     // Don't unparse anything that isn't owned by this SecondaryToken
     /*
      * TODO Either this really needs to be a check against the subtoken
      * (which thus needs to be stored in the ChooseInfo) or there needs
      * to be a loadtime check that no more than once CHOOSE subtoken
      * uses the same AssociationListKey... :P
      */
     return null;
   }
   if (!tc.getGroupingState().isValid()) {
     context.addWriteMessage(
         "Invalid combination of objects"
             + " was used in: "
             + getParentToken()
             + ":"
             + getTokenName());
     return null;
   }
   StringBuilder sb = new StringBuilder();
   sb.append(tc.getLSTformat());
   String title = tc.getTitle();
   if (!title.equals(getDefaultTitle())) {
     sb.append("|TITLE=");
     sb.append(title);
   }
   return new String[] {sb.toString()};
 }
Esempio n. 12
0
 public String[] unparse(LoadContext context, EquipmentModifier mod) {
   Changes<SpecialProperty> changes =
       context.getObjectContext().getListChanges(mod, ListKey.SPECIAL_PROPERTIES);
   if (changes == null || changes.isEmpty()) {
     return null;
   }
   List<String> list = new ArrayList<String>();
   Collection<SpecialProperty> added = changes.getAdded();
   boolean globalClear = changes.includesGlobalClear();
   if (globalClear) {
     list.add(Constants.LST_DOT_CLEAR);
   }
   if (added != null && !added.isEmpty()) {
     for (SpecialProperty sp : added) {
       StringBuilder sb = new StringBuilder();
       sb.append(sp.getDisplayName());
       if (sp.hasPrerequisites()) {
         sb.append(Constants.PIPE);
         sb.append(getPrerequisiteString(context, sp.getPrerequisiteList()));
       }
       list.add(sb.toString());
     }
   }
   if (list.isEmpty()) {
     context.addWriteMessage(
         getTokenName()
             + " was expecting non-empty changes to include "
             + "added items or global clear");
     return null;
   }
   return list.toArray(new String[list.size()]);
 }
Esempio n. 13
0
 @Override
 public String[] unparse(LoadContext context, CDOMObject obj) {
   Changes<PersistentTransitionChoice<?>> grantChanges =
       context.getObjectContext().getListChanges(obj, ListKey.REMOVE);
   Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
   if (addedItems == null || addedItems.isEmpty()) {
     // Zero indicates no Token
     return null;
   }
   List<String> addStrings = new ArrayList<String>();
   for (TransitionChoice<?> container : addedItems) {
     SelectableSet<?> cs = container.getChoices();
     if (getTokenName().equals(cs.getName())
         && CAT_ABILITY_SELECTION_CLASS.equals(cs.getChoiceClass())) {
       Formula f = container.getCount();
       if (f == null) {
         context.addWriteMessage("Unable to find " + getFullName() + " Count");
         return null;
       }
       StringBuilder sb = new StringBuilder();
       if (!FormulaFactory.ONE.equals(f)) {
         sb.append(f).append(Constants.PIPE);
       }
       sb.append(cs.getLSTformat());
       addStrings.add(sb.toString());
     }
   }
   return addStrings.toArray(new String[addStrings.size()]);
 }
Esempio n. 14
0
 public static PersistentTransitionChoice<?> processOldAdd(LoadContext context, String first)
     throws PersistenceLayerException {
   int openParenLoc = first.indexOf('(');
   if (openParenLoc == -1) {
     Logging.errorPrint("Expected to have a ( : " + first);
     return null;
   }
   int closeParenLoc = first.lastIndexOf(')');
   if (openParenLoc == -1) {
     Logging.errorPrint("Expected to have a ) : " + first);
     return null;
   }
   String key = first.substring(7, openParenLoc);
   String choices = first.substring(openParenLoc + 1, closeParenLoc);
   String count = "";
   if (closeParenLoc != first.length() - 1) {
     count = first.substring(closeParenLoc + 1) + '|';
   }
   PCClass applied = new PCClass();
   ParseResult pr = context.processSubToken(applied, "ADD", key, count + choices);
   pr.printMessages();
   if (!pr.passed()) {
     return null;
   }
   context.commit();
   PersistentTransitionChoice<?> ptc = applied.getListFor(ListKey.ADD).get(0);
   return ptc;
 }
  /**
   * Test to ensure that a character will fail a test if it does not have the correct number of
   * levels in the class.
   *
   * @throws Exception
   */
  public void testCharWithMultipleSpellClasses() throws Exception {
    LoadContext context = Globals.getContext();
    final PCClass pcClass = new PCClass();
    pcClass.setName("MyClass");
    context.unconditionallyProcess(pcClass, "SPELLSTAT", "CHA");
    pcClass.put(StringKey.SPELLTYPE, "ARCANE");
    context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "CAST", "5,4");

    final PCClass pcClass2 = new PCClass();
    pcClass2.setName("Other Class");
    context.unconditionallyProcess(pcClass2, "SPELLSTAT", "INT");
    pcClass2.put(StringKey.SPELLTYPE, "ARCANE");
    context.unconditionallyProcess(pcClass2.getOriginalClassLevel(1), "CAST", "5,4");

    final PlayerCharacter character = getCharacter();
    setPCStat(character, cha, 12);
    setPCStat(character, intel, 12);
    character.incrementClassLevel(1, pcClass);
    character.incrementClassLevel(2, pcClass2);

    final PreClassParser producer = new PreClassParser();

    final Prerequisite prereq =
        producer.parse("CLASS", "1,SPELLCASTER.Arcane,SPELLCASTER.Arcane=2", false, false);

    final PreMult test = new PreMult();
    final int passes = test.passes(prereq, character, null);
    assertEquals(1, passes);
  }
 protected void resetContext() {
   URI testURI = testCampaign.getURI();
   context =
       new RuntimeLoadContext(new RuntimeReferenceContext(), new ConsolidatedListCommitStrategy());
   context.setSourceURI(testURI);
   context.setExtractURI(testURI);
   fd = new FactSetDefinition();
 }
Esempio n. 17
0
  @Override
  public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<FollowerOption> changes =
        context.getObjectContext().getListChanges(obj, ListKey.COMPANIONLIST);
    Collection<FollowerOption> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
      context.addWriteMessage(getTokenName() + " does not support .CLEAR");
      return null;
    }
    Collection<FollowerOption> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
      // Zero indicates no Token (and no global clear, so nothing to do)
      return null;
    }
    TripleKeyMapToList<
            Set<Prerequisite>, CDOMReference<? extends CDOMList<?>>, Integer, CDOMReference<Race>>
        m = new TripleKeyMapToList<>();
    for (FollowerOption fo : added) {
      m.addToListFor(
          new HashSet<>(fo.getPrerequisiteList()),
          fo.getListRef(),
          fo.getAdjustment(),
          fo.getRaceRef());
    }
    Set<String> set = new TreeSet<>();
    StringBuilder sb = new StringBuilder();
    for (Set<Prerequisite> prereqs : m.getKeySet()) {
      String prereqString = null;
      if (prereqs != null && !prereqs.isEmpty()) {
        prereqString = getPrerequisiteString(context, prereqs);
      }

      for (CDOMReference<? extends CDOMList<?>> cl : m.getSecondaryKeySet(prereqs)) {
        for (Integer fa : m.getTertiaryKeySet(prereqs, cl)) {
          sb.setLength(0);
          sb.append(cl.getLSTformat(false));
          sb.append(Constants.PIPE);
          Set<CDOMReference<Race>> raceSet = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
          raceSet.addAll(m.getListFor(prereqs, cl, fa));
          sb.append(ReferenceUtilities.joinLstFormat(raceSet, Constants.COMMA, true));
          if (fa != null && fa != 0) {
            sb.append(Constants.PIPE);
            sb.append("FOLLOWERADJUSTMENT:");
            sb.append(fa);
          }
          if (prereqString != null) {
            sb.append(Constants.PIPE);
            sb.append(prereqString);
          }
          set.add(sb.toString());
        }
      }
    }
    return set.toArray(new String[set.size()]);
  }
Esempio n. 18
0
 /**
  * Report where an issue was encountered.
  *
  * @param context the LoadContext containing the resource
  */
 public static void reportSource(final Level lvl, final LoadContext context) {
   Logger l = getLogger();
   if (l.isLoggable(lvl)) {
     if (context != null
         && context.getObjectContext() != null
         && context.getObjectContext().getSourceURI() != null) {
       l.log(lvl, " (Source: " + context.getObjectContext().getSourceURI() + " )");
     } else {
       l.log(lvl, " (Source unknown)");
     }
   }
 }
Esempio n. 19
0
  @Override
  public void unloadLstFiles(LoadContext lc, Collection<CampaignSourceEntry> files) {
    HashMapToList<Class<?>, CDOMSubLineLoader<?>> loaderMap =
        new HashMapToList<Class<?>, CDOMSubLineLoader<?>>();
    for (CDOMSubLineLoader<?> loader : loadMap.values()) {
      loaderMap.addToListFor(loader.getLoadedClass(), loader);
    }
    for (CampaignSourceEntry cse : files) {
      lc.setExtractURI(cse.getURI());
      URI writeURI = cse.getWriteURI();
      File f = new File(writeURI);
      ensureCreated(f.getParentFile());
      try {
        TreeSet<String> set = new TreeSet<String>();
        for (Kit k : lc.getReferenceContext().getConstructedCDOMObjects(Kit.class)) {
          if (cse.getURI().equals(k.getSourceURI())) {
            StringBuilder sb = new StringBuilder();
            String[] unparse = lc.unparseSubtoken(k, "*KITTOKEN");
            sb.append("STARTPACK:");
            sb.append(k.getDisplayName());
            if (unparse != null) {
              sb.append('\t').append(StringUtil.join(unparse, "\t"));
            }
            sb.append('\n');

            Changes<BaseKit> changes = lc.getObjectContext().getListChanges(k, ListKey.KIT_TASKS);
            Collection<BaseKit> tasks = changes.getAdded();
            if (tasks == null) {
              continue;
            }
            for (BaseKit kt : tasks) {
              List<CDOMSubLineLoader<?>> loaders = loaderMap.getListFor(kt.getClass());
              for (CDOMSubLineLoader loader : loaders) {
                processTask(lc, kt, loader, sb);
              }
            }
            sb.append('\n');
            set.add(sb.toString());
          }
        }
        PrintWriter pw = new PrintWriter(f);
        pw.println("#~PARAGRAPH");
        for (String s : set) {
          pw.print(s);
        }
        pw.close();
      } catch (IOException e) {
        Logging.errorPrint("Exception in Load: ", e);
      }
    }
  }
Esempio n. 20
0
 @Override
 public String[] unparse(LoadContext context, CDOMObject obj) {
   Changes<ShieldProfProvider> changes = context.obj.getListChanges(obj, ListKey.AUTO_SHIELDPROF);
   Changes<ChooseSelectionActor<?>> listChanges =
       context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
   Collection<ShieldProfProvider> added = changes.getAdded();
   Set<String> set = new TreeSet<String>();
   Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
   boolean foundAny = false;
   boolean foundOther = false;
   if (listAdded != null && !listAdded.isEmpty()) {
     for (ChooseSelectionActor<?> cra : listAdded) {
       if (cra.getSource().equals(getTokenName())) {
         try {
           set.add(cra.getLstFormat());
           foundOther = true;
         } catch (PersistenceLayerException e) {
           context.addWriteMessage("Error writing Prerequisite: " + e);
           return null;
         }
       }
     }
   }
   if (added != null) {
     for (ShieldProfProvider spp : added) {
       StringBuilder sb = new StringBuilder();
       sb.append(spp.getLstFormat());
       if (spp.hasPrerequisites()) {
         sb.append('|');
         sb.append(getPrerequisiteString(context, spp.getPrerequisiteList()));
       }
       String ab = sb.toString();
       boolean isUnconditionalAll = Constants.LST_ALL.equals(ab);
       foundAny |= isUnconditionalAll;
       foundOther |= !isUnconditionalAll;
       set.add(ab);
     }
   }
   if (foundAny && foundOther) {
     context.addWriteMessage(
         "Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + set);
     return null;
   }
   if (set.isEmpty()) {
     // okay
     return null;
   }
   return set.toArray(new String[set.size()]);
 }
Esempio n. 21
0
  @Override
  protected ParseResult parseTokenWithSeparator(
      LoadContext context, EquipmentModifier mod, String value) {
    if (Constants.LST_DOT_CLEAR.equals(value)) {
      context.getObjectContext().removeList(mod, ListKey.SPECIAL_PROPERTIES);
      return ParseResult.SUCCESS;
    }

    SpecialProperty sa = SpecialProperty.createFromLst(value);
    if (sa == null) {
      return ParseResult.INTERNAL_ERROR;
    }
    context.getObjectContext().addToList(mod, ListKey.SPECIAL_PROPERTIES, sa);
    return ParseResult.SUCCESS;
  }
Esempio n. 22
0
 @Override
 public boolean initialize(LoadContext context, Class<T> cl, String value, String args) {
   if (args == null) {
     Logging.errorPrint("Syntax for ABILITY primitive is ABILITY=category[key]");
     return false;
   }
   Category<Ability> cat =
       context
           .getReferenceContext()
           .silentlyGetConstructedCDOMObject(ABILITY_CATEGORY_CLASS, value);
   category = cat;
   ref = context.getReferenceContext().getCDOMReference(Ability.class, cat, args);
   refClass = cl;
   return true;
 }
Esempio n. 23
0
 public String[] unparse(LoadContext context, EquipmentModifier mod) {
   Formula f = context.getObjectContext().getFormula(mod, FormulaKey.BASECOST);
   if (f == null) {
     return null;
   }
   return new String[] {f.toString()};
 }
Esempio n. 24
0
 public String[] unparse(LoadContext context, Campaign campaign) {
   String title = context.getObjectContext().getString(campaign, StringKey.PUB_NAME_WEB);
   if (title == null) {
     return null;
   }
   return new String[] {title};
 }
Esempio n. 25
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, T obj, String value) {
    FormatManager<F> fmtManager = def.getFormatManager();
    FactSetKey<F> fsk = def.getFactSetKey();
    StringTokenizer st = new StringTokenizer(value, Constants.PIPE);
    boolean firstToken = true;
    AbstractObjectContext objContext = context.getObjectContext();
    while (st.hasMoreTokens()) {
      String token = st.nextToken();
      if (Constants.LST_DOT_CLEAR_ALL.equals(token)) {
        if (!firstToken) {
          return new ParseResult.Fail(
              "Non-sensical situation was "
                  + "encountered while parsing "
                  + getParentToken()
                  + Constants.PIPE
                  + getTokenName()
                  + ": When used, .CLEARALL must be the first argument",
              context);
        }
        objContext.removeSet(obj, fsk);
      }

      ObjectContainer<F> indirect = fmtManager.convertObjectContainer(token);
      objContext.addToSet(obj, fsk, indirect);
    }
    return ParseResult.SUCCESS;
  }
Esempio n. 26
0
 public String[] unparse(LoadContext context, PCClass pcc) {
   Visibility vis = context.getObjectContext().getObject(pcc, ObjectKey.VISIBILITY);
   if (vis == null) {
     return null;
   }
   String visString;
   if (vis.equals(Visibility.DEFAULT)) {
     visString = "YES";
   } else if (vis.equals(Visibility.HIDDEN)) {
     visString = "NO";
   } else {
     context.addWriteMessage("Visibility " + vis + " is not a valid Visibility for a PCClass");
     return null;
   }
   return new String[] {visString};
 }
Esempio n. 27
0
 @Override
 public String[] unparse(LoadContext context, KitTable kitTable) {
   StringBuilder sb = new StringBuilder();
   List<TableEntry> list = kitTable.getList();
   if (list.isEmpty()) {
     return null;
   }
   boolean first = true;
   for (TableEntry rl : list) {
     if (!first) {
       sb.append(Constants.PIPE);
     }
     Collection<String> unparse = context.unparse(rl.gear);
     if (unparse.size() == 1) {
       sb.append(unparse.iterator().next());
     } else {
       for (String s : unparse) {
         sb.append('[');
         sb.append(s);
         sb.append(']');
       }
     }
     sb.append(Constants.PIPE);
     sb.append(rl.lowRange.toString());
     if (!rl.lowRange.equals(rl.highRange)) {
       sb.append(',');
       sb.append(rl.highRange.toString());
     }
     first = false;
   }
   return new String[] {sb.toString()};
 }
Esempio n. 28
0
  /**
   * Beep and print error message if PCGen is debugging.
   *
   * @param s String error message
   * @param context the LoadContext containing the deprecated resource
   */
  public static void errorPrint(final String s, final LoadContext context) {
    if (isDebugMode()) {
      s_TOOLKIT.beep();
    }

    Logger l = getLogger();
    if (l.isLoggable(ERROR)) {
      if (context != null
          && context.getObjectContext() != null
          && context.getObjectContext().getSourceURI() != null) {
        l.log(ERROR, s + " (Source: " + context.getObjectContext().getSourceURI() + " )");
      } else {
        l.log(ERROR, s);
      }
    }
  }
Esempio n. 29
0
 @Override
 public String[] unparse(LoadContext context, PCClass obj) {
   Changes<BonusObj> changes = context.getObjectContext().getListChanges(obj, ListKey.BONUS);
   if (changes == null || changes.isEmpty()) {
     // Empty indicates no token present
     return null;
   }
   // CONSIDER need to deal with removed...
   Collection<BonusObj> added = changes.getAdded();
   String tokenName = getTokenName();
   Set<String> bonusSet = new TreeSet<String>();
   for (BonusObj bonus : added) {
     if (tokenName.equals(bonus.getTokenSource())) {
       StringBuilder sb = new StringBuilder();
       sb.append(bonus.getValue());
       List<Prerequisite> prereqList = new ArrayList<Prerequisite>(bonus.getPrerequisiteList());
       Prerequisite prereq = getPrerequisite("PRELEVELMAX:1");
       prereqList.remove(prereq);
       if (!prereqList.isEmpty()) {
         sb.append('|');
         sb.append(getPrerequisiteString(context, prereqList));
       }
       bonusSet.add(sb.toString());
     }
   }
   if (bonusSet.isEmpty()) {
     // This is okay - just no BONUSes from this token
     return null;
   }
   return bonusSet.toArray(new String[bonusSet.size()]);
 }
Esempio n. 30
0
  /**
   * Beep and print error message if PCGen is debugging.
   *
   * @param s String error message
   * @param context the LoadContext containing the deprecated resource
   */
  public static void deprecationPrint(final String s, final LoadContext context) {
    if (isDebugMode()) {
      s_TOOLKIT.beep();
    }

    Logger l = getLogger();
    if (l.isLoggable(LST_WARNING) && SettingsHandler.outputDeprecationMessages()) {
      if (context != null
          && context.getObjectContext() != null
          && context.getObjectContext().getSourceURI() != null) {
        l.log(LST_WARNING, s + " (Source: " + context.getObjectContext().getSourceURI() + " )");
      } else {
        l.log(LST_WARNING, s);
      }
    }
  }