use of pcgen.core.kit.BaseKit in project pcgen by PCGen.
the class Gui2InfoFactory method getHTMLInfo.
@Override
public String getHTMLInfo(KitFacade kitFacade) {
if (kitFacade == null) {
return EMPTY_STRING;
}
Kit kit = (Kit) kitFacade;
final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
infoText.appendTitleElement(OutputNameFormatting.piString(kit, false));
appendFacts(infoText, kit);
String aString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, kit.getPrerequisiteList(), false);
if (!aString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_requirements", aString);
}
List<BaseKit> sortedObjects = new ArrayList<>();
sortedObjects.addAll(kit.getSafeListFor(ListKey.KIT_TASKS));
sortedObjects.sort(new ObjectTypeComparator());
String lastObjectName = EMPTY_STRING;
for (BaseKit bk : sortedObjects) {
String objName = bk.getObjectName();
if (!objName.equals(lastObjectName)) {
if (!EMPTY_STRING.equals(lastObjectName)) {
infoText.append("; ");
} else {
infoText.appendLineBreak();
}
infoText.append(" <b>" + objName + "</b>: ");
lastObjectName = objName;
} else {
infoText.append(", ");
}
infoText.append(bk.toString());
}
BigDecimal totalCost = kit.getTotalCost(pc);
if (totalCost != null) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nFormattedElement(//$NON-NLS-1$
"in_kitInfo_TotalCost", COST_FMT.format(totalCost), SettingsHandler.getGame().getCurrencyDisplay());
}
String desc = pc.getDescription(kit);
if (!desc.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nFormattedElement(//$NON-NLS-1$
"in_InfoDescription", DescriptionFormatting.piWrapDesc(kit, desc, false));
}
aString = kit.getSource();
if (!aString.isEmpty()) {
infoText.appendLineBreak();
//$NON-NLS-1$
infoText.appendI18nElement("in_sourceLabel", aString);
}
//TODO ListKey.KIT_TASKS
return infoText.toString();
}
use of pcgen.core.kit.BaseKit in project pcgen by PCGen.
the class Kit method processKit.
/**
* The method that actually adds the various items in this Kit to the PC.
* Takes account of Kit Number
*
* @param pc The Player Character object that we will be applying
* the kit to.
* @param thingsToAdd The list of things that will be added by this kit
* wrapped in KitWrapper objects
* @param kitNo An integer that will be used to set the kit number
* in items of equipment added by this kit
*/
public void processKit(final PlayerCharacter pc, final List<BaseKit> thingsToAdd, final int kitNo) {
BigDecimal totalCostToBeCharged = getTotalCostToBeCharged(pc);
if (totalCostToBeCharged != null) {
pc.setGold(pc.getGold().subtract(totalCostToBeCharged));
}
for (KitStat kStat : getStats()) {
kStat.apply(pc);
}
for (BaseKit bk : thingsToAdd) {
bk.apply(pc);
}
pc.setCalcEquipmentList();
if (getSafe(ObjectKey.APPLY_MODE) == KitApply.PERMANENT) {
pc.addKit(this);
}
}
use of pcgen.core.kit.BaseKit in project pcgen by PCGen.
the class Kit method getInfo.
/**
* Get the Kit info for this PC
* @param aPC the PC this kit is being applied to.
* @return the Kit info for this PC
*/
public String getInfo(PlayerCharacter aPC) {
StringBuilder info = new StringBuilder(255);
info.append("<html>");
info.append("<b><font size=+1>");
info.append(OutputNameFormatting.piString(this, false));
info.append("</font></b><br>\n");
String aString = getPreReqHTMLStrings(aPC);
if (!aString.isEmpty()) {
info.append(" <b>Requirements</b>: ").append(aString);
}
List<BaseKit> sortedObjects = new ArrayList<>();
sortedObjects.addAll(getSafeListFor(ListKey.KIT_TASKS));
sortedObjects.sort(new ObjectTypeComparator());
String lastObjectName = "";
for (BaseKit bk : sortedObjects) {
String objName = bk.getObjectName();
if (!objName.equals(lastObjectName)) {
if (!"".equals(lastObjectName)) {
info.append("; ");
}
info.append(" <b>" + objName + "</b>: ");
lastObjectName = objName;
} else {
info.append(", ");
}
info.append(bk.toString());
}
info.append(" <b>Source</b>: ").append(SourceFormat.getFormattedString(this, Globals.getSourceDisplay(), true));
info.append("</html>");
//TODO ListKey.KIT_TASKS
return info.toString();
}
use of pcgen.core.kit.BaseKit in project pcgen by PCGen.
the class Kit method testApplyKit.
/**
* Test applying the kit and record the choices made and any warnings
* encountered. Note these changes are made on a copy of the character.
*
* @param aPC PlayerCharacter
* @param thingsToAdd List of kit actions to be taken.
* @param warnings List of issues to be reported to the user.
* @param subkit Is this kit being added by a parent kit?
*/
public void testApplyKit(PlayerCharacter aPC, List<BaseKit> thingsToAdd, List<String> warnings, boolean subkit) {
// Ensure a reset of random values from a prior run
selectValue = -1;
// We will create a copy of the PC since we may need to add classes and
// levels to the PC that the user may choose not to apply.
// NOTE: These methods need to be called in the correct order.
PlayerCharacter tempPC = subkit ? aPC : aPC.clone();
for (KitStat kStat : getStats()) {
kStat.testApply(this, tempPC, warnings);
}
for (BaseKit bk : getSafeListFor(ListKey.KIT_TASKS)) {
if (!PrereqHandler.passesAll(bk.getPrerequisiteList(), tempPC, this)) {
continue;
}
if (selectValue != -1 && bk.isOptional() && !bk.isOption(tempPC, selectValue)) {
continue;
}
if (bk.testApply(this, tempPC, warnings)) {
thingsToAdd.add(bk);
}
}
BigDecimal totalCostToBeCharged = getTotalCostToBeCharged(tempPC);
if (totalCostToBeCharged != null) {
BigDecimal pcGold = tempPC.getGold();
if (pcGold.compareTo(BigDecimal.ZERO) >= 0 && pcGold.compareTo(totalCostToBeCharged) < 0) {
warnings.add("Could not purchase kit. Not enough funds.");
} else {
tempPC.setGold(pcGold.subtract(totalCostToBeCharged));
}
}
}
use of pcgen.core.kit.BaseKit in project pcgen by PCGen.
the class CharacterFacadeImpl method addKit.
@Override
public void addKit(KitFacade obj) {
if (obj == null || !(obj instanceof Kit)) {
return;
}
Kit kit = (Kit) obj;
if (!theCharacter.isQualified(kit)) {
return;
}
Logging.log(Logging.INFO, charDisplay.getName() + ": Testing kit " + //$NON-NLS-1$
kit);
List<BaseKit> thingsToAdd = new ArrayList<>();
List<String> warnings = new ArrayList<>();
kit.testApplyKit(theCharacter, thingsToAdd, warnings);
if (!showKitWarnings(kit, warnings)) {
return;
}
// The user is applying the kit so use the real PC now.
Logging.log(Logging.INFO, charDisplay.getName() + ": Adding kit " + //$NON-NLS-1$
kit);
kit.processKit(theCharacter, thingsToAdd);
kitList.addElement(obj);
// Kits can upate most things so do a thorough refresh
race.set(charDisplay.getRace());
refreshRaceRelatedFields();
name.set(charDisplay.getName());
characterType.set(charDisplay.getCharacterType());
// Deity and domains
deity.set(charDisplay.getDeity());
buildAvailableDomainsList();
refreshStatScores();
}
Aggregations