Search in sources :

Example 16 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class PCClass method getUDamForEffLevel.

/**
	 * Get the unarmed Damage for this class at the given level.
	 *
	 * @param aLevel the given level.
	 * @param aPC the PC with the level.
	 * @param adjustForPCSize whether to adjust the result for the PC's size.
	 * @return the unarmed damage string
	 */
String getUDamForEffLevel(int aLevel, final PlayerCharacter aPC, boolean adjustForPCSize) {
    int pcSize = adjustForPCSize ? aPC.sizeInt() : aPC.getDisplay().racialSizeInt();
    //
    // Check "Unarmed Strike", then default to "1d3"
    //
    String aDamage;
    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    final Equipment eq = ref.silentlyGetConstructedCDOMObject(Equipment.class, "KEY_Unarmed Strike");
    if (eq != null) {
        aDamage = eq.getDamage(aPC);
    } else {
        aDamage = "1d3";
    }
    // resize the damage as if it were a weapon
    if (adjustForPCSize) {
        int defSize = SizeUtilities.getDefaultSizeAdjustment().get(IntegerKey.SIZEORDER);
        aDamage = Globals.adjustDamage(aDamage, defSize, pcSize);
    }
    //
    // Check the UDAM list for monk-like damage
    //
    List<CDOMObject> classObjects = new ArrayList<>();
    //Negative increment to start at highest level until an UDAM is found
    for (int i = aLevel; i >= 1; i--) {
        classObjects.add(aPC.getActiveClassLevel(this, i));
    }
    classObjects.add(this);
    for (CDOMObject cdo : classObjects) {
        List<String> udam = cdo.getListFor(ListKey.UNARMED_DAMAGE);
        if (udam != null) {
            if (udam.size() == 1) {
                aDamage = udam.get(0);
            } else {
                aDamage = udam.get(pcSize);
            }
            break;
        }
    }
    return aDamage;
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList)

Example 17 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class EquipmentChoice method addSelectableAbilities.

/**
	 * Add abilities of Category aCategory and Type typeString to the
	 * available list of the Equipment Chooser equipChoice
	 * @param typeString  the type of Ability to add to the chooser
	 * @param aCategory   the Category of Ability to add to the chooser
	 */
public void addSelectableAbilities(final String typeString, final String aCategory) {
    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    AbilityCategory cat = ref.silentlyGetConstructedCDOMObject(AbilityCategory.class, aCategory);
    for (Ability anAbility : ref.getManufacturer(Ability.class, cat).getAllObjects()) {
        boolean matchesType = (typeString.equalsIgnoreCase("ALL") || anAbility.isType(typeString));
        if ((anAbility.getSafe(ObjectKey.VISIBILITY) == Visibility.DEFAULT) && !this.getAvailableList().contains(anAbility.getKeyName())) {
            if (matchesType && !ChooseActivation.hasNewChooseToken(anAbility)) {
                this.getAvailableList().add(anAbility.getKeyName());
            }
        }
    }
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext)

Example 18 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class Globals method adjustDamage.

/**
	 * Adjust damage
	 * @param aDamage
	 * @param baseSize
	 * @param finalSize
	 * @return adjusted damage
	 */
public static String adjustDamage(final String aDamage, final int baseSize, final int finalSize) {
    final AbstractReferenceContext ref = getContext().getReferenceContext();
    BaseDice bd = ref.silentlyGetConstructedCDOMObject(BaseDice.class, aDamage);
    int multiplier = 0;
    if (bd == null) {
        //Need to test for higher dice
        final RollInfo aRollInfo = new RollInfo(aDamage);
        final String baseDice = "1d" + Integer.toString(aRollInfo.sides);
        bd = ref.silentlyGetConstructedCDOMObject(BaseDice.class, baseDice);
        if (bd != null) {
            multiplier = aRollInfo.times;
        }
    } else {
        multiplier = 1;
    }
    RollInfo bi;
    if (bd == null) {
        bi = new RollInfo(aDamage);
    } else {
        List<RollInfo> steps = null;
        if (baseSize < finalSize) {
            steps = bd.getUpSteps();
        } else if (baseSize > finalSize) {
            steps = bd.getDownSteps();
        } else {
            // Not a warning?
            return aDamage;
        }
        final int difference = Math.abs(baseSize - finalSize);
        final int index;
        if (steps.size() > difference) {
            index = difference - 1;
        } else {
            index = steps.size() - 1;
        }
        bi = steps.get(index);
    }
    if (multiplier > 1) {
        // Ugh, have to do this for "cloning" to avoid polluting the master
        // RollInfo
        bi = new RollInfo(bi.toString());
        bi.times *= multiplier;
    }
    return bi.toString();
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) BaseDice(pcgen.cdom.content.BaseDice)

Example 19 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class AbstractTokenModelTest method setUpContext.

