2021-02-11 00:07:13 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-02-09 23:32:55 +01:00
|
|
|
import { SoSUtility } from "./sos-utility.js";
|
2021-01-21 17:16:01 +01:00
|
|
|
|
2021-02-11 00:07:13 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-01-21 17:16:01 +01:00
|
|
|
export class SoSFlipDialog extends Dialog {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
constructor(flipData, html) {
|
|
|
|
let conf = {
|
|
|
|
title: 'Flip Dialog',
|
|
|
|
content: html,
|
|
|
|
buttons: {
|
2021-01-24 23:18:50 +01:00
|
|
|
'flip-close': { label: 'Cancel and Close', callback: html => this.onFlipClose() }
|
2021-01-21 17:16:01 +01:00
|
|
|
},
|
|
|
|
default: 'flip'
|
|
|
|
};
|
2021-02-09 23:32:55 +01:00
|
|
|
super(conf, { classes: ["sosdialog"], width: 800 });
|
2021-01-21 17:16:01 +01:00
|
|
|
|
|
|
|
this.flipData = flipData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
onFlipClose( ) {
|
2021-01-24 23:18:50 +01:00
|
|
|
this.close();
|
2021-01-21 17:16:01 +01:00
|
|
|
}
|
|
|
|
|
2021-02-09 23:32:55 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
updateScoreBase( ) {
|
|
|
|
let scoreBase = 0;
|
2021-02-11 00:07:13 +01:00
|
|
|
if ( this.flipData.mode == 'skill' || this.flipData.mode == 'weapon' ) {
|
2021-02-09 23:32:55 +01:00
|
|
|
let statKey = $('#statSelect').val();
|
|
|
|
this.flipData.stat = duplicate( this.flipData.statList[ statKey ] );
|
|
|
|
scoreBase = Math.floor(this.flipData.statList[ statKey ].value / 2) + this.flipData.skill.data.value;
|
|
|
|
} else { //Stat mode
|
|
|
|
let statKey = $('#statSelect').val();
|
2021-02-17 20:45:52 +01:00
|
|
|
scoreBase = this.flipData.stat.value;
|
2021-02-09 23:32:55 +01:00
|
|
|
}
|
2021-02-17 20:45:52 +01:00
|
|
|
this.flipData.woundMalus = 0;
|
|
|
|
this.flipData.woundMalus += ($('#wound-light-checkbox').is(":checked")) ? (-1) : 0;
|
|
|
|
this.flipData.woundMalus += ($('#wound-moderate-checkbox').is(":checked")) ? (-2) : 0;
|
|
|
|
this.flipData.woundMalus += ($('#wound-severe-checkbox').is(":checked")) ? (-3) : 0;
|
|
|
|
this.flipData.woundMalus += ($('#wound-critical-checkbox').is(":checked")) ? (-4) : 0;
|
2021-02-09 23:32:55 +01:00
|
|
|
scoreBase += this.flipData.malusConsequence;
|
2021-02-16 23:01:42 +01:00
|
|
|
scoreBase += this.flipData.bonusConsequence;
|
2021-02-17 20:45:52 +01:00
|
|
|
scoreBase += this.flipData.woundMalus;
|
|
|
|
$('#wound-malus').text(this.flipData.woundMalus);
|
2021-02-09 23:32:55 +01:00
|
|
|
$('#score-base').text( scoreBase);
|
|
|
|
}
|
|
|
|
|
2021-01-21 17:16:01 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async updateFlip( flipData ) {
|
2021-02-09 23:32:55 +01:00
|
|
|
//console.log("UPDATE !!!", flipData);
|
2021-01-21 17:16:01 +01:00
|
|
|
$('.view-deck').remove();
|
|
|
|
$("#view-deck").append(await flipData.actor.cardDeck.getDeckHTML());
|
|
|
|
|
|
|
|
$('.view-edge').remove();
|
2021-02-16 23:01:42 +01:00
|
|
|
$("#view-edge").append(await flipData.actor.cardDeck.getEdgeHTMLForFlip());
|
2021-01-24 23:18:50 +01:00
|
|
|
|
2021-02-09 23:32:55 +01:00
|
|
|
this.updateScoreBase();
|
|
|
|
|
2021-01-24 23:18:50 +01:00
|
|
|
$('.edge-card').click((event) => {
|
2021-02-11 00:07:13 +01:00
|
|
|
let flipData = this.flipData;
|
2021-01-24 23:18:50 +01:00
|
|
|
flipData.modifier = $('#modifier').val();
|
2021-02-11 00:07:13 +01:00
|
|
|
flipData.tn = (flipData.target) ? flipData.target.actor.data.data.scores.defense.value : $('#tn').val();
|
2021-01-24 23:18:50 +01:00
|
|
|
flipData.edgeName = event.currentTarget.attributes['data-edge-card'].value;
|
2021-02-16 23:01:42 +01:00
|
|
|
flipData.edgeLuck = $('#edge-luck').is(":checked");
|
2021-01-24 23:18:50 +01:00
|
|
|
flipData.cardOrigin = "Edge";
|
2021-02-11 00:07:13 +01:00
|
|
|
if ( flipData.mode == 'skill' || flipData.mode == 'weapon') {
|
2021-01-24 23:18:50 +01:00
|
|
|
flipData.stat = duplicate( flipData.statList[ $('#statSelect').val() ] );
|
|
|
|
}
|
2021-02-11 00:07:13 +01:00
|
|
|
console.log("CLICK:", flipData);
|
2021-01-24 23:18:50 +01:00
|
|
|
this.flipData.actor.cardDeck.doFlipFromDeckOrEdge(flipData);
|
|
|
|
this.onFlipClose();
|
|
|
|
});
|
|
|
|
|
2021-01-21 17:16:01 +01:00
|
|
|
}
|
|
|
|
|
2021-02-09 23:32:55 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-02-16 23:01:42 +01:00
|
|
|
updateConsequenceMalus(event) {
|
|
|
|
this.flipData.consequencesSelected = $('#consequenceSelectMalus').val();
|
2021-02-09 23:32:55 +01:00
|
|
|
let malusConsequence = 0;
|
|
|
|
for (let consequenceId of this.flipData.consequencesSelected) {
|
|
|
|
let consequence = this.flipData.consequencesList.find( item => item._id == consequenceId);
|
|
|
|
console.log(consequence, consequenceId);
|
|
|
|
malusConsequence += SoSUtility.getConsequenceMalus( consequence.data.severity );
|
|
|
|
}
|
|
|
|
$('#consequence-malus').text(malusConsequence);
|
|
|
|
this.flipData.malusConsequence = malusConsequence;
|
|
|
|
this.updateScoreBase();
|
|
|
|
}
|
|
|
|
|
2021-02-16 23:01:42 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
updateConsequenceBonus(event) {
|
|
|
|
this.flipData.consequencesSelected = $('#consequenceSelectBonus').val();
|
|
|
|
let bonusConsequence = 0;
|
|
|
|
for (let consequenceId of this.flipData.consequencesSelected) {
|
|
|
|
let consequence = this.flipData.consequencesList.find( item => item._id == consequenceId);
|
|
|
|
console.log(consequence, consequenceId);
|
|
|
|
bonusConsequence += SoSUtility.getConsequenceBonus( consequence.data.severity );
|
|
|
|
}
|
|
|
|
$('#consequence-bonus').text(bonusConsequence);
|
|
|
|
this.flipData.bonusConsequence = bonusConsequence;
|
|
|
|
this.updateScoreBase();
|
|
|
|
}
|
|
|
|
|
2021-01-21 17:16:01 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
this.bringToTop();
|
|
|
|
|
|
|
|
var dialog = this;
|
|
|
|
|
|
|
|
function onLoad() {
|
|
|
|
let flipData = dialog.flipData;
|
|
|
|
dialog.updateFlip(flipData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup everything onload
|
|
|
|
$(function () { onLoad(); });
|
|
|
|
|
2021-02-09 23:32:55 +01:00
|
|
|
html.find('#statSelect').change((event) => {
|
|
|
|
this.updateFlip(dialog.flipData );
|
|
|
|
} );
|
|
|
|
|
2021-02-16 23:01:42 +01:00
|
|
|
html.find('#consequenceSelectMalus').change((event) => {
|
|
|
|
this.updateConsequenceMalus( event );
|
|
|
|
} );
|
|
|
|
html.find('#consequenceSelectBonus').change((event) => {
|
|
|
|
this.updateConsequenceBonus( event );
|
2021-02-09 23:32:55 +01:00
|
|
|
} );
|
2021-02-17 20:45:52 +01:00
|
|
|
html.find('#wound-light-checkbox').change((event) => {
|
|
|
|
this.updateScoreBase( event );
|
|
|
|
} );
|
|
|
|
html.find('#wound-moderate-checkbox').change((event) => {
|
|
|
|
this.updateScoreBase( event );
|
|
|
|
} );
|
|
|
|
html.find('#wound-severe-checkbox').change((event) => {
|
|
|
|
this.updateScoreBase( event );
|
|
|
|
} );
|
|
|
|
html.find('#wound-critical-checkbox').change((event) => {
|
|
|
|
this.updateScoreBase( event );
|
|
|
|
} );
|
2021-02-09 23:32:55 +01:00
|
|
|
|
2021-01-24 23:18:50 +01:00
|
|
|
html.find('.class-view-deck').click((event) => {
|
2021-02-11 00:07:13 +01:00
|
|
|
let flipData = this.flipData;
|
2021-01-24 23:18:50 +01:00
|
|
|
flipData.modifier = html.find('#modifier').val();
|
2021-02-11 00:07:13 +01:00
|
|
|
if ( flipData.mode == 'skill' || flipData.mode == 'weapon') {
|
2021-01-25 11:16:45 +01:00
|
|
|
let statKey = $('#statSelect').val();
|
|
|
|
flipData.stat = duplicate( flipData.statList[ statKey ] );
|
2021-01-24 23:18:50 +01:00
|
|
|
}
|
|
|
|
flipData.cardOrigin = "Deck";
|
2021-02-11 00:07:13 +01:00
|
|
|
flipData.tn = (flipData.target) ? flipData.target.actor.data.data.scores.defense.value : $('#tn').val();
|
2021-01-24 23:18:50 +01:00
|
|
|
dialog.flipData.actor.cardDeck.doFlipFromDeckOrEdge(flipData);
|
|
|
|
dialog.onFlipClose();
|
2021-01-21 17:16:01 +01:00
|
|
|
});
|
2021-01-24 23:18:50 +01:00
|
|
|
|
2021-01-21 17:16:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|