use of pcgen.core.character.WieldCategory in project pcgen by PCGen.
the class DownToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, WieldCategory wc, String value) {
StringTokenizer st = new StringTokenizer(value, Constants.PIPE);
int count = -1;
while (st.hasMoreTokens()) {
CDOMSingleRef<WieldCategory> stepCat = context.getReferenceContext().getCDOMReference(WIELD_CATEGORY_CLASS, st.nextToken());
wc.setWieldCategoryStep(count--, stepCat);
}
return ParseResult.SUCCESS;
}
use of pcgen.core.character.WieldCategory in project pcgen by PCGen.
the class Equipment method getEffectiveWieldCategory.
/**
* Gets the minimum WieldCategory this weapon can be used at. Accounts for
* all modifiers that affect WieldCategory. 3.0 weapon sizes are mapped to
* appropriate WieldCategories.
*
* @param aPC The PlayerCharacter using the weapon
* @return The minimum WieldCategory required to use the weapon.
*/
public WieldCategory getEffectiveWieldCategory(final PlayerCharacter aPC) {
CDOMSingleRef<WeaponProf> ref = get(ObjectKey.WEAPON_PROF);
WeaponProf wp = ref == null ? null : ref.get();
WieldCategory wCat = get(ObjectKey.WIELD);
if (wCat != null && !Globals.checkRule(RuleConstants.SIZEOBJ)) {
// Get the starting effective wield category
wCat = wCat.adjustForSize(aPC, this);
} else {
int pcSize = aPC.sizeInt();
if (wp != null) {
pcSize += aPC.getTotalBonusTo("WEAPONPROF=" + wp.getKeyName(), "PCSIZE");
}
int sizeDiff;
if (wCat != null && Globals.checkRule(RuleConstants.SIZEOBJ)) {
// In this case we have a 3.5 style equipments size.
// We need to map to a 3.0 style
sizeDiff = wCat.getObjectSizeInt(this) - pcSize;
} else {
sizeDiff = sizeInt() - pcSize;
}
if (sizeDiff > 1) {
wCat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TooLarge");
} else if (sizeDiff == 1) {
wCat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded");
} else if (sizeDiff == 0) {
wCat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded");
} else {
wCat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "Light");
}
}
int aBump = 0;
// TODO Remove this code when support for this "feature" goes away
if (wp != null) {
int iHands = wp.getSafe(IntegerKey.HANDS);
if (iHands == Constants.HANDS_SIZE_DEPENDENT) {
if (aPC.sizeInt() > sizeInt()) {
iHands = 1;
} else {
iHands = 2;
}
}
while (wCat.getHandsRequired() < iHands) {
wCat = wCat.getWieldCategoryStep(1);
}
// See if there is a bonus associated with just this weapon
final String expProfName = wp.getKeyName();
aBump += (int) aPC.getTotalBonusTo("WEAPONPROF=" + expProfName, "WIELDCATEGORY");
// loops for each equipment type
int modWield = 0;
for (String eqType : typeList()) {
final StringBuilder sB = new StringBuilder("WEAPONPROF=TYPE.");
sB.append(eqType);
// get the type bonus (ex TYPE.MARTIAL)
final int i = (int) aPC.getTotalBonusTo(sB.toString(), "WIELDCATEGORY");
// get the highest bonus
if (i < modWield) {
modWield = i;
}
}
aBump += modWield;
}
// or a bonus from the weapon itself
aBump += (int) bonusTo(aPC, "WEAPON", "WIELDCATEGORY", true);
if (aBump == 0) {
return wCat;
}
return wCat.getWieldCategoryStep(aBump);
}
use of pcgen.core.character.WieldCategory in project pcgen by PCGen.
the class WieldCategoryLoader method parseLine.
/**
* Parse the WIELDCATEGORY line
*
* @param gameMode
* @param lstLine
* @throws PersistenceLayerException
*/
public void parseLine(GameMode gameMode, String lstLine, URI source) throws PersistenceLayerException {
LoadContext context = gameMode.getModeContext();
StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
WieldCategory cat = null;
String preKey = null;
CDOMSingleRef<WieldCategory> preVal = null;
while (colToken.hasMoreTokens()) {
final String colString = colToken.nextToken().trim();
final int idxColon = colString.indexOf(':');
String key = "";
try {
key = colString.substring(0, idxColon);
} catch (StringIndexOutOfBoundsException e) {
// TODO Deal with Exception
}
if (key.equals("WIELDCATEGORY")) {
final String value = colString.substring(idxColon + 1).trim();
cat = context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, value);
if (cat == null) {
cat = new WieldCategory();
cat.setName(value.intern());
gameMode.addWieldCategory(cat);
}
} else if (colString.startsWith("PREVAR")) {
//TODO ensure preKey is null
// a PREVARxx formula used to switch
// weapon categories based on size
preKey = colString;
} else if (key.equals("SWITCH")) {
//TODO ensure preVal is null
// If matches PRE, switch category to this
preVal = context.getReferenceContext().getCDOMReference(WieldCategory.class, colString.substring(7));
} else {
final String value = colString.substring(idxColon + 1).trim();
if (context.processToken(cat, key, value)) {
context.commit();
} else {
context.rollback();
Logging.replayParsedMessages();
}
Logging.clearParseMessages();
}
}
//TODO Error checking if preVal w/o preKey, vice versa, etc.
if ((cat != null) && (preVal != null) && (preKey != null)) {
try {
QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(preVal);
qo.addPrerequisite(prereqParser.parse(preKey));
cat.addCategorySwitch(qo);
} catch (PersistenceLayerException ple) {
Logging.errorPrint("Error parsing Prerequisite in " + source + ": " + preKey + "\n " + ple.getMessage());
}
}
}
use of pcgen.core.character.WieldCategory in project pcgen by PCGen.
the class PreEquipPrimaryTest method testWield.
/**
* Test wield category tests
* @throws Exception
*/
public void testWield() throws Exception {
final PlayerCharacter character = getCharacter();
final Race race = new Race();
race.setName("Test Race");
CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
character.setRace(race);
LoadContext context = Globals.getContext();
final Equipment longsword = new Equipment();
longsword.setName("Dagger");
character.addEquipment(longsword);
longsword.setIsEquipped(true, character);
longsword.setLocation(EquipmentLocation.EQUIPPED_PRIMARY);
character.doAfavorForAunitTestThatIgnoresEquippingRules();
Prerequisite prereq = new Prerequisite();
prereq.setKind("equipprimary");
prereq.setKey("WIELDCATEGORY=OneHanded");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.EQ);
// Test 3.0 Style
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
assertTrue("Weapon is M therefore OneHanded", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.SIZE, largeRef);
longsword.put(ObjectKey.BASESIZE, largeRef);
assertFalse("Weapon is L therefore TwoHanded", PrereqHandler.passes(prereq, character, null));
// Test 3.5 style
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
assertFalse("Weapon is TwoHanded", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
assertTrue("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.character.WieldCategory in project pcgen by PCGen.
the class PreEquipSecondaryTest method testWield.
/**
* Test wield category tests
* @throws Exception
*/
public void testWield() throws Exception {
final PlayerCharacter character = getCharacter();
final Race race = new Race();
race.setName("Test Race");
CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
CDOMDirectSingleRef<SizeAdjustment> smallRef = CDOMDirectSingleRef.getRef(small);
race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
character.setRace(race);
LoadContext context = Globals.getContext();
final Equipment longsword = new Equipment();
longsword.setName("Longsword");
character.addEquipment(longsword);
longsword.setIsEquipped(true, character);
longsword.setLocation(EquipmentLocation.EQUIPPED_SECONDARY);
character.doAfavorForAunitTestThatIgnoresEquippingRules();
Prerequisite prereq = new Prerequisite();
prereq.setKind("equipsecondary");
prereq.setKey("WIELDCATEGORY=Light");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.EQ);
// Test 3.0 Style
longsword.put(ObjectKey.SIZE, smallRef);
longsword.put(ObjectKey.BASESIZE, smallRef);
assertTrue("Weapon is S therefore Light", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
assertFalse("Weapon is M therefore OneHanded", PrereqHandler.passes(prereq, character, null));
// Test 3.5 style
longsword.put(ObjectKey.SIZE, mediumRef);
longsword.put(ObjectKey.BASESIZE, mediumRef);
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
assertFalse("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "Light"));
assertTrue("Weapon is Light", PrereqHandler.passes(prereq, character, null));
}
Aggregations