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);
}
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;
}
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()]);
}
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()]);
}
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()]);
}
Aggregations