protected void setUpContext() throws PersistenceLayerException {
    ChooserFactory.pushChooserClassname(RandomChooser.class.getName());
    TokenRegistration.clearTokens();
    TokenRegistration.register(AUTO_LANG_TOKEN);
    TokenRegistration.register(ABILITY_VISIBLE_TOKEN);
    TokenRegistration.register(AUTO_TOKEN);
    TokenRegistration.register(CHOOSE_TOKEN);
    TokenRegistration.register(CHOOSE_LANG_TOKEN);
    TokenRegistration.register(ABILITY_MULT_TOKEN);
    TokenRegistration.register(EQUIP_TYPE_TOKEN);
    TokenRegistration.register(EQUIP_PROFICIENCY_TOKEN);
    TokenRegistration.register(LANGBONUS_PRIM);
    TokenRegistration.register(PC_QUAL);
    TokenRegistration.register(getToken());
    TokenRegistration.register(plugin.bonustokens.Feat.class);
    directAbilityFacet = FacetLibrary.getFacet(DirectAbilityFacet.class);
    activeEqModFacet = FacetLibrary.getFacet(ActiveEqModFacet.class);
    alignmentFacet = FacetLibrary.getFacet(AlignmentFacet.class);
    bioSetFacet = FacetLibrary.getFacet(BioSetFacet.class);
    checkFacet = FacetLibrary.getFacet(CheckFacet.class);
    classFacet = FacetLibrary.getFacet(ClassFacet.class);
    classLevelFacet = FacetLibrary.getFacet(ClassLevelFacet.class);
    companionModFacet = FacetLibrary.getFacet(CompanionModFacet.class);
    deityFacet = FacetLibrary.getFacet(DeityFacet.class);
    domainFacet = FacetLibrary.getFacet(DomainFacet.class);
    expandedCampaignFacet = FacetLibrary.getFacet(ExpandedCampaignFacet.class);
    languageFacet = FacetLibrary.getFacet(LanguageFacet.class);
    raceFacet = FacetLibrary.getFacet(RaceInputFacet.class);
    sizeFacet = FacetLibrary.getFacet(SizeFacet.class);
    skillFacet = FacetLibrary.getFacet(SkillFacet.class);
    statFacet = FacetLibrary.getFacet(StatFacet.class);
    templateInputFacet = FacetLibrary.getFacet(TemplateInputFacet.class);
    templateConsolidationFacet = FacetLibrary.getFacet(TemplateFacet.class);
    weaponProfModelFacet = FacetLibrary.getFacet(WeaponProfModelFacet.class);
    Globals.createEmptyRace();
    Globals.setUseGUI(false);
    Globals.emptyLists();
    GameMode gamemode = SettingsHandler.getGame();
    gamemode.clearLoadContext();
    str = BuildUtilities.createStat("Strength", "STR");
    str.put(VariableKey.getConstant("LOADSCORE"), FormulaFactory.getFormulaFor("STRSCORE"));
    str.put(VariableKey.getConstant("OFFHANDLIGHTBONUS"), FormulaFactory.getFormulaFor(2));
    dex = BuildUtilities.createStat("Dexterity", "DEX");
    PCStat con = BuildUtilities.createStat("Constitution", "CON");
    intel = BuildUtilities.createStat("Intelligence", "INT");
    wis = BuildUtilities.createStat("Wisdom", "WIS");
    cha = BuildUtilities.createStat("Charisma", "CHA");
    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    lg = BuildUtilities.createAlignment("Lawful Good", "LG");
    ref.importObject(lg);
    ln = BuildUtilities.createAlignment("Lawful Neutral", "LN");
    ref.importObject(ln);
    le = BuildUtilities.createAlignment("Lawful Evil", "LE");
    ref.importObject(le);
    ng = BuildUtilities.createAlignment("Neutral Good", "NG");
    ref.importObject(ng);
    tn = BuildUtilities.createAlignment("True Neutral", "TN");
    ref.importObject(tn);
    ne = BuildUtilities.createAlignment("Neutral Evil", "NE");
    ref.importObject(ne);
    cg = BuildUtilities.createAlignment("Chaotic Good", "CG");
    ref.importObject(cg);
    cn = BuildUtilities.createAlignment("Chaotic Neutral", "CN");
    ref.importObject(cn);
    ce = BuildUtilities.createAlignment("Chaotic Evil", "CE");
    ref.importObject(ce);
    ref.importObject(BuildUtilities.createAlignment("None", "NONE"));
    ref.importObject(BuildUtilities.createAlignment("Deity's", "Deity"));
    gamemode.setBonusFeatLevels("3|3");
    SettingsHandler.setGame("3.5");
    ref.importObject(str);
    ref.importObject(dex);
    ref.importObject(con);
    ref.importObject(intel);
    ref.importObject(wis);
    ref.importObject(cha);
    fine = BuildUtilities.createSize("Fine", 0);
    diminutive = BuildUtilities.createSize("Diminutive", 1);
    tiny = BuildUtilities.createSize("Tiny", 2);
    small = BuildUtilities.createSize("Small", 3);
    medium = BuildUtilities.createSize("Medium", 4);
    medium.put(ObjectKey.IS_DEFAULT_SIZE, true);
    large = BuildUtilities.createSize("Large", 5);
    huge = BuildUtilities.createSize("Huge", 6);
    gargantuan = BuildUtilities.createSize("Gargantuan", 7);
    colossal = BuildUtilities.createSize("Colossal", 8);
    context = Globals.getContext();
    create(Language.class, "Common");
    BuildUtilities.createFact(context, "ClassType", PCClass.class);
    FactDefinition<?, String> fd = BuildUtilities.createFact(context, "SpellType", PCClass.class);
    fd.setSelectable(true);
    context.getReferenceContext().importObject(AbilityCategory.FEAT);
    SourceFileLoader.createLangBonusObject(Globals.getContext());
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) TemplateFacet(pcgen.cdom.facet.model.TemplateFacet) RandomChooser(pcgen.util.chooser.RandomChooser) CompanionModFacet(pcgen.cdom.facet.model.CompanionModFacet) DomainFacet(pcgen.cdom.facet.model.DomainFacet) StatFacet(pcgen.cdom.facet.model.StatFacet) AlignmentFacet(pcgen.cdom.facet.model.AlignmentFacet) ActiveEqModFacet(pcgen.cdom.facet.model.ActiveEqModFacet) ClassFacet(pcgen.cdom.facet.model.ClassFacet) WeaponProfModelFacet(pcgen.cdom.facet.model.WeaponProfModelFacet) ClassLevelFacet(pcgen.cdom.facet.model.ClassLevelFacet) CheckFacet(pcgen.cdom.facet.model.CheckFacet) BioSetFacet(pcgen.cdom.facet.model.BioSetFacet) GameMode(pcgen.core.GameMode) RaceInputFacet(pcgen.cdom.facet.input.RaceInputFacet) SizeFacet(pcgen.cdom.facet.model.SizeFacet) ExpandedCampaignFacet(pcgen.cdom.facet.model.ExpandedCampaignFacet) DeityFacet(pcgen.cdom.facet.model.DeityFacet) DirectAbilityFacet(pcgen.cdom.facet.DirectAbilityFacet) TemplateInputFacet(pcgen.cdom.facet.input.TemplateInputFacet) PCStat(pcgen.core.PCStat) LanguageFacet(pcgen.cdom.facet.model.LanguageFacet) SkillFacet(pcgen.cdom.facet.model.SkillFacet)

