use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class CharacterFacadeImpl method buildAppliedTempBonusList.
/**
* Build up the list of temporary bonuses which have been applied to this character.
*/
private void buildAppliedTempBonusList() {
Set<String> found = new HashSet<>();
for (TempBonusInfo tbi : theCharacter.getTempBonusMap().values()) {
Object aC = tbi.source;
Object aT = tbi.target;
String name = BonusDisplay.getBonusDisplayName(tbi);
if (!found.contains(name)) {
found.add(name);
TempBonusFacadeImpl facade = new TempBonusFacadeImpl((CDOMObject) aC, aT, name);
facade.setActive(!theCharacter.getTempBonusFilters().contains(name));
appliedTempBonuses.addElement(facade);
}
}
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class CompanionSupportFacadeImpl method initCompData.
/**
* Initialisation of the character's companion data.
* @param rebuildCompanionList Should the list of the character;s companions be rebuilt?
*/
private void initCompData(boolean rebuildCompanionList) {
List<CompanionStub> companions = new ArrayList<>();
for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
keyToCompanionListMap.put(compList.getKeyName(), compList);
Map<FollowerOption, CDOMObject> fMap = charDisplay.getAvailableFollowers(compList.getKeyName(), null);
for (FollowerOption followerOpt : fMap.keySet()) {
if (followerOpt.getRace() != Globals.s_EMPTYRACE && followerOpt.qualifies(theCharacter, null)) {
companions.add(new CompanionStub(followerOpt.getRace(), compList.getKeyName()));
}
}
int maxVal = theCharacter.getMaxFollowers(compList);
if (maxVal == 0) {
maxCompanionsMap.removeKey(compList.toString());
} else {
maxCompanionsMap.putValue(compList.toString(), maxVal);
}
}
availCompList.updateContents(companions);
if (rebuildCompanionList) {
for (Follower follower : charDisplay.getFollowerList()) {
CompanionFacade comp = new CompanionNotLoaded(follower.getName(), new File(follower.getFileName()), follower.getRace(), follower.getType().toString());
CompanionFacadeDelegate delegate = new CompanionFacadeDelegate();
delegate.setCompanionFacade(comp);
companionList.addElement(delegate);
}
}
//Logging.debugPrint("Companion list " + companionList);
for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
updateCompanionTodo(compList.toString());
}
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class VariableFacet method dataAdded.
/**
* Adds variables and their Formulas when a variable is granted by a
* CDOMObject which is added to a Player Character.
*
* Triggered when one of the Facets to which VariableFacet listens fires a
* DataFacetChangeEvent to indicate a CDOMObject was added to a Player
* Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
Set<VariableKey> keys = cdo.getVariableKeys();
CharID id = dfce.getCharID();
for (VariableKey vk : keys) {
add(id, vk, cdo.get(vk), cdo);
}
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class VisionFacet method getActiveVision.
/**
* Returns a non-null copy of the Collection of Vision objects which are
* active on the Player Character identified by the given CharID.
*
* This method is value-semantic in that ownership of the returned
* Collection is transferred to the class calling this method. Modification
* of the returned Collection will not modify this VisionFacet and
* modification of this VisionFacet will not modify the returned Collection.
* Modifications to the returned Collection will also not modify any future
* or previous objects returned by this (or other) methods on VisionFacet.
* If you wish to modify the information stored in this VisionFacet, you
* must use the add*() and remove*() methods of VisionFacet.
*
* @param id
* The CharID identifying the Player Character for which the
* active Vision objects is to be returned
* @return a non-null copy of the Collection of Vision objects which are
* active on the Player Character identified by the given CharID
*/
public Collection<Vision> getActiveVision(CharID id) {
Map<QualifiedObject<Vision>, Set<Object>> componentMap = getCachedMap(id);
if (componentMap == null) {
return Collections.emptyList();
}
Map<VisionType, Integer> map = new HashMap<>();
for (Map.Entry<QualifiedObject<Vision>, Set<Object>> me : componentMap.entrySet()) {
QualifiedObject<Vision> qo = me.getKey();
for (Object source : me.getValue()) {
if (prerequisiteFacet.qualifies(id, qo, source)) {
String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
Vision v = qo.getRawObject();
Formula distance = v.getDistance();
int a = formulaResolvingFacet.resolve(id, distance, sourceString).intValue();
VisionType visType = v.getType();
Integer current = map.get(visType);
if (current == null || current < a) {
map.put(visType, a);
}
}
}
}
/*
* parse through the global list of vision tags and see if this PC has
* any BONUS:VISION tags which will create a new visionMap entry, and
* add any BONUS to existing entries in the map
*/
for (VisionType vType : VisionType.getAllVisionTypes()) {
int aVal = (int) bonusCheckingFacet.getBonus(id, "VISION", vType.toString());
if (aVal > 0) {
Integer current = map.get(vType);
map.put(vType, aVal + (current == null ? 0 : current));
}
}
TreeSet<Vision> returnSet = new TreeSet<>();
for (Map.Entry<VisionType, Integer> me : map.entrySet()) {
returnSet.add(new Vision(me.getKey(), FormulaFactory.getFormulaFor(me.getValue())));
}
return returnSet;
}
use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.
the class AbstractReferenceManufacturer method validateDuplicates.
private boolean validateDuplicates() {
boolean returnGood = true;
for (CaseInsensitiveString second : duplicates.getKeySet()) {
List<T> list = duplicates.getListFor(second);
T good = active.get(second.toString());
/*
* CONSIDER Should get CDOMObject reference out of here :(
*/
if (good instanceof CDOMObject) {
CDOMObject cdo = (CDOMObject) good;
for (int i = 0; i < list.size(); i++) {
T dupe = list.get(i);
if (cdo.isCDOMEqual((CDOMObject) dupe)) {
for (Iterator<WeakReference<T>> it = manufactured.iterator(); it.hasNext(); ) {
WeakReference<T> wr = it.next();
T mfg = wr.get();
if (mfg == null) {
it.remove();
} else // Yes this is instance equality, not .equals
if (mfg == good) {
forgetObject(good);
break;
}
}
}
}
}
if (duplicates.containsListFor(second)) {
Logging.errorPrint("More than one " + factory.getReferenceDescription() + " with key/name " + good.getKeyName() + " was built");
List<T> dupes = duplicates.getListFor(second);
StringBuilder sb = new StringBuilder(1000);
sb.append("Sources: ");
sb.append(good.isInternal() ? "<internal>" : good.getSourceURI());
for (T dupe : dupes) {
sb.append(", ").append(dupe.isInternal() ? "<internal>" : dupe.getSourceURI());
if (!dupe.getKeyName().equals(good.getKeyName())) {
Logging.errorPrint("Key case differed for " + dupe.getKeyName());
}
}
Logging.errorPrint(sb.toString());
returnGood = false;
}
}
return returnGood;
}
Aggregations