Search in sources :

Example 26 with Equipment

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

the class CharacterFacadeImpl method modifyCharges.

@Override
public void modifyCharges(List<EquipmentFacade> targets) {
    List<Equipment> chargedEquip = new ArrayList<>();
    for (EquipmentFacade equipmentFacade : targets) {
        if (equipmentFacade instanceof Equipment && ((Equipment) equipmentFacade).getMaxCharges() > 0) {
            chargedEquip.add((Equipment) equipmentFacade);
        }
    }
    if (chargedEquip.isEmpty()) {
        return;
    }
    for (Equipment equip : chargedEquip) {
        int selectedCharges = getSelectedCharges(equip);
        if (selectedCharges < 0) {
            return;
        }
        equip.setRemainingCharges(selectedCharges);
        purchasedEquip.modifyElement(equip);
    }
}
Also used : EquipmentFacade(pcgen.facade.core.EquipmentFacade) Equipment(pcgen.core.Equipment) ArrayList(java.util.ArrayList)

Example 27 with Equipment

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

the class CharacterFacadeImpl method addTempBonus.

@Override
public void addTempBonus(TempBonusFacade bonusFacade) {
    if (bonusFacade == null || !(bonusFacade instanceof TempBonusFacadeImpl)) {
        return;
    }
    TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) bonusFacade;
    // Allow selection of target for bonus affecting equipment
    CDOMObject originObj = tempBonus.getOriginObj();
    Equipment aEq = null;
    Object target = TempBonusHelper.getTempBonusTarget(originObj, theCharacter, delegate, infoFactory);
    if (target == null) {
        return;
    }
    TempBonusFacadeImpl appliedTempBonus;
    if (target instanceof Equipment) {
        aEq = (Equipment) target;
        appliedTempBonus = TempBonusHelper.applyBonusToCharacterEquipment(aEq, originObj, theCharacter);
    } else {
        appliedTempBonus = TempBonusHelper.applyBonusToCharacter(originObj, theCharacter);
    }
    // Resolve choices and apply the bonus to the character.
    if (appliedTempBonus == null) {
        return;
    }
    appliedTempBonuses.addElement(appliedTempBonus);
    refreshStatScores();
    postLevellingUpdates();
}
Also used : Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) QualifiedObject(pcgen.core.QualifiedObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject)

Example 28 with Equipment

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

the class WeaponToken method getTotalHitToken.

/**
	 * Get total hit token
	 * @param pc
	 * @param eq
	 * @param range
	 * @param content
	 * @param ammo
	 * @param attackNum
	 * @return total hit token
	 */
public static String getTotalHitToken(PlayerCharacter pc, Equipment eq, int range, int content, int ammo, int attackNum) {
    CharacterDisplay display = pc.getDisplay();
    boolean isDouble = (eq.isDouble() && (eq.getLocation() == EquipmentLocation.EQUIPPED_TWO_HANDS));
    boolean isDoubleSplit = (eq.isType("Head1") || eq.isType("Head2"));
    int hitMode = HITMODE_TOTALHIT;
    // First do unarmed.
    if (eq.isUnarmed()) {
        hitMode = HITMODE_BASEHIT;
    } else // next do Double weapons
    if (isDouble && !isDoubleSplit) {
        hitMode = HITMODE_TWOHIT;
    } else if (!isDouble && isDoubleSplit) {
        hitMode = HITMODE_THHIT;
    } else // eq is Primary
    if (display.isPrimaryWeapon(eq) && display.hasSecondaryWeapons()) {
        Equipment sEq = display.getSecondaryWeapons().iterator().next();
        if (sEq == null) {
            // Hmm, weird
            // default to off-hand light
            hitMode = HITMODE_TWPHITL;
        } else if (sEq.isWeaponLightForPC(pc)) {
            // offhand light
            hitMode = HITMODE_TWPHITL;
        } else {
            // offhand heavy
            hitMode = HITMODE_TWPHITH;
        }
    } else // eq is Secondary
    if (display.isSecondaryWeapon(eq) && display.hasPrimaryWeapons()) {
        if (eq.isWeaponLightForPC(pc)) {
            // offhand light
            hitMode = HITMODE_TWFOHL;
        } else {
            // offhand heavy
            hitMode = HITMODE_TWFOHH;
        }
    } else // Just a single off-hand weapon
    if (display.isSecondaryWeapon(eq) && !display.hasPrimaryWeapons()) {
        hitMode = HITMODE_OHHIT;
    } else // Just a single primary weapon
    if (display.isPrimaryWeapon(eq) && !display.hasSecondaryWeapons()) {
        if (eq.getLocation() == EquipmentLocation.EQUIPPED_BOTH) {
            // both hands
            hitMode = HITMODE_THHIT;
        } else {
            // single hand
            hitMode = HITMODE_BASEHIT;
        }
    } else {
        // probably just carried
        if (eq.isWeaponTwoHanded(pc)) {
            // Two Handed weapon
            hitMode = HITMODE_THHIT;
        } else {
            // one handed weapon
            hitMode = HITMODE_BASEHIT;
        }
    }
    return getToHit(pc, eq, range, content, ammo, hitMode, attackNum);
}
Also used : Equipment(pcgen.core.Equipment) CharacterDisplay(pcgen.core.display.CharacterDisplay)