Example 20 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class PObjectLoaderTest method testUnlockDefineStat.

public void testUnlockDefineStat() throws Exception {
    LoadContext context = Globals.getContext();
    AbstractReferenceContext ref = context.getReferenceContext();
    ref.importObject(BuildUtilities.createStat("Constitution", "CON"));
    ref.importObject(BuildUtilities.createStat("Intelligence", "INT"));
    Ability feat = new Ability();
    is(context.processToken(feat, "DEFINESTAT", "UNLOCK|INT"), eq(true), "Parse fails for unlock");
    context.commit();
    assertTrue(context.getReferenceContext().resolveReferences(null));
    Logging.clearParseMessages();
    List<CDOMSingleRef<PCStat>> statList = feat.getListFor(ListKey.UNLOCKED_STATS);
    assertEquals(1, statList.size());
    assertEquals("INT", statList.get(0).get().getKeyName());
}
Also used : Ability(pcgen.core.Ability) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) LoadContext(pcgen.rules.context.LoadContext) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Aggregations

AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)29 PCStat (pcgen.core.PCStat)7 GameMode (pcgen.core.GameMode)6 ArrayList (java.util.ArrayList)3 SizeAdjustment (pcgen.core.SizeAdjustment)3 LoadContext (pcgen.rules.context.LoadContext)3 CDOMObject (pcgen.cdom.base.CDOMObject)2 DirectAbilityFacet (pcgen.cdom.facet.DirectAbilityFacet)2 ActiveEqModFacet (pcgen.cdom.facet.model.ActiveEqModFacet)2 AlignmentFacet (pcgen.cdom.facet.model.AlignmentFacet)2 BioSetFacet (pcgen.cdom.facet.model.BioSetFacet)2 CheckFacet (pcgen.cdom.facet.model.CheckFacet)2 ClassFacet (pcgen.cdom.facet.model.ClassFacet)2 ClassLevelFacet (pcgen.cdom.facet.model.ClassLevelFacet)2 CompanionModFacet (pcgen.cdom.facet.model.CompanionModFacet)2 DeityFacet (pcgen.cdom.facet.model.DeityFacet)2 DomainFacet (pcgen.cdom.facet.model.DomainFacet)2 ExpandedCampaignFacet (pcgen.cdom.facet.model.ExpandedCampaignFacet)2 LanguageFacet (pcgen.cdom.facet.model.LanguageFacet)2 SizeFacet (pcgen.cdom.facet.model.SizeFacet)2