Пример #1
0
 public void testConditional() {
   Ability source = create(Ability.class, "Source");
   context.ref.reassociateCategory(AbilityCategory.FEAT, source);
   ParseResult result =
       token.parseToken(context, source, "CLASS|Wizard=2|Fireball|PREVARLTEQ:3,MyCasterLevel");
   if (result != ParseResult.SUCCESS) {
     result.printMessages();
     fail("Test Setup Failed");
   }
   finishLoad();
   assertEquals(baseCount(), targetFacetCount());
   CategorizedAbilitySelection cas =
       new CategorizedAbilitySelection(AbilityCategory.FEAT, source, Nature.AUTOMATIC);
   directAbilityFacet.add(id, cas);
   assertFalse(containsExpected());
   PCTemplate varsource = create(PCTemplate.class, "VarSource");
   varsource.put(VariableKey.getConstant("MyCasterLevel"), FormulaFactory.getFormulaFor(4.0));
   Selection<PCTemplate, ?> sel = new Selection<PCTemplate, Object>(varsource, null);
   templateFacet.add(id, sel, this);
   // pc.setDirty(true);
   assertTrue(containsExpected());
   assertEquals(baseCount() + 1, targetFacetCount());
   directAbilityFacet.remove(id, cas);
   pc.setDirty(true);
   assertEquals(baseCount(), targetFacetCount());
 }
Пример #2
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;
 }
Пример #3
0
 @Override
 protected ParseResult parseNonEmptyToken(LoadContext context, Campaign campaign, String value) {
   ParseResult pr = checkForInvalidXMLChars(value);
   if (pr.passed()) {
     context.getObjectContext().put(campaign, StringKey.DESCRIPTION, value);
   }
   return pr;
 }
Пример #4
0
  @Override
  protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
      count = FormulaFactory.ONE;
    } else {
      count = FormulaFactory.getFormulaFor(activeValue);
      if (!count.isValid()) {
        return new ParseResult.Fail(
            "Count in " + getTokenName() + " was not valid: " + count.toString());
      }
      if (count.isStatic() && count.resolve(null, "").doubleValue() <= 0) {
        return new ParseResult.Fail("Count in " + getFullName() + " must be > 0");
      }
      activeValue = sep.next();
    }
    if (sep.hasNext()) {
      return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value);
    }
    ParseResult pr = checkSeparatorsAndNonEmpty(',', activeValue);
    if (!pr.passed()) {
      return pr;
    }

    List<CDOMReference<Language>> refs = new ArrayList<CDOMReference<Language>>();
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    while (tok.hasMoreTokens()) {
      String tokText = tok.nextToken();
      CDOMReference<Language> lang = TokenUtilities.getReference(context, LANGUAGE_CLASS, tokText);
      if (lang == null) {
        return new ParseResult.Fail(
            "  Error was encountered while parsing "
                + getFullName()
                + ": "
                + value
                + " had an invalid reference: "
                + tokText);
      }
      refs.add(lang);
    }

    ReferenceChoiceSet<Language> rcs = new ReferenceChoiceSet<Language>(refs);
    if (!rcs.getGroupingState().isValid()) {
      return new ParseResult.Fail(
          "Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value);
    }

    ChoiceSet<Language> cs = new ChoiceSet<Language>(getTokenName(), rcs);
    cs.setTitle("Language Choice");
    PersistentTransitionChoice<Language> tc =
        new ConcretePersistentTransitionChoice<Language>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
  }
Пример #5
0
 @Override
 public void processToken(CDOMObject source) {
   ParseResult result = token.parseToken(context, source, "Granted");
   if (result != ParseResult.SUCCESS) {
     result.printMessages();
     fail("Test Setup Failed");
   }
   finishLoad();
 }
