Search in sources :

Example 1 with CategorisedKey

use of pcgen.io.migration.AbilityMigration.CategorisedKey in project pcgen by PCGen.

the class AbilityMigrationTest method testMaxVer.

/**
	 * Test that rules for max version only are applied correctly.  
	 */
public void testMaxVer() {
    CategorisedKey catKey = AbilityMigration.getNewAbilityKey("OldCat", "OldKey1", new int[] { 6, 0, 0 }, gameMode);
    assertEquals("OldCat", catKey.getCategory());
    assertEquals("NewKey1", catKey.getKey());
    catKey = AbilityMigration.getNewAbilityKey("OldCat", "OldKey1", new int[] { 6, 0, 2 }, gameMode);
    assertEquals("OldCat", catKey.getCategory());
    assertEquals("OldKey1", catKey.getKey());
}
Also used : CategorisedKey(pcgen.io.migration.AbilityMigration.CategorisedKey)

Example 2 with CategorisedKey

use of pcgen.io.migration.AbilityMigration.CategorisedKey in project pcgen by PCGen.

the class PCGVer2Parser method parseAbilityLine.

/*
	 * ###############################################################
	 * Character Ability methods
	 * ###############################################################
	 */
private void parseAbilityLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalAbility", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    AbilityCategory category = null;
    Nature nature = Nature.NORMAL;
    String abilityCat = null;
    Ability ability = null;
    String missingCat = null;
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the AbilityCategory key name
    if (it.hasNext()) {
        final PCGElement element = it.next();
        final String categoryKey = EntityEncoder.decode(element.getText());
        category = SettingsHandler.getGame().getAbilityCategory(categoryKey);
        if (category == null) {
            missingCat = categoryKey;
        }
    }
    // The next element will be the nature
    if (it.hasNext()) {
        final PCGElement element = it.next();
        final String natureKey = EntityEncoder.decode(element.getText());
        nature = Nature.valueOf(natureKey);
    }
    // The next element will be the ability's innate category
    if (it.hasNext()) {
        final PCGElement element = it.next();
        abilityCat = EntityEncoder.decode(element.getText());
    }
    // The next element will be the ability key
    if (it.hasNext()) {
        final PCGElement element = it.next();
        String abilityKey = EntityEncoder.decode(element.getText());
        // Check for an ability that has been updated.
        CategorisedKey categorisedKey = AbilityMigration.getNewAbilityKey(abilityCat, abilityKey, pcgenVersion, SettingsHandler.getGame().getName());
        abilityCat = categorisedKey.getCategory();
        abilityKey = categorisedKey.getKey();
        AbilityCategory innateCategory = SettingsHandler.getGame().getAbilityCategory(abilityCat);
        if (innateCategory == null) {
            missingCat = abilityCat;
        }
        if (innateCategory == null || category == null) {
            final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
            "Warnings.PCGenParser.AbilityCategoryNotFound", abilityKey, missingCat);
            warnings.add(msg);
            return;
        }
        ability = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, innateCategory, abilityKey);
        if (ability == null) {
            warnings.add("Unable to Find Ability: " + abilityKey);
            return;
        }
    }
    List<String> associations = new ArrayList<>();
    List<BonusObj> bonuses = new ArrayList<>();
    while (it.hasNext()) {
        final PCGElement element = it.next();
        final String tag = element.getName();
        if (tag.equals(IOConstants.TAG_APPLIEDTO)) {
            associations.add(EntityEncoder.decode(element.getText()));
        } else if (IOConstants.TAG_SAVE.equals(tag)) {
            final String saveKey = EntityEncoder.decode(element.getText());
            // TODO - This never gets written to the file
            if (saveKey.startsWith(IOConstants.TAG_BONUS) && (saveKey.length() > 6)) {
                final BonusObj aBonus = Bonus.newBonus(Globals.getContext(), saveKey.substring(6));
                if (aBonus != null) {
                    bonuses.add(aBonus);
                }
            } else {
                if (Logging.isDebugMode()) {
                    Logging.debugPrint("Ignoring SAVE:" + saveKey);
                }
            }
        }
    }
    if (ability != null && category != null && nature != null) {
        CNAbility cna = null;
        boolean needError = true;
        if (nature == Nature.NORMAL) {
            // lines, save the feat now.
            if (!featsPresent || category != AbilityCategory.FEAT) {
                try {
                    cna = CNAbilityFactory.getCNAbility(category, nature, ability);
                } catch (IllegalArgumentException e) {
                    Logging.log(Logging.INFO, "Unabe to parse ability line: " + e.getMessage());
                }
            } else {
                needError = false;
            }
        } else if (nature == Nature.VIRTUAL) {
            cna = CNAbilityFactory.getCNAbility(category, nature, ability);
        }
        if (cna == null) {
            if (needError) {
                warnings.add("Unable to build Ability: " + ability);
            }
        } else {
            if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
                for (String appliedToKey : associations) {
                    String[] assoc = appliedToKey.split(Constants.COMMA, -1);
                    for (String string : assoc) {
                        CNAbilitySelection cnas = new CNAbilitySelection(cna, string);
                        try {
                            if (nature == Nature.VIRTUAL) {
                                thePC.addSavedAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
                            } else {
                                thePC.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
                            }
                        } catch (IllegalArgumentException e) {
                            Logging.errorPrint("PCGVer2Parser.parseAbilityLine failed", e);
                            warnings.add(cna + " with selection: " + string + " is no longer valid.");
                        }
                    }
                }
            } else {
                if (associations != null && !associations.isEmpty()) {
                    warnings.add(cna + " found with selections: " + associations + " but is MULT:NO in the data");
                }
                CNAbilitySelection cnas = new CNAbilitySelection(cna);
                if (nature == Nature.VIRTUAL) {
                    thePC.addSavedAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
                } else {
                    thePC.addAbility(cnas, UserSelection.getInstance(), UserSelection.getInstance());
                }
            }
            for (BonusObj b : bonuses) {
                thePC.addSaveableBonus(b, cna.getAbility());
            }
        }
    }
}
Also used : Nature(pcgen.cdom.enumeration.Nature) CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) CategorisedKey(pcgen.io.migration.AbilityMigration.CategorisedKey) CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) AbilityCategory(pcgen.core.AbilityCategory)

