예제 #1
0
  public static void addSpellsToClassForLevels(
      PlayerCharacter pc, Domain d, PCClass aClass, int minLevel, int maxLevel) {
    if (aClass == null) {
      return;
    }

    for (int aLevel = minLevel; aLevel <= maxLevel; aLevel++) {
      Collection<Spell> domainSpells = pc.getSpellsIn(d.get(ObjectKey.DOMAIN_SPELLLIST), aLevel);
      for (Spell spell : domainSpells) {
        List<CharacterSpell> slist =
            pc.getCharacterSpells(aClass, spell, Globals.getDefaultSpellBook(), aLevel);
        boolean flag = true;

        for (CharacterSpell cs1 : slist) {
          flag = !(cs1.getOwner().equals(d));

          if (!flag) {
            break;
          }
        }

        if (flag) {
          CharacterSpell cs = new CharacterSpell(d, spell);
          cs.addInfo(aLevel, 1, Globals.getDefaultSpellBook());
          pc.addCharacterSpell(aClass, cs);
        }
      }
    }
  }
예제 #2
0
  /*
   * @see TestCase#tearDown()
   */
  @Override
  protected void tearDown() throws Exception {
    Globals.getContext().getReferenceContext().forget(divineClass);
    Globals.getContext().getReferenceContext().forget(arcaneClass);

    super.tearDown();
  }
  /* (non-Javadoc)
   * @see pcgen.AbstractCharacterTestCase#setUp()
   */
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    dataset = new MockDataSetFacade();
    dataset.addEquipmentLocation(new BodyStructure(Constants.EQUIP_LOCATION_EQUIPPED, true));
    dataset.addEquipmentLocation(new BodyStructure(LOC_HANDS, false));
    dataset.addEquipmentLocation(new BodyStructure(LOC_BODY, false));
    if (SystemCollections.getUnmodifiableEquipSlotList().isEmpty()) {
      EquipSlot equipSlot = new EquipSlot();
      equipSlot.setSlotName(SLOT_WEAPON);
      equipSlot.addContainedType("Weapon");
      equipSlot.setContainNum(1);
      equipSlot.setSlotNumType("HANDS");
      SystemCollections.addToEquipSlotsList(equipSlot, SettingsHandler.getGame().getName());
      Globals.setEquipSlotTypeCount("HANDS", "2");

      equipSlot = new EquipSlot();
      equipSlot.setSlotName(SLOT_RING);
      equipSlot.addContainedType("Ring");
      equipSlot.setContainNum(2);
      equipSlot.setSlotNumType("BODY");
      SystemCollections.addToEquipSlotsList(equipSlot, SettingsHandler.getGame().getName());
      Globals.setEquipSlotTypeCount("BODY", "1");
    }
    uiDelegate = new MockUIDelegate();
  }
예제 #4
0
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
   */
  @Override
  public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {

    //
    // If game mode doesn't support alignment, then pass the prereq
    //
    int runningTotal = 0;

    if (Globals.getGameModeAlignmentText().length() == 0) {
      runningTotal = 1;
    } else {
      CDOMSingleRef<PCAlignment> deityAlign = null; // $NON-NLS-1$
      Deity deity = display.getDeity();
      if (deity != null) {
        deityAlign = deity.get(ObjectKey.ALIGNMENT);
      }
      if (deityAlign != null) {
        String desiredAlignIdentifier = prereq.getOperand();
        PCAlignment desiredAlign = getPCAlignment(desiredAlignIdentifier);

        if (desiredAlign.equals(deityAlign.get())) {
          runningTotal = 1;
        }
      }
    }

    return countedTotal(prereq, runningTotal);
  }
예제 #5
0
  /**
   * 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);
  }
예제 #6
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;
  }
예제 #7
0
 /** @see pcgen.output.base.OutputActor#process(java.lang.Object) */
 @Override
 public TemplateModel process(CDOMObject d) throws TemplateModelException {
   // TODO Why does a global setting limit the output rather than specifying what is desired?
   SourceFormat sourceDisplay = Globals.getSourceDisplay();
   String sourceString = SourceFormat.getFormattedString(d, sourceDisplay, true);
   return ObjectWrapper.SIMPLE_WRAPPER.wrap(sourceString);
 }
