Search in sources :

Example 26 with SizeAdjustment

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

the class SizeFacet method update.

/**
	 * Forces a complete update of the size information for the Player Character
	 * identified by the given CharID.
	 * 
	 * @param id
	 *            The CharID indicating the Player Character on which to update
	 *            the size information
	 */
public void update(CharID id) {
    SizeFacetInfo info = getConstructingInfo(id);
    int iSize = calcRacialSizeInt(id);
    Race race = raceFacet.get(id);
    if (race != null) {
        // Now check and see if a class has modified
        // the size of the character with something like:
        // BONUS:SIZEMOD|NUMBER|+1
        iSize += (int) bonusCheckingFacet.getBonus(id, "SIZEMOD", "NUMBER");
        // Now see if there is a HD advancement in size
        // (Such as for Dragons)
        iSize += sizesToAdvance(id, race);
        //
        // Must still be a valid size
        //
        int maxIndex = Globals.getContext().getReferenceContext().getConstructedObjectCount(SIZEADJUSTMENT_CLASS) - 1;
        iSize = Math.min(maxIndex, Math.max(0, iSize));
    }
    info.sizeInt = iSize;
    SizeAdjustment oldSize = info.sizeAdj;
    SizeAdjustment newSize = Globals.getContext().getReferenceContext().getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(sizeInt(id));
    info.sizeAdj = newSize;
    if (oldSize != newSize) {
        if (oldSize != null) {
            fireDataFacetChangeEvent(id, oldSize, DataFacetChangeEvent.DATA_REMOVED);
        }
        fireDataFacetChangeEvent(id, newSize, DataFacetChangeEvent.DATA_ADDED);
    }
}
Also used : Race(pcgen.core.Race) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 27 with SizeAdjustment

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

the class UnarmedDamageFacet method getUDamForRace.

/**
	 * Returns the unarmed damage String for the Race of the Player Character
	 * identified by the given CharID.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character
	 * @return The unarmed damage String for the Race of the Player Character
	 *         identified by the given CharID
	 */
public String getUDamForRace(CharID id) {
    Race race = raceFacet.get(id);
    int iSize = formulaResolvingFacet.resolve(id, race.getSafe(FormulaKey.SIZE), race.getQualifiedKey()).intValue();
    SizeAdjustment defAdj = SizeUtilities.getDefaultSizeAdjustment();
    SizeAdjustment sizAdj = Globals.getContext().getReferenceContext().getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(iSize);
    if (sizAdj != null) {
        return Globals.adjustDamage("1d3", defAdj, sizAdj);
    }
    return "1d3";
}
Also used : Race(pcgen.core.Race) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 28 with SizeAdjustment

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

the class SizeTokenTest method setUp.

@Override
@Before
public void setUp() throws PersistenceLayerException, URISyntaxException {
    super.setUp();
    ps = BuildUtilities.createSize("S", 0);
    primaryContext.getReferenceContext().importObject(ps);
    SizeAdjustment pm = BuildUtilities.createSize("M", 1);
    primaryContext.getReferenceContext().importObject(pm);
    SizeAdjustment ss = BuildUtilities.createSize("S", 0);
    secondaryContext.getReferenceContext().importObject(ss);
    SizeAdjustment sm = BuildUtilities.createSize("M", 1);
    secondaryContext.getReferenceContext().importObject(sm);
}
Also used : SizeAdjustment(pcgen.core.SizeAdjustment) Before(org.junit.Before)

Example 29 with SizeAdjustment

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

the class CharacterUtils method selectClothes.

