Search in sources :

Example 1 with SpecialProperty

use of pcgen.core.SpecialProperty in project pcgen by PCGen.

the class NaturalattacksLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<Equipment> changes = context.getObjectContext().getListChanges(obj, ListKey.NATURAL_WEAPON);
    Collection<Equipment> eqadded = changes.getAdded();
    if (eqadded == null || eqadded.isEmpty()) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Equipment lstw : eqadded) {
        if (!first) {
            sb.append(Constants.PIPE);
        }
        Equipment eq = Equipment.class.cast(lstw);
        String name = eq.getDisplayName();
        // TODO objcontext.getString(eq, StringKey.NAME);
        if (name == null) {
            context.addWriteMessage(getTokenName() + " expected Equipment to have a name");
            return null;
        }
        sb.append(name).append(Constants.COMMA);
        List<Type> type = eq.getListFor(ListKey.TYPE);
        if (type == null || type.isEmpty()) {
            context.addWriteMessage(getTokenName() + " expected Equipment to have a type");
            return null;
        }
        sb.append(StringUtil.join(type, Constants.DOT));
        sb.append(Constants.COMMA);
        Boolean attProgress = eq.get(ObjectKey.ATTACKS_PROGRESS);
        if (attProgress == null) {
            context.addWriteMessage(getTokenName() + " expected Equipment to know ATTACKS_PROGRESS state");
            return null;
        } else if (!attProgress.booleanValue()) {
            sb.append(Constants.CHAR_ASTERISK);
        }
        List<BonusObj> bonuses = eq.getListFor(ListKey.BONUS);
        if (bonuses == null || bonuses.isEmpty()) {
            sb.append('1');
        } else {
            if (bonuses.size() != 1) {
                context.addWriteMessage(getTokenName() + " expected only one BONUS on Equipment: " + bonuses);
                return null;
            }
            // TODO Validate BONUS type?
            BonusObj extraAttacks = bonuses.iterator().next();
            sb.append(Integer.parseInt(extraAttacks.getValue()) + 1);
        }
        sb.append(Constants.COMMA);
        EquipmentHead head = eq.getEquipmentHeadReference(1);
        if (head == null) {
            context.addWriteMessage(getTokenName() + " expected an EquipmentHead on Equipment");
            return null;
        }
        String damage = head.get(StringKey.DAMAGE);
        if (damage == null) {
            context.addWriteMessage(getTokenName() + " expected a Damage on EquipmentHead");
            return null;
        }
        sb.append(damage);
        Integer hands = eq.get(IntegerKey.SLOTS);
        if (hands != null && hands != 0) {
            sb.append(',').append(hands);
        }
        List<SpecialProperty> spropList = eq.getSafeListFor(ListKey.SPECIAL_PROPERTIES);
        for (SpecialProperty sprop : spropList) {
            sb.append(",SPROP=").append(sprop.toString());
        }
        first = false;
    }
    return new String[] { sb.toString() };
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Type(pcgen.cdom.enumeration.Type) Equipment(pcgen.core.Equipment) SpecialProperty(pcgen.core.SpecialProperty)

Example 2 with SpecialProperty

use of pcgen.core.SpecialProperty in project pcgen by PCGen.

the class SpropToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Equipment eq, String value) {
    if (Constants.LST_DOT_CLEAR.equals(value)) {
        context.getObjectContext().removeList(eq, ListKey.SPECIAL_PROPERTIES);
        return ParseResult.SUCCESS;
    }
    SpecialProperty sa = SpecialProperty.createFromLst(value);
    if (sa == null) {
        return ParseResult.INTERNAL_ERROR;
    }
    context.getObjectContext().addToList(eq, ListKey.SPECIAL_PROPERTIES, sa);
    return ParseResult.SUCCESS;
}
Also used : SpecialProperty(pcgen.core.SpecialProperty)

Example 3 with SpecialProperty

use of pcgen.core.SpecialProperty in project pcgen by PCGen.

the class SpropToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, EquipmentModifier mod, String value) {
    if (Constants.LST_DOT_CLEAR.equals(value)) {
        context.getObjectContext().removeList(mod, ListKey.SPECIAL_PROPERTIES);
        return ParseResult.SUCCESS;
    }
    SpecialProperty sa = SpecialProperty.createFromLst(value);
    if (sa == null) {
        return ParseResult.INTERNAL_ERROR;
    }
    context.getObjectContext().addToList(mod, ListKey.SPECIAL_PROPERTIES, sa);
    return ParseResult.SUCCESS;
}
Also used : SpecialProperty(pcgen.core.SpecialProperty)

Example 4 with SpecialProperty

use of pcgen.core.SpecialProperty in project pcgen by PCGen.

the class Gui2InfoFactory method getHTMLInfo.

