use of pcgen.cdom.content.ACControl 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.cdom.content.ACControl in project pcgen by PCGen.
the class ArmorClassFacet method calcACOfType.
/**
* Calculates the Armor Class of a certain type. These types are defined in
* the game mode; there are no hardcoded Armor Class types here - (and none
* should be added!)
*
* @param id
* The CharId identifying the Player Character for which a
* specific type of Armor Class should be calculated
* @param type
* The type of the Armor Class to be calculated. Defined in the
* Game Mode files
* @return The armor class of the given type for the Player Character
* identified by the given CharID
*/
@Deprecated
public int calcACOfType(CharID id, String type) {
/*
* CONSIDER should AC types be a type safe list?
*/
final List<ACControl> addList = SettingsHandler.getGame().getACTypeAddString(type);
final List<ACControl> removeList = SettingsHandler.getGame().getACTypeRemoveString(type);
if ((addList == null) && (removeList == null)) {
Logging.errorPrint("Invalid ACType: " + type);
return 0;
}
int armorClass = 0;
if (addList != null) {
PlayerCharacter pc = trackingFacet.getPC(id);
for (ACControl acc : addList) {
if (prerequisiteFacet.qualifies(id, acc, null)) {
armorClass += Integer.parseInt(BonusToken.getBonusToken("BONUS.COMBAT.AC." + acc.getType(), pc));
}
}
}
if (removeList != null) {
PlayerCharacter pc = trackingFacet.getPC(id);
for (ACControl acc : removeList) {
if (prerequisiteFacet.qualifies(id, acc, null)) {
armorClass -= Integer.parseInt(BonusToken.getBonusToken("BONUS.COMBAT.AC." + acc.getType(), pc));
}
}
}
return armorClass;
}
use of pcgen.cdom.content.ACControl in project pcgen by PCGen.
the class ActypeToken method parseACControl.
private Collection<ACControl> parseACControl(String str) {
StringTokenizer st = new StringTokenizer(str, Constants.PIPE);
List<ACControl> acTypes = new ArrayList<>();
String token;
while (true) {
token = st.nextToken();
if (PreParserFactory.isPreReqString(token)) {
break;
}
acTypes.add(new ACControl(token));
if (!st.hasMoreTokens()) {
return acTypes;
}
}
if (acTypes.isEmpty()) {
Logging.errorPrint("No types found in actype control: " + str);
return null;
}
while (true) {
try {
PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite prereq = factory.parse(token);
for (ACControl acc : acTypes) {
acc.addPrerequisite(prereq);
}
} catch (PersistenceLayerException ple) {
Logging.errorPrint(ple.getMessage(), ple);
return null;
}
if (!st.hasMoreTokens()) {
break;
}
token = st.nextToken();
if (!PreParserFactory.isPreReqString(token)) {
Logging.errorPrint("ERROR: Type found after" + " PRExxx in actype control: " + str);
return null;
}
}
return acTypes;
}
use of pcgen.cdom.content.ACControl in project pcgen by PCGen.
the class ActypeToken method parse.
@Override
public boolean parse(GameMode gameMode, String value, URI source) {
final StringTokenizer aTok = new StringTokenizer(value, "\t");
if (!aTok.hasMoreTokens()) {
Logging.errorPrint("Empty tag in miscinfo.ACTYPE");
return false;
}
final String acType = aTok.nextToken();
while (aTok.hasMoreTokens()) {
final String aString = aTok.nextToken();
if (aString.startsWith("ADD:")) {
Collection<ACControl> controls = parseACControl(aString.substring(4));
if (controls == null) {
return false;
}
gameMode.addACAdds(acType, controls);
} else if (aString.startsWith("REMOVE:")) {
Collection<ACControl> controls = parseACControl(aString.substring(7));
if (controls == null) {
return false;
}
gameMode.addACRemoves(acType, controls);
} else {
Logging.errorPrint("Incorrect tag in miscinfo.ACTYPE: " + aString);
return false;
}
}
return true;
}
Aggregations