Search in sources :

Example 1 with PcgCombatant

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();
}
Also used : PcgCombatant(gmgen.plugin.PcgCombatant) RequestToSavePlayerCharacterMessage(pcgen.pluginmgr.messages.RequestToSavePlayerCharacterMessage) InitHolder(gmgen.plugin.InitHolder)

Example 2 with PcgCombatant

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);
            }
        }
    }
}
Also used : PcgCombatant(gmgen.plugin.PcgCombatant) SpellModel(plugin.initiative.SpellModel) DiceRollModel(plugin.initiative.DiceRollModel) PObjectModel(plugin.initiative.PObjectModel) SaveModel(plugin.initiative.SaveModel) AttackModel(plugin.initiative.AttackModel) CheckModel(plugin.initiative.CheckModel) InitHolder(gmgen.plugin.InitHolder)

Example 3 with PcgCombatant

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);
        }
    }
}
Also used : PcgCombatant(gmgen.plugin.PcgCombatant) JFormattedTextField(javax.swing.JFormattedTextField) DefaultFormatter(javax.swing.text.DefaultFormatter) InitHolder(gmgen.plugin.InitHolder) XMLCombatant(plugin.initiative.XMLCombatant) NumberFormatter(javax.swing.text.NumberFormatter)

Example 4 with PcgCombatant

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);
    }
}
Also used : PcgCombatant(gmgen.plugin.PcgCombatant)

Example 5 with PcgCombatant

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();
}
Also used : PcgCombatant(gmgen.plugin.PcgCombatant) List(java.util.List) InitHolderList(gmgen.plugin.InitHolderList) ArrayList(java.util.ArrayList) Vector(java.util.Vector) InitHolder(gmgen.plugin.InitHolder)

Aggregations

PcgCombatant (gmgen.plugin.PcgCombatant)15 InitHolder (gmgen.plugin.InitHolder)8 XMLCombatant (plugin.initiative.XMLCombatant)5 PlayerCharacter (pcgen.core.PlayerCharacter)4 InitHolderList (gmgen.plugin.InitHolderList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Combatant (gmgen.plugin.Combatant)1 Event (gmgen.plugin.Event)1 PlayerCharacterOutput (gmgen.plugin.PlayerCharacterOutput)1 Spell (gmgen.plugin.Spell)1 SystemAttribute (gmgen.plugin.SystemAttribute)1 SystemHP (gmgen.plugin.SystemHP)1 SystemInitiative (gmgen.plugin.SystemInitiative)1 ActionEvent (java.awt.event.ActionEvent)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 JFormattedTextField (javax.swing.JFormattedTextField)1 JFrame (javax.swing.JFrame)1 HyperlinkEvent (javax.swing.event.HyperlinkEvent)1