Search in sources :

Example 16 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class KitAbilities method testApply.

@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
    abilitiesToAdd = new ArrayList<>();
    double minCost = Double.MAX_VALUE;
    List<AbilitySelection> available = new ArrayList<>();
    for (CDOMReference<Ability> ref : abilities) {
        String choice = ref.getChoice();
        for (Ability a : ref.getContainedObjects()) {
            if (a == null) {
                warnings.add("ABILITY: " + ref + " could not be found.");
                minCost = 0;
                continue;
            }
            if (a.getCost() < minCost) {
                minCost = a.getCost();
            }
            if ((choice == null) && a.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
                available.add(new AbilitySelection(a, ""));
            } else {
                available.add(new AbilitySelection(a, choice));
            }
        }
    }
    int numberOfChoices = getSafeCount();
    // TODO this fails if SELECT != 1
    if (numberOfChoices > available.size()) {
        numberOfChoices = available.size();
    }
    /*
		 * this section needs to be rewritten once we determine how
		 * the new Ability Pools are going to work
		 */
    AbilityCategory category = catRef.get();
    boolean tooManyAbilities = false;
    // Don't allow choosing of more than allotted number of abilities
    int maxChoices = minCost > 0.0d ? aPC.getAvailableAbilityPool(category).divide(new BigDecimal(minCost)).intValue() : numberOfChoices;
    if (!isFree() && numberOfChoices > maxChoices) {
        numberOfChoices = maxChoices;
        tooManyAbilities = true;
    }
    if (!isFree() && numberOfChoices == 0) {
        warnings.add("ABILITY: Not enough " + category.getPluralName() + " available to take \"" + this + "\"");
        return false;
    }
    List<AbilitySelection> selected;
    if (numberOfChoices == available.size()) {
        selected = available;
    } else {
        selected = new ArrayList<>();
        // Force user to make enough selections
        while (true) {
            selected = Globals.getChoiceFromList("Choose abilities", available, new ArrayList<>(), numberOfChoices, aPC);
            if (!selected.isEmpty()) {
                break;
            }
        }
    }
    // Add to list of things to add to the character
    for (AbilitySelection as : selected) {
        Ability ability = as.ability;
        if (isFree()) {
            // Need to pay for it first
            if (free) {
                aPC.adjustAbilities(category, BigDecimal.ONE);
            }
        }
        if (ability.getCost() > aPC.getAvailableAbilityPool(category).doubleValue()) {
            tooManyAbilities = true;
        } else {
            CNAbility cna = CNAbilityFactory.getCNAbility(category, Nature.NORMAL, ability);
            CNAbilitySelection cnas = new CNAbilitySelection(cna, as.selection);
            abilitiesToAdd.add(cnas);
            aPC.addAbility(cnas, UserSelection.getInstance(), this);
        }
    }
    if (tooManyAbilities) {
        warnings.add("ABILITY: Some Abilities were not granted -- not enough remaining feats");
        return false;
    }
    return true;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) AbilityCategory(pcgen.core.AbilityCategory)

Example 17 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class KitAbilities method apply.

@Override
public void apply(PlayerCharacter aPC) {
    for (CNAbilitySelection cnas : abilitiesToAdd) {
        aPC.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
        if (isFree()) {
            AbilityCategory category = catRef.get();
            aPC.adjustAbilities(category, BigDecimal.ONE);
        }
    }
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) AbilityCategory(pcgen.core.AbilityCategory)

Example 18 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbilityTargetSaveRestoreTest method applyObject.

@Override
protected void applyObject(Ability obj) {
    String assoc = null;
    if (ChooseActivation.hasNewChooseToken(obj)) {
        assoc = "Granted";
    }
    CNAbility cna = CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, obj);
    CNAbilitySelection cnas = new CNAbilitySelection(cna, assoc);
    pc.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 19 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbilityUtilities method processSelection.

private static <T> void processSelection(PlayerCharacter pc, CNAbility cna, ChoiceManagerList<T> aMan, boolean toAdd) {
    ArrayList<T> availableList = new ArrayList<>();
    ArrayList<T> selectedList = new ArrayList<>();
    aMan.getChoices(pc, availableList, selectedList);
    if (availableList.isEmpty() && selectedList.isEmpty()) {
        //TODO Log error? (ignored choice?)
        return;
    }
    List<T> origSelections = new ArrayList<>(selectedList);
    List<T> removedSelections = new ArrayList<>(selectedList);
    ArrayList<String> reservedList = new ArrayList<>();
    List<T> newSelections;
    if (toAdd) {
        newSelections = aMan.doChooser(pc, availableList, selectedList, reservedList);
    } else {
        newSelections = aMan.doChooserRemove(pc, availableList, selectedList, reservedList);
    }
    //Need to use only the new ones
    for (T obj : newSelections) {
        removedSelections.remove(obj);
    }
    //removedSelections.removeAll(newSelections);
    for (T obj : origSelections) {
        newSelections.remove(obj);
    }
    for (T sel : newSelections) {
        String selection = aMan.encodeChoice(sel);
        CNAbilitySelection cnas = new CNAbilitySelection(cna, selection);
        pc.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
    }
    for (T sel : removedSelections) {
        String selection = aMan.encodeChoice(sel);
        CNAbilitySelection cnas = new CNAbilitySelection(cna, selection);
        pc.removeAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
    }
}
Also used : ArrayList(java.util.ArrayList) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection)

Example 20 with CNAbilitySelection

use of pcgen.cdom.helper.CNAbilitySelection in project pcgen by PCGen.

the class AbstractCNASEnforcingFacet method add.

public boolean add(CharID id, CNAbilitySelection cnas, Object source) {
    if (cnas == null) {
        throw new IllegalArgumentException("Attempt to add null to list");
    }
    if (source == null) {
        throw new IllegalArgumentException("Attempt to add object with null source to list");
    }
    List<List<SourcedCNAS>> list = getConstructingList(id);
    for (List<SourcedCNAS> slist : list) {
        CNAbilitySelection main = slist.get(0).cnas;
        if (!CNAbilitySelectionUtilities.canCoExist(main, cnas)) {
            slist.add(new SourcedCNAS(cnas, source));
            return false;
        }
    }
    List<SourcedCNAS> newList = new ArrayList<>(1);
    newList.add(new SourcedCNAS(cnas, source));
    list.add(newList);
    fireDataFacetChangeEvent(id, cnas, DataFacetChangeEvent.DATA_ADDED);
    return true;
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)70 CNAbility (pcgen.cdom.content.CNAbility)35 Test (org.junit.Test)28 Ability (pcgen.core.Ability)26 ArrayList (java.util.ArrayList)17 AbilityCategory (pcgen.core.AbilityCategory)7 CDOMReference (pcgen.cdom.base.CDOMReference)6 PlayerCharacter (pcgen.core.PlayerCharacter)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)5 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)5 Nature (pcgen.cdom.enumeration.Nature)5 PCTemplate (pcgen.core.PCTemplate)5 CharID (pcgen.cdom.enumeration.CharID)4 List (java.util.List)3 AbilityChoiceSet (pcgen.cdom.base.ChoiceSet.AbilityChoiceSet)3 SpecialAbility (pcgen.core.SpecialAbility)3 BonusObj (pcgen.core.bonus.BonusObj)3 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)3 HashSet (java.util.HashSet)2