예제 #8
0
  /* (non-Javadoc)
   * @see pcgen.core.facade.SpellSupportFacade#removeSpellList(java.lang.String)
   */
  @Override
  public void removeSpellList(String spellList) {
    if (spellList.equalsIgnoreCase(Globals.getDefaultSpellBook())) {
      Logging.errorPrint(
          LanguageBundle.getString("InfoSpells.can.not.delete.default.spellbook")); // $NON-NLS-1$

      return;
    }

    if (pc.delSpellBook(spellList)) {
      pc.setDirty(true);
      for (Iterator<SpellNode> iterator = preparedSpellLists.iterator(); iterator.hasNext(); ) {
        SpellNode listNode = iterator.next();
        if (spellList.equals(listNode.getRootNode().getName())) {
          iterator.remove();
        }
      }

      for (Iterator<SpellNode> iterator = preparedSpellNodes.iterator(); iterator.hasNext(); ) {
        SpellNode spell = iterator.next();
        if (spellList.equals(spell.getRootNode().getName())) {
          iterator.remove();
        }
      }
    } else {
      Logging.errorPrint("delBookButton:failed "); // $NON-NLS-1$

      return;
    }
  }
예제 #9
0
 @Override
 public int getBonus() {
   String initiativeVar =
       ControlUtilities.getControlToken(Globals.getContext(), CControl.INITIATIVE);
   String initiativeStatVar =
       ControlUtilities.getControlToken(Globals.getContext(), CControl.INITIATIVESTAT);
   if (initiativeVar == null) {
     PCStat dex =
         Globals.getContext()
             .getReferenceContext()
             .silentlyGetConstructedCDOMObject(PCStat.class, "DEX");
     return display.processOldInitiativeMod() - pc.getStatModFor(dex) + incrementalBonus;
   }
   return ((Number) pc.getGlobal(initiativeVar)).intValue()
       - ((Number) pc.getGlobal(initiativeStatVar)).intValue()
       + incrementalBonus;
 }
예제 #10
0
 @Override
 public SystemAttribute getAttribute() {
   PCStat stat =
       Globals.getContext()
           .getReferenceContext()
           .silentlyGetConstructedCDOMObject(PCStat.class, "DEX");
   return new SystemAttribute("Dexterity", pc.getTotalStatFor(stat));
 }
예제 #11
0
  private static String getNumCast(PCClass aClass, int level, PlayerCharacter pc) {
    String sbook = Globals.getDefaultSpellBook();
    final String cast =
        pc.getSpellSupport(aClass).getCastForLevel(level, sbook, true, false, pc)
            + pc.getSpellSupport(aClass).getBonusCastForLevelString(level, sbook, pc);

    return cast;
  }
예제 #12
0
 @Override
 public String evaluate(Equipment eq, boolean primary, PlayerCharacter pc) {
   if (ControlUtilities.hasControlToken(Globals.getContext(), "EQACCHECK")) {
     Logging.errorPrint(
         "EQACCHECK term is deprecated (does not function)" + " when ACCHECK CodeControl is used");
   }
   return Integer.toString(eq.getSafe(IntegerKey.AC_CHECK));
 }
예제 #13
0
 /**
  * Returns the unarmed damage String for the Race of the Player Character identified by the given
  * CharID.
  *
  * @param id The CharID identifying the Player Character
  * @return The unarmed damage String for the Race of the Player Character identified by the given
  *     CharID
  */
 public String getUDamForRace(CharID id) {
   Race race = raceFacet.get(id);
   int iSize =
       formulaResolvingFacet
           .resolve(id, race.getSafe(FormulaKey.SIZE), race.getQualifiedKey())
           .intValue();
   SizeAdjustment defAdj = SizeUtilities.getDefaultSizeAdjustment();
   SizeAdjustment sizAdj =
       Globals.getContext()
           .getReferenceContext()
           .getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER)
           .get(iSize);
   if (sizAdj != null) {
     return Globals.adjustDamage("1d3", defAdj, sizAdj);
   }
   return "1d3";
 }
  @Override
  public String evaluate(PlayerCharacter pc) {
    Skill skill = Globals.getContext().ref.silentlyGetConstructedCDOMObject(Skill.class, rank);
    if (skill == null || !pc.hasSkill(skill)) {
      return "0.0";
    }

    return SkillRankControl.getRank(pc, skill).toString();
  }
