Skip to content

Commit

Permalink
- Added Power Strike
Browse files Browse the repository at this point in the history
- Added Kai Weapon bonuses
  • Loading branch information
lonevvolf committed Sep 24, 2024
1 parent b4f7990 commit 2ad0be1
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 8 deletions.
70 changes: 67 additions & 3 deletions src/ts/controller/mechanics/combatMechanics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { state, mechanicsEngine, Combat, template, SpecialObjectsUse, CombatTurn, GndDiscipline, translations, BookSeriesId, NewOrderDiscipline } from "../..";
import { state, mechanicsEngine, Combat, template, SpecialObjectsUse, CombatTurn, GndDiscipline, translations, BookSeriesId, NewOrderDiscipline, BookSeries } from "../..";
import striptags from 'striptags';

/**
Expand All @@ -18,12 +18,15 @@ export class CombatMechanics {
/** Selector for XXX surge checkbox */
public static readonly SURGE_CHECK_SELECTOR = ".psisurgecheck input";

/** Selector for XXX surge checkbox */
/** Selector for XXX Blast checkbox */
public static readonly BLAST_CHECK_SELECTOR = ".kaiblastcheck input";

/** Selector for XXX surge checkbox */
/** Selector for XXX Ray checkbox */
public static readonly RAY_CHECK_SELECTOR = ".kairaycheck input";

/** Selector for XXX Power Strike checkbox */
public static readonly POWER_STRIKE_CHECK_SELECTOR = ".powerstrikecheck input";

/**
* Render section combats
*/
Expand Down Expand Up @@ -122,6 +125,7 @@ export class CombatMechanics {
CombatMechanics.setupSurgeUI($combatUI, combat);
CombatMechanics.setupBlastUI($combatUI, combat);
CombatMechanics.setupRayUI($combatUI, combat);
CombatMechanics.setupPowerStrikeUI($combatUI, combat);
});
}

