@Test
 public void testRoundRobinWithEqualType() throws PersistenceLayerException {
   if (isTypeLegal()) {
     construct(primaryContext, "TestWP1");
     construct(primaryContext, "TestWP2");
     construct(secondaryContext, "TestWP1");
     construct(secondaryContext, "TestWP2");
     CDOMObject a = construct(primaryContext, "TestWP3");
     a.addToListFor(ListKey.TYPE, Type.getConstant("OtherTestType"));
     CDOMObject c = construct(secondaryContext, "TestWP3");
     c.addToListFor(ListKey.TYPE, Type.getConstant("OtherTestType"));
     CDOMObject b = construct(primaryContext, "TestWP4");
     b.addToListFor(ListKey.TYPE, Type.getConstant("TestType"));
     CDOMObject d = construct(secondaryContext, "TestWP4");
     d.addToListFor(ListKey.TYPE, Type.getConstant("TestType"));
     runRoundRobin(
         "TestWP1"
             + getJoinCharacter()
             + "TestWP2"
             + getJoinCharacter()
             + "TYPE=OtherTestType"
             + getJoinCharacter()
             + "TYPE=TestType");
   }
 }
示例#2
0
 @Test
 public void testRoundRobinType() throws PersistenceLayerException {
   Spell a = primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
   a.addToListFor(ListKey.TYPE, Type.getConstant("Foo"));
   Spell b = secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
   b.addToListFor(ListKey.TYPE, Type.getConstant("Foo"));
   runRoundRobin("TYPE.Foo=2");
 }
 @Test
 public void testRoundRobinTestEquals() throws PersistenceLayerException {
   if (isTypeLegal()) {
     CDOMObject b = construct(primaryContext, "TestWP3");
     b.addToListFor(ListKey.TYPE, Type.getConstant("TestType"));
     CDOMObject d = construct(secondaryContext, "TestWP3");
     d.addToListFor(ListKey.TYPE, Type.getConstant("TestType"));
     runRoundRobin("TYPE=TestType");
   }
 }
 @Test
 public void testValidInputTypeDot() throws PersistenceLayerException {
   if (isTypeLegal()) {
     CDOMObject b = construct(primaryContext, "TestWP3");
     b.addToListFor(ListKey.TYPE, Type.getConstant("TestType"));
     CDOMObject d = construct(secondaryContext, "TestWP3");
     d.addToListFor(ListKey.TYPE, Type.getConstant("TestType"));
     assertTrue(parse("TYPE.TestType"));
     assertCleanConstruction();
   }
 }
示例#5
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;
  }
示例#6
0
 private void loadHiddenTypes(DataSetID id, ListKey<String> listKey, Class<?> cl, Campaign c) {
   List<String> hiddentypes = c.getSafeListFor(listKey);
   for (String s : hiddentypes) {
     add(id, cl, Type.getConstant(s), c);
   }
 }
  /**
   * Test to ensure that a number of feat test will correctly require a number of separate feats in
   * any combination of two types.
   *
   * @throws Exception
   */
  public void testMultiFeats() throws Exception {
    final Ability metamagic1 = new Ability();
    metamagic1.addToListFor(ListKey.TYPE, Type.getConstant("METAMAGIC"));
    metamagic1.setName("MM1");
    metamagic1.put(StringKey.KEY_NAME, "MM1");
    metamagic1.setCDOMCategory(AbilityCategory.FEAT);

    final Ability metamagic2 = new Ability();
    metamagic2.addToListFor(ListKey.TYPE, Type.getConstant("METAMAGIC"));
    metamagic2.setName("MM2");
    metamagic2.put(StringKey.KEY_NAME, "MM2");
    metamagic2.setCDOMCategory(AbilityCategory.FEAT);

    final Ability metamagic3 = new Ability();
    metamagic3.addToListFor(ListKey.TYPE, Type.getConstant("METAMAGIC"));
    metamagic3.setName("MM3");
    metamagic3.put(StringKey.KEY_NAME, "MM3");
    metamagic3.setCDOMCategory(AbilityCategory.FEAT);

    final Ability item1 = new Ability();
    item1.addToListFor(ListKey.TYPE, Type.getConstant("ItemCreation"));
    item1.setName("IC1");
    item1.put(StringKey.KEY_NAME, "IC1");
    item1.setCDOMCategory(AbilityCategory.FEAT);

    final Ability item2 = new Ability();
    item2.addToListFor(ListKey.TYPE, Type.getConstant("ItemCreation"));
    item2.setName("IC2");
    item2.put(StringKey.KEY_NAME, "IC2");
    item2.setCDOMCategory(AbilityCategory.FEAT);

    final Ability item3 = new Ability();
    item3.addToListFor(ListKey.TYPE, Type.getConstant("ItemCreation"));
    item3.setName("IC3");
    item3.put(StringKey.KEY_NAME, "IC3");
    item3.setCDOMCategory(AbilityCategory.FEAT);

    final PlayerCharacter character = getCharacter();

    final PreFeatParser producer = new PreFeatParser();

    final Prerequisite prereq =
        producer.parse("FEAT", "3,TYPE=Metamagic,TYPE=ItemCreation", false, false);

    final PreMult test = new PreMult();
    int passes = test.passes(prereq, character, null);
    assertEquals("No feats should not pass", 0, passes);

    character.addAbilityNeedCheck(AbilityCategory.FEAT, metamagic1);
    passes = test.passes(prereq, character, null);
    assertEquals("One feat should not pass", 0, passes);

    character.addAbilityNeedCheck(AbilityCategory.FEAT, metamagic2);
    passes = test.passes(prereq, character, null);
    assertEquals("Two feats should not pass", 0, passes);

    character.addAbilityNeedCheck(AbilityCategory.FEAT, metamagic3);
    passes = test.passes(prereq, character, null);
    assertEquals("Three feats should pass", 1, passes);

    character.removeRealAbility(AbilityCategory.FEAT, metamagic3);
    character.addAbilityNeedCheck(AbilityCategory.FEAT, item1);
    passes = test.passes(prereq, character, null);
    assertEquals("Three feats should pass", 1, passes);

    character.addAbilityNeedCheck(AbilityCategory.FEAT, item2);
    character.addAbilityNeedCheck(AbilityCategory.FEAT, item3);
    character.addAbilityNeedCheck(AbilityCategory.FEAT, metamagic3);
    passes = test.passes(prereq, character, null);
    assertEquals("Six feats should pass", 1, passes);

    character.removeRealAbility(AbilityCategory.FEAT, metamagic3);
    character.removeRealAbility(AbilityCategory.FEAT, item3);
    character.removeRealAbility(AbilityCategory.FEAT, item2);
    character.removeRealAbility(AbilityCategory.FEAT, item1);
    character.removeRealAbility(AbilityCategory.FEAT, metamagic2);
    character.removeRealAbility(AbilityCategory.FEAT, metamagic1);
  }
示例#8
0
 @Override
 public Type getConstant(String string) {
   return Type.getConstant(string);
 }