v12 support
This commit is contained in:
@@ -10,7 +10,7 @@ export class SoSActorSheet extends ActorSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["sos", "sheet", "actor"],
|
||||
template: "systems/foundryvtt-shadows-over-sol/templates/actor-sheet.html",
|
||||
width: 640,
|
||||
@@ -81,7 +81,7 @@ export class SoSActorSheet extends ActorSheet {
|
||||
formData.weapons = this.actor.items.filter( item => item.type == 'weapon');
|
||||
formData.armors = this.actor.items.filter( item => item.type == 'armor');
|
||||
formData.totalEncumbrance = SoSUtility.computeEncumbrance(this.actor.items);
|
||||
formData.wounds = duplicate(this.actor.system.wounds);
|
||||
formData.wounds = foundry.utils.duplicate(this.actor.system.wounds);
|
||||
formData.isGM = game.user.isGM;
|
||||
formData.currentWounds = this.actor.computeCurrentWounds();
|
||||
formData.totalWounds = this.actor.system.scores.wound.value;
|
||||
|
||||
@@ -61,24 +61,24 @@ export class SoSActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
checkDeck() {
|
||||
if ( !this.cardDeck && this.hasPlayerOwner ) {
|
||||
this.cardDeck = new SoSCardDeck();
|
||||
this.cardDeck.initCardDeck( this, this.system.internals.deck );
|
||||
if ( !this.system.cardDeck && this.hasPlayerOwner ) {
|
||||
this.system.cardDeck = new SoSCardDeck();
|
||||
this.system.cardDeck.initCardDeck( this, this.system.internals.deck );
|
||||
}
|
||||
if ( !this.hasPlayerOwner ) {
|
||||
this.cardDeck = game.system.sos.gmDeck.GMdeck;
|
||||
console.log("DECK : ", this.cardDeck);
|
||||
this.system.cardDeck = game.system.sos.gmDeck.GMdeck;
|
||||
console.log("DECK : ", this.system.cardDeck);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDeckSize() {
|
||||
return this.cardDeck.getDeckSize();
|
||||
return this.system.cardDeck.getDeckSize();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getEdgesCard( ) {
|
||||
let edgesCard = duplicate(this.cardDeck.data.cardEdge);
|
||||
let edgesCard = foundry.utils.duplicate(this.system.cardDeck.data.cardEdge);
|
||||
for (let edge of edgesCard) {
|
||||
edge.path = `systems/foundryvtt-shadows-over-sol/img/cards/${edge.cardName}.webp`
|
||||
}
|
||||
@@ -86,36 +86,36 @@ export class SoSActor extends Actor {
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
resetDeckFull( ) {
|
||||
this.cardDeck.shuffleDeck();
|
||||
this.cardDeck.drawEdge( this.system.scores.edge.value );
|
||||
this.system.cardDeck.shuffleDeck();
|
||||
this.system.cardDeck.drawEdge( this.system.scores.edge.value );
|
||||
this.saveDeck();
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
drawNewEdge( ) {
|
||||
this.cardDeck.drawEdge( 1 );
|
||||
this.system.cardDeck.drawEdge( 1 );
|
||||
this.saveDeck();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
discardEdge( cardName ) {
|
||||
this.cardDeck.discardEdge( cardName );
|
||||
this.system.cardDeck.discardEdge( cardName );
|
||||
this.saveDeck();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
resetDeck( ) {
|
||||
this.cardDeck.resetDeck();
|
||||
this.system.cardDeck.resetDeck();
|
||||
this.saveDeck();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
saveDeck( ) {
|
||||
let deck = { deck: duplicate(this.cardDeck.data.deck),
|
||||
discard: duplicate(this.cardDeck.data.discard),
|
||||
cardEdge: duplicate(this.cardDeck.data.cardEdge)
|
||||
let deck = { deck: foundry.utils.duplicate(this.system.cardDeck.data.deck),
|
||||
discard: foundry.utils.duplicate(this.system.cardDeck.data.discard),
|
||||
cardEdge: foundry.utils.duplicate(this.system.cardDeck.data.cardEdge)
|
||||
}
|
||||
if ( this.hasPlayerOwner ) {
|
||||
this.update( { 'data.internals.deck': deck });
|
||||
this.update( { 'system.internals.deck': deck });
|
||||
} else {
|
||||
game.settings.set("foundryvtt-shadows-over-sol", "gmDeck", deck );
|
||||
}
|
||||
@@ -213,7 +213,7 @@ export class SoSActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async updateWound(woundName, value) {
|
||||
let wounds = duplicate(this.system.wounds)
|
||||
let wounds = foundry.utils.duplicate(this.system.wounds)
|
||||
wounds[woundName] = value;
|
||||
await this.update( { 'system.wounds': wounds } );
|
||||
}
|
||||
@@ -246,13 +246,13 @@ export class SoSActor extends Actor {
|
||||
|
||||
let flipData = {
|
||||
mode: 'stat',
|
||||
stat: duplicate(this.system.stats[statKey]),
|
||||
stat: foundry.utils.duplicate(this.system.stats[statKey]),
|
||||
actor: this,
|
||||
modifierList: SoSUtility.fillRange(-10, +10),
|
||||
tnList: SoSUtility.fillRange(6, 20),
|
||||
consequencesList: duplicate( this.getApplicableConsequences() ),
|
||||
consequencesList: foundry.utils.duplicate( this.getApplicableConsequences() ),
|
||||
weaknessList: this.items.filter( item => item.type == 'weakness' ),
|
||||
wounds: duplicate( this.system.wounds),
|
||||
wounds: foundry.utils.duplicate( this.system.wounds),
|
||||
malusConsequence: 0,
|
||||
bonusConsequence: 0,
|
||||
woundMalus: 0
|
||||
@@ -265,12 +265,12 @@ export class SoSActor extends Actor {
|
||||
async rollSkill( skill ) {
|
||||
let flipData = {
|
||||
mode: 'skill',
|
||||
statList: duplicate(this.system.stats),
|
||||
statList: foundry.utils.duplicate(this.system.stats),
|
||||
selectedStat: 'strength',
|
||||
consequencesList: duplicate( this.getApplicableConsequences() ),
|
||||
wounds: duplicate( this.system.wounds),
|
||||
consequencesList: foundry.utils.duplicate( this.getApplicableConsequences() ),
|
||||
wounds: foundry.utils.duplicate( this.system.wounds),
|
||||
skillExperienceList: this.getSkillExperience( skill.name),
|
||||
skill: duplicate(skill),
|
||||
skill: foundry.utils.duplicate(skill),
|
||||
actor: this,
|
||||
modifierList: SoSUtility.fillRange(-10, +10),
|
||||
tnList: SoSUtility.fillRange(6, 20),
|
||||
@@ -301,14 +301,14 @@ export class SoSActor extends Actor {
|
||||
|
||||
let flipData = {
|
||||
mode: 'weapon',
|
||||
weapon: duplicate(weapon),
|
||||
statList: duplicate(this.system.stats),
|
||||
weapon: foundry.utils.duplicate(weapon),
|
||||
statList: foundry.utils.duplicate(this.system.stats),
|
||||
target: target,
|
||||
selectedStat: selectedStatName,
|
||||
consequencesList: duplicate( this.getApplicableConsequences() ),
|
||||
consequencesList: foundry.utils.duplicate( this.getApplicableConsequences() ),
|
||||
skillExperienceList: this.getSkillExperience( skill.name),
|
||||
wounds: duplicate( this.system.wounds),
|
||||
skill: duplicate(skill),
|
||||
wounds: foundry.utils.duplicate( this.system.wounds),
|
||||
skill: foundry.utils.duplicate(skill),
|
||||
actor: this,
|
||||
modifierList: SoSUtility.fillRange(-10, +10),
|
||||
tnList: SoSUtility.fillRange(6, 20),
|
||||
@@ -349,14 +349,14 @@ export class SoSActor extends Actor {
|
||||
async applyConsequenceWound( severity, consequenceName) {
|
||||
if ( severity == 'none') return; // Nothing !
|
||||
|
||||
let wounds = duplicate(this.system.wounds);
|
||||
let wounds = foundry.utils.duplicate(this.system.wounds);
|
||||
if (severity == 'light' ) wounds.light += 1;
|
||||
if (severity == 'moderate' ) wounds.moderate += 1;
|
||||
if (severity == 'severe' ) wounds.severe += 1;
|
||||
if (severity == 'critical' ) wounds.critical += 1;
|
||||
|
||||
let sumWound = wounds.light + (wounds.moderate*2) + (wounds.severe*3) + (wounds.critical*4);
|
||||
let currentWounds = duplicate(this.system.scores.currentwounds);
|
||||
let currentWounds = foundry.utils.duplicate(this.system.scores.currentwounds);
|
||||
currentWounds.value = sumWound;
|
||||
await this.update( { 'data.scores.currentwounds': currentWounds, 'data.wounds': wounds } );
|
||||
|
||||
@@ -403,7 +403,7 @@ export class SoSActor extends Actor {
|
||||
return;
|
||||
}
|
||||
|
||||
let wounds = duplicate(this.system.wounds);
|
||||
let wounds = foundry.utils.duplicate(this.system.wounds);
|
||||
for (let wound of flipData.woundsList ) {
|
||||
if (wound == 'L' ) wounds.light += 1;
|
||||
if (wound == 'M' ) wounds.moderate += 1;
|
||||
@@ -412,7 +412,7 @@ export class SoSActor extends Actor {
|
||||
}
|
||||
// Compute total
|
||||
let sumWound = wounds.light + (wounds.moderate*2) + (wounds.severe*3) + (wounds.critical*4);
|
||||
let currentWounds = duplicate(this.system.scores.currentwounds);
|
||||
let currentWounds = foundry.utils.duplicate(this.system.scores.currentwounds);
|
||||
currentWounds.value = sumWound;
|
||||
if ( sumWound >= this.system.scores.wound.value) {
|
||||
let bleeding = this.items.find( item => item.type == 'consequence' && item.name == 'Bleeding');
|
||||
|
||||
@@ -8,7 +8,7 @@ export class SoSItemSheet extends ItemSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["foundryvtt-shadows-over-sol", "sheet", "item"],
|
||||
template: "systems/foundryvtt-shadows-over-sol/templates/item-sheet.html",
|
||||
width: 550,
|
||||
|
||||
@@ -8,7 +8,7 @@ const IDX2CARDFAMILY = ['c', 'd', 'h', 's'];
|
||||
export class SoSCardDeck {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
initCardDeck(actor, savedDeck = undefined ) {
|
||||
async initCardDeck(actor, savedDeck = undefined ) {
|
||||
|
||||
this.data = {};
|
||||
|
||||
@@ -18,27 +18,28 @@ export class SoSCardDeck {
|
||||
this.data.cardEdge = [];
|
||||
|
||||
if ( savedDeck.deck && savedDeck.deck.length > 0 ) {
|
||||
this.data.deck = duplicate(savedDeck.deck);
|
||||
this.data.deck = foundry.utils.duplicate(savedDeck.deck);
|
||||
}
|
||||
if ( savedDeck.discard && savedDeck.discard.length > 0 ) {
|
||||
this.data.discard = duplicate(savedDeck.discard);
|
||||
this.data.discard = foundry.utils.duplicate(savedDeck.discard);
|
||||
}
|
||||
if ( savedDeck.cardEdge && savedDeck.cardEdge.length > 0 ) {
|
||||
this.data.cardEdge = duplicate(savedDeck.cardEdge);
|
||||
this.data.cardEdge = foundry.utils.duplicate(savedDeck.cardEdge);
|
||||
}
|
||||
|
||||
this.data.actor = actor;
|
||||
if ( this.data.deck.length == 0 && this.data.discard.length == 0) {
|
||||
this.shuffleDeck();
|
||||
await this.shuffleDeck();
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
shuffleDeck() {
|
||||
async shuffleDeck() {
|
||||
this.cleanCardList();
|
||||
// Randomize deck
|
||||
while (this.data.deck.length != NB_POKER_CARD) {
|
||||
let idx = new Roll("1d54").roll( {async:false} ).total;
|
||||
let roll = await new Roll("1d54").roll();
|
||||
let idx = roll.total;
|
||||
if (!this.data.cardState[idx - 1]) {
|
||||
if (idx == 53) { // Red Joker
|
||||
this.data.deck.push( { cardName: 'jr' } );
|
||||
@@ -57,8 +58,8 @@ export class SoSCardDeck {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
resetDeck() {
|
||||
let newdeck = duplicate(this.data.deck).concat( duplicate (this.data.discard) )
|
||||
async resetDeck() {
|
||||
let newdeck = foundry.utils.duplicate(this.data.deck).concat( foundry.utils.duplicate (this.data.discard) )
|
||||
this.data.discard = [] // Reinit discard pile
|
||||
this.data.deck = []
|
||||
let decklen = newdeck.length
|
||||
@@ -68,7 +69,8 @@ export class SoSCardDeck {
|
||||
}
|
||||
// Randomize deck
|
||||
while (this.data.deck.length != decklen) {
|
||||
let idx = new Roll("1d"+decklen).roll({async : false}).total
|
||||
let roll = await new Roll("1d"+decklen).roll()
|
||||
let idx = roll.total
|
||||
//console.log("Deck stuff", this.data.deck.length, decklen, idx)
|
||||
if (!cardState[idx-1]) {
|
||||
this.data.deck.push( newdeck[idx-1] )
|
||||
@@ -104,7 +106,7 @@ export class SoSCardDeck {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDeckSize() {
|
||||
return this.data.deck.length;
|
||||
return this.data.deck.length;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
@@ -14,7 +14,7 @@ export class SoSCombat extends Combat {
|
||||
this.phaseSetup = {}; // Reset each new round/update
|
||||
for (let combatant of this.combatants) {
|
||||
this.setInitiative(combatant.id, -1); // Reset init
|
||||
let uniq = randomID(16)
|
||||
let uniq = foundry.utils.randomID(16)
|
||||
const name = combatant.actor ? combatant.actor.name : combatant.name;
|
||||
if (combatant.players && combatant.players[0] ) {
|
||||
// A player controls this combatant -> message !
|
||||
@@ -80,7 +80,7 @@ export class SoSCombat extends Combat {
|
||||
|
||||
// Now push specific messages
|
||||
for (let action of actionList) {
|
||||
let uniq = randomID(16);
|
||||
let uniq = foundry.utils.randomID(16);
|
||||
action.uniqId = uniq; // Easy tracking with chat messages
|
||||
const name = action.combatant.actor ? action.combatant.actor.name : action.combatant.name;
|
||||
if (action.combatant.players[0]) {
|
||||
|
||||
@@ -53,11 +53,11 @@ export class SoSDialogCombatActions extends Dialog {
|
||||
super.close();
|
||||
|
||||
let action3Index = $('#action3').val();
|
||||
let action3 = duplicate(this.combatActions.actionsList[action3Index]);
|
||||
let action3 = foundry.utils.duplicate(this.combatActions.actionsList[action3Index]);
|
||||
let action2Index = $('#action2').val();
|
||||
let action2 = duplicate(this.combatActions.actionsList[action2Index]);
|
||||
let action2 = foundry.utils.duplicate(this.combatActions.actionsList[action2Index]);
|
||||
let action1Index = $('#action1').val();
|
||||
let action1 = duplicate(this.combatActions.actionsList[action1Index]);
|
||||
let action1 = foundry.utils.duplicate(this.combatActions.actionsList[action1Index]);
|
||||
|
||||
let combatant3Id = $('#combatant3').val();
|
||||
let combatant2Id = $('#combatant2').val();
|
||||
|
||||
@@ -29,7 +29,7 @@ export class SoSFlipDialog extends Dialog {
|
||||
let scoreBase = 0;
|
||||
if ( this.flipData.mode == 'skill' || this.flipData.mode == 'weapon' ) {
|
||||
let statKey = $('#statSelect').val();
|
||||
this.flipData.stat = duplicate( this.flipData.statList[ statKey ] );
|
||||
this.flipData.stat = foundry.utils.duplicate( this.flipData.statList[ statKey ] );
|
||||
scoreBase = Math.floor(this.flipData.statList[ statKey ].value / 2) + this.flipData.skill.system.value
|
||||
} else { //Stat mode
|
||||
let statKey = $('#statSelect').val();
|
||||
@@ -52,10 +52,10 @@ export class SoSFlipDialog extends Dialog {
|
||||
async updateFlip( flipData ) {
|
||||
//console.log("UPDATE !!!", flipData);
|
||||
$('.view-deck').remove();
|
||||
$("#view-deck").append(await flipData.actor.cardDeck.getDeckHTML());
|
||||
$("#view-deck").append(await flipData.actor.system.cardDeck.getDeckHTML());
|
||||
|
||||
$('.view-edge').remove();
|
||||
$("#view-edge").append(await flipData.actor.cardDeck.getEdgeHTMLForFlip());
|
||||
$("#view-edge").append(await flipData.actor.system.cardDeck.getEdgeHTMLForFlip());
|
||||
|
||||
this.updateScoreBase();
|
||||
|
||||
@@ -67,10 +67,10 @@ export class SoSFlipDialog extends Dialog {
|
||||
flipData.edgeLuck = $('#edge-luck').is(":checked");
|
||||
flipData.cardOrigin = "Edge";
|
||||
if ( flipData.mode == 'skill' || flipData.mode == 'weapon') {
|
||||
flipData.stat = duplicate( flipData.statList[ $('#statSelect').val() ] );
|
||||
flipData.stat = foundry.utils.duplicate( flipData.statList[ $('#statSelect').val() ] );
|
||||
}
|
||||
console.log("CLICK:", flipData);
|
||||
this.flipData.actor.cardDeck.doFlipFromDeckOrEdge(flipData);
|
||||
this.flipData.actor.system.cardDeck.doFlipFromDeckOrEdge(flipData);
|
||||
this.onFlipClose();
|
||||
});
|
||||
|
||||
@@ -161,11 +161,11 @@ export class SoSFlipDialog extends Dialog {
|
||||
flipData.modifier = html.find('#modifier').val();
|
||||
if ( flipData.mode == 'skill' || flipData.mode == 'weapon') {
|
||||
let statKey = $('#statSelect').val();
|
||||
flipData.stat = duplicate( flipData.statList[ statKey ] );
|
||||
flipData.stat = foundry.utils.duplicate( flipData.statList[ statKey ] );
|
||||
}
|
||||
flipData.cardOrigin = "Deck";
|
||||
flipData.tn = (flipData.target) ? flipData.target.actor.system.scores.defense.value : $('#tn').val();
|
||||
dialog.flipData.actor.cardDeck.doFlipFromDeckOrEdge(flipData);
|
||||
dialog.flipData.actor.system.cardDeck.doFlipFromDeckOrEdge(flipData);
|
||||
dialog.onFlipClose();
|
||||
});
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ export class SoSGMDeck extends Dialog {
|
||||
/* -------------------------------------------- */
|
||||
saveDeck( ) {
|
||||
let deck = {
|
||||
deck: duplicate(this.GMdeck.data.deck),
|
||||
discard: duplicate(this.GMdeck.data.discard),
|
||||
cardEdge: duplicate(this.GMdeck.data.cardEdge)
|
||||
deck: foundry.utils.duplicate(this.GMdeck.data.deck),
|
||||
discard: foundry.utils.duplicate(this.GMdeck.data.discard),
|
||||
cardEdge: foundry.utils.duplicate(this.GMdeck.data.cardEdge)
|
||||
}
|
||||
game.settings.set("foundryvtt-shadows-over-sol", "gmDeck", deck );
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ Hooks.once("ready", function () {
|
||||
});
|
||||
}
|
||||
ClassCounter.registerUsageCount()
|
||||
SoSUtility.ready()
|
||||
|
||||
welcomeMessage();
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/* -------------------------------------------- */
|
||||
/* -------------------------------------------- */
|
||||
import { SoSCombat } from "./sos-combat.js";
|
||||
import { SoSDialogCombatActions } from "./sos-dialog-combat-actions.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
const severity2malus = { "none": 0, "light": -1, "moderate": -2, "severe": -3, "critical": -4};
|
||||
/* -------------------------------------------- */
|
||||
const severity2bonus = { "none": 0, "light": 1, "moderate": 2, "severe": 3, "critical": 4};
|
||||
/* -------------------------------------------- */
|
||||
const severity2malus = { "none": 0, "light": -1, "moderate": -2, "severe": -3, "critical": -4 };
|
||||
/* -------------------------------------------- */
|
||||
const severity2bonus = { "none": 0, "light": 1, "moderate": 2, "severe": 3, "critical": 4 };
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class SoSUtility {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* -------------------------------------------- */
|
||||
export class SoSUtility {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async preloadHandlebarsTemplates() {
|
||||
|
||||
|
||||
const templatePaths = [
|
||||
'systems/foundryvtt-shadows-over-sol/templates/actor-sheet.html',
|
||||
'systems/foundryvtt-shadows-over-sol/templates/editor-notes-gm.html',
|
||||
@@ -27,31 +27,41 @@ export class SoSUtility {
|
||||
|
||||
'systems/foundryvtt-shadows-over-sol/templates/dialog-flip.html'
|
||||
]
|
||||
return loadTemplates(templatePaths);
|
||||
return loadTemplates(templatePaths);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static fillRange (start, end) {
|
||||
static ready() {
|
||||
Handlebars.registerHelper('select', function (selected, options) {
|
||||
const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected));
|
||||
const rgx = new RegExp(' value=[\"\']' + escapedValue + '[\"\']');
|
||||
const html = options.fn(this);
|
||||
return html.replace(rgx, "$& selected");
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static fillRange(start, end) {
|
||||
return Array(end - start + 1).fill().map((item, index) => start + index);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static onSocketMesssage( msg ) {
|
||||
if( !game.user.isGM ) return; // Only GM
|
||||
|
||||
if (msg.name == 'msg_declare_actions' ) {
|
||||
let combat = game.combats.get( msg.data.combatId); // Get the associated combat
|
||||
combat.setupActorActions( msg.data );
|
||||
/* -------------------------------------------- */
|
||||
static onSocketMesssage(msg) {
|
||||
if (!game.user.isGM) return; // Only GM
|
||||
|
||||
if (msg.name == 'msg_declare_actions') {
|
||||
let combat = game.combats.get(msg.data.combatId); // Get the associated combat
|
||||
combat.setupActorActions(msg.data);
|
||||
} else if (msg.name == 'msg_close_action') {
|
||||
game.combat.closeAction( msg.data.uniqId );
|
||||
game.combat.closeAction(msg.data.uniqId);
|
||||
} else if (msg.name == 'msg_request_defense') {
|
||||
SoSUtility.applyDamage( msg.data );
|
||||
SoSUtility.applyDamage(msg.data);
|
||||
} else if (msg.name == 'msg_reaction_cover') {
|
||||
SoSUtility.reactionCover( msg.data.uniqId );
|
||||
SoSUtility.reactionCover(msg.data.uniqId);
|
||||
} else if (msg.name == 'msg_reaction_melee') {
|
||||
SoSUtility.reactionMelee( msg.data.uniqId );
|
||||
SoSUtility.reactionMelee(msg.data.uniqId);
|
||||
} else if (msg.name == 'msg_reaction_hit') {
|
||||
SoSUtility.reactionHit( msg.data.uniqId );
|
||||
SoSUtility.reactionHit(msg.data.uniqId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,13 +70,13 @@ export class SoSUtility {
|
||||
const pack = game.packs.get(compendium);
|
||||
return await pack?.getDocuments() ?? [];
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendium(compendium, filter = item => true) {
|
||||
let compendiumData = await SoSUtility.loadCompendiumData(compendium);
|
||||
return compendiumData.filter(filter);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendiumNames(compendium) {
|
||||
const pack = game.packs.get(compendium);
|
||||
@@ -74,38 +84,21 @@ export class SoSUtility {
|
||||
await pack.getIndex().then(index => competences = index);
|
||||
return competences;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/*static async loadCompendium(compendium, filter = item => true) {
|
||||
let compendiumItems = await SoSUtility.loadCompendiumNames(compendium);
|
||||
|
||||
const pack = game.packs.get(compendium);
|
||||
let list = [];
|
||||
for (let compendiumItem of compendiumItems) {
|
||||
await pack.getEntity(compendiumItem.id).then(it => {
|
||||
const item = it.data;
|
||||
if (filter(item)) {
|
||||
list.push(item);
|
||||
}
|
||||
});
|
||||
};
|
||||
return list;
|
||||
}*/
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static updateCombat(combat, round, diff, id) {
|
||||
combat.requestActions();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async openDeclareActions( event) {
|
||||
static async openDeclareActions(event) {
|
||||
event.preventDefault();
|
||||
let round = event.currentTarget.attributes['data-round'].value;
|
||||
let combatantId = event.currentTarget.attributes['data-combatant-id'].value;
|
||||
let combatId = event.currentTarget.attributes['data-combat-id'].value;
|
||||
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
|
||||
let d = await SoSDialogCombatActions.create( combatId, combatantId, round, uniqId );
|
||||
d.render(true);
|
||||
let d = await SoSDialogCombatActions.create(combatId, combatantId, round, uniqId);
|
||||
d.render(true);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -116,13 +109,13 @@ export class SoSUtility {
|
||||
static getConsequenceBonus(severity) {
|
||||
return severity2bonus[severity] ?? 0;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static computeEncumbrance( items) {
|
||||
let trappings = items.filter( item => item.type == 'gear' || item.type == 'armor' || item.type == 'weapon' );
|
||||
static computeEncumbrance(items) {
|
||||
let trappings = items.filter(item => item.type == 'gear' || item.type == 'armor' || item.type == 'weapon');
|
||||
let sumEnc = 0;
|
||||
for (let object of trappings) {
|
||||
if ( (!object.system.worn) && (!object.system.neg) && (!object.system.software) && (!object.system.implant) && (!object.system.containerid || object.system.containerid == "") ) {
|
||||
if ((!object.system.worn) && (!object.system.neg) && (!object.system.software) && (!object.system.implant) && (!object.system.containerid || object.system.containerid == "")) {
|
||||
sumEnc += (object.big > 0) ? object.big : 1;
|
||||
}
|
||||
}
|
||||
@@ -133,48 +126,49 @@ export class SoSUtility {
|
||||
static closeAction(event) {
|
||||
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
|
||||
|
||||
if ( game.user.isGM ) {
|
||||
game.combat.closeAction( uniqId );
|
||||
if (game.user.isGM) {
|
||||
game.combat.closeAction(uniqId);
|
||||
} else {
|
||||
game.socket.emit("system.foundryvtt-shadows-over-sol", {
|
||||
name: "msg_close_action", data: { uniqId: uniqId} } );
|
||||
name: "msg_close_action", data: { uniqId: uniqId }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async registerChatCallbacks(html) {
|
||||
html.on("click", '#button-declare-actions', event => {
|
||||
SoSUtility.openDeclareActions( event );
|
||||
SoSUtility.openDeclareActions(event);
|
||||
});
|
||||
html.on("click", '#button-end-action', event => {
|
||||
SoSUtility.closeAction( event );
|
||||
});
|
||||
SoSUtility.closeAction(event);
|
||||
});
|
||||
|
||||
html.on("click", '#button-reaction-cover', event => {
|
||||
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
|
||||
if ( game.user.isGM ) {
|
||||
SoSUtility.reactionCover( uniqId );
|
||||
if (game.user.isGM) {
|
||||
SoSUtility.reactionCover(uniqId);
|
||||
} else {
|
||||
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_cover", data: { uniqId: uniqId} } );
|
||||
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_cover", data: { uniqId: uniqId } });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
html.on("click", '#button-reaction-melee', event => {
|
||||
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
|
||||
if ( game.user.isGM ) {
|
||||
SoSUtility.reactionMelee( uniqId );
|
||||
if (game.user.isGM) {
|
||||
SoSUtility.reactionMelee(uniqId);
|
||||
} else {
|
||||
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_melee", data: { uniqId: uniqId} } );
|
||||
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_melee", data: { uniqId: uniqId } });
|
||||
}
|
||||
});
|
||||
});
|
||||
html.on("click", '#button-reaction-hit', event => {
|
||||
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
|
||||
if ( game.user.isGM ) {
|
||||
SoSUtility.reactionHit( uniqId );
|
||||
if (game.user.isGM) {
|
||||
SoSUtility.reactionHit(uniqId);
|
||||
} else {
|
||||
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_hit", data: { uniqId: uniqId} } );
|
||||
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_hit", data: { uniqId: uniqId } });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -188,46 +182,46 @@ export class SoSUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static increaseConsequenceSeverity( severity ) {
|
||||
if ( severity == 'none') return 'light';
|
||||
if ( severity == 'light') return 'moderate';
|
||||
if ( severity == 'moderate') return 'severe';
|
||||
if ( severity == 'severe') return 'critical';
|
||||
static increaseConsequenceSeverity(severity) {
|
||||
if (severity == 'none') return 'light';
|
||||
if (severity == 'light') return 'moderate';
|
||||
if (severity == 'moderate') return 'severe';
|
||||
if (severity == 'severe') return 'critical';
|
||||
return 'critical';
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getConsequenceSeverityLevel( severity) {
|
||||
if ( severity == 'none') return 0;
|
||||
if ( severity == 'light') return 1;
|
||||
if ( severity == 'moderate') return 2;
|
||||
if ( severity == 'severe') return 3;
|
||||
if ( severity == 'critical') return 4;
|
||||
static getConsequenceSeverityLevel(severity) {
|
||||
if (severity == 'none') return 0;
|
||||
if (severity == 'light') return 1;
|
||||
if (severity == 'moderate') return 2;
|
||||
if (severity == 'severe') return 3;
|
||||
if (severity == 'critical') return 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static increaseSeverity( severity ) {
|
||||
if ( severity == 'L') return 'M';
|
||||
if ( severity == 'M') return 'S';
|
||||
if ( severity == 'S') return 'C';
|
||||
if ( severity == 'C') return 'F';
|
||||
static increaseSeverity(severity) {
|
||||
if (severity == 'L') return 'M';
|
||||
if (severity == 'M') return 'S';
|
||||
if (severity == 'S') return 'C';
|
||||
if (severity == 'C') return 'F';
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static decreaseSeverity( severity ) {
|
||||
if ( severity == 'C') return 'S';
|
||||
if ( severity == 'S') return 'M';
|
||||
if ( severity == 'M') return 'L';
|
||||
if ( severity == 'L') return 'N';
|
||||
static decreaseSeverity(severity) {
|
||||
if (severity == 'C') return 'S';
|
||||
if (severity == 'S') return 'M';
|
||||
if (severity == 'M') return 'L';
|
||||
if (severity == 'L') return 'N';
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getSeverityLevel( severity) {
|
||||
if ( severity == 'C') return 4;
|
||||
if ( severity == 'S') return 3;
|
||||
if ( severity == 'M') return 2;
|
||||
if ( severity == 'L') return 1;
|
||||
static getSeverityLevel(severity) {
|
||||
if (severity == 'C') return 4;
|
||||
if (severity == 'S') return 3;
|
||||
if (severity == 'M') return 2;
|
||||
if (severity == 'L') return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -238,53 +232,53 @@ export class SoSUtility {
|
||||
let msgTxt = "<p>Are you sure to delete this item ?";
|
||||
let buttons = {
|
||||
delete: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: "Yes, delete it",
|
||||
callback: () => {
|
||||
console.log("Delete : ", itemId);
|
||||
actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]);
|
||||
li.slideUp(200, () => actorSheet.render(false));
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
label: "Cancel"
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: "Yes, delete it",
|
||||
callback: () => {
|
||||
console.log("Delete : ", itemId);
|
||||
actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]);
|
||||
li.slideUp(200, () => actorSheet.render(false));
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
label: "Cancel"
|
||||
}
|
||||
msgTxt += "</p>";
|
||||
let d = new Dialog({
|
||||
title: "Confirm deletion",
|
||||
content: msgTxt,
|
||||
buttons: buttons,
|
||||
default: "cancel"
|
||||
});
|
||||
d.render(true);
|
||||
}
|
||||
|
||||
msgTxt += "</p>";
|
||||
let d = new Dialog({
|
||||
title: "Confirm deletion",
|
||||
content: msgTxt,
|
||||
buttons: buttons,
|
||||
default: "cancel"
|
||||
});
|
||||
d.render(true);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async applyDamage( flipData ) {
|
||||
static async applyDamage(flipData) {
|
||||
if (!this.registry) this.registry = {};
|
||||
|
||||
if ( flipData.isReaction) { // Check again resut in case of reaction !
|
||||
if (flipData.isReaction) { // Check again resut in case of reaction !
|
||||
flipData.magnitude = flipData.finalScore - flipData.tn; // Update magnitude
|
||||
if ( flipData.magnitude < 0 ) {
|
||||
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-reaction-result.html', flipData );
|
||||
ChatMessage.create( { content: html });
|
||||
if (flipData.magnitude < 0) {
|
||||
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-reaction-result.html', flipData);
|
||||
ChatMessage.create({ content: html });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// DR management
|
||||
let armor = flipData.target.actor.system.items.find( item => item.type == 'armor' && item.system.worn);
|
||||
let armor = flipData.target.actor.system.items.find(item => item.type == 'armor' && item.system.worn);
|
||||
flipData.armorDR = armor ? armor.system.dr : 0;
|
||||
flipData.armorGel = armor ?armor.system.gel : 0;
|
||||
flipData.armorGel = armor ? armor.system.gel : 0;
|
||||
flipData.armorReflect = armor ? armor.system.reflect : 0;
|
||||
let dr = flipData.target.actor.system.scores.dr.value + flipData.armorDR;
|
||||
if (flipData.weapon.system.category == 'ballistic') {
|
||||
dr += flipData.armorGel;
|
||||
dr += flipData.armorGel;
|
||||
}
|
||||
if (flipData.weapon.system.category == 'laser') {
|
||||
dr += flipData.armorReflect;
|
||||
dr += flipData.armorReflect;
|
||||
}
|
||||
|
||||
let shock = flipData.target.actor.system.scores.shock.value || 1;
|
||||
@@ -292,106 +286,106 @@ export class SoSUtility {
|
||||
flipData.damageStatus = 'apply_damage';
|
||||
|
||||
flipData.targetShock = shock;
|
||||
flipData.targetDR = dr;
|
||||
flipData.targetDR = dr;
|
||||
flipData.targetCritical = defenseCritical;
|
||||
// DR management
|
||||
if ( flipData.damageValue < dr) {
|
||||
if (flipData.damageValue < dr) {
|
||||
if (flipData.damageValue < dr / 2) {
|
||||
flipData.damageStatus = "no_damage";
|
||||
flipData.damageReason = "Damage are lesser than DR/2";
|
||||
} else {
|
||||
flipData.damageSeverity = this.decreaseSeverity(flipData.damageSeverity );
|
||||
if ( flipData.damageSeverity == 'N') {
|
||||
flipData.damageSeverity = this.decreaseSeverity(flipData.damageSeverity);
|
||||
if (flipData.damageSeverity == 'N') {
|
||||
flipData.damageStatus = "no_damage";
|
||||
flipData.damageReason = "Severity decreased to nothing";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Shock management
|
||||
flipData.woundsList = [];
|
||||
flipData.nbStun = 0;
|
||||
if ( flipData.weapon.stun ) { // Stun weapon case
|
||||
if ( flipData.damageValue >= shock ) {
|
||||
if (flipData.weapon.stun) { // Stun weapon case
|
||||
if (flipData.damageValue >= shock) {
|
||||
flipData.nbStun = Math.floor(flipData.damageValue / shock);
|
||||
}
|
||||
} else {
|
||||
if ( flipData.damageValue >= shock ) {
|
||||
if (flipData.damageValue >= shock) {
|
||||
let incSeverity = Math.floor(flipData.damageValue / shock);
|
||||
for (let i=0; i<incSeverity; i++) {
|
||||
if ( flipData.damageSeverity == 'C') {
|
||||
flipData.woundsList.push( flipData.damageSeverity );
|
||||
for (let i = 0; i < incSeverity; i++) {
|
||||
if (flipData.damageSeverity == 'C') {
|
||||
flipData.woundsList.push(flipData.damageSeverity);
|
||||
flipData.damageSeverity = 'L';
|
||||
} else {
|
||||
flipData.nbStun++;
|
||||
flipData.damageSeverity = this.increaseSeverity( flipData.damageSeverity );
|
||||
flipData.damageSeverity = this.increaseSeverity(flipData.damageSeverity);
|
||||
flipData.damageReason = "Severity increased";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
flipData.woundsList.push( flipData.damageSeverity );
|
||||
flipData.woundsList.push(flipData.damageSeverity);
|
||||
flipData.nbWounds = flipData.woundsList.length;
|
||||
|
||||
// Critical management
|
||||
flipData.isCritical = ( flipData.cardTotal >= defenseCritical);
|
||||
flipData.isCritical = (flipData.cardTotal >= defenseCritical);
|
||||
|
||||
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-target.html', flipData );
|
||||
ChatMessage.create( { content: html });
|
||||
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-target.html', flipData);
|
||||
ChatMessage.create({ content: html });
|
||||
|
||||
// Is target able to dodge ??
|
||||
let defender = game.actors.get( flipData.target.actor._id);
|
||||
flipData.coverConsequence = defender.items.find( item => item.type == 'consequence' && item.name == 'Cover');
|
||||
flipData.APavailable = game.combat.getAPFromActor( defender._id );
|
||||
let defender = game.actors.get(flipData.target.actor._id);
|
||||
flipData.coverConsequence = defender.items.find(item => item.type == 'consequence' && item.name == 'Cover');
|
||||
flipData.APavailable = game.combat.getAPFromActor(defender._id);
|
||||
console.log("FLIPDATE : ", flipData);
|
||||
if ( !flipData.isReaction && flipData.APavailable > 0) {
|
||||
if ( (flipData.weapon.system.category == 'melee' ) || ( (flipData.weapon.system.category == 'laser' || flipData.weapon.system.category == 'ballistic') &&
|
||||
flipData.coverConsequence.system.severity != 'none') ) {
|
||||
flipData.coverSeverityLevel = this.getConsequenceSeverityLevel( flipData.coverConsequence.system.severity ) * 2;
|
||||
flipData.coverSeverityFlag = (flipData.coverSeverityLevel > 0);
|
||||
flipData.isMelee = (flipData.weapon.system.category == 'melee' );
|
||||
let melee = defender.items.find( item => item.type == 'skill' && item.name == 'Melee');
|
||||
if (!flipData.isReaction && flipData.APavailable > 0) {
|
||||
if ((flipData.weapon.system.category == 'melee') || ((flipData.weapon.system.category == 'laser' || flipData.weapon.system.category == 'ballistic') &&
|
||||
flipData.coverConsequence.system.severity != 'none')) {
|
||||
flipData.coverSeverityLevel = this.getConsequenceSeverityLevel(flipData.coverConsequence.system.severity) * 2;
|
||||
flipData.coverSeverityFlag = (flipData.coverSeverityLevel > 0);
|
||||
flipData.isMelee = (flipData.weapon.system.category == 'melee');
|
||||
let melee = defender.items.find(item => item.type == 'skill' && item.name == 'Melee');
|
||||
flipData.defenderMelee = melee.system.value;
|
||||
flipData.uniqId = randomID(16);
|
||||
flipData.uniqId = foundry.utils.randomID(16);
|
||||
this.registry[flipData.uniqId] = flipData;
|
||||
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-request-dodge.html', flipData );
|
||||
ChatMessage.create( { content: html, whisper: ChatMessage.getWhisperRecipients(flipData.target.actor.name).concat(ChatMessage.getWhisperRecipients("GM")) } );
|
||||
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-request-dodge.html', flipData);
|
||||
ChatMessage.create({ content: html, whisper: ChatMessage.getWhisperRecipients(flipData.target.actor.name).concat(ChatMessage.getWhisperRecipients("GM")) });
|
||||
return; // Wait message response
|
||||
}
|
||||
}
|
||||
flipData.isReaction = false;
|
||||
this.takeWounds( flipData);
|
||||
this.takeWounds(flipData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static reactionCover( uniqId) {
|
||||
/* -------------------------------------------- */
|
||||
static reactionCover(uniqId) {
|
||||
let flipData = this.registry[uniqId];
|
||||
flipData.tn += flipData.coverSeverityLevel;
|
||||
flipData.isReaction = true;
|
||||
game.combat.decreaseAPFromActor( flipData.target.actor._id );
|
||||
SoSUtility.applyDamage( flipData);
|
||||
}
|
||||
game.combat.decreaseAPFromActor(flipData.target.actor._id);
|
||||
SoSUtility.applyDamage(flipData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static reactionMelee( uniqId) {
|
||||
static reactionMelee(uniqId) {
|
||||
let flipData = this.registry[uniqId];
|
||||
flipData.tn += flipData.defenderMelee;
|
||||
flipData.isReaction = true;
|
||||
game.combat.decreaseAPFromActor( flipData.target.actor._id );
|
||||
SoSUtility.applyDamage( flipData);
|
||||
game.combat.decreaseAPFromActor(flipData.target.actor._id);
|
||||
SoSUtility.applyDamage(flipData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static reactionHit( uniqId) {
|
||||
static reactionHit(uniqId) {
|
||||
let flipData = this.registry[uniqId];
|
||||
flipData.isReaction = true;
|
||||
SoSUtility.takeWounds( flipData);
|
||||
SoSUtility.takeWounds(flipData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static takeWounds( flipData ) {
|
||||
let defender = game.actors.get( flipData.target.actor._id);
|
||||
defender.applyWounds( flipData );
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static takeWounds(flipData) {
|
||||
let defender = game.actors.get(flipData.target.actor._id);
|
||||
defender.applyWounds(flipData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -402,7 +396,7 @@ export class SoSUtility {
|
||||
let objectId = item.id
|
||||
console.log("ID", dragData, dropId, objectId)
|
||||
if (dragData.type == 'Item' && dropId) {
|
||||
actorSheet.actor.addObjectToContainer(objectId, dropId );
|
||||
actorSheet.actor.addObjectToContainer(objectId, dropId);
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user