Search in sources :

Example 31 with Deity

use of pcgen.core.Deity in project pcgen by PCGen.

the class DeityTokenTest method testUnparseSingle.

@Test
public void testUnparseSingle() throws PersistenceLayerException {
    Deity wp1 = construct(primaryContext, "TestWP1");
    primaryProf.addToListFor(ListKey.DEITY, CDOMDirectSingleRef.getRef(wp1));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getLegalValue());
}
Also used : Deity(pcgen.core.Deity) Test(org.junit.Test)

Example 32 with Deity

use of pcgen.core.Deity in project pcgen by PCGen.

the class PCGVer2Creator method appendDeityLine.

/*
	 * ###############################################################
	 * Character Deity/Domain methods
	 * ###############################################################
	 */
private void appendDeityLine(StringBuilder buffer) {
    if (charDisplay.getDeity() != null) {
        final Deity aDeity = charDisplay.getDeity();
        buffer.append(IOConstants.TAG_DEITY).append(':');
        buffer.append(EntityEncoder.encode(aDeity.getKeyName()));
        /*
			 * currently unused information
			 *
			 * author: Thomas Behr 09-09-02
			 */
        buffer.append('|');
        buffer.append(IOConstants.TAG_DEITYDOMAINS).append(':');
        buffer.append('[');
        String del = Constants.EMPTY_STRING;
        for (CDOMReference<Domain> ref : aDeity.getSafeListMods(Deity.DOMAINLIST)) {
            for (Domain d : ref.getContainedObjects()) {
                buffer.append(del);
                buffer.append(IOConstants.TAG_DOMAIN).append(':');
                buffer.append(EntityEncoder.encode(d.getKeyName()));
                //$NON-NLS-1$
                del = "|";
            }
        }
        buffer.append(']');
        buffer.append('|');
        buffer.append(IOConstants.TAG_ALIGNALLOW).append(':');
        //TODO Need to clean this up?
        for (final Description desc : aDeity.getSafeListFor(ListKey.DESCRIPTION)) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_DESC).append(':');
            buffer.append(desc.getPCCText());
        }
        buffer.append('|');
        buffer.append(IOConstants.TAG_DEITYFAVWEAP).append(':');
        buffer.append('[');
        List<CDOMReference<WeaponProf>> dwp = aDeity.getListFor(ListKey.DEITYWEAPON);
        if (dwp != null) {
            del = Constants.EMPTY_STRING;
            for (CDOMReference<WeaponProf> ref : dwp) {
                buffer.append(del);
                buffer.append(IOConstants.TAG_WEAPON).append(':');
                buffer.append(EntityEncoder.encode(ref.getLSTformat(false)));
                //$NON-NLS-1$
                del = "|";
            }
        }
        buffer.append(']');
        buffer.append('|');
        buffer.append(IOConstants.TAG_DEITYALIGN).append(':');
        CDOMSingleRef<PCAlignment> al = aDeity.get(ObjectKey.ALIGNMENT);
        if (al != null) {
            buffer.append(al.getLSTformat(false));
        }
        buffer.append(IOConstants.LINE_SEP);
    }
}
Also used : Deity(pcgen.core.Deity) PCAlignment(pcgen.core.PCAlignment) Description(pcgen.core.Description) WeaponProf(pcgen.core.WeaponProf) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 33 with Deity

use of pcgen.core.Deity in project pcgen by PCGen.

the class PCGVer2Parser method parseDeityLine.

/**
	 * ###############################################################
	 * Character Deity/Domain methods
	 * ###############################################################
	 * @param line
	 **/
private void parseDeityLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalDeity", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    final String deityKey = EntityEncoder.decode(tokens.getElements().get(0).getText());
    Deity aDeity = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Deity.class, deityKey);
    if (aDeity != null) {
        thePC.setDeity(aDeity);
    } else if (!Constants.NONE.equals(deityKey)) {
        // TODO
        // create Deity object from information contained in pcg
        // for now issue a warning
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.DeityNotFound", deityKey);
        warnings.add(msg);
    }
}
Also used : Deity(pcgen.core.Deity)

Example 34 with Deity

use of pcgen.core.Deity in project pcgen by PCGen.

the class PreDeityDomainTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
	 */
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {
    int runningTotal = 0;
    Deity deity = display.getDeity();
    if (deity != null) {
        if (deity.hasObjectOnList(Deity.DOMAINLIST, Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, prereq.getKey()))) {
            runningTotal++;
        }
    }
    return countedTotal(prereq, runningTotal);
}
Also used : Deity(pcgen.core.Deity) Domain(pcgen.core.Domain)

Example 35 with Deity

use of pcgen.core.Deity in project pcgen by PCGen.

the class AbilityRefChoiceSet method addMultiplySelectableAbility.

private Collection<CNAbilitySelection> addMultiplySelectableAbility(final PlayerCharacter aPC, Ability ability, String subName) {
    boolean isPattern = false;
    String nameRoot = null;
    if (subName != null) {
        final int percIdx = subName.indexOf('%');
        if (percIdx > -1) {
            isPattern = true;
            nameRoot = subName.substring(0, percIdx);
        } else if (!subName.isEmpty()) {
            nameRoot = subName;
        }
    }
    ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
    final List<String> availableList = getAvailableList(aPC, chooseInfo);
    /*
		 * TODO Need a general solution for this special assignment in parens
		 */
    if ("DEITYWEAPON".equals(nameRoot) && (chooseInfo != null) && chooseInfo.getClassIdentity().getChoiceClass().equals(WeaponProf.class)) {
        Deity deity = aPC.getDeity();
        if (deity == null) {
            availableList.clear();
        } else {
            List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
            Set<String> set = new HashSet<>();
            for (CDOMReference<WeaponProf> ref : dwp) {
                for (WeaponProf wp : ref.getContainedObjects()) {
                    set.add(wp.getKeyName());
                }
            }
            availableList.retainAll(set);
        }
    } else if (nameRoot != null && !nameRoot.isEmpty()) {
        for (int n = availableList.size() - 1; n >= 0; --n) {
            final String aString = availableList.get(n);
            if (!aString.startsWith(nameRoot)) {
                availableList.remove(n);
            }
        }
        if (isPattern && !availableList.isEmpty()) {
            availableList.add(nameRoot);
        }
    }
    List<CNAbilitySelection> returnList = new ArrayList<>(availableList.size());
    for (String s : availableList) {
        returnList.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(category.get(), nature, ability), s));
    }
    return returnList;
}
Also used : Deity(pcgen.core.Deity) ArrayList(java.util.ArrayList) WeaponProf(pcgen.core.WeaponProf) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) CDOMReference(pcgen.cdom.base.CDOMReference) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Deity (pcgen.core.Deity)39 CDOMReference (pcgen.cdom.base.CDOMReference)8 Domain (pcgen.core.Domain)8 Test (org.junit.Test)5 WeaponProf (pcgen.core.WeaponProf)5 HashSet (java.util.HashSet)3 TreeSet (java.util.TreeSet)3 StringManager (pcgen.base.format.StringManager)3 PCAlignment (pcgen.core.PCAlignment)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)2 SimpleAssociatedObject (pcgen.cdom.base.SimpleAssociatedObject)2 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 NumberManager (pcgen.base.format.NumberManager)1 Indirect (pcgen.base.util.Indirect)1 WeightedCollection (pcgen.base.util.WeightedCollection)1 WrappedMapSet (pcgen.base.util.WrappedMapSet)1