public static void selectClothes(final PlayerCharacter aPC) {
    if (Globals.checkRule(RuleConstants.FREECLOTHES) && //$NON-NLS-1$
    ((aPC.getDisplay().totalNonMonsterLevels()) == 1)) {
        //
        // See what the PC is already carrying
        //
        List<Equipment> clothes = aPC.getEquipmentOfType("Clothing.Resizable", //$NON-NLS-1$ //$NON-NLS-2$
        3);
        //
        // Check to see if any of the clothing the PC
        // is carrying will actually fit and
        // has a zero price attached
        //
        boolean hasClothes = false;
        SizeAdjustment pcSizeAdj = aPC.getDisplay().getSizeAdjustment();
        if (!clothes.isEmpty()) {
            for (Equipment eq : clothes) {
                if (!eq.isType("Magic") && (CoreUtility.doublesEqual(eq.getCost(aPC).doubleValue(), 0.0)) && pcSizeAdj.equals(eq.getSafe(ObjectKey.SIZE))) {
                    hasClothes = true;
                    break;
                }
            }
        }
        //
        if (!hasClothes) {
            clothes = EquipmentList.getEquipmentOfType("Clothing.Resizable.Starting", "Magic.Custom.Auto_Gen");
            if (clothes.isEmpty()) {
                clothes = EquipmentList.getEquipmentOfType("Clothing.Resizable", "Magic.Custom.Auto_Gen");
            }
            List<Equipment> selectedClothes = new ArrayList<>();
            selectedClothes = Globals.getChoiceFromList(//$NON-NLS-1$ 
            LanguageBundle.getString("in_sumSelectAFreeSetOfClothing"), clothes, selectedClothes, 1, aPC);
            if (!selectedClothes.isEmpty()) {
                Equipment eq = selectedClothes.get(0);
                if (eq != null) {
                    eq = eq.clone();
                    eq.setQty(new Float(1));
                    //
                    if (!pcSizeAdj.equals(eq.getSafe(ObjectKey.SIZE))) {
                        eq.resizeItem(aPC, pcSizeAdj);
                    }
                    // make cost 0
                    eq.setCostMod('-' + eq.getCost(aPC).toString());
                    if (aPC.getEquipmentNamed(eq.nameItemFromModifiers(aPC)) == null) {
                        aPC.addEquipment(eq);
                    } else {
                        Logging.errorPrint(//$NON-NLS-1$
                        "Cannot add duplicate equipment to PC");
                    }
                }
            }
        }
    }
}
Also used : Equipment(pcgen.core.Equipment) ArrayList(java.util.ArrayList) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 30 with SizeAdjustment

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

the class CharacterFacadeImpl method getEquipmentSizedForCharacter.

/**
	 * @see pcgen.core.facade.CharacterFacade#getEquipmentSizedForCharacter(pcgen.core.facade.EquipmentFacade)
	 */
@Override
public EquipmentFacade getEquipmentSizedForCharacter(EquipmentFacade equipment) {
    final Equipment equip = (Equipment) equipment;
    final SizeAdjustment newSize = charDisplay.getSizeAdjustment();
    if (equip.getSizeAdjustment() == newSize || !Globals.canResizeHaveEffect(equip, null)) {
        return equipment;
    }
    final String existingKey = equip.getKeyName();
    final String newKey = equip.createKeyForAutoResize(newSize);
    Equipment potential = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, newKey);
    if (newKey.equals(existingKey)) {
        return equipment;
    }
    // in place of the selected equipment.
    if (potential != null) {
        return potential;
    }
    final String newName = equip.createNameForAutoResize(newSize);
    potential = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, newName);
    if (potential != null) {
        return potential;
    }
    final Equipment newEq = equip.clone();
    if (!newEq.containsKey(ObjectKey.BASE_ITEM)) {
        newEq.put(ObjectKey.BASE_ITEM, CDOMDirectSingleRef.getRef(equip));
    }
    newEq.setName(newName);
    newEq.put(StringKey.OUTPUT_NAME, newName);
    newEq.put(StringKey.KEY_NAME, newKey);
    newEq.resizeItem(theCharacter, newSize);
    newEq.removeType(Type.AUTO_GEN);
    newEq.removeType(Type.STANDARD);
    if (!newEq.isType(Constants.TYPE_CUSTOM)) {
        newEq.addType(Type.CUSTOM);
    }
    Globals.getContext().getReferenceContext().importObject(newEq);
    return newEq;
}
Also used : Equipment(pcgen.core.Equipment) SizeAdjustment(pcgen.core.SizeAdjustment)

Aggregations

SizeAdjustment (pcgen.core.SizeAdjustment)43 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)14 Equipment (pcgen.core.Equipment)11 Race (pcgen.core.Race)10 LoadContext (pcgen.rules.context.LoadContext)10 PlayerCharacter (pcgen.core.PlayerCharacter)8 Before (org.junit.Before)7 WieldCategory (pcgen.core.character.WieldCategory)7 Formula (pcgen.base.formula.Formula)3 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)3 Campaign (pcgen.core.Campaign)3 Description (pcgen.core.Description)3 GameMode (pcgen.core.GameMode)3 PCClass (pcgen.core.PCClass)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)3 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2