예제 #15
0
 @Override
 public int getModifier() {
   String initiativeVar =
       ControlUtilities.getControlToken(Globals.getContext(), CControl.INITIATIVE);
   if (initiativeVar == null) {
     return pc.getDisplay().processOldInitiativeMod() + incrementalBonus;
   }
   return ((Number) pc.getGlobal(initiativeVar)).intValue() + incrementalBonus;
 }
예제 #16
0
 private PCAlignment getPCAlignment(String desiredAlignIdentifier) {
   PCAlignment desiredAlign =
       Globals.getContext()
           .getReferenceContext()
           .silentlyGetConstructedCDOMObject(PCAlignment.class, desiredAlignIdentifier);
   if (desiredAlign == null) {
     Logging.errorPrint("Unable to find alignment that matches: " + desiredAlignIdentifier);
   }
   return desiredAlign;
 }
예제 #17
0
 /* (non-Javadoc)
  * @see pcgen.core.facade.SpellSupportFacade#removeKnownSpell(pcgen.core.facade.SpellSupportFacade.SpellNode)
  */
 @Override
 public void removeKnownSpell(SpellNode spell) {
   // TODO: This should also remove the spell from books and lists
   if (removeSpellFromCharacter(spell, Globals.getDefaultSpellBook())) {
     allKnownSpellNodes.removeElement(spell);
     knownSpellNodes.removeElement(spell);
   }
   updateSpellsTodo();
   pcFacade.refreshAvailableTempBonuses();
 }
예제 #18
0
 @Override
 public void setBonus(int bonus) {
   String initiativeVar =
       ControlUtilities.getControlToken(Globals.getContext(), CControl.INITIATIVE);
   if (initiativeVar == null) {
     this.incrementalBonus = bonus - display.processOldInitiativeMod();
   } else {
     this.incrementalBonus = bonus - ((Number) pc.getGlobal(initiativeVar)).intValue();
   }
   setCurrentInitiative(roll + getModifier() + mod);
 }
예제 #19
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    Domain goodDomain = new Domain();
    goodDomain.setName("Good");
    Globals.getContext().ref.importObject(goodDomain);

    Domain animalDomain = new Domain();
    animalDomain.setName("Animal");
    Globals.getContext().ref.importObject(animalDomain);

    deity = new Deity();
    deity.setName("Test Deity");
    deity.put(ObjectKey.ALIGNMENT, ng);
    deity.putToList(
        Deity.DOMAINLIST, CDOMDirectSingleRef.getRef(goodDomain), new SimpleAssociatedObject());
    deity.putToList(
        Deity.DOMAINLIST, CDOMDirectSingleRef.getRef(animalDomain), new SimpleAssociatedObject());
  }
예제 #20
0
 public PcgSystemInitiative(PlayerCharacter pc) {
   this.pc = pc;
   display = pc.getDisplay();
   PCStat stat =
       Globals.getContext()
           .getReferenceContext()
           .silentlyGetConstructedCDOMObject(PCStat.class, "DEX");
   this.attribute = new SystemAttribute("Dexterity", pc.getTotalStatFor(stat));
   incrementalBonus = 0;
   die = new Dice(1, 20);
 }
예제 #21
0
  /** Ensure a character with the requested template correctly passes a wildcard test */
  public void test990007_5() {
    final PlayerCharacter character = getCharacter();

    final PCTemplate template = new PCTemplate();
    template.setName("Half-Dragon");
    Globals.getContext().getReferenceContext().importObject(template);
    character.addTemplate(template);

    final PCTemplate template2 = new PCTemplate();
    template2.setName("Half-Celestial");
    Globals.getContext().getReferenceContext().importObject(template2);
    character.addTemplate(template2);

    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("template");
    prereq.setKey("half%");
    prereq.setOperator(PrerequisiteOperator.GTEQ);
    prereq.setOperand("1");

    final boolean passes = PrereqHandler.passes(prereq, character, null);
    assertTrue(passes);
  }
예제 #22
0
 /* (non-Javadoc)
  * @see pcgen.core.facade.SpellSupportFacade#addKnownSpell(pcgen.core.facade.SpellSupportFacade.SpellNode)
  */
 @Override
 public void addKnownSpell(SpellNode spell) {
   SpellNode node = addSpellToCharacter(spell, Globals.getDefaultSpellBook(), new ArrayList<>());
   if (node != null) {
     allKnownSpellNodes.addElement(node);
     knownSpellNodes.addElement(node);
     if (!StringUtils.isEmpty(charDisplay.getSpellBookNameToAutoAddKnown())) {
       addToSpellBook(node, charDisplay.getSpellBookNameToAutoAddKnown());
     }
   }
   updateSpellsTodo();
   pcFacade.refreshAvailableTempBonuses();
 }