Пример #6
0
  @Override
  protected ParseResult parseNonEmptyToken(LoadContext context, BaseKit kit, String value) {
    ParsingSeparator pipeSep = new ParsingSeparator(value, '|');
    pipeSep.addGroupingPair('[', ']');
    pipeSep.addGroupingPair('(', ')');

    while (pipeSep.hasNext()) {
      String subTok = pipeSep.next();
      if (subTok.length() == 0) {
        return new ParseResult.Fail(
            getTokenName() + " arguments has invalid pipe separator: " + value, context);
      }
      ParseResult pr = checkForIllegalSeparator(',', subTok);
      if (!pr.passed()) {
        return pr;
      }
      ParsingSeparator commaSep = new ParsingSeparator(subTok, ',');
      commaSep.addGroupingPair('[', ']');
      commaSep.addGroupingPair('(', ')');
      String minString = commaSep.next();
      String maxString;
      if (commaSep.hasNext()) {
        maxString = commaSep.next();
      } else {
        maxString = subTok;
      }
      if (commaSep.hasNext()) {
        return new ParseResult.Fail("Token cannot have more than one separator ','", context);
      }
      Formula min = FormulaFactory.getFormulaFor(minString);
      if (!min.isValid()) {
        return new ParseResult.Fail(
            "Min Formula in " + getTokenName() + " was not valid: " + min.toString(), context);
      }
      Formula max = FormulaFactory.getFormulaFor(maxString);
      if (!max.isValid()) {
        return new ParseResult.Fail(
            "Max Formula in " + getTokenName() + " was not valid: " + max.toString(), context);
      }
      kit.setOptionBounds(min, max);
    }
    return ParseResult.SUCCESS;
  }
Пример #7
0
 @Test
 public void testDirect() throws PersistenceLayerException {
   Race source = create(Race.class, "Source");
   ParseResult result = token.parseToken(context, source, "MySkill");
   if (result != ParseResult.SUCCESS) {
     result.printMessages();
     fail("Test Setup Failed");
   }
   new ExclusiveToken().parseToken(context, sk, "Yes");
   finishLoad();
   assertEquals(SkillCost.EXCLUSIVE, pc.getSkillCostForClass(sk, dragon));
   raceFacet.directSet(id, source, getAssoc());
   ClassSkillList dragonCSL =
       context.ref.silentlyGetConstructedCDOMObject(ClassSkillList.class, "Dragon");
   assertEquals(SkillCost.EXCLUSIVE, pc.getSkillCostForClass(sk, dragon));
   pc.incrementClassLevel(1, dragon);
   assertEquals(SkillCost.CROSS_CLASS, pc.getSkillCostForClass(sk, dragon));
   assertTrue(lscFacet.contains(id, dragonCSL, SkillCost.CROSS_CLASS, sk));
   raceFacet.remove(id);
   assertFalse(lscFacet.contains(id, dragonCSL, SkillCost.CROSS_CLASS, sk));
 }
Пример #8
0
  @Override
  protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String shieldProf;
    Prerequisite prereq = null; // Do not initialize, null is significant!
    boolean isPre = false;
    if (value.indexOf("[") == -1) {
      // Supported version of PRExxx using |.  Needs to be at the front of the
      // Parsing code because many objects expect the pre to have been determined
      // Ahead of time.  Until deprecated code is removed, it will have to stay
      // like this.
      shieldProf = value;
      StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE);
      while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (PreParserFactory.isPreReqString(token)) {
          if (isPre) {
            String errorText =
                "Invalid "
                    + getTokenName()
                    + ": "
                    + value
                    + "  PRExxx must be at the END of the Token";
            Logging.errorPrint(errorText);
            return new ParseResult.Fail(errorText, context);
          }
          prereq = getPrerequisite(token);
          if (prereq == null) {
            return new ParseResult.Fail(
                "Error generating Prerequisite " + prereq + " in " + getFullName(), context);
          }
          int preStart = value.indexOf(token) - 1;
          shieldProf = value.substring(0, preStart);
          isPre = true;
        }
      }
    } else {
      return new ParseResult.Fail(
          "Use of [] for Prerequisites has been removed. " + "Please use | based standard",
          context);
    }

    ParseResult pr = checkForIllegalSeparator('|', shieldProf);
    if (!pr.passed()) {
      return pr;
    }

    boolean foundAny = false;
    boolean foundOther = false;

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

    List<CDOMReference<ShieldProf>> shieldProfs = new ArrayList<CDOMReference<ShieldProf>>();
    List<CDOMReference<Equipment>> equipTypes = new ArrayList<CDOMReference<Equipment>>();

    while (tok.hasMoreTokens()) {
      String aProf = tok.nextToken();

      if (Constants.LST_PERCENT_LIST.equals(aProf)) {
        foundOther = true;
        ChooseSelectionActor<ShieldProf> cra;
        if (prereq == null) {
          cra = this;
        } else {
          ConditionalSelectionActor<ShieldProf> cca =
              new ConditionalSelectionActor<ShieldProf>(this);
          cca.addPrerequisite(prereq);
          cra = cca;
        }
        context.obj.addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
      } else if (Constants.LST_ALL.equalsIgnoreCase(aProf)) {
        foundAny = true;
        shieldProfs.add(context.ref.getCDOMAllReference(SHIELDPROF_CLASS));
      } else if (aProf.startsWith("SHIELDTYPE.") || aProf.startsWith("SHIELDTYPE=")) {
        foundOther = true;
        CDOMReference<Equipment> ref =
            TokenUtilities.getTypeReference(
                context, EQUIPMENT_CLASS, "SHIELD." + aProf.substring(11));
        if (ref == null) {
          return ParseResult.INTERNAL_ERROR;
        }
        equipTypes.add(ref);
      } else {
        foundOther = true;
        shieldProfs.add(context.ref.getCDOMReference(SHIELDPROF_CLASS, aProf));
      }
    }
    if (foundAny && foundOther) {
      return new ParseResult.Fail(
          "Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value,
          context);
    }

    if (!shieldProfs.isEmpty() || !equipTypes.isEmpty()) {
      ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
      if (prereq != null) {
        pp.addPrerequisite(prereq);
      }
      context.obj.addToList(obj, ListKey.AUTO_SHIELDPROF, pp);
    }

    return ParseResult.SUCCESS;
  }
