use of gmgen.plugin.PcgCombatant in project pcgen by PCGen.
the class InitiativePlugin method fileSave.
/**
* <p>
* Saves the combatants to a file
* </p>
*/
private void fileSave() {
for (int i = 0; i < theView.initList.size(); i++) {
InitHolder iH = theView.initList.get(i);
if (iH instanceof PcgCombatant) {
PcgCombatant pcgcbt = (PcgCombatant) iH;
messageHandler.handleMessage(new RequestToSavePlayerCharacterMessage(this, pcgcbt.getPC()));
}
}
theView.saveToFile();
}
use of gmgen.plugin.PcgCombatant in project pcgen by PCGen.
the class Initiative method hyperLinkSelected.
/**
* <p>Called when a hyperlink is selected in one of the text panes in {@code tpaneInfo}.
* Used to generate attack/skill, etc. dialogs.</p>
*
* @param e {@code HyperLinkEvent} that called this method.
* @param cbt {@code PcgCombatant} to perform action for.
*/
private void hyperLinkSelected(HyperlinkEvent e, InitHolder cbt) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
PObjectModel model = PObjectModel.Factory(e.getDescription());
if (model != null) {
if ((model instanceof AttackModel) && (cbt instanceof PcgCombatant)) {
InitHolder pcgcbt = cbt;
performAttack((AttackModel) model, pcgcbt);
} else if (model instanceof CheckModel) {
performCheck((CheckModel) model);
} else if (model instanceof SpellModel) {
castSpell((SpellModel) model, cbt);
} else if (model instanceof SaveModel) {
performSave((SaveModel) model, cbt);
} else if ((model instanceof DiceRollModel) && (cbt instanceof PcgCombatant)) {
performDiceRoll((DiceRollModel) model);
}
}
}
}
use of gmgen.plugin.PcgCombatant 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 gmgen.plugin.PcgCombatant in project pcgen by PCGen.
the class AttackDialog method handleTargetAction.
/**
* Handles actions from <code>m_targetsCombo</code>; sets chosen combatant
* and value of armor class.
*
* @param e Event which fired this handler
*/
protected void handleTargetAction(ActionEvent e) {
if ((m_targetsCombo != null) && (m_targetsCombo.getSelectedItem() != null) && m_targetsCombo.getSelectedItem() instanceof PcgCombatant) {
PcgCombatant combatant = (PcgCombatant) m_targetsCombo.getSelectedItem();
m_field.setValue(combatant.getPC().getDisplay().calcACOfType(m_acTypeCombo.getSelectedItem().toString()));
m_tableModel.setTarget(combatant);
}
}
use of gmgen.plugin.PcgCombatant in project pcgen by PCGen.
the class Initiative method performAttack.
/**
* <p>Performs an attack action for the specified combatant. This method
* constructs an AttackModel from the specified string and displays an attack
* dialog.</p>
* <p>If other combatants are present, this method passes the attack dialog
* a list of such combatants, and the user can choose to damage one or more of them.
* Deceased combatants are removed from this list, as is the current combatant.</p>
*
* @param attack
* @param combatant
*/
private void performAttack(AttackModel attack, InitHolder combatant) {
Vector combatants = new Vector(initList.size());
combatants.addAll(initList.stream().filter(anInitList -> (anInitList instanceof PcgCombatant) && (anInitList != combatant) && ((anInitList.getStatus() != State.Dead) || showDead.isSelected())).collect(Collectors.toList()));
AttackDialog dlg = new AttackDialog(attack, combatants);
dlg.setModal(true);
dlg.setVisible(true);
final List<Integer> dmgList = dlg.getDamageList();
final List targetList = dlg.getDamagedCombatants();
if ((dmgList != null) && (targetList != null) && (!dmgList.isEmpty()) && (!targetList.isEmpty())) {
writeToCombatTabWithRound(combatant.getName() + " successfully attacks using " + attack);
for (int i = 0; (i < dmgList.size()) && (i < targetList.size()); i++) {
if (dlg.isSubdual()) {
int subdualType = SettingsHandler.getGMGenOption(InitiativePlugin.LOG_NAME + ".Damage.Subdual", PreferencesDamagePanel.DAMAGE_SUBDUAL);
if (subdualType == PreferencesDamagePanel.DAMAGE_SUBDUAL) {
doSubdual(dmgList.get(i), (InitHolder) targetList.get(i));
} else if (subdualType == PreferencesDamagePanel.DAMAGE_NON_LETHAL) {
doNonLethal(dmgList.get(i), (InitHolder) targetList.get(i));
}
} else {
doDamage(dmgList.get(i), (InitHolder) targetList.get(i));
}
}
initList.sort();
refreshTable();
} else if ((dmgList != null) && (!dmgList.isEmpty())) {
writeToCombatTabWithRound(combatant.getName() + " successfully attacks using " + attack);
} else {
writeToCombatTabWithRound(combatant.getName() + " fails with attack using " + attack);
}
dlg.dispose();
}
Aggregations