예제 #23
0
  private void updateSpellsTodo() {
    boolean hasFree = false;
    for (PCClass aClass : charDisplay.getClassSet()) {
      if (pc.getSpellSupport(aClass).hasKnownList()
          || pc.getSpellSupport(aClass).hasKnownSpells(pc)) {
        int highestSpellLevel = pc.getSpellSupport(aClass).getHighestLevelSpell(pc);
        for (int i = 0; i <= highestSpellLevel; ++i) {
          if (pc.availableSpells(i, aClass, Globals.getDefaultSpellBook(), true, false)
              || pc.availableSpells(i, aClass, Globals.getDefaultSpellBook(), true, true)) {
            hasFree = true;
            break;
          }
        }
      }
    }

    if (hasFree) {
      todoManager.addTodo(new TodoFacadeImpl(Tab.SPELLS, "Known", "in_splTodoRemain", 120));
    } else {
      todoManager.removeTodo("in_splTodoRemain");
    }
  }
예제 #24
0
  @Override
  public Float resolve(PlayerCharacter pc) {
    if (ControlUtilities.hasControlToken(Globals.getContext(), CControl.EQACCHECK)) {
      Logging.errorPrint(
          originalText
              + " term is deprecated (does not function)"
              + " when EQACCHECK CodeControl is used");
    }
    if ("".equals(eqKey)) {
      return 0.0f;
    } else {
      final Equipment eq =
          Globals.getContext()
              .getReferenceContext()
              .silentlyGetConstructedCDOMObject(Equipment.class, eqKey);

      if (eq == null || pc.isProficientWith(eq)) {
        return 0.0f;
      } else {
        return (float) eq.preFormulaAcCheck(pc);
      }
    }
  }
예제 #25
0
  /* (non-Javadoc)
   * @see junit.framework.TestCase#setUp()
   */
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    final PlayerCharacter character = getCharacter();

    myClass = new PCClass();
    myClass.setName("My Class");

    knowledge = new Skill();
    Globals.getContext().unconditionallyProcess(knowledge, "CLASSES", "My Class");
    knowledge.setName("KNOWLEDGE (ARCANA)");
    TestHelper.addType(knowledge, "KNOWLEDGE.INT");
    character.addSkill(knowledge);
    SkillRankControl.modRanks(8.0, myClass, true, character, knowledge);
  }
예제 #26
0
  /*
   * @see TestCase#setUp()
   */
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();

    SettingsHandler.getGame().setSpellBaseDC("10+SPELLLEVEL+BASESPELLSTAT");

    SimpleLoader<BonusSpellInfo> bonusSpellLoader =
        new SimpleLoader<BonusSpellInfo>(BonusSpellInfo.class);
    try {
      URI testURI = new URI("file:/" + getClass().getName() + ".java");
      bonusSpellLoader.parseLine(context, "1	BASESTATSCORE:12	STATRANGE:8", testURI);
      bonusSpellLoader.parseLine(context, "2	BASESTATSCORE:14	STATRANGE:8", testURI);
      bonusSpellLoader.parseLine(context, "3	BASESTATSCORE:16	STATRANGE:8", testURI);
    } catch (URISyntaxException e) {
      throw new UnreachableError(e);
    }

    // Human
    human = new Race();

    final BonusObj bon = Bonus.newBonus(context, "FEAT|POOL|2");
    human.addToListFor(ListKey.BONUS, bon);

    arcaneClass = new PCClass();
    arcaneClass.setName("TestArcane");
    arcaneClass.put(StringKey.SPELLTYPE, "ARCANE");
    context.unconditionallyProcess(arcaneClass, "SPELLSTAT", "CHA");
    arcaneClass.put(ObjectKey.SPELLBOOK, false);
    arcaneClass.put(ObjectKey.MEMORIZE_SPELLS, false);
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "KNOWN", "4,2,1");
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "CAST", "3,1,0");
    context.getReferenceContext().importObject(arcaneClass);

    divineClass = new PCClass();
    divineClass.setName("TestDivine");
    divineClass.put(StringKey.SPELLTYPE, "DIVINE");
    context.unconditionallyProcess(divineClass, "SPELLSTAT", "WIS");
    divineClass.put(ObjectKey.SPELLBOOK, false);
    divineClass.put(ObjectKey.MEMORIZE_SPELLS, true);
    context.unconditionallyProcess(divineClass.getOriginalClassLevel(1), "CAST", "3,1,0");
    context.unconditionallyProcess(
        divineClass, "SPELLLEVEL", "CLASS|SPELLCASTER.Divine=1|Cure Light Wounds");
    context.getReferenceContext().importObject(divineClass);
    context.resolveDeferredTokens();
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().resolveReferences(null);
  }