@Override
public String getHTMLInfo(EquipModFacade equipModFacade, EquipmentFacade equipFacade) {
    if (equipModFacade == null || !(equipModFacade instanceof EquipmentModifier) || equipFacade == null || !(equipFacade instanceof Equipment)) {
        return EMPTY_STRING;
    }
    EquipmentModifier equipMod = (EquipmentModifier) equipModFacade;
    Equipment equip = (Equipment) equipFacade;
    final StringBuilder title = new StringBuilder(50);
    title.append(OutputNameFormatting.piString(equipMod, false));
    final HtmlInfoBuilder b = new HtmlInfoBuilder(null, false);
    b.appendTitleElement(title.toString());
    b.appendLineBreak();
    //$NON-NLS-1$
    b.appendI18nElement(//$NON-NLS-1$
    "in_igInfoLabelTextType", StringUtil.join(equipMod.getTrueTypeList(true), ". "));
    // Various cost types
    int iPlus = equipMod.getSafe(IntegerKey.PLUS);
    if (iPlus != 0) {
        b.appendLineBreak();
        b.appendI18nElement("in_igInfoLabelTextPlus", String.valueOf(iPlus));
    }
    Formula baseCost = equipMod.getSafe(FormulaKey.BASECOST);
    if (!"0".equals(baseCost.toString())) {
        b.appendLineBreak();
        b.appendI18nElement("in_igInfoLabelTextPrecost", String.valueOf(baseCost));
    }
    Formula cost = equipMod.getSafe(FormulaKey.COST);
    if (!"0".equals(cost.toString())) {
        b.appendLineBreak();
        b.appendI18nElement("in_igEqModelColCost", String.valueOf(cost));
    }
    //Description
    String desc = pc.getDescription(equipMod);
    if (!desc.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nFormattedElement(//$NON-NLS-1$
        "in_InfoDescription", DescriptionFormatting.piWrapDesc(equipMod, desc, false));
    }
    // Special properties
    StringBuilder sb = new StringBuilder(100);
    boolean first = true;
    for (SpecialProperty sp : equipMod.getSafeListFor(ListKey.SPECIAL_PROPERTIES)) {
        if (!first) {
            sb.append(", ");
        }
        first = false;
        sb.append(sp.getDisplayName());
    }
    if (sb.length() > 0) {
        b.appendLineBreak();
        b.appendI18nElement("in_igInfoLabelTextSprop", sb.toString());
    }
    final String cString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, equip, equipMod.getPrerequisiteList(), false);
    if (!cString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextReq", cString);
    }
    String bString = equipMod.getSource();
    if (!bString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextSource", bString);
    }
    b.appendLineBreak();
    return b.toString();
}
Also used : Formula(pcgen.base.formula.Formula) EquipmentModifier(pcgen.core.EquipmentModifier) Equipment(pcgen.core.Equipment) SpecialProperty(pcgen.core.SpecialProperty) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder)

Example 5 with SpecialProperty

use of pcgen.core.SpecialProperty in project pcgen by PCGen.

the class SpropToken method unparse.

@Override
public String[] unparse(LoadContext context, Equipment eq) {
    Changes<SpecialProperty> changes = context.getObjectContext().getListChanges(eq, ListKey.SPECIAL_PROPERTIES);
    if (changes == null || changes.isEmpty()) {
        return null;
    }
    List<String> list = new ArrayList<>();
    Collection<SpecialProperty> added = changes.getAdded();
    boolean globalClear = changes.includesGlobalClear();
    if (globalClear) {
        list.add(Constants.LST_DOT_CLEAR);
    }
    if (added != null && !added.isEmpty()) {
        for (SpecialProperty sp : added) {
            StringBuilder sb = new StringBuilder();
            sb.append(sp.getDisplayName());
            if (sp.hasPrerequisites()) {
                sb.append(Constants.PIPE);
                sb.append(getPrerequisiteString(context, sp.getPrerequisiteList()));
            }
            list.add(sb.toString());
        }
    }
    if (list.isEmpty()) {
        context.addWriteMessage(getTokenName() + " was expecting non-empty changes to include " + "added items or global clear");
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : SpecialProperty(pcgen.core.SpecialProperty) ArrayList(java.util.ArrayList)

Aggregations

SpecialProperty (pcgen.core.SpecialProperty)6 ArrayList (java.util.ArrayList)2 Equipment (pcgen.core.Equipment)2 Formula (pcgen.base.formula.Formula)1 Type (pcgen.cdom.enumeration.Type)1 EquipmentHead (pcgen.cdom.inst.EquipmentHead)1 EquipmentModifier (pcgen.core.EquipmentModifier)1 BonusObj (pcgen.core.bonus.BonusObj)1 HtmlInfoBuilder (pcgen.gui2.util.HtmlInfoBuilder)1