Ejemplo n.º 1
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};
 }
Ejemplo n.º 2
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()]);
 }
Ejemplo n.º 3
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()]);
 }
Ejemplo n.º 4
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()]);
 }
Ejemplo n.º 5
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()]);
 }
Ejemplo n.º 6
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()};
 }
Ejemplo n.º 7
0
 @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()};
 }
Ejemplo n.º 8
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()]);
 }
Ejemplo n.º 9
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()]);
 }
Ejemplo n.º 10
0
 @Override
 public String[] unparse(LoadContext context, FactSetDefinition def) {
   Class cl = def.getUsableLocation();
   String name = def.getFactSetName();
   if (cl == null) {
     if (name == null) {
       return null;
     } else {
       context.addWriteMessage("Found FactDefinition with location but no name");
       return null;
     }
   } else if (name == null) {
     context.addWriteMessage("Found FactDefinition with name but no location");
     return null;
   }
   return new String[] {StringPClassUtil.getStringFor(cl) + Constants.PIPE + name};
 }
Ejemplo n.º 11
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()]);
  }
Ejemplo n.º 12
0
  public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<PersistentTransitionChoice<?>> grantChanges =
        context.getObjectContext().getListChanges(obj, ListKey.ADD);
    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 (cs.getName().equals(getTokenName()) && LANGUAGE_CLASS.equals(cs.getChoiceClass())) {
        Formula f = container.getCount();
        if (f == null) {
          context.addWriteMessage("Unable to find " + getFullName() + " Count");
          return null;
        }
        if (f.isStatic() && f.resolve(null, "").doubleValue() <= 0) {
          context.addWriteMessage("Count in " + getFullName() + " must be > 0");
          return null;
        }
        if (!cs.getGroupingState().isValid()) {
          context.addWriteMessage(
              "Non-sensical "
                  + getFullName()
                  + ": Contains ANY and a specific reference: "
                  + cs.getLSTformat());
          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());

        // assoc.getAssociation(AssociationKey.CHOICE_MAXCOUNT);
      }
    }
    return addStrings.toArray(new String[addStrings.size()]);
  }
Ejemplo n.º 13
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};
 }
Ejemplo n.º 14
0
 public String[] unparse(LoadContext context, EquipmentModifier eqm) {
   Visibility vis = context.getObjectContext().getObject(eqm, ObjectKey.VISIBILITY);
   if (vis == null) {
     return null;
   }
   String visString;
   if (vis.equals(Visibility.DEFAULT)) {
     visString = "YES";
   } else if (vis.equals(Visibility.QUALIFY)) {
     visString = "QUALIFY";
   } else if (vis.equals(Visibility.HIDDEN)) {
     visString = "NO";
   } else {
     context.addWriteMessage("Visibility " + vis + " is not a valid Visibility for a EqMod");
     return null;
   }
   return new String[] {visString};
 }
Ejemplo n.º 15
0
 @Override
 public String[] unparse(LoadContext context, PCClass pcc) {
   TransitionChoice<ClassSkillList> grantChanges =
       context.getObjectContext().getObject(pcc, ObjectKey.SKILLLIST_CHOICE);
   if (grantChanges == null) {
     // Zero indicates no Token
     return null;
   }
   StringBuilder sb = new StringBuilder();
   Formula count = grantChanges.getCount();
   if (count == null) {
     context.addWriteMessage("Unable to find " + getTokenName() + " Count");
     return null;
   }
   sb.append(count);
   sb.append(Constants.PIPE);
   sb.append(grantChanges.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
   return new String[] {sb.toString()};
 }
Ejemplo n.º 16
0
 @Override
 public String[] unparse(LoadContext context, AbilityCategory ac) {
   Visibility vis = ac.getVisibility();
   String visString;
   if (vis.equals(Visibility.DEFAULT)) {
     visString = "YES";
   } else if (vis.equals(Visibility.QUALIFY)) {
     visString = "QUALIFY";
   } else if (vis.equals(Visibility.HIDDEN)) {
     visString = "NO";
   } else {
     context.addWriteMessage(
         "Visibility "
             + vis
             + " is not a valid Visibility for "
             + ac.getClass().getSimpleName()
             + " "
             + ac.getKeyName());
     return null;
   }
   return new String[] {visString};
 }
Ejemplo n.º 17
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()]);
 }
