Example #1
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()]);
 }
Example #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()]);
 }
Example #3
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()};
 }
Example #4
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()]);
 }
Example #5
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()]);
  }
Example #6
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);
      }
    }
  }
Example #7
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()]);
 }
Example #8
0
  @Override
  public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<ChangeProf> changes =
        context.getObjectContext().getListChanges(obj, ListKey.CHANGEPROF);
    Collection<ChangeProf> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
      // Zero indicates no Token
      return null;
    }
    HashMapToList<CDOMGroupRef<WeaponProf>, CDOMReference<WeaponProf>> m =
        new HashMapToList<CDOMGroupRef<WeaponProf>, CDOMReference<WeaponProf>>();
    for (ChangeProf cp : added) {
      CDOMReference<WeaponProf> source = cp.getSource();
      CDOMGroupRef<WeaponProf> result = cp.getResult();
      m.addToListFor(result, source);
    }

    SortedSet<CDOMReference<WeaponProf>> set =
        new TreeSet<CDOMReference<WeaponProf>>(ReferenceUtilities.REFERENCE_SORTER);
    Set<String> returnSet = new TreeSet<String>();
    for (CDOMGroupRef<WeaponProf> result : m.getKeySet()) {
      StringBuilder sb = new StringBuilder();
      boolean needComma = false;
      set.clear();
      set.addAll(m.getListFor(result));
      for (CDOMReference<WeaponProf> source : set) {
        if (needComma) {
          sb.append(Constants.COMMA);
        }
        needComma = true;
        String sourceLst = source.getLSTformat(false);
        if (sourceLst.startsWith(Constants.LST_TYPE_EQUAL)) {
          sb.append(Constants.LST_TYPE_DOT);
          sb.append(sourceLst.substring(5));
        } else {
          sb.append(sourceLst);
        }
      }
      sb.append(Constants.EQUALS).append(result.getLSTformat(false).substring(5));
      returnSet.add(sb.toString());
    }
    return new String[] {StringUtil.join(returnSet, Constants.PIPE)};
  }
Example #9
0
 @Override
 public String[] unparse(LoadContext context, Skill skill) {
   Changes<String> changes = context.getObjectContext().getListChanges(skill, ListKey.SITUATION);
   if (changes == null || changes.isEmpty()) {
     return null;
   }
   List<String> list = new ArrayList<String>();
   Collection<String> removedItems = changes.getRemoved();
   if (removedItems != null && !removedItems.isEmpty()) {
     context.addWriteMessage(".CLEAR. not supported");
     return null;
   }
   if (changes.includesGlobalClear()) {
     list.add(Constants.LST_DOT_CLEAR);
   }
   Collection<String> 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()]);
 }