use of pcgen.core.Equipment in project pcgen by PCGen.
the class PreArmorProfTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
int runningTotal = 0;
final int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException exceptn) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("Prereq.error", "PREARMOR", //$NON-NLS-1$ //$NON-NLS-2$
prereq.toString()));
}
final String aString = prereq.getKey();
Equipment keyEquip = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, aString);
final boolean isType = aString.startsWith("TYPE") && aString.length() > 5;
final boolean isArmorType = aString.startsWith("ARMORTYPE") && aString.length() > 11;
String typeString = null;
if (isType) {
typeString = "ARMOR." + aString.substring(5);
} else if (isArmorType) {
typeString = "ARMOR." + aString.substring(10);
}
for (ProfProvider<ArmorProf> spp : display.getArmorProfList()) {
if (keyEquip != null && spp.providesProficiency(keyEquip.getArmorProf())) {
runningTotal++;
} else if (keyEquip != null && spp.providesEquipmentType(keyEquip.getType())) {
runningTotal++;
} else if (isType && spp.providesEquipmentType(typeString)) {
runningTotal++;
} else if (isArmorType && spp.providesEquipmentType(typeString)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class PreArmorTypeTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
// TODO All the equipment related PRE tag code should be refactored into a
// common base class.
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {
int runningTotal = 0;
if (display.hasEquipment()) {
final String desiredType = prereq.getKey();
for (Equipment eq : display.getEquippedEquipmentSet()) {
if (!eq.isArmor()) {
continue;
}
// Match against a TYPE of armour
if (desiredType.startsWith(Constants.LST_TYPE_EQUAL) || desiredType.startsWith(Constants.LST_TYPE_DOT)) {
String stripped = desiredType.substring(Constants.SUBSTRING_LENGTH_FIVE);
StringTokenizer tok = new StringTokenizer(stripped.toUpperCase(), ".");
boolean match = false;
if (tok.hasMoreTokens()) {
match = true;
}
//
while (tok.hasMoreTokens()) {
final String type = tok.nextToken();
if (!eq.isType(type)) {
match = false;
break;
}
}
if (match) {
runningTotal++;
break;
}
} else {
//not a TYPE string
final String eqName = eq.getName().toUpperCase();
if (desiredType.indexOf('%') >= 0) {
//handle wildcards (always assume they
// end the line)
final int percentPos = desiredType.indexOf('%');
final String substring = desiredType.substring(0, percentPos).toUpperCase();
if (eqName.startsWith(substring)) {
runningTotal++;
break;
}
} else if (//$NON-NLS-1$
desiredType.indexOf("LIST") >= 0) {
if (display.isProficientWithArmor(eq)) {
runningTotal++;
break;
}
} else if (//just a straight String compare
eqName.equals(desiredType)) {
runningTotal++;
break;
}
}
}
}
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class PreItemTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
// TODO Refactor this with all the equipment tests.
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
final int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException e) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreItem.error.bad_operand", //$NON-NLS-1$
prereq.toString()));
}
int runningTotal = 0;
if (display.hasEquipment()) {
// Work out exactlywhat we are going to test.
final String aString = prereq.getKey();
List<String> typeList = null;
if (aString.startsWith(Constants.LST_TYPE_EQUAL) || aString.startsWith(Constants.LST_TYPE_DOT)) {
String stripped = aString.substring(Constants.SUBSTRING_LENGTH_FIVE);
typeList = CoreUtility.split(stripped, '.');
}
for (Equipment eq : display.getEquipmentSet()) {
if (typeList != null) {
// Check to see if the equipment matches
// all of the types in the requested list;
boolean bMatches = true;
for (int i = 0, x = typeList.size(); i < x; ++i) {
if (!eq.isType(typeList.get(i))) {
bMatches = false;
break;
}
}
if (bMatches) {
runningTotal++;
}
} else {
//not a TYPE string
final String eqName = eq.getName().toUpperCase();
if (aString.indexOf('%') >= 0) {
//handle wildcards (always assume
// they end the line)
final int percentPos = aString.indexOf('%');
final String substring = aString.substring(0, percentPos).toUpperCase();
if ((eqName.startsWith(substring))) {
++runningTotal;
break;
}
} else if (eqName.equalsIgnoreCase(aString)) {
//just a straight String compare
++runningTotal;
break;
}
}
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class ACTokenTest method setUp.
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
LoadContext context = Globals.getContext();
PlayerCharacter character = getCharacter();
setPCStat(character, dex, 14);
dex.removeListFor(ListKey.BONUS);
BonusObj aBonus = Bonus.newBonus(context, "COMBAT|AC|10|TYPE=Base");
if (aBonus != null) {
dex.addToListFor(ListKey.BONUS, aBonus);
}
// Ignoring max dex
aBonus = Bonus.newBonus(context, "COMBAT|AC|DEX|TYPE=Ability");
if (aBonus != null) {
dex.addToListFor(ListKey.BONUS, aBonus);
}
EquipSet def = new EquipSet("0.1", "Default");
character.addEquipSet(def);
character.setCalcEquipmentList();
character.calcActiveBonuses();
// Create non magic armor
chainShirt = new Equipment();
chainShirt.setName("Chain Shirt");
chainShirt.put(StringKey.KEY_NAME, "KEY_Chain_Shirt");
TestHelper.addType(chainShirt, "Armor.Light.Suit.Standard");
chainShirt.put(IntegerKey.AC_CHECK, -2);
aBonus = Bonus.newBonus(context, "COMBAT|AC|4|TYPE=Armor.REPLACE");
if (aBonus != null) {
chainShirt.addToListFor(ListKey.BONUS, aBonus);
}
// Create magic armor enhancement
masterwork = new EquipmentModifier();
masterwork.setName("Masterwork");
masterwork.put(StringKey.KEY_NAME, "MWORKA");
TestHelper.addType(masterwork, "Armor.Shield");
masterwork.addToListFor(ListKey.ITEM_TYPES, "Masterwork");
aBonus = Bonus.newBonus(context, "EQMARMOR|ACCHECK|1|TYPE=Enhancement");
if (aBonus != null) {
masterwork.addToListFor(ListKey.BONUS, aBonus);
}
context.getReferenceContext().importObject(masterwork);
plus1 = new EquipmentModifier();
plus1.setName("Plus 1 Enhancement");
plus1.put(StringKey.KEY_NAME, "PLUS1A");
TestHelper.addType(plus1, "Armor.Shield");
plus1.put(IntegerKey.PLUS, 1);
plus1.addToListFor(ListKey.ITEM_TYPES, "Enhancement");
plus1.addToListFor(ListKey.ITEM_TYPES, "Magic");
plus1.addToListFor(ListKey.ITEM_TYPES, "Plus1");
aBonus = Bonus.newBonus(context, "COMBAT|AC|1|TYPE=Armor.REPLACE");
if (aBonus != null) {
plus1.addToListFor(ListKey.BONUS, aBonus);
}
Globals.getContext().getReferenceContext().importObject(plus1);
// Load AC definitions - but only once
final GameMode gamemode = SettingsHandler.getGame();
if (!gamemode.isValidACType("Total")) {
gamemode.addACAdds("Total", Collections.singletonList(new ACControl("TOTAL")));
gamemode.addACAdds("Armor", Collections.singletonList(new ACControl("Armor")));
gamemode.addACAdds("Ability", Collections.singletonList(new ACControl("Ability")));
}
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class BonusTest method testSkillPrereq.
/**
* Test the skill pre reqs
* @throws Exception
*/
public void testSkillPrereq() throws Exception {
LoadContext context = Globals.getContext();
final Skill rideSkill = new Skill();
rideSkill.setName("Ride");
rideSkill.put(StringKey.KEY_NAME, "Ride");
rideSkill.addToListFor(ListKey.TYPE, Type.getConstant("DEX"));
final Ability skillFocus = new Ability();
skillFocus.setName("Skill Focus");
skillFocus.put(StringKey.KEY_NAME, "Skill Focus");
final BonusObj saddleBonus = Bonus.newBonus(context, "SKILL|Ride|-5|!PREITEM:1,TYPE.Saddle");
rideSkill.addToListFor(ListKey.BONUS, saddleBonus);
final Equipment saddle = new Equipment();
saddle.setName("Saddle, Test");
saddle.addToListFor(ListKey.TYPE, Type.getConstant("SADDLE"));
final PlayerCharacter pc = getCharacter();
BonusActivation.activateBonuses(rideSkill, pc);
double iBonus = saddleBonus.resolve(pc, "").doubleValue();
assertEquals("Bonus value", -5.0, iBonus, 0.05);
assertTrue("No saddle, should have a penalty", pc.isApplied(saddleBonus));
pc.addEquipment(saddle);
final EquipSet eqSet = new EquipSet("Test", "Test", "", saddle);
pc.addEquipSet(eqSet);
pc.calcActiveBonuses();
BonusActivation.activateBonuses(rideSkill, pc);
assertFalse("Saddle, should not have a penalty", pc.isApplied(saddleBonus));
}
Aggregations