Search in sources :

Example 51 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class TempBonusHelper method removeBonusFromCharacter.

static void removeBonusFromCharacter(PlayerCharacter pc, Equipment aEq, CDOMObject aCreator) {
    for (Map.Entry<BonusObj, BonusManager.TempBonusInfo> me : pc.getTempBonusMap().entrySet()) {
        BonusObj aBonus = me.getKey();
        TempBonusInfo tbi = me.getValue();
        Object aC = tbi.source;
        if (aCreator != aC) {
            continue;
        }
        Object aT = tbi.target;
        if ((aT instanceof Equipment) && (aEq != null)) {
            if (aEq.equals(aT)) {
                pc.removeTempBonus(aBonus);
                pc.removeTempBonusItemList((Equipment) aT);
                ((Equipment) aT).removeTempBonus(aBonus);
                ((Equipment) aT).setAppliedName(EMPTY_STRING);
            }
        } else if ((aT instanceof PlayerCharacter) && (aEq == null)) {
            pc.removeTempBonus(aBonus);
        }
    }
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) PlayerCharacter(pcgen.core.PlayerCharacter) BonusObj(pcgen.core.bonus.BonusObj) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) Map(java.util.Map)

Example 52 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class Gui2InfoFactory method getDescription.

@Override
public String getDescription(TempBonusFacade tempBonusFacade) {
    if (tempBonusFacade == null || !(tempBonusFacade instanceof TempBonusFacadeImpl)) {
        return EMPTY_STRING;
    }
    try {
        TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) tempBonusFacade;
        CDOMObject originObj = tempBonus.getOriginObj();
        String desc = originObj.getSafe(StringKey.TEMP_DESCRIPTION);
        if (StringUtils.isEmpty(desc)) {
            if (originObj instanceof Spell) {
                Spell sp = (Spell) originObj;
                desc = DescriptionFormatting.piWrapDesc(sp, pc.getDescription(sp), false);
            } else if (originObj instanceof Ability) {
                Ability ab = (Ability) originObj;
                List<CNAbility> wrappedAbility = Collections.singletonList(CNAbilityFactory.getCNAbility(ab.getCDOMCategory(), Nature.NORMAL, ab));
                desc = DescriptionFormatting.piWrapDesc(ab, pc.getDescription(wrappedAbility), false);
            }
        }
        return desc;
    } catch (Exception e) {
        //$NON-NLS-1$
        Logging.errorPrint("Failed to get description for " + tempBonusFacade, e);
        return EMPTY_STRING;
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) List(java.util.List) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 53 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class StatIntegrationTest method testUnlockInnocent.

@Test
public void testUnlockInnocent() {
    CDOMObject r1 = new Race();
    causeUnlock(r1, stat2);
    testNonAbilityUnset();
    testLockUnset();
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) Race(pcgen.core.Race) Test(org.junit.Test)

Example 54 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class GlobalCompanionListTest method containsExpected.

@Override
protected boolean containsExpected() {
    /*
		 * TODO This indicates that FollowerOptionFacet is not really pure
		 * content - it is doing filtering as well
		 */
    Map<FollowerOption, CDOMObject> available = foFacet.getAvailableFollowers(id, "Animal Companion", null);
    if (available.size() != 1) {
        return false;
    }
    FollowerOption entry = available.keySet().iterator().next();
    boolean raceMatches = entry.getRaceRef().equals(context.getReferenceContext().getCDOMReference(Race.class, "Ape"));
    boolean listMatches = entry.getListRef().equals(context.getReferenceContext().getCDOMReference(CompanionList.class, "Animal Companion"));
    boolean adjMatches = entry.getAdjustment() == -3;
    return raceMatches && listMatches && adjMatches;
}
Also used : FollowerOption(pcgen.core.FollowerOption) CDOMObject(pcgen.cdom.base.CDOMObject) CompanionList(pcgen.cdom.list.CompanionList) Race(pcgen.core.Race)

Example 55 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class BonusManager method calcBonusesWithCost.

public double calcBonusesWithCost(List<BonusObj> list) {
    double totalBonus = 0;
    for (BonusObj aBonus : list) {
        final CDOMObject anObj = (CDOMObject) getSourceObject(aBonus);
        if (anObj == null) {
            continue;
        }
        double iBonus = 0;
        if (aBonus.qualifies(pc, anObj)) {
            iBonus = aBonus.resolve(pc, anObj.getQualifiedKey()).doubleValue();
        }
        int k;
        if (ChooseActivation.hasNewChooseToken(anObj)) {
            k = 0;
            for (String aString : pc.getConsolidatedAssociationList(anObj)) {
                if (aString.equalsIgnoreCase(aBonus.getBonusInfo())) {
                    ++k;
                }
            }
        } else {
            k = 1;
        }
        if ((k == 0) && !CoreUtility.doublesEqual(iBonus, 0)) {
            totalBonus += iBonus;
        } else {
            totalBonus += (iBonus * k);
        }
    }
    return totalBonus;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) CDOMObject(pcgen.cdom.base.CDOMObject)

Aggregations

CDOMObject (pcgen.cdom.base.CDOMObject)235 Test (org.junit.Test)68 CharID (pcgen.cdom.enumeration.CharID)53 PCTemplate (pcgen.core.PCTemplate)30 ArrayList (java.util.ArrayList)22 PCClass (pcgen.core.PCClass)18 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)17 Race (pcgen.core.Race)17 Equipment (pcgen.core.Equipment)15 PlayerCharacter (pcgen.core.PlayerCharacter)15 Map (java.util.Map)14 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)14 CDOMReference (pcgen.cdom.base.CDOMReference)14 BonusObj (pcgen.core.bonus.BonusObj)14 IdentityHashMap (java.util.IdentityHashMap)12 Set (java.util.Set)12 VariableKey (pcgen.cdom.enumeration.VariableKey)11 HashMap (java.util.HashMap)10 CNAbility (pcgen.cdom.content.CNAbility)10 Spell (pcgen.core.spell.Spell)9