Пример #9
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
      return new ParseResult.Fail(
          "Cannot use "
              + getTokenName()
              + " on an Ungranted object type: "
              + obj.getClass().getSimpleName(),
          context);
    }
    StringTokenizer tok = new StringTokenizer(value, LstUtils.PIPE);

    String companionType = tok.nextToken();

    if (!tok.hasMoreTokens()) {
      return new ParseResult.Fail(
          getTokenName() + " requires more than just a Type: " + value, context);
    }

    String list = tok.nextToken();

    ParseResult pr = checkForIllegalSeparator(',', list);
    if (!pr.passed()) {
      return pr;
    }

    StringTokenizer subTok = new StringTokenizer(list, LstUtils.COMMA);

    Set<CDOMReference<Race>> races = new HashSet<>();
    boolean foundAny = false;
    while (subTok.hasMoreTokens()) {
      String tokString = subTok.nextToken();
      if (Constants.LST_ANY.equalsIgnoreCase(tokString)) {
        foundAny = true;
        races.add(context.getReferenceContext().getCDOMAllReference(Race.class));
      } else if (tokString.startsWith("RACETYPE=")) {
        String raceType = tokString.substring(9);
        if (raceType.isEmpty()) {
          return new ParseResult.Fail(
              getTokenName() + " Error: RaceType was not specified.", context);
        }
        races.add(
            new ObjectMatchingReference<>(
                tokString,
                Race.class,
                context.getReferenceContext().getCDOMAllReference(Race.class),
                ObjectKey.RACETYPE,
                RaceType.getConstant(raceType)));
      } else if (tokString.startsWith("RACESUBTYPE=")) {
        String raceSubType = tokString.substring(12);
        if (raceSubType.isEmpty()) {
          return new ParseResult.Fail(
              getTokenName() + " Error: RaceSubType was not specified.", context);
        }
        races.add(
            new ListMatchingReference<>(
                tokString,
                Race.class,
                context.getReferenceContext().getCDOMAllReference(Race.class),
                ListKey.RACESUBTYPE,
                RaceSubType.getConstant(raceSubType)));
      } else if (looksLikeAPrerequisite(tokString)) {
        return new ParseResult.Fail(
            getTokenName() + " Error: " + tokString + " found where companion race expected.",
            context);
      } else {
        races.add(context.getReferenceContext().getCDOMReference(Race.class, tokString));
      }
    }
    if (foundAny && races.size() > 1) {
      return new ParseResult.Fail(
          "Non-sensical Race List includes Any and specific races: " + value, context);
    }

    if (!tok.hasMoreTokens()) {
      // No other args, so we're done
      finish(context, obj, companionType, races, null, null);
      return ParseResult.SUCCESS;
    }

    // The remainder of the elements are optional.
    Integer followerAdjustment = null;
    String optArg = tok.nextToken();
    while (true) {
      if (optArg.startsWith(FOLLOWERADJUSTMENT)) {
        if (followerAdjustment != null) {
          return new ParseResult.Fail(
              getTokenName() + " Error: Multiple " + FOLLOWERADJUSTMENT + " tags specified.",
              context);
        }

        int faStringLength = FOLLOWERADJUSTMENT.length();
        if (optArg.length() <= faStringLength + 1) {
          return new ParseResult.Fail(
              "Empty FOLLOWERADJUSTMENT value in " + getTokenName() + " is prohibited", context);
        }
        String adj = optArg.substring(faStringLength + 1);

        try {
          followerAdjustment = Integer.valueOf(adj);
        } catch (NumberFormatException nfe) {
          ComplexParseResult cpr = new ComplexParseResult();
          cpr.addErrorMessage("Expecting a number for FOLLOWERADJUSTMENT: " + adj);
          cpr.addErrorMessage("  was parsing Token " + getTokenName());
          return cpr;
        }
      } else if (looksLikeAPrerequisite(optArg)) {
        break;
      } else {
        return new ParseResult.Fail(
            getTokenName()
                + ": Unknown argument (was expecting FOLLOWERADJUSTMENT: or PRExxx): "
                + optArg,
            context);
      }
      if (!tok.hasMoreTokens()) {
        // No prereqs, so we're done
        finish(context, obj, companionType, races, followerAdjustment, null);
        return ParseResult.SUCCESS;
      }
      optArg = tok.nextToken();
    }

    List<Prerequisite> prereqs = new ArrayList<>();

    while (true) {
      Prerequisite prereq = getPrerequisite(optArg);
      if (prereq == null) {
        return new ParseResult.Fail(
            "   (Did you put items after the " + "PRExxx tags in " + getTokenName() + ":?)",
            context);
      }
      prereqs.add(prereq);
      if (!tok.hasMoreTokens()) {
        break;
      }
      optArg = tok.nextToken();
    }

    finish(context, obj, companionType, races, followerAdjustment, prereqs);
    return ParseResult.SUCCESS;
  }