Example 3 with CategorisedKey

use of pcgen.io.migration.AbilityMigration.CategorisedKey in project pcgen by PCGen.

the class AbilityMigrationTest method testCaseInsensitive.

/**
	 * Test that matches are case insensitive.  
	 */
public void testCaseInsensitive() {
    CategorisedKey catKey = AbilityMigration.getNewAbilityKey("OldCAT", "OldKey1", new int[] { 6, 0, 0 }, gameMode);
    assertEquals("OldCAT", catKey.getCategory());
    assertEquals("NewKey1", catKey.getKey());
    catKey = AbilityMigration.getNewAbilityKey("OldCat", "OldKEY1", new int[] { 6, 0, 0 }, gameMode);
    assertEquals("OldCat", catKey.getCategory());
    assertEquals("NewKey1", catKey.getKey());
}
Also used : CategorisedKey(pcgen.io.migration.AbilityMigration.CategorisedKey)

Example 4 with CategorisedKey

use of pcgen.io.migration.AbilityMigration.CategorisedKey in project pcgen by PCGen.

the class AbilityMigrationTest method testCatChange.

/**
	 * Test that rules for category changes are applied correctly.  
	 */
public void testCatChange() {
    CategorisedKey catKey = AbilityMigration.getNewAbilityKey("OldCat", "OldKey2", new int[] { 5, 17, 5 }, gameMode);
    assertEquals("EarlyNewCat", catKey.getCategory());
    assertEquals("EarlyNewKey", catKey.getKey());
}
Also used : CategorisedKey(pcgen.io.migration.AbilityMigration.CategorisedKey)

Aggregations

CategorisedKey (pcgen.io.migration.AbilityMigration.CategorisedKey)4 ArrayList (java.util.ArrayList)1 CNAbility (pcgen.cdom.content.CNAbility)1 Nature (pcgen.cdom.enumeration.Nature)1 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)1 Ability (pcgen.core.Ability)1 AbilityCategory (pcgen.core.AbilityCategory)1 SpecialAbility (pcgen.core.SpecialAbility)1 BonusObj (pcgen.core.bonus.BonusObj)1