Expand Down Expand Up @@ -304,6 +308,8 @@ export class CombatMechanics {

// Check if the XXX-surge should be disabled after this turn
CombatMechanics.checkSurgeEnabled();
// Check if Power Strike checkbox should be locked in
CombatMechanics.disablePowerStrikeCheck();

// For testing, add marker to notify to the test we are ready
template.addSectionReadyMarker();
Expand Down Expand Up @@ -391,6 +397,50 @@ export class CombatMechanics {
template.addSectionReadyMarker();
}

/**
* Setup the Power Strike checkbox for a given combat
* @param $combatUI Combat UI main tag
* @param combat Related combat info
*/
private static setupPowerStrikeUI($combatUI: JQuery<HTMLElement>, combat: Combat) {

// Check if player can use Power Strike
const hasPowerStrike = state.actionChart.hasNewOrderDiscipline(NewOrderDiscipline.MagiMagic);
if (state.book.getBookSeries().id !== BookSeriesId.NewOrder ||
!hasPowerStrike || state.actionChart.getDisciplines().length < 13 || combat.mentalOnly) {
// Hide Power Strike check
$combatUI.find(".powerstrikecheck").hide();
return;
}

const $powerStrikeCheck = $combatUI.find(CombatMechanics.POWER_STRIKE_CHECK_SELECTOR);
const currentSection = state.sectionStates.getSectionState();
$powerStrikeCheck.prop("disabled", currentSection.areCombatsStarted());
$powerStrikeCheck.prop("checked", combat.powerStrike);

// Power Strike selection
const powerStrikeText = translations.text("mechanics-combat-powerstrike" );
$combatUI.find(".mechanics-combat-powerstrike").text( powerStrikeText );
$powerStrikeCheck.on("click", (e: JQuery.Event) => CombatMechanics.onPowerStrikeClick(e, $powerStrikeCheck));
}

/**
* Power Strike checkbox event handler
*/
private static onPowerStrikeClick(e: JQuery.Event, $powerStrikeCheck: JQuery<HTMLElement>) {
const $combatUI = $powerStrikeCheck.parents(".mechanics-combatUI").first();
const combatIndex = Number( $combatUI.attr( "data-combatIdx" ) );
const sectionState = state.sectionStates.getSectionState();
const combat = sectionState.combats[ combatIndex ];

const selected: boolean = $powerStrikeCheck.prop( "checked" ) ? true : false;
combat.powerStrike = selected;

CombatMechanics.updateCombatRatio( $combatUI , combat);

template.addSectionReadyMarker();
}

/**
* Setup the Kai-blast checkbox for a given combat
* @param $combatUI Combat UI main tag
Expand Down Expand Up @@ -538,6 +588,20 @@ export class CombatMechanics {
}
}

/**
* Disable the Power Strike checkbox if combats have started
*/
public static disablePowerStrikeCheck() {
const sectionState = state.sectionStates.getSectionState();
for ( let i = 0; i < sectionState.combats.length; i++ ) {
const $combatUI = $(`.mechanics-combatUI:eq(${i})`);
const $powerStrikeCheck = $combatUI.find(CombatMechanics.POWER_STRIKE_CHECK_SELECTOR);
const currentSection = state.sectionStates.getSectionState();
$powerStrikeCheck.prop("disabled", currentSection.areCombatsStarted());
$powerStrikeCheck.prop("checked", sectionState.combats[i].powerStrike);
}
}

/**
* Check if the XXX-Surge can be enabled on a given combat
* @param $combatUI Combat UI main tag
Expand Down
10 changes: 9 additions & 1 deletion src/ts/model/actionChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,6 @@ export class ActionChart {
increment: combat.getFinalSurgeBonus(MgnDiscipline.PsiSurge)
});
}

} else if (!combat.noMindblast) {
if (((this.hasKaiDiscipline(KaiDiscipline.Mindblast) || this.hasMgnDiscipline(MgnDiscipline.PsiSurge) ||
this.hasGndDiscipline(GndDiscipline.KaiSurge)) && state.book.getBookSeries().id !== BookSeriesId.NewOrder)
Expand All @@ -1018,6 +1017,15 @@ export class ActionChart {
}
}

if (!combat.mentalOnly) {
if (combat.powerStrike) {
bonuses.push({
concept: translations.text("powerstrike"),
increment: +1
});
}
}

// Other objects (not weapons). Ex. shield. They are not applied for bow combats
if (!combat.mentalOnly && !combat.bowCombat && !combat.noObjectBonuses) {
this.enumerateObjectsAsItems((o: Item) => {
Expand Down
5 changes: 4 additions & 1 deletion src/ts/model/combat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Combat {

/** The state of the kai-ray usage (0: not used, 1: selected, 2: used) */
public kaiRayUse = 0;

/** The CS multiplier to apply to Mindblast/Psi-Surge attacks. It can have decimals (ex. 0.5) */
public mindblastMultiplier = 1;

Expand Down Expand Up @@ -143,6 +143,9 @@ export class Combat {
/** Kai-blast is activated on this combat? */
public kaiBlast = false;

/** Power Strike is activated on this combat? */
public powerStrike = false;

/** Kai-blast rolls */
public kaiBlastRolls = 2;

Expand Down
2 changes: 2 additions & 0 deletions src/ts/views/viewsUtils/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class Translations {
"mindblast" : "Mindblast",
"psisurge" : "Psi-surge",
"kaisurge" : "Kai-surge",
"powerstrike" : "Power Strike",
"countAsObjects" : "(Counts as {0} items)",
"circleFire" : "Circle of Fire",
"circleLight" : "Circle of Light",
Expand Down Expand Up @@ -105,6 +106,7 @@ export class Translations {
"mechanics-combat-kaisurge" : "Kai-surge: +{0} CS, -{1} EP per round",
"mechanics-combat-kaiblast" : "Kai-blast: -4EP, enemy loses a Random Number{0} of EP {1} times",
"mechanics-combat-kairay" : "Kai-ray: -4EP, enemy loses {0}EP (one time per combat)",
"mechanics-combat-powerstrike" : "Power Strike: -3 EP (once), +1 CS, -1 EP to enemy per round",
"sectionModifier" : "Section modifier",
"objectsUse" : "Objects use",
"enemyMindblast" : "Enemy mindblast",
Expand Down
Loading

0 comments on commit 2ad0be1

Please sign in to comment.