Example 29 with Equipment

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

the class WeaponToken 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) {
    StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
    //Weapon Token
    aTok.nextToken();
    int merge = Constants.MERGE_ALL;
    int weapon = 0;
    Equipment eq;
    // First check to see if there is a MERGE token
    String token = aTok.nextToken();
    if (token.equals("MERGENONE")) {
        merge = Constants.MERGE_NONE;
        token = aTok.nextToken();
    } else if (token.equals("MERGELOC")) {
        merge = Constants.MERGE_LOCATION;
        token = aTok.nextToken();
    } else if (token.equals("MERGEALL")) {
        merge = Constants.MERGE_ALL;
        token = aTok.nextToken();
    }
    List<Equipment> weaponList = pc.getExpandedWeapons(merge);
    if (token.equals("ALL")) {
        token = aTok.nextToken();
    } else if (token.equals("EQUIPPED")) {
        // remove all weapons which are not equipped from list
        for (Iterator<Equipment> it = weaponList.iterator(); it.hasNext(); ) {
            if (!it.next().isEquipped()) {
                it.remove();
            }
        }
        token = aTok.nextToken();
    } else if (token.equals("NOT_EQUIPPED")) {
        // remove all weapons which are equipped from list
        for (Iterator<Equipment> it = weaponList.iterator(); it.hasNext(); ) {
            if (it.next().isEquipped()) {
                it.remove();
            }
        }
        token = aTok.nextToken();
    } else if (token.equals("CARRIED")) {
        // remove all weapons which are not carried from list
        for (Iterator<Equipment> it = weaponList.iterator(); it.hasNext(); ) {
            if (it.next().numberCarried().intValue() == 0) {
                it.remove();
            }
        }
        token = aTok.nextToken();
    } else if (token.equals("NOT_CARRIED")) {
        // remove all weapons which are carried from list
        for (Iterator<Equipment> it = weaponList.iterator(); it.hasNext(); ) {
            if (it.next().numberCarried().intValue() > 0) {
                it.remove();
            }
        }
        token = aTok.nextToken();
    }
    weapon = getIntToken(token, 0);
    if (weapon < weaponList.size()) {
        eq = weaponList.get(weapon);
        if (weapon == weaponList.size() - 1 && eh != null && eh.getExistsOnly()) {
            eh.setNoMoreItems(true);
        }
        return getWeaponToken(pc, eq, aTok, tokenSource);
    } else if (eh != null && eh.getExistsOnly()) {
        eh.setNoMoreItems(true);
        if (eh.getCheckBefore()) {
            eh.setCanWrite(false);
        }
    }
    return "";
}
Also used : StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment) Iterator(java.util.Iterator)

Example 30 with Equipment

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

the class WeaponToken method getAmmunitionCountToken.

/**
	 * Get ammunition count sub token
	 * @param pc
	 * @param eq
	 * @return ammunition count sub token
	 */
public static int getAmmunitionCountToken(PlayerCharacter pc, Equipment eq) {
    int ammoCount = 0;
    String containerCapacity = eq.getContainerCapacityString().toUpperCase();
    for (Equipment equip : pc.getEquipmentListInOutputOrder()) {
        for (String type : equip.typeList()) {
            if (containerCapacity.indexOf(type) >= 0) {
                ++ammoCount;
                break;
            }
        }
    }
    return ammoCount;
}
Also used : Equipment(pcgen.core.Equipment)

Aggregations

Equipment (pcgen.core.Equipment)166 PlayerCharacter (pcgen.core.PlayerCharacter)41 ArrayList (java.util.ArrayList)28 StringTokenizer (java.util.StringTokenizer)25 EquipSet (pcgen.core.character.EquipSet)22 CDOMObject (pcgen.cdom.base.CDOMObject)20 LoadContext (pcgen.rules.context.LoadContext)15 SizeAdjustment (pcgen.core.SizeAdjustment)11 EquipmentHead (pcgen.cdom.inst.EquipmentHead)10 WeaponProf (pcgen.core.WeaponProf)10 CharID (pcgen.cdom.enumeration.CharID)9 WieldCategory (pcgen.core.character.WieldCategory)9 CDOMReference (pcgen.cdom.base.CDOMReference)8 ArmorProf (pcgen.core.ArmorProf)8 EquipmentModifier (pcgen.core.EquipmentModifier)8 Race (pcgen.core.Race)8 ShieldProf (pcgen.core.ShieldProf)8 BonusObj (pcgen.core.bonus.BonusObj)8 Test (org.junit.Test)7 ScopeInstance (pcgen.base.formula.base.ScopeInstance)7