Search in sources :

Example 11 with InitHolder

use of gmgen.plugin.InitHolder 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)

Example 12 with InitHolder

use of gmgen.plugin.InitHolder in project pcgen by PCGen.

the class Initiative method refocusCombatant.

/**  Refocuses the selected combatants */
private void refocusCombatant() {
    final List selectedList = getSelected();
    while (!selectedList.isEmpty()) {
        InitHolder iH = (InitHolder) selectedList.remove(0);
        if (iH instanceof Combatant) {
            Combatant cbt = (Combatant) iH;
            cbt.init.refocus();
            combatantUpdated(cbt);
            writeToCombatTabWithRound(cbt.getName() + " (" + cbt.getPlayer() + ") Refocused");
        }
    }
    initList.sort();
    refreshTable();
}
Also used : Combatant(gmgen.plugin.Combatant) PcgCombatant(gmgen.plugin.PcgCombatant) XMLCombatant(plugin.initiative.XMLCombatant) List(java.util.List) InitHolderList(gmgen.plugin.InitHolderList) ArrayList(java.util.ArrayList) InitHolder(gmgen.plugin.InitHolder)

Example 13 with InitHolder

use of gmgen.plugin.InitHolder in project pcgen by PCGen.

the class Initiative method nextInit.

/**  Moves to the next active initiative */
private void nextInit() {
    int oldInit = currentInit;
    setCurrentInit(currentInit - 1);
    int bleedingTime = SettingsHandler.getGMGenOption(InitiativePlugin.LOG_NAME + ".Damage.Dying", PreferencesDamagePanel.DAMAGE_DYING_END);
    for (int i = 0; i < initList.size(); i++) {
        InitHolder iH = initList.get(i);
        if (iH instanceof Event) {
            Event e = (Event) iH;
            int eInit = e.getInitiative().getCurrentInitiative();
            if (oldInit == eInit) {
                int duration = e.decDuration();
                if (duration < 0) {
                    writeToCombatTabWithRound(e.getPlayer() + "'s " + e.getName() + " ended");
                    if (e.isAlert()) {
                        JOptionPane.showMessageDialog(this, e.getEndText());
                    }
                    initList.remove(i);
                }
            }
        } else if (iH instanceof Combatant) {
            Combatant cbt = (Combatant) iH;
            int cInit = cbt.getInitiative().getCurrentInitiative();
            if (oldInit == cInit) {
                cbt.decDuration();
                if (bleedingTime == PreferencesDamagePanel.DAMAGE_DYING_INITIATIVE) {
                    bleed((Combatant) iH);
                }
            }
        }
    }
    if (currentInit <= 0) {
        int maxInit = initList.getMaxInit();
        setCurrentInit(maxInit);
        for (InitHolder anInitList : initList) {
            if (bleedingTime == PreferencesDamagePanel.DAMAGE_DYING_END) {
                if (anInitList instanceof Combatant) {
                    bleed((Combatant) anInitList);
                }
            }
            anInitList.endRound();
        }
        round++;
        writeToCombatTab("Round " + round);
        setCurrentInit(maxInit);
    } else if (!initList.initValid(currentInit)) {
        nextInit();
    }
    refreshTable();
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ActionEvent(java.awt.event.ActionEvent) Event(gmgen.plugin.Event) Combatant(gmgen.plugin.Combatant) PcgCombatant(gmgen.plugin.PcgCombatant) XMLCombatant(plugin.initiative.XMLCombatant) InitHolder(gmgen.plugin.InitHolder)

Example 14 with InitHolder

use of gmgen.plugin.InitHolder in project pcgen by PCGen.

the class Initiative method getSelected.

/**
	 *  Looks at each line in the table, and returns an ArrayList of lines that are Selected.
	 *
	 *@return    An ArrayList of currently selected InitHolders
	 */
private List<InitHolder> getSelected() {
    final List<InitHolder> retList = new ArrayList<>();
    int j = -1;
    for (int i = 0; i < combatantTable.getRowCount(); i++) {
        j++;
        InitHolder iH = initList.get(j);
        if ((iH.getStatus() == State.Dead) && !showDead.isSelected()) {
            i--;
            continue;
        }
        if ((iH instanceof Event) && !showEvents.isSelected()) {
            i--;
            continue;
        }
        if (combatantTable.isRowSelected(i)) {
            retList.add(iH);
        }
    }
    return retList;
}
Also used : ArrayList(java.util.ArrayList) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ActionEvent(java.awt.event.ActionEvent) Event(gmgen.plugin.Event) InitHolder(gmgen.plugin.InitHolder)

Example 15 with InitHolder

use of gmgen.plugin.InitHolder in project pcgen by PCGen.

the class Initiative method combatantDied.

/**
	 * Set the current initiative holder to dead
	 * @param deadIH
	 */
private void combatantDied(InitHolder deadIH) {
    writeToCombatTabWithRound(deadIH.getName() + " (" + deadIH.getPlayer() + ") Killed");
    for (InitHolder anInitList : initList) {
        String cbtType = "";
        if (anInitList instanceof Combatant) {
            Combatant cbt = (Combatant) anInitList;
            cbtType = cbt.getCombatantType();
        }
        if (cbtType.equals("Enemy") && (anInitList.getStatus() != State.Dead)) {
            return;
        }
    }
    writeToCombatTabWithRound("Combat finished, all enemies killed");
    checkDeadTabs();
}
Also used : Combatant(gmgen.plugin.Combatant) PcgCombatant(gmgen.plugin.PcgCombatant) XMLCombatant(plugin.initiative.XMLCombatant) InitHolder(gmgen.plugin.InitHolder)

Aggregations

InitHolder (gmgen.plugin.InitHolder)31 PcgCombatant (gmgen.plugin.PcgCombatant)18 XMLCombatant (plugin.initiative.XMLCombatant)13 Combatant (gmgen.plugin.Combatant)11 InitHolderList (gmgen.plugin.InitHolderList)7 ArrayList (java.util.ArrayList)7 Event (gmgen.plugin.Event)6 ActionEvent (java.awt.event.ActionEvent)6 HyperlinkEvent (javax.swing.event.HyperlinkEvent)6 ListSelectionEvent (javax.swing.event.ListSelectionEvent)6 List (java.util.List)5 Vector (java.util.Vector)2 Element (org.jdom2.Element)2 SaveModel (plugin.initiative.SaveModel)2 Spell (gmgen.plugin.Spell)1 SystemHP (gmgen.plugin.SystemHP)1 SystemInitiative (gmgen.plugin.SystemInitiative)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1