Search in sources :

Example 1 with PCAlignment

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

the class GlobalQualifyTest method testFromAlignment.

@Override
@Test
public void testFromAlignment() throws PersistenceLayerException {
    PCAlignment source = create(PCAlignment.class, "Source");
    ParseResult result = token.parseToken(context, source, "RACE|Dwarf");
    assertFalse(result.passed());
}
Also used : PCAlignment(pcgen.core.PCAlignment) ParseResult(pcgen.rules.persistence.token.ParseResult) Test(org.junit.Test) AbstractContentTokenTest(tokencontent.testsupport.AbstractContentTokenTest)

Example 2 with PCAlignment

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

the class CharacterFacadeImpl method validateAlignmentChange.

/**
	 * Validate the new alignment matches those allowed for the character's 
	 * classes. If not offer the user a choice of backing out or making the 
	 * classes into ex-classes.
	 * 
	 * @param newAlign The alignment to be set
	 */
private boolean validateAlignmentChange(AlignmentFacade newAlign) {
    AlignmentFacade oldAlign = this.alignment.get();
    if (oldAlign == null || newAlign.equals(oldAlign)) {
        return true;
    }
    // We can't do any validation if the new alignment isn't a known class
    if (!(newAlign instanceof PCAlignment)) {
        return true;
    }
    //
    // Get a list of classes that will become unqualified (and have an ex-class)
    //
    StringBuilder unqualified = new StringBuilder(100);
    List<PCClass> classList = charDisplay.getClassList();
    List<PCClass> exclassList = new ArrayList<>();
    PCAlignment savedAlignmnet = charDisplay.getPCAlignment();
    for (PCClass aClass : classList) {
        theCharacter.setAlignment((PCAlignment) newAlign);
        {
            if (!theCharacter.isQualified(aClass)) {
                if (aClass.containsKey(ObjectKey.EX_CLASS)) {
                    if (unqualified.length() > 0) {
                        //$NON-NLS-1$
                        unqualified.append(", ");
                    }
                    unqualified.append(aClass.getKeyName());
                    exclassList.add(aClass);
                }
            }
        }
    }
    //
    if (unqualified.length() > 0) {
        if (!delegate.showWarningConfirm(Constants.APPLICATION_NAME, LanguageBundle.getString("in_sumExClassesWarning") + Constants.LINE_SEPARATOR + unqualified)) {
            theCharacter.setAlignment(savedAlignmnet);
            return false;
        }
    }
    //
    for (PCClass aClass : exclassList) {
        theCharacter.makeIntoExClass(aClass);
    }
    // Update the facade and UI
    refreshClassLevelModel();
    return true;
}
Also used : PCAlignment(pcgen.core.PCAlignment) ArrayList(java.util.ArrayList) AlignmentFacade(pcgen.facade.core.AlignmentFacade) PCClass(pcgen.core.PCClass)

Example 3 with PCAlignment

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

the class KitAlignment method toString.

@Override
public String toString() {
    if (alignments == null || alignments.isEmpty()) {
        //CONSIDER can this ever happen and not be an error that should be caught at LST load?
        return "";
    }
    if (alignments.size() == 1) {
        return alignments.get(0).get().getDisplayName();
    } else {
        // Build the string list.
        StringBuilder buf = new StringBuilder();
        buf.append("One of (");
        boolean needComma = false;
        for (CDOMSingleRef<PCAlignment> alref : alignments) {
            PCAlignment al = alref.get();
            if (needComma) {
                buf.append(", ");
            }
            needComma = true;
            buf.append(al.getDisplayName());
        }
        buf.append(")");
        return buf.toString();
    }
}
Also used : PCAlignment(pcgen.core.PCAlignment)

Example 4 with PCAlignment

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

