use of pcgen.base.util.WrappedMapSet in project pcgen by PCGen.
the class BonusManager method buildActiveBonusMap.
/**
* Build the bonus HashMap from all active BonusObj's
*/
void buildActiveBonusMap() {
activeBonusMap = new ConcurrentHashMap<>();
cachedActiveBonusSumsMap = new ConcurrentHashMap<>();
Map<String, String> nonStackMap = new ConcurrentHashMap<>();
Map<String, String> stackMap = new ConcurrentHashMap<>();
Set<BonusObj> processedBonuses = new WrappedMapSet<>(IdentityHashMap.class);
//Logging.log(Logging.INFO, "=== Start bonus processing.");
//
// We do a first pass of just the "static" bonuses
// as they require less computation and no recursion
List<BonusObj> bonusListCopy = new ArrayList<>();
bonusListCopy.addAll(getActiveBonusList());
for (BonusObj bonus : bonusListCopy) {
if (!bonus.isValueStatic()) {
continue;
}
final Object source = getSourceObject(bonus);
if (source == null) {
if (Logging.isDebugMode()) {
Logging.debugPrint("BONUS: " + bonus + " ignored due to no creator");
}
continue;
}
// Keep track of which bonuses have been calculated
//Logging.log(Logging.INFO, "Processing bonus " + bonus + " - static.");
processedBonuses.add(bonus);
for (BonusPair bp : getStringListFromBonus(bonus)) {
final double iBonus = bp.resolve(pc).doubleValue();
setActiveBonusStack(iBonus, bp.fullyQualifiedBonusType, nonStackMap, stackMap);
totalBonusesForType(nonStackMap, stackMap, bp.fullyQualifiedBonusType, activeBonusMap);
if (Logging.isDebugMode()) {
String id;
if (source instanceof CDOMObject) {
id = ((CDOMObject) source).getDisplayName();
} else {
id = source.toString();
}
Logging.debugPrint("BONUS: " + id + " : " + iBonus + " : " + bp.fullyQualifiedBonusType);
}
}
}
//
// Now we do all the BonusObj's that require calculations
bonusListCopy = new ArrayList<>();
bonusListCopy.addAll(getActiveBonusList());
for (BonusObj bonus : getActiveBonusList()) {
if (processedBonuses.contains(bonus)) {
continue;
}
final CDOMObject anObj = (CDOMObject) getSourceObject(bonus);
if (anObj == null) {
continue;
}
try {
processBonus(bonus, new WrappedMapSet<>(IdentityHashMap.class), processedBonuses, nonStackMap, stackMap);
} catch (Exception e) {
Logging.errorPrint(e.getLocalizedMessage(), e);
continue;
}
}
}
use of pcgen.base.util.WrappedMapSet in project pcgen by PCGen.
the class PreDeityTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
int runningTotal;
if (//$NON-NLS-1$
prereq.getKey().startsWith("PANTHEON.")) {
try {
String pantheon = prereq.getKey().substring(9);
Deity deity = display.getDeity();
Set<String> charDeityPantheon = new WrappedMapSet<>(CaseInsensitiveMap.class);
if (deity != null) {
FactSetKey<String> fk = FactSetKey.valueOf("Pantheon");
for (Indirect<String> indirect : deity.getSafeSetFor(fk)) {
charDeityPantheon.add(indirect.get());
}
}
if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
runningTotal = (charDeityPantheon.contains(pantheon)) ? 1 : 0;
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
runningTotal = (charDeityPantheon.contains(pantheon)) ? 0 : 1;
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
prereq.toString()));
}
} catch (IllegalArgumentException e) {
//This is okay, just indicates the Pantheon asked for can't exist in any PC
if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
runningTotal = 0;
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
runningTotal = 1;
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
prereq.toString()));
}
}
} else {
final String charDeity = display.getDeity() != null ? display.getDeity().getKeyName() : //$NON-NLS-1$
"";
if (prereq.getOperator().equals(PrerequisiteOperator.EQ) || prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) {
runningTotal = (charDeity.equalsIgnoreCase(prereq.getKey())) ? 1 : 0;
} else if (prereq.getOperator().equals(PrerequisiteOperator.NEQ) || prereq.getOperator().equals(PrerequisiteOperator.LT)) {
runningTotal = (charDeity.equalsIgnoreCase(prereq.getKey())) ? 0 : 1;
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreDeity.error.bad_coparator", //$NON-NLS-1$
prereq.toString()));
}
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.base.util.WrappedMapSet in project pcgen by PCGen.
the class AbilityCategory method populate.
@Override
public boolean populate(ReferenceManufacturer<Ability> parentCrm, ReferenceManufacturer<Ability> rm, UnconstructedValidator validator) {
if (parentCrm == null) {
return true;
}
Collection<Ability> allObjects = parentCrm.getAllObjects();
// Don't add things twice or we'll get dupe messages :)
Set<Ability> added = new WrappedMapSet<>(IdentityHashMap.class);
/*
* Pull in all the base objects... note this skips containsDirectly
* because items haven't been resolved
*/
for (final Ability ability : allObjects) {
boolean use = isAllAbilityTypes;
if (!use && (types != null)) {
for (Type type : types) {
if (ability.isType(type.toString())) {
use = true;
break;
}
}
}
if (use) {
added.add(ability);
rm.addObject(ability, ability.getKeyName());
}
}
boolean returnGood = true;
if (containedAbilities != null) {
for (CDOMSingleRef<Ability> ref : containedAbilities) {
boolean res = doResolve(parentCrm, ref.getLSTformat(false), ref, validator);
if (res) {
Ability ability = ref.get();
if (added.add(ability)) {
rm.addObject(ability, ability.getKeyName());
}
}
returnGood &= res;
}
}
return returnGood;
}
use of pcgen.base.util.WrappedMapSet in project pcgen by PCGen.
the class FollowerLimitFacet method add.
private void add(CharID id, FollowerLimit fo, CDOMObject cdo) {
if (fo == null) {
throw new IllegalArgumentException("Object to add may not be null");
}
CompanionList cl = fo.getCompanionList().get();
Map<FollowerLimit, Set<CDOMObject>> foMap = getConstructingCachedMap(id, cl);
Set<CDOMObject> set = foMap.get(fo);
if (set == null) {
set = new WrappedMapSet<>(IdentityHashMap.class);
foMap.put(fo, set);
}
set.add(cdo);
}
use of pcgen.base.util.WrappedMapSet in project pcgen by PCGen.
the class PrerequisiteUtilities method buildAbilityList.
/**
* Build up a list of the character's abilities which match the category requirements.
*
* @param character The character to be tested.
* @param categoryName The name of the required category, null if any category will be matched.
* @return A list of categories matching.
*/
private static Set<Ability> buildAbilityList(final PlayerCharacter character, String categoryName) {
final Set<Ability> abilityList = new WrappedMapSet<>(IdentityHashMap.class);
if (character != null) {
AbilityCategory cat = SettingsHandler.getGame().getAbilityCategory(categoryName);
if (cat == null) {
Logging.errorPrint("Invalid category " + categoryName + " in PREABILITY");
return abilityList;
}
if (!cat.getParentCategory().equals(cat)) {
Logging.errorPrint("Invalid use of child category in PREABILITY");
}
for (CNAbility cna : character.getCNAbilities(cat)) {
abilityList.add(cna.getAbility());
}
Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
// Now scan for relevant SERVESAS occurrences
for (AbilityCategory aCat : allCats) {
for (CNAbility cna : character.getPoolAbilities(aCat)) {
for (CDOMReference<Ability> ref : cna.getAbility().getSafeListFor(ListKey.SERVES_AS_ABILITY)) {
for (Ability ab : ref.getContainedObjects()) {
abilityList.add(ab);
}
}
}
}
}
return abilityList;
}
Aggregations