use of plugin.initiative.XMLCombatant in project pcgen by PCGen.
the class Initiative method bDuplicateCombatantActionPerformed.
/**
* @param evt
*/
private void bDuplicateCombatantActionPerformed(ActionEvent evt) {
//TODO: This only works for saved pcgen files and xml combatants.
//For pcgen files, it reloads the file, since there's no good way
//curently to clone a PlayerCharacter.
DefaultFormatter formatter = new NumberFormatter();
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
formatter.setValueClass(Integer.class);
JFormattedTextField field = new JFormattedTextField(formatter);
field.setValue(1);
int choice = JOptionPane.showConfirmDialog(GMGenSystem.inst, field, "How many copies?", JOptionPane.OK_CANCEL_OPTION);
if (choice == JOptionPane.CANCEL_OPTION) {
return;
}
int count = ((Number) field.getValue()).intValue();
for (InitHolder holderToCopy : getSelected()) {
if ((holderToCopy instanceof XMLCombatant) || (holderToCopy instanceof PcgCombatant)) {
if (holderToCopy instanceof PcgCombatant) {
if ((((PcgCombatant) holderToCopy).getPC().getFileName() != null) && (!((PcgCombatant) holderToCopy).getPC().getFileName().isEmpty())) {
pasteNew(holderToCopy, count);
} else {
JOptionPane.showMessageDialog(GMGenSystem.inst, "Combatant " + holderToCopy.getName() + " cannot be duplicated because it has not been saved to a valid .pcg file.", "Cannot Duplicate", JOptionPane.WARNING_MESSAGE);
}
} else {
pasteNew(holderToCopy, count);
}
} else {
JOptionPane.showMessageDialog(GMGenSystem.inst, "Combatant " + holderToCopy.getName() + " cannot be duplicated because it is not a PCGen or XML combatant.", "Cannot Duplicate", JOptionPane.WARNING_MESSAGE);
}
}
}
use of plugin.initiative.XMLCombatant in project pcgen by PCGen.
the class AddCombatant method applyButtonActionPerformed.
protected void applyButtonActionPerformed() {
String comString = (String) typeCombo.getSelectedItem();
if (comString.equals("Non Combatant")) {
comString = "-";
}
// If we are creating multiple guys, loop
if (getIntegerValue(numberField, 1) > 1) {
for (int i = 1; i <= getIntegerValue(numberField, 1); i++) {
XMLCombatant xmlcbt = new XMLCombatant(nameField.getText() + " (" + i + ')', playerField.getText(), getIntegerValue(strField, 10), getIntegerValue(dexField, 10), getIntegerValue(conField, 10), getIntegerValue(intField, 10), getIntegerValue(wisField, 10), getIntegerValue(chaField, 10), getIntegerValue(fortitudeField, 0), getIntegerValue(reflexField, 0), getIntegerValue(willField, 0), getIntegerValue(hpField, 1), getIntegerValue(hpField, 1), 0, getIntegerValue(bonusField, 0), comString, getFloatValue(crField, 1), 0);
initiative.initList.add(xmlcbt);
initiative.addTab(xmlcbt);
}
} else // If if not, just add one
{
XMLCombatant xmlcbt = new XMLCombatant(nameField.getText(), playerField.getText(), getIntegerValue(strField, 10), getIntegerValue(dexField, 10), getIntegerValue(conField, 10), getIntegerValue(intField, 10), getIntegerValue(wisField, 10), getIntegerValue(chaField, 10), getIntegerValue(fortitudeField, 0), getIntegerValue(reflexField, 0), getIntegerValue(willField, 0), getIntegerValue(hpField, 1), getIntegerValue(hpField, 1), 0, getIntegerValue(bonusField, 0), comString, getFloatValue(crField, 1), 0);
initiative.initList.add(xmlcbt);
initiative.addTab(xmlcbt);
}
initiative.refreshTable();
initiative.focusRoll();
}
use of plugin.initiative.XMLCombatant in project pcgen by PCGen.
the class Initiative method loadFromDocument.
/**
* Loads a character or party from an XML document
*
*@param character XML document containing a character or a party
* @param comp
*/
private void loadFromDocument(Document character, PCGenMessageHandler comp) {
if (character.getRootElement().getName().equals("Party")) {
Element party = character.getRootElement();
List xmlList = party.getChildren("Character");
for (Object aXmlList : xmlList) {
Element eCharacter = (Element) aXmlList;
InitHolder combatant = new XMLCombatant(eCharacter);
initList.add(combatant);
}
List pcgList = party.getChildren("PcgCombatant");
for (Object aPcgList : pcgList) {
Element eCharacter = (Element) aPcgList;
final PcgCombatant combatant = new PcgCombatant(eCharacter, comp, messageHandler);
initList.add(combatant);
addTab(combatant);
}
List eventList = party.getChildren("Event");
for (Object anEventList : eventList) {
Element eCharacter = (Element) anEventList;
InitHolder combatant = new Event(eCharacter);
initList.add(combatant);
}
List spellList = party.getChildren("Spell");
for (Object aSpellList : spellList) {
Element eCharacter = (Element) aSpellList;
InitHolder combatant = new Spell(eCharacter);
initList.add(combatant);
}
initList.calculateNumberField();
} else if (character.getRootElement().getName().equals("Character")) {
Element eCharacter = character.getRootElement();
InitHolder combatant = new XMLCombatant(eCharacter);
initList.add(combatant);
}
}
use of plugin.initiative.XMLCombatant in project pcgen by PCGen.
the class Initiative method pasteNew.
/** pastes the copied combatant
* @param toPaste
*/
private void pasteNew(InitHolder toPaste) {
if (toPaste instanceof XMLCombatant) {
XMLCombatant cb = (XMLCombatant) toPaste;
SystemInitiative init = cb.getInitiative();
SystemHP hitPoints = cb.getHP();
String name = initList.getUniqueName(cb.getName());
InitHolder newCbt = new XMLCombatant(name, toPaste.getPlayer(), init.getAttribute().getValue(), hitPoints.getAttribute().getValue(), hitPoints.getMax(), hitPoints.getCurrent(), hitPoints.getSubdual(), init.getBonus(), cb.getCombatantType(), cb.getCR());
initList.add(newCbt);
}
if (toPaste instanceof PcgCombatant) {
// PcgCombatant cb = (PcgCombatant) toPaste;
// PCGen_Frame1.getInst().loadPCFromFile(
// new File(cb.getPC().getFileName()), false, true);
// As character exists in pcgen it is automatically added in to the init list
}
refreshTable();
}
use of plugin.initiative.XMLCombatant in project pcgen by PCGen.
the class Initiative method doNonLethal.
/**
* <p>Applies non-lethal combatant. This allows other methods to damage
* combatants who are not necessarily selected at the time.</p>
*
* @param damage
* Points of damage to do.
* @param iH
* InitHolder to damage.
*/
private void doNonLethal(int damage, InitHolder iH) {
if (iH instanceof Combatant) {
Combatant cbt = (Combatant) iH;
boolean isEnough = false;
if (cbt instanceof XMLCombatant) {
XMLCombatant xmlcbt = (XMLCombatant) cbt;
if (damage > xmlcbt.getHP().getAttribute().getValue()) {
isEnough = true;
}
}
if (cbt instanceof PcgCombatant) {
PcgCombatant pcgcbt = (PcgCombatant) cbt;
PlayerCharacter pc = pcgcbt.getPC();
PCStat stat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCStat.class, "CON");
if (damage > pc.getTotalStatFor(stat)) {
isEnough = true;
}
}
if (isEnough) {
SavingThrowDialog dialog = new SavingThrowDialog(GMGenSystem.inst, true, cbt, 15, SavingThrowDialog.FORT_SAVE);
dialog.setVisible(true);
dialog.dispose();
//Show the dialog and get it's results
int returnVal = dialog.getReturnValue();
int roll = dialog.getRoll();
int total = dialog.getTotal();
int dc = dialog.getDC();
//Create a message out with the results
StringBuilder sb = new StringBuilder();
sb.append(dialog.getSaveAbbrev(dialog.getSaveType()));
sb.append(" save DC " + dc);
if (roll > 0) {
sb.append(" with a roll of " + (roll + total));
sb.append(" (" + total + " + Roll: " + roll + ')');
}
if (returnVal == SavingThrowDialog.PASS_OPTION) {
writeToCombatTabWithRound(cbt.getName() + " (" + cbt.getPlayer() + ") Passed a " + sb + " to avoid unconsiousness");
cbt.nonLethalDamage(false);
} else if (returnVal == SavingThrowDialog.FAIL_OPTION) {
writeToCombatTabWithRound(cbt.getName() + " (" + cbt.getPlayer() + ") Failed a " + sb + " to avoid unconsiousness");
cbt.nonLethalDamage(true);
}
}
combatantUpdated(cbt);
}
}
Aggregations