the class DeityToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    String retString = "";
    CharacterDisplay display = pc.getDisplay();
    Deity deity = display.getDeity();
    if (deity != null) {
        StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
        String subTag = "OUTPUTNAME";
        if (aTok.countTokens() > 1) {
            aTok.nextToken();
            subTag = aTok.nextToken();
        }
        if ("NAME".equals(subTag)) {
            if (!display.getSuppressBioField(BiographyField.DEITY)) {
                retString = deity.getDisplayName();
            }
        } else if ("OUTPUTNAME".equals(subTag)) {
            if (!display.getSuppressBioField(BiographyField.DEITY)) {
                retString = OutputNameFormatting.getOutputName(deity);
            }
        } else if ("DOMAINLIST".equals(subTag)) {
            retString = getDomainListToken(deity);
        } else if ("FOLLOWERALIGNMENT".equals(subTag)) {
            Logging.errorPrint("Output Sheet uses DEITY.FOLLOWERALIGN: " + "Function has been removed from PCGen");
        } else if ("ALIGNMENT".equals(subTag)) {
            CDOMSingleRef<PCAlignment> al = deity.get(ObjectKey.ALIGNMENT);
            retString = al == null ? "" : al.get().getKeyName();
        } else if ("APPEARANCE".equals(subTag)) {
            FactKey<String> fk = FactKey.valueOf("Appearance");
            String str = deity.getResolved(fk);
            retString = (str == null) ? "" : str;
        } else if ("DESCRIPTION".equals(subTag)) {
            retString = pc.getDescription(deity);
        } else if ("HOLYITEM".equals(subTag)) {
            FactKey<String> fk = FactKey.valueOf("Symbol");
            String str = deity.getResolved(fk);
            retString = (str == null) ? "" : str;
        } else if ("FAVOREDWEAPON".equals(subTag)) {
            List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
            retString = ReferenceUtilities.joinLstFormat(dwp, Constants.PIPE, true);
        } else if ("PANTHEONLIST".equals(subTag)) {
            FactSetKey<String> fk = FactSetKey.valueOf("Pantheon");
            Set<String> pset = new TreeSet<>();
            for (Indirect<String> indirect : deity.getSafeSetFor(fk)) {
                pset.add(indirect.get());
            }
            retString = StringUtil.join(pset, ", ");
        } else if ("SOURCE".equals(subTag)) {
            retString = SourceFormat.getFormattedString(deity, Globals.getSourceDisplay(), true);
        } else if ("SA".equals(subTag)) {
            retString = getSAToken(deity, display);
        } else if ("TITLE".equals(subTag)) {
            FactKey<String> fk = FactKey.valueOf("Title");
            String str = deity.getResolved(fk);
            retString = (str == null) ? "" : str;
        } else if ("WORSHIPPERS".equals(subTag)) {
            FactKey<String> fk = FactKey.valueOf("Worshippers");
            String str = deity.getResolved(fk);
            retString = (str == null) ? "" : str;
        }
    }
    return retString;
}
Also used : Deity(pcgen.core.Deity) TreeSet(java.util.TreeSet) Set(java.util.Set) CharacterDisplay(pcgen.core.display.CharacterDisplay) Indirect(pcgen.base.util.Indirect) FactKey(pcgen.cdom.enumeration.FactKey) StringTokenizer(java.util.StringTokenizer) PCAlignment(pcgen.core.PCAlignment) FactSetKey(pcgen.cdom.enumeration.FactSetKey) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 5 with PCAlignment

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

the class AlignTokenTest method setUp.

@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
    super.setUp();
    PCAlignment lg = BuildUtilities.createAlignment("Lawful Good", "LG");
    primaryContext.getReferenceContext().importObject(lg);
    PCAlignment slg = BuildUtilities.createAlignment("Lawful Good", "LG");
    secondaryContext.getReferenceContext().importObject(slg);
    TokenRegistration.register(ALIGN_TOKEN);
}
Also used : PCAlignment(pcgen.core.PCAlignment)

Aggregations

PCAlignment (pcgen.core.PCAlignment)19 Before (org.junit.Before)3 Deity (pcgen.core.Deity)3 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2 CDOMReference (pcgen.cdom.base.CDOMReference)2 PCClass (pcgen.core.PCClass)2 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1 Indirect (pcgen.base.util.Indirect)1 WeightedCollection (pcgen.base.util.WeightedCollection)1 FactKey (pcgen.cdom.enumeration.FactKey)1 FactSetKey (pcgen.cdom.enumeration.FactSetKey)1 Gender (pcgen.cdom.enumeration.Gender)1 Ability (pcgen.core.Ability)1 Description (pcgen.core.Description)1 Domain (pcgen.core.Domain)1 Race (pcgen.core.Race)1 WeaponProf (pcgen.core.WeaponProf)1