Search in sources :

Example 1 with WeightedCollection

use of pcgen.base.util.WeightedCollection in project pcgen by PCGen.

the class NPCGenerator method selectDomainSpell.

private void selectDomainSpell(final PlayerCharacter aPC, final PCClass aClass, final int aLevel) {
    if (!aPC.hasDomains()) {
        return;
    }
    final WeightedCollection<Domain> domains = new WeightedCollection<>();
    for (Domain d : aPC.getDomainSet()) {
        // and is a valid domain, add them
        if (aClass.equals(aPC.getDomainSource(d).getPcclass())) {
            domains.add(d);
        }
    }
    final Domain domain = domains.getRandomValue();
    final WeightedCollection<Spell> domainSpells = new WeightedCollection<>(aPC.getSpellsIn(domain.get(ObjectKey.DOMAIN_SPELLLIST), aLevel));
    //$NON-NLS-1$
    selectSpell(aPC, aClass, domain, "Prepared Spells", domainSpells, aLevel);
}
Also used : WeightedCollection(pcgen.base.util.WeightedCollection) Domain(pcgen.core.Domain) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 2 with WeightedCollection

use of pcgen.base.util.WeightedCollection in project pcgen by PCGen.

the class NPCGenerator method getStatWeights.

private List<PCStat> getStatWeights(PlayerCharacter pc, final PCClass aClass) {
    final WeightedCollection<PCStat> stats = new WeightedCollection<>(theConfiguration.getStatWeights(aClass.getKeyName()));
    final List<PCStat> ret = new ArrayList<>();
    for (int i = 0; i < pc.getDisplay().getStatCount(); i++) {
        final PCStat stat = stats.getRandomValue();
        ret.add(stat);
        stats.remove(stat);
    }
    return ret;
}
Also used : WeightedCollection(pcgen.base.util.WeightedCollection) ArrayList(java.util.ArrayList) PCStat(pcgen.core.PCStat)

Example 3 with WeightedCollection

use of pcgen.base.util.WeightedCollection in project pcgen by PCGen.

the class StartfeatsToken method unparse.

@Override
public String[] unparse(LoadContext context, Race race) {
    Changes<BonusObj> changes = context.getObjectContext().getListChanges(race, ListKey.BONUS);
    if (changes == null || changes.isEmpty()) {
        // Empty indicates no token present
        return null;
    }
    // CONSIDER need to deal with removed...
    Collection<BonusObj> added = changes.getAdded();
    String tokenName = getTokenName();
    Collection<String> bonusSet = new WeightedCollection<>(String.CASE_INSENSITIVE_ORDER);
    for (BonusObj bonus : added) {
        if (tokenName.equals(bonus.getTokenSource())) {
            bonusSet.add(bonus.getValue());
        }
    }
    if (bonusSet.isEmpty()) {
        // This is okay - just no BONUSes from this token
        return null;
    }
    return bonusSet.toArray(new String[bonusSet.size()]);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) WeightedCollection(pcgen.base.util.WeightedCollection)

Example 4 with WeightedCollection

use of pcgen.base.util.WeightedCollection in project pcgen by PCGen.

the class MovecloneLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<Movement> changes = context.getObjectContext().getListChanges(obj, ListKey.MOVEMENT);
    Collection<Movement> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    WeightedCollection<String> set = new WeightedCollection<>(String.CASE_INSENSITIVE_ORDER);
    for (Movement m : added) {
        if (m.getMoveRatesFlag() == 2) {
            StringBuilder sb = new StringBuilder();
            m.addTokenContents(sb);
            set.add(sb.toString());
        }
    }
    if (set.isEmpty()) {
        return null;
    }
    return set.toArray(new String[set.size()]);
}
Also used : Movement(pcgen.core.Movement) WeightedCollection(pcgen.base.util.WeightedCollection)

Example 5 with WeightedCollection

use of pcgen.base.util.WeightedCollection in project pcgen by PCGen.

the class EquipToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    List<String> list = new ArrayList<>();
    PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
    Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Changes<QualifiedObject<CDOMReference<Equipment>>> changes = context.getObjectContext().getListChanges(obj, ListKey.EQUIPMENT);
    Collection<QualifiedObject<CDOMReference<Equipment>>> added = changes.getAdded();
    HashMapToList<List<Prerequisite>, CDOMReference<Equipment>> m = new HashMapToList<>();
    if (added != null) {
        for (QualifiedObject<CDOMReference<Equipment>> qo : added) {
            m.addToListFor(qo.getPrerequisiteList(), qo.getRawObject());
        }
    }
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    if (listAdded != null && !listAdded.isEmpty()) {
        for (ChooseSelectionActor<?> cra : listAdded) {
            if (cra.getSource().equals(getTokenName())) {
                try {
                    list.add(cra.getLstFormat());
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
            }
        }
    }
    for (List<Prerequisite> prereqs : m.getKeySet()) {
        List<CDOMReference<Equipment>> eq = m.getListFor(prereqs);
        WeightedCollection<CDOMReference<Equipment>> refs = new WeightedCollection<>(ReferenceUtilities.REFERENCE_SORTER);
        refs.addAll(eq);
        String ab = ReferenceUtilities.joinLstFormat(refs, Constants.PIPE);
        if (prereqs != null && !prereqs.isEmpty()) {
            if (prereqs.size() > 1) {
                context.addWriteMessage("Error: " + obj.getClass().getSimpleName() + " had more than one Prerequisite for " + getFullName());
                return null;
            }
            Prerequisite p = prereqs.get(0);
            StringWriter swriter = new StringWriter();
            try {
                prereqWriter.write(swriter, p);
            } catch (PersistenceLayerException e) {
                context.addWriteMessage("Error writing Prerequisite: " + e);
                return null;
            }
            ab = ab + '|' + swriter.toString();
        }
        list.add(ab);
    }
    if (list.isEmpty()) {
        // Empty indicates no Token
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : PrerequisiteWriter(pcgen.persistence.lst.output.prereq.PrerequisiteWriter) ArrayList(java.util.ArrayList) ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) HashMapToList(pcgen.base.util.HashMapToList) Equipment(pcgen.core.Equipment) StringWriter(java.io.StringWriter) QualifiedObject(pcgen.core.QualifiedObject) WeightedCollection(pcgen.base.util.WeightedCollection) ArrayList(java.util.ArrayList) HashMapToList(pcgen.base.util.HashMapToList) List(java.util.List) CDOMReference(pcgen.cdom.base.CDOMReference) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

WeightedCollection (pcgen.base.util.WeightedCollection)7 ArrayList (java.util.ArrayList)2 CharacterSpell (pcgen.core.character.CharacterSpell)2 Spell (pcgen.core.spell.Spell)2 StringWriter (java.io.StringWriter)1 List (java.util.List)1 HashMapToList (pcgen.base.util.HashMapToList)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)1 Gender (pcgen.cdom.enumeration.Gender)1 Ability (pcgen.core.Ability)1 Deity (pcgen.core.Deity)1 Domain (pcgen.core.Domain)1 Equipment (pcgen.core.Equipment)1 Movement (pcgen.core.Movement)1 PCAlignment (pcgen.core.PCAlignment)1 PCClass (pcgen.core.PCClass)1 PCStat (pcgen.core.PCStat)1 QualifiedObject (pcgen.core.QualifiedObject)1 Race (pcgen.core.Race)1