Ejemplo n.º 18
0
  @Override
  public String[] unparse(LoadContext context, CDOMObject obj) {
    Collection<CDOMReference<? extends CDOMList<?>>> changedLists =
        context.getListContext().getChangedLists(obj, AbilityList.class);
    Changes<ListKey<ChooseSelectionActor<?>>> actors =
        context.getObjectContext().getListChanges(obj, ListKey.GA_CAKEYS);
    Set<String> returnSet = new TreeSet<String>();
    TripleKeyMapToList<
            Nature, CDOMSingleRef<AbilityCategory>, List<Prerequisite>, CDOMReference<Ability>>
        m =
            new TripleKeyMapToList<
                Nature,
                CDOMSingleRef<AbilityCategory>,
                List<Prerequisite>,
                CDOMReference<Ability>>();
    TripleKeyMapToList<
            Nature, CDOMSingleRef<AbilityCategory>, List<Prerequisite>, CDOMReference<Ability>>
        clear =
            new TripleKeyMapToList<
                Nature,
                CDOMSingleRef<AbilityCategory>,
                List<Prerequisite>,
                CDOMReference<Ability>>();

    Changes<ChooseSelectionActor<?>> listChanges =
        context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    if (listAdded != null && !listAdded.isEmpty()) {
      for (ChooseSelectionActor<?> csa : listAdded) {
        if (csa.getSource().equals(getTokenName())) {
          try {
            AbilitySelector as = (AbilitySelector) csa;
            StringBuilder sb = new StringBuilder();
            sb.append(as.getAbilityCategory().getLSTformat(false)).append(Constants.PIPE);
            sb.append(as.getNature()).append(Constants.PIPE);
            sb.append(as.getLstFormat());
            returnSet.add(sb.toString());
          } catch (PersistenceLayerException e) {
            context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
            return null;
          }
        }
      }
    }

    for (CDOMReference ref : changedLists) {
      AssociatedChanges<CDOMReference<Ability>> changes =
          context.getListContext().getChangesInList(getTokenName(), obj, ref);
      if (changes.includesGlobalClear()) {
        CDOMDirectSingleRef<AbilityList> dr = (CDOMDirectSingleRef<AbilityList>) ref;
        AbilityList al = dr.get();
        StringBuilder sb = new StringBuilder();
        sb.append(al.getCategory().getLSTformat(false)).append(Constants.PIPE);
        sb.append(al.getNature()).append(Constants.PIPE);
        sb.append(Constants.LST_DOT_CLEAR);
        returnSet.add(sb.toString());
      }
      MapToList<CDOMReference<Ability>, AssociatedPrereqObject> mtl =
          changes.getAddedAssociations();
      if (mtl != null) {
        for (CDOMReference<Ability> ab : mtl.getKeySet()) {
          for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
            Nature nature = assoc.getAssociation(AssociationKey.NATURE);
            CDOMSingleRef<AbilityCategory> cat = assoc.getAssociation(AssociationKey.CATEGORY);
            m.addToListFor(nature, cat, assoc.getPrerequisiteList(), ab);
          }
        }
      }
      mtl = changes.getRemovedAssociations();
      if (mtl != null) {
        for (CDOMReference<Ability> ab : mtl.getKeySet()) {
          for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
            Nature nature = assoc.getAssociation(AssociationKey.NATURE);
            CDOMSingleRef<AbilityCategory> cat = assoc.getAssociation(AssociationKey.CATEGORY);
            clear.addToListFor(nature, cat, assoc.getPrerequisiteList(), ab);
          }
        }
      }
    }

    for (Nature nature : m.getKeySet()) {
      for (CDOMSingleRef<AbilityCategory> category : m.getSecondaryKeySet(nature)) {
        for (List<Prerequisite> prereqs : m.getTertiaryKeySet(nature, category)) {
          StringBuilder sb = new StringBuilder();
          sb.append(category.getLSTformat(false)).append(Constants.PIPE);
          sb.append(nature);
          List<CDOMReference<Ability>> clearList = clear.removeListFor(nature, category, prereqs);
          if (clearList != null && !clearList.isEmpty()) {
            sb.append(Constants.PIPE);
            sb.append(Constants.LST_DOT_CLEAR_DOT);
            sb.append(
                ReferenceUtilities.joinLstFormat(
                    clearList, Constants.PIPE + Constants.LST_DOT_CLEAR_DOT));
          }
          sb.append(Constants.PIPE);
          sb.append(
              ReferenceUtilities.joinLstFormat(
                  m.getListFor(nature, category, prereqs), Constants.PIPE));
          if (prereqs != null && !prereqs.isEmpty()) {
            sb.append(Constants.PIPE);
            sb.append(getPrerequisiteString(context, prereqs));
          }
          returnSet.add(sb.toString());
        }
      }
    }
    for (Nature nature : clear.getKeySet()) {
      for (CDOMSingleRef<AbilityCategory> category : clear.getSecondaryKeySet(nature)) {
        for (List<Prerequisite> prereqs : clear.getTertiaryKeySet(nature, category)) {
          StringBuilder sb = new StringBuilder();
          sb.append(category.getLSTformat(false)).append(Constants.PIPE);
          sb.append(nature).append(Constants.PIPE).append(Constants.LST_DOT_CLEAR_DOT);
          sb.append(
              ReferenceUtilities.joinLstFormat(
                  clear.getListFor(nature, category, prereqs),
                  Constants.PIPE + Constants.LST_DOT_CLEAR_DOT));
          if (prereqs != null && !prereqs.isEmpty()) {
            sb.append(Constants.PIPE);
            sb.append(getPrerequisiteString(context, prereqs));
          }
          returnSet.add(sb.toString());
        }
      }
    }
    Collection<ListKey<ChooseSelectionActor<?>>> addedActors = actors.getAdded();
    if (addedActors != null) {
      for (ListKey<ChooseSelectionActor<?>> lk : addedActors) {
        Changes<ChooseSelectionActor<?>> cras = context.getObjectContext().getListChanges(obj, lk);
        for (ChooseSelectionActor<?> cra : cras.getAdded()) {
          if (getTokenName().equals(cra.getSource())) {
            try {
              AbilityTargetSelector ats = (AbilityTargetSelector) cra;
              StringBuilder sb = new StringBuilder();
              sb.append(ats.getAbilityCategory().getLSTformat(false)).append(Constants.PIPE);
              sb.append(ats.getNature()).append(Constants.PIPE).append(cra.getLstFormat());
              List<Prerequisite> prereqs = ats.getPrerequisiteList();
              if (prereqs != null && !prereqs.isEmpty()) {
                sb.append(Constants.PIPE);
                sb.append(getPrerequisiteString(context, prereqs));
              }
              returnSet.add(sb.toString());
            } catch (PersistenceLayerException e) {
              context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
              return null;
            }
          }
        }
      }
    }
    if (returnSet.isEmpty()) {
      return null;
    }
    return returnSet.toArray(new String[returnSet.size()]);
  }
