Search in sources :

Example 1 with CompanionMod

use of pcgen.core.character.CompanionMod in project pcgen by PCGen.

the class CompanionModLoader method getLoadable.

@Override
protected CompanionMod getLoadable(LoadContext context, String firstToken, URI sourceURI) throws PersistenceLayerException {
    String name = processFirstToken(context, firstToken);
    if (name == null) {
        return null;
    }
    //Always create a new CompanionMod (no Copy Mod or Forget)
    //But we need to create a unique name (and do it with something that is unique-ish)
    //Note there is currently no risk of name conflict here since they cannot be uniquely named
    String uniqueName = "COMPANIONMOD_" + COMPANION_MOD_ID++;
    CompanionMod mod = super.getLoadable(context, uniqueName, sourceURI);
    //Process the first token since it's not really a name...
    LstUtils.processToken(context, mod, sourceURI, firstToken);
    return mod;
}
Also used : CompanionMod(pcgen.core.character.CompanionMod)

Example 2 with CompanionMod

use of pcgen.core.character.CompanionMod in project pcgen by PCGen.

the class GlobalQualifyTest method testFromCompanionMod.

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

Example 3 with CompanionMod

use of pcgen.core.character.CompanionMod in project pcgen by PCGen.

the class PlayerCharacter method getEffectiveCompanionLevel.

/**
	 * This method returns the effective level of this character for purposes of
	 * applying companion mods to a companion of the specified type.
	 * <p>
	 * <b>Note</b>: This whole structure is kind of messed up since nothing
	 * enforces that a companion mod of a given type always looks at the same
	 * variable (either Class or Variable).  Note it seems that this used to
	 * be driven off types but now it's driven from a list of companion mods
	 * but the java doc has not been updated.
	 *
	 * @param compList
	 *            A list of companionMods to get level for
	 * @return The effective level for this companion type
	 */
public int getEffectiveCompanionLevel(final CompanionList compList) {
    for (CompanionMod cMod : Globals.getContext().getReferenceContext().getManufacturer(CompanionMod.class, compList).getAllObjects()) {
        Map<String, Integer> varmap = cMod.getMapFor(MapKey.APPLIED_VARIABLE);
        for (final String varName : varmap.keySet()) {
            final int lvl = this.getVariableValue(varName, Constants.EMPTY_STRING).intValue();
            if (lvl > 0) {
                return lvl;
            }
        }
        Map<CDOMSingleRef<? extends PCClass>, Integer> ac = cMod.getMapFor(MapKey.APPLIED_CLASS);
        for (Map.Entry<CDOMSingleRef<? extends PCClass>, Integer> me : ac.entrySet()) {
            PCClass pcclass = me.getKey().get();
            String key = pcclass.getKeyName();
            int lvl = getLevel(getClassKeyed(key));
            if (lvl > 0) {
                return lvl;
            }
        }
    }
    return 0;
}
Also used : CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Map(java.util.Map) HashMap(java.util.HashMap) CompanionMod(pcgen.core.character.CompanionMod)

Example 4 with CompanionMod

use of pcgen.core.character.CompanionMod in project pcgen by PCGen.

the class PlayerCharacter method getOldFollowerLimit.

private int getOldFollowerLimit(CompanionList cList) {
    // they can take unlimited number of them.
    for (CompanionMod cMod : Globals.getContext().getReferenceContext().getManufacturer(CompanionMod.class, cList).getAllObjects()) {
        Map<String, Integer> varmap = cMod.getMapFor(MapKey.APPLIED_VARIABLE);
        for (String varName : varmap.keySet()) {
            if (this.getVariableValue(varName, Constants.EMPTY_STRING).intValue() > 0) {
                return -1;
            }
        }
        Map<CDOMSingleRef<? extends PCClass>, Integer> ac = cMod.getMapFor(MapKey.APPLIED_CLASS);
        for (Map.Entry<CDOMSingleRef<? extends PCClass>, Integer> me : ac.entrySet()) {
            PCClass pcclass = me.getKey().get();
            String key = pcclass.getKeyName();
            for (PCClass pcClass : getClassSet()) {
                if (pcClass.getKeyName().equals(key)) {
                    return me.getValue();
                }
            }
        }
    }
    return 0;
}
Also used : CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Map(java.util.Map) HashMap(java.util.HashMap) CompanionMod(pcgen.core.character.CompanionMod)

Example 5 with CompanionMod

use of pcgen.core.character.CompanionMod in project pcgen by PCGen.

the class RaceTypeFacetTest method testGetFromTemplateOverridesRaceandCMod.

@Test
public void testGetFromTemplateOverridesRaceandCMod() {
    Race r = new Race();
    r.put(ObjectKey.RACETYPE, TEST_RACE_TYPE);
    rfacet.set(id, r);
    assertSame(TEST_RACE_TYPE, facet.getRaceType(id));
    CompanionMod c = new CompanionMod();
    c.put(ObjectKey.RACETYPE, RACE_TYPE_TOO);
    cfacet.add(id, c);
    assertSame(RACE_TYPE_TOO, facet.getRaceType(id));
    PCTemplate t = new PCTemplate();
    t.put(ObjectKey.RACETYPE, LAST_RACE_TYPE);
    tfacet.add(id, t, this);
    assertSame(LAST_RACE_TYPE, facet.getRaceType(id));
    tfacet.remove(id, t, this);
    assertSame(RACE_TYPE_TOO, facet.getRaceType(id));
    cfacet.remove(id, c);
    assertSame(TEST_RACE_TYPE, facet.getRaceType(id));
}
Also used : Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate) CompanionMod(pcgen.core.character.CompanionMod) Test(org.junit.Test)

Aggregations

CompanionMod (pcgen.core.character.CompanionMod)16 Test (org.junit.Test)6 Race (pcgen.core.Race)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)2 PCTemplate (pcgen.core.PCTemplate)2 ArrayList (java.util.ArrayList)1 ChooseInformation (pcgen.cdom.base.ChooseInformation)1 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)1 RaceType (pcgen.cdom.enumeration.RaceType)1 Type (pcgen.cdom.enumeration.Type)1 CompanionList (pcgen.cdom.list.CompanionList)1 Follower (pcgen.core.character.Follower)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1 AbstractContentTokenTest (tokencontent.testsupport.AbstractContentTokenTest)1 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)1