use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class NaturalattacksLst method createNaturalWeapon.
/**
* Create the Natural weapon equipment item aTok = primary weapon
* name,weapon type,num attacks,damage for Example:
* Tentacle,Weapon.Natural.Melee.Slashing,*4,1d6
*
* @param aTok
* @param size
* @return natural weapon
*/
private Equipment createNaturalWeapon(LoadContext context, CDOMObject obj, String wpn) {
StringTokenizer commaTok = new StringTokenizer(wpn, Constants.COMMA);
int numTokens = commaTok.countTokens();
if (numTokens < 4) {
Logging.errorPrint("Invalid Build of " + "Natural Weapon in " + getTokenName() + ": " + wpn);
return null;
}
String attackName = commaTok.nextToken();
if (attackName.equalsIgnoreCase(Constants.LST_NONE)) {
Logging.errorPrint("Attempt to Build 'None' as a " + "Natural Weapon in " + getTokenName() + ": " + wpn);
return null;
}
attackName = attackName.intern();
Equipment anEquip = new Equipment();
anEquip.setName(attackName);
anEquip.put(ObjectKey.PARENT, obj);
/*
* This really can't be raw equipment... It really never needs to be
* referred to, but this means that duplicates are never being detected
* and resolved... this needs to have a KEY defined, to keep it
* unique... hopefully this is good enough :)
*
* CONSIDER This really isn't that great, because it's String dependent,
* and may not remove identical items... it certainly works, but is ugly
*/
// anEquip.setKeyName(obj.getClass().getSimpleName() + ","
// + obj.getKeyName() + "," + wpn);
/*
* Perhaps the construction above should be through context just to
* guarantee uniqueness of the key?? - that's too paranoid
*/
EquipmentHead equipHead = anEquip.getEquipmentHead(1);
String profType = commaTok.nextToken();
if (hasIllegalSeparator('.', profType)) {
return null;
}
StringTokenizer dotTok = new StringTokenizer(profType, Constants.DOT);
while (dotTok.hasMoreTokens()) {
Type type = Type.getConstant(dotTok.nextToken());
anEquip.addToListFor(ListKey.TYPE, type);
}
String numAttacks = commaTok.nextToken();
boolean attacksFixed = !numAttacks.isEmpty() && numAttacks.charAt(0) == '*';
if (attacksFixed) {
numAttacks = numAttacks.substring(1);
}
anEquip.put(ObjectKey.ATTACKS_PROGRESS, !attacksFixed);
try {
int bonusAttacks = Integer.parseInt(numAttacks) - 1;
final BonusObj aBonus = Bonus.newBonus(context, "WEAPON|ATTACKS|" + bonusAttacks);
if (aBonus == null) {
Logging.errorPrint(getTokenName() + " was given invalid number of attacks: " + bonusAttacks);
return null;
}
anEquip.addToListFor(ListKey.BONUS, aBonus);
} catch (NumberFormatException exc) {
Logging.errorPrint("Non-numeric value for number of attacks in " + getTokenName() + ": '" + numAttacks + '\'');
return null;
}
equipHead.put(StringKey.DAMAGE, commaTok.nextToken());
// sage_sam 02 Dec 2002 for Bug #586332
// allow hands to be required to equip natural weapons
int handsrequired = 0;
while (commaTok.hasMoreTokens()) {
final String hString = commaTok.nextToken();
if (hString.startsWith("SPROP=")) {
anEquip.addToListFor(ListKey.SPECIAL_PROPERTIES, SpecialProperty.createFromLst(hString.substring(6)));
} else {
try {
handsrequired = Integer.parseInt(hString);
} catch (NumberFormatException exc) {
Logging.errorPrint("Non-numeric value for hands required: '" + hString + '\'');
return null;
}
}
}
anEquip.put(IntegerKey.SLOTS, handsrequired);
anEquip.put(ObjectKey.WEIGHT, BigDecimal.ZERO);
WeaponProf cwp = context.getReferenceContext().silentlyGetConstructedCDOMObject(WEAPONPROF_CLASS, attackName);
if (cwp == null) {
cwp = context.getReferenceContext().constructNowIfNecessary(WEAPONPROF_CLASS, attackName);
cwp.addToListFor(ListKey.TYPE, Type.NATURAL);
}
CDOMSingleRef<WeaponProf> wp = context.getReferenceContext().getCDOMReference(WEAPONPROF_CLASS, attackName);
anEquip.put(ObjectKey.WEAPON_PROF, wp);
anEquip.addToListFor(ListKey.IMPLIED_WEAPONPROF, wp);
if (!ControlUtilities.hasControlToken(context, CControl.CRITRANGE)) {
equipHead.put(IntegerKey.CRIT_RANGE, 1);
}
if (!ControlUtilities.hasControlToken(context, CControl.CRITMULT)) {
equipHead.put(IntegerKey.CRIT_MULT, 2);
}
return anEquip;
}
use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class AbilityRefChoiceSet method addMultiplySelectableAbility.
private Collection<CNAbilitySelection> addMultiplySelectableAbility(final PlayerCharacter aPC, Ability ability, String subName) {
boolean isPattern = false;
String nameRoot = null;
if (subName != null) {
final int percIdx = subName.indexOf('%');
if (percIdx > -1) {
isPattern = true;
nameRoot = subName.substring(0, percIdx);
} else if (!subName.isEmpty()) {
nameRoot = subName;
}
}
ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
final List<String> availableList = getAvailableList(aPC, chooseInfo);
/*
* TODO Need a general solution for this special assignment in parens
*/
if ("DEITYWEAPON".equals(nameRoot) && (chooseInfo != null) && chooseInfo.getClassIdentity().getChoiceClass().equals(WeaponProf.class)) {
Deity deity = aPC.getDeity();
if (deity == null) {
availableList.clear();
} else {
List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
Set<String> set = new HashSet<>();
for (CDOMReference<WeaponProf> ref : dwp) {
for (WeaponProf wp : ref.getContainedObjects()) {
set.add(wp.getKeyName());
}
}
availableList.retainAll(set);
}
} else if (nameRoot != null && !nameRoot.isEmpty()) {
for (int n = availableList.size() - 1; n >= 0; --n) {
final String aString = availableList.get(n);
if (!aString.startsWith(nameRoot)) {
availableList.remove(n);
}
}
if (isPattern && !availableList.isEmpty()) {
availableList.add(nameRoot);
}
}
List<CNAbilitySelection> returnList = new ArrayList<>(availableList.size());
for (String s : availableList) {
returnList.add(new CNAbilitySelection(CNAbilityFactory.getCNAbility(category.get(), nature, ability), s));
}
return returnList;
}
use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class DeityWeaponProfFacet method dataAdded.
/**
* Adds WeaponProfs granted to the Player Character due to the Deity
* selection of the Player Character.
*
* Triggered when one of the Facets to which DeityWeaponProfFacet listens
* fires a DataFacetChangeEvent to indicate a Deity was added to a Player
* Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, Deity> dfce) {
Deity deity = dfce.getCDOMObject();
List<CDOMReference<WeaponProf>> weaponList = deity.getListFor(ListKey.DEITYWEAPON);
if (weaponList != null) {
for (CDOMReference<WeaponProf> ref : weaponList) {
for (WeaponProf wp : ref.getContainedObjects()) {
/*
* CONSIDER This is an open question, IMHO - why is natural
* excluded here? This is magic to me - thpr Oct 14, 2008
*/
if (!wp.isType("Natural")) {
add(dfce.getCharID(), wp, dfce.getCDOMObject());
}
}
}
}
}
use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class KitProf method testApply.
@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
thePObject = null;
weaponProfs = null;
PersistentTransitionChoice<WeaponProf> wpPTC = null;
if (isRacial()) {
final Race pcRace = aPC.getRace();
if (pcRace == null) {
warnings.add("PROF: PC has no race");
return false;
}
if (!aPC.hasBonusWeaponProfs(pcRace)) {
warnings.add("PROF: Race has already selected bonus weapon proficiency");
return false;
}
thePObject = pcRace;
wpPTC = getPTC(pcRace);
if (wpPTC == null) {
warnings.add("PROF: PC race has no WEAPONBONUS");
return false;
}
} else {
Collection<PCClass> pcClasses = aPC.getClassSet();
if (pcClasses == null || pcClasses.isEmpty()) {
warnings.add("PROF: No owning class found.");
return false;
}
// Search for a class that has bonusWeaponProfs.
PCClass pcClass = null;
for (Iterator<PCClass> i = pcClasses.iterator(); i.hasNext(); ) {
pcClass = i.next();
wpPTC = getPTC(pcClass);
if (wpPTC != null) {
break;
}
}
if (wpPTC == null) {
warnings.add("PROF: PC classes have no WEAPONBONUS");
return false;
}
thePObject = pcClass;
if (!aPC.hasBonusWeaponProfs(pcClass)) {
warnings.add("PROF: Class has already selected bonus weapon proficiency");
return false;
}
}
final List<WeaponProf> aProfList = new ArrayList<>();
Collection<?> choices = wpPTC.getChoices().getSet(aPC);
for (CDOMSingleRef<WeaponProf> profKey : profList) {
WeaponProf wp = profKey.get();
if (choices.contains(wp)) {
wpPTC.act(Collections.singleton(wp), thePObject, aPC);
} else {
warnings.add("PROF: Weapon proficiency \"" + wp.getKeyName() + "\" is not in list of choices");
}
}
int numberOfChoices = getSafeCount();
//
if (numberOfChoices > aProfList.size()) {
numberOfChoices = aProfList.size();
}
if (numberOfChoices == 0) {
return false;
}
List<WeaponProf> xs;
if (numberOfChoices == aProfList.size()) {
xs = aProfList;
} else {
//
while (true) {
xs = Globals.getChoiceFromList("Choose Proficiencies", aProfList, new ArrayList<>(), numberOfChoices, aPC);
if (!xs.isEmpty()) {
break;
}
}
}
//
for (WeaponProf prof : xs) {
if (weaponProfs == null) {
weaponProfs = new ArrayList<>();
}
weaponProfs.add(prof);
}
return false;
}
use of pcgen.core.WeaponProf in project pcgen by PCGen.
the class PreWeaponProfTester method passes.
/**
* <b>Tag Name</b>: {@code PREWEAPONPROF:x,y,y}<br>
* <b>Variables Used (x)</b>: <i>Number</i> (The number of proficiencies that must match the specified requirements). <br>
* <b>Variables Used (y)</b>: <i>Text</i> (The name of a weapon proficiency). <br>
* <b>Variables Used (y)</b>: {@code TYPE.}<i>Text</i> (The name of a weaponprof type). <br>
* <b>Variables Used (y)</b>: {@code DEITYWEAPON} (The favored weapon of the character's deity). <br>
* <p>
* <b>What it does:</b><br>
* Sets weapon proficiency requirements.
* <p>
* <b>Examples</b>: <br>
* {@code PREWEAPONPROF:2,Kama,Katana}<br>
* Character must have both "Kama" and "Katana".
* <p>
* {@code PREWEAPONPROF:1,TYPE.Exotic} <br>
* Character must have proficiency with any one exotic weaponprof type.
* <p>
* {@code PREWEAPONPROF:1,TYPE.Martial,Chain (Spiked)} <br>
* Character must have proficiency with either the Chain (Spiked) or any martial weapon.
* <p>
* {@code PREWEAPONPROF:1,DEITYWEAPON} <br>
* Weapon Prof in question must be one of the chosen deity's favored weapons.
*
* @see pcgen.core.prereq.AbstractPrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.PlayerCharacter, CDOMObject)
*/
@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("PreFeat.error", //$NON-NLS-1$
prereq.toString()));
}
final String aString = prereq.getKey();
if (//$NON-NLS-1$
"DEITYWEAPON".equals(aString) && display.getDeity() != null) {
List<CDOMReference<WeaponProf>> dwp = display.getDeity().getSafeListFor(ListKey.DEITYWEAPON);
DEITYWPN: for (CDOMReference<WeaponProf> ref : dwp) {
for (WeaponProf wp : ref.getContainedObjects()) {
if (display.hasWeaponProf(wp)) {
runningTotal++;
break DEITYWPN;
}
}
}
} else if (//$NON-NLS-1$ //$NON-NLS-2$
aString.startsWith("TYPE.") || aString.startsWith("TYPE=")) {
final String requiredType = aString.substring(5);
for (WeaponProf wp : display.getWeaponProfSet()) {
if (wp.isType(requiredType)) {
runningTotal++;
} else {
final Equipment eq = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, wp.getKeyName());
if (eq != null) {
if (eq.isType(requiredType)) {
runningTotal++;
}
}
}
}
} else {
WeaponProf wp = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WeaponProf.class, aString);
if ((wp != null && display.hasWeaponProf(wp))) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
Aggregations