use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class EquipmentSetFacadeImpl method sortEquipment.
@Override
public boolean sortEquipment(EquipNode parentNode) {
// Confirm our assumptions
if (!(parentNode instanceof EquipNodeImpl) || !(parentNode.getBodyStructure() instanceof BodyStructure) || ((parentNode.getNodeType() != NodeType.EQUIPMENT) && (parentNode.getNodeType() != NodeType.BODY_SLOT))) {
return false;
}
BodyStructure bodyStruct = (BodyStructure) parentNode.getBodyStructure();
if (!bodyStruct.isHoldsAnyType()) {
return false;
}
String pid = ((EquipNodeImpl) parentNode).idPath;
boolean isBodyStructure = parentNode.getBodyStructure() instanceof BodyStructure;
List<EquipNodeImpl> childList = new ArrayList<>();
Map<String, EquipNodeImpl> origPathToNode = buildPathNodeMap();
Map<String, EquipSet> origPathToEquipSet = buildPathEquipSetMap();
for (Map.Entry<String, EquipNodeImpl> entry : origPathToNode.entrySet()) {
final String origPath = entry.getKey();
final EquipNodeImpl node = entry.getValue();
EquipSet es = origPathToEquipSet.get(origPath);
if (node.parent == parentNode) {
childList.add(node);
if (pid == null) {
pid = es.getParentIdPath();
}
}
}
// Sort child list
childList.sort(new EquipNameComparator());
// Renumber paths
// need to start from a unique id if only sorting some nodes at a level
int id = isBodyStructure ? theCharacter.getNewChildId(pid) : 1;
NumberFormat format = new DecimalFormat("00");
for (EquipNodeImpl childNode : childList) {
String origPath = childNode.idPath;
String newPath = pid + '.' + format.format(id);
nodeList.removeElement(childNode);
EquipSet es = origPathToEquipSet.get(origPath);
es.setIdPath(newPath);
updateContainerPath(origPath, newPath, origPathToNode, origPathToEquipSet);
childNode.setIdPath(newPath);
nodeList.addElement(childNode);
id++;
}
return true;
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class CharacterFacadeImpl method initEquipSet.
/**
* Initialise the equipment set facades, ensuring that the character has a
* default equipment set.
*/
private void initEquipSet() {
// Setup the default EquipSet if not already present
if (!charDisplay.hasEquipSet()) {
String id = EquipmentSetFacadeImpl.getNewIdPath(charDisplay, null);
EquipSet eSet = new EquipSet(id, LanguageBundle.getString("in_ieDefault"));
theCharacter.addEquipSet(eSet);
theCharacter.setCalcEquipSetId(id);
}
// Detach listeners from old set
if (equipSet.get() != null) {
EquipmentListFacade equippedItems = equipSet.get().getEquippedItems();
equippedItems.removeListListener(this);
equippedItems.removeEquipmentListListener(this);
}
// Make facades for each root equipset.
List<EquipmentSetFacade> eqSetList = new ArrayList<>();
EquipmentSetFacade currSet = null;
String currIdPath = theCharacter.getCalcEquipSetId();
for (EquipSet es : charDisplay.getEquipSet()) {
if (es.getParentIdPath().equals("0")) {
final EquipmentSetFacadeImpl facade = new EquipmentSetFacadeImpl(delegate, theCharacter, es, dataSet, purchasedEquip, todoManager, this);
eqSetList.add(facade);
if (es.getIdPath().equals(currIdPath)) {
currSet = facade;
}
}
}
equipmentSets.updateContents(eqSetList);
if (currSet != null) {
equipSet.set(currSet);
}
EquipmentSetFacade set = equipSet.get();
set.getEquippedItems().addListListener(this);
set.getEquippedItems().addEquipmentListListener(this);
refreshTotalWeight();
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class EquipSetLoopDirective method execute.
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
if (body == null) {
throw new TemplateModelException("This directive must have content.");
}
List<EquipSet> eqSetList = new ArrayList<>();
EquipSet currSet = null;
String currIdPath = pc.getCalcEquipSetId();
for (EquipSet es : pc.getDisplay().getEquipSet()) {
if (es.getParentIdPath().equals("0")) {
eqSetList.add(es);
if (es.getIdPath().equals(currIdPath)) {
currSet = es;
}
}
}
for (EquipSet equipSet : eqSetList) {
pc.setCalcEquipSetId(equipSet.getIdPath());
pc.setCalcEquipmentList(equipSet.getUseTempMods());
// Executes the nested body (same as <#nested> in FTL). In this
// case we don't provide a special writer as the parameter:
body.render(env.getOut());
}
if (currSet != null) {
pc.setCalcEquipSetId(currSet.getIdPath());
pc.setCalcEquipmentList(currSet.getUseTempMods());
}
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class EquipSetMigration method renumberEquipmentSets.
/**
* Renumber the equipment sets so that they are sortable in current output
* order. For each equipment set, change the format of the idpaths from
* 0.1.1.1 to 0.1.01.01 and renumber items in a container in accordance with
* their output order
* @param pc The character to have equipment sets renumbered.
*/
static void renumberEquipmentSets(PlayerCharacter pc) {
Collection<EquipSet> allEquipSets = pc.getDisplay().getEquipSet();
List<EquipSet> sortedChildrenEs = getSortedChildren(allEquipSets, "0");
for (EquipSet equipSet : sortedChildrenEs) {
List<EquipSet> children = getSortedChildren(allEquipSets, equipSet.getIdPath());
renumberChildren(children, allEquipSets, equipSet.getIdPath());
}
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class ACTokenTest method testNonMagic.
/**
* Test the character's AC calcs with armor with no equip mods applied.
* @throws Exception
*/
public void testNonMagic() throws Exception {
PlayerCharacter character = getCharacter();
EquipSet es = new EquipSet("0.1.2", "Chain Shirt", chainShirt.getName(), chainShirt);
character.addEquipSet(es);
character.setCalcEquipmentList();
character.calcActiveBonuses();
assertEquals("Ability AC normal armor", "2", new ACToken().getToken("AC.Ability", getCharacter(), null));
assertEquals("Armor AC with normal armor", "4", new ACToken().getToken("AC.Armor", getCharacter(), null));
assertEquals("Total AC with normal armor", "16", new ACToken().getToken("AC.Total", getCharacter(), null));
}
Aggregations