Пример #10
0
  @Override
  protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject cdo, String value) {
    if (value.startsWith(".CLEAR")) {
      context.getObjectContext().removeList(cdo, ListKey.TYPE);
      if (value.length() == 6) {
        return ParseResult.SUCCESS;
      } else if (value.charAt(6) == '.') {
        value = value.substring(7);
        if (isEmpty(value)) {
          return new ParseResult.Fail(
              getTokenName() + "started with .CLEAR. but expected to have a Type after .: " + value,
              context);
        }
      } else {
        return new ParseResult.Fail(
            getTokenName() + "started with .CLEAR but expected next character to be .: " + value,
            context);
      }
    }
    ParseResult pr = checkForIllegalSeparator('.', value);
    if (!pr.passed()) {
      return pr;
    }

    StringTokenizer aTok = new StringTokenizer(value, Constants.DOT);

    boolean bRemove = false;
    boolean bAdd = false;
    while (aTok.hasMoreTokens()) {
      final String aType = aTok.nextToken();
      if ("ADD".equals(aType)) {
        if (bRemove) {
          return new ParseResult.Fail(
              "Non-sensical use of .REMOVE.ADD. in " + getTokenName() + ": " + value, context);
        }
        bRemove = false;
        bAdd = true;
      } else if ("REMOVE".equals(aType)) {
        if (bAdd) {
          return new ParseResult.Fail(
              "Non-sensical use of .ADD.REMOVE. in " + getTokenName() + ": " + value, context);
        }
        bRemove = true;
      } else if ("CLEAR".equals(aType)) {
        return new ParseResult.Fail(
            "Non-sensical use of .CLEAR in " + getTokenName() + ": " + value, context);
      } else if (bRemove) {
        Type type = Type.getConstant(aType);
        context.getObjectContext().removeFromList(cdo, ListKey.TYPE, type);
        bRemove = false;
      } else {
        Type type = Type.getConstant(aType);
        context.getObjectContext().addToList(cdo, ListKey.TYPE, type);
        bAdd = false;
      }
    }
    if (bRemove) {
      return new ParseResult.Fail(
          getTokenName() + "ended with REMOVE, so didn't have any Type to remove: " + value,
          context);
    }
    if (bAdd) {
      return new ParseResult.Fail(
          getTokenName() + "ended with ADD, so didn't have any Type to add: " + value, context);
    }
    return ParseResult.SUCCESS;
  }