Ejemplo n.º 19
0
  @Override
  public String[] unparse(LoadContext context, CDOMObject obj) {
    Set<String> returnSet = new TreeSet<String>();
    List<String> returnList = new ArrayList<String>();
    MapToList<List<Prerequisite>, CDOMReference<Ability>> m =
        new HashMapToList<List<Prerequisite>, CDOMReference<Ability>>();
    AbilityCategory category = AbilityCategory.FEAT;
    Nature nature = Nature.AUTOMATIC;

    CDOMReference<AbilityList> abilList = AbilityList.getAbilityListReference(category, nature);
    AssociatedChanges<CDOMReference<Ability>> changes =
        context.getListContext().getChangesInList(getFullName(), obj, abilList);
    Collection<CDOMReference<Ability>> 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;
      }
      returnList.add(Constants.LST_DOT_CLEAR);
    } else if (removedItems != null && !removedItems.isEmpty()) {
      returnList.add(
          Constants.LST_DOT_CLEAR_DOT
              + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR.", true));
    }

    Changes<ChooseSelectionActor<?>> listChanges =
        context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    if (listAdded != null && !listAdded.isEmpty()) {
      for (ChooseSelectionActor<?> csa : listAdded) {
        if (csa.getSource().equals(SOURCE)) {
          try {
            returnList.add(csa.getLstFormat());
          } catch (PersistenceLayerException e) {
            context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
            return null;
          }
        }
      }
    }

    MapToList<CDOMReference<Ability>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
    if (mtl != null) {
      for (CDOMReference<Ability> ab : mtl.getKeySet()) {
        for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
          m.addToListFor(assoc.getPrerequisiteList(), ab);
        }
      }
    }

    for (List<Prerequisite> prereqs : m.getKeySet()) {
      StringBuilder sb = new StringBuilder();
      sb.append(ReferenceUtilities.joinLstFormat(m.getListFor(prereqs), Constants.PIPE));
      if (prereqs != null && !prereqs.isEmpty()) {
        sb.append(Constants.PIPE);
        sb.append(getPrerequisiteString(context, prereqs));
      }
      returnSet.add(sb.toString());
    }
    returnList.addAll(returnSet);
    return returnList.toArray(new String[returnList.size()]);
  }