예제 #27
0
  @Override
  public Float resolve(PlayerCharacter pc) {
    if (ControlUtilities.hasControlToken(Globals.getContext(), "EQACCHECK")) {
      Logging.errorPrint(
          originalText
              + " term is deprecated (does not function)"
              + " when EQACCHECK CodeControl is used");
    }
    int maxCheck = 0;

    for (Equipment eq : pc.getEquipmentOfType("Armor", 1)) {
      maxCheck += eq.preFormulaAcCheck(pc);
    }

    return (float) maxCheck;
  }
예제 #28
0
  private void buildKnownPreparedSpellsForCDOMObject(CDOMObject pObject) {
    Collection<? extends CharacterSpell> sp = charDisplay.getCharacterSpells(pObject);
    List<CharacterSpell> cSpells = new ArrayList<>(sp);

    // Add in the spells granted by objects
    pc.addBonusKnownSpellsToList(pObject, cSpells);
    PCClass pcClass = (PCClass) (pObject instanceof PCClass ? pObject : null);

    for (CharacterSpell charSpell : cSpells) {
      for (SpellInfo spellInfo : charSpell.getInfoList()) {
        // Create SpellNodeImpl for each spell
        String book = spellInfo.getBook();
        boolean isKnown = Globals.getDefaultSpellBook().equals(book);
        SpellFacadeImplem spellImplem =
            new SpellFacadeImplem(pc, charSpell.getSpell(), charSpell, spellInfo);
        SpellNodeImpl node;
        if (pcClass != null) {
          node =
              new SpellNodeImpl(
                  spellImplem,
                  pcClass,
                  String.valueOf(spellInfo.getActualLevel()),
                  getRootNode(book));
        } else {
          node =
              new SpellNodeImpl(
                  spellImplem, String.valueOf(spellInfo.getActualLevel()), getRootNode(book));
        }
        if (spellInfo.getTimes() > 1) {
          node.addCount(spellInfo.getTimes() - 1);
        }
        boolean isSpellBook =
            charDisplay.getSpellBookByName(book).getType() == SpellBook.TYPE_SPELL_BOOK;
        // Add to list
        if (isKnown) {
          allKnownSpellNodes.addElement(node);
          knownSpellNodes.addElement(node);
        } else if (isSpellBook) {
          bookSpellNodes.addElement(node);
        } else if (pObject instanceof Race) {
          allKnownSpellNodes.addElement(node);
        } else {
          preparedSpellNodes.addElement(node);
        }
      }
    }
  }
예제 #29
0
  private RootNodeImpl getRootNode(String bookName) {
    if (Globals.getDefaultSpellBook().equals(bookName)) {
      return null;
    }

    RootNodeImpl rootNode = rootNodeMap.get(bookName);
    if (rootNode == null) {
      SpellBook book = charDisplay.getSpellBookByName(bookName);
      if (book == null) {
        return null;
      }

      rootNode = new RootNodeImpl(book);
      rootNodeMap.put(bookName, rootNode);
    }

    return rootNode;
  }
예제 #30
0
 private static synchronized void staticSetUp() {
   if (!staticDone) {
     SettingsHandler.getGame().clearLoadContext();
     AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
     t = BuildUtilities.createSize("Tiny", 0);
     ref.importObject(t);
     s = BuildUtilities.createSize("Small", 1);
     ref.importObject(s);
     m = BuildUtilities.createSize("Medium", 2);
     m.put(ObjectKey.IS_DEFAULT_SIZE, true);
     ref.importObject(m);
     l = BuildUtilities.createSize("Large", 3);
     ref.importObject(l);
     h = BuildUtilities.createSize("Huge", 4);
     ref.importObject(h);
     staticDone = true;
   }
 }