Exemplo n.º 1
0
  /** Construct the list of available spells for the character. */
  private void buildAvailableNodes() {
    availableSpellNodes.clearContents();
    // Scan character classes for spell classes
    List<PCClass> classList = getCharactersSpellcastingClasses();

    // Look at each spell on each spellcasting class
    for (PCClass pcClass : classList) {
      DoubleKeyMapToList<SpellFacade, String, SpellNode> existingSpells =
          buildExistingSpellMap(availableSpellNodes, pcClass);

      for (Spell spell : pc.getAllSpellsInLists(charDisplay.getSpellLists(pcClass))) {
        // Create SpellNodeImpl for each spell
        CharacterSpell charSpell = new CharacterSpell(pcClass, spell);
        SpellFacadeImplem spellImplem = new SpellFacadeImplem(pc, spell, charSpell, null);

        HashMapToList<CDOMList<Spell>, Integer> levelInfo = pc.getSpellLevelInfo(spell);

        for (CDOMList<Spell> spellList : charDisplay.getSpellLists(pcClass)) {
          List<Integer> levels = levelInfo.getListFor(spellList);
          if (levels != null) {
            for (Integer level : levels) {
              SpellNodeImpl node =
                  new SpellNodeImpl(spellImplem, pcClass, String.valueOf(level), null);
              if (!existingSpells.containsInList(spellImplem, node.getSpellLevel(), node)) {
                // Add to list
                availableSpellNodes.addElement(node);
              }
            }
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Create a map of the spell nodes for a class in the supplied list. This is intended to allow
   * quick checking of the presence of a spell in the list.
   *
   * @param spellNodeList The list of spell nodes
   * @param pcClass The class to filter the map by
   * @return A double map to the class' spells from the list.
   */
  private DoubleKeyMapToList<SpellFacade, String, SpellNode> buildExistingSpellMap(
      DefaultListFacade<SpellNode> spellNodeList, PCClass pcClass) {
    DoubleKeyMapToList<SpellFacade, String, SpellNode> spellMap = new DoubleKeyMapToList<>();

    for (SpellNode spellNode : spellNodeList) {
      if (pcClass.equals(spellNode.getSpellcastingClass())) {
        spellMap.addToListFor(spellNode.getSpell(), spellNode.getSpellLevel(), spellNode);
      }
    }

    return spellMap;
  }