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();
}
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();
}
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();
}
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;
}
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();
}
Aggregations