Manage luck with Edge

This commit is contained in:
sladecraven 2021-02-16 23:01:42 +01:00
parent e5fd4dc01f
commit de738326c9
8 changed files with 156 additions and 64 deletions

View File

@ -136,6 +136,10 @@ export class SoSActorSheet extends ActorSheet {
this.actor.resetDeck(); this.actor.resetDeck();
this.render(true); this.render(true);
}); });
html.find('.discard-card').click((event) => {
const cardName = $(event.currentTarget).data("discard");
this.actor.discardEdge( cardName );
});
html.find('.consequence-severity').click((event) => { html.find('.consequence-severity').click((event) => {
const li = $(event.currentTarget).parents(".item"); const li = $(event.currentTarget).parents(".item");
const item = this.actor.getOwnedItem(li.data("item-id")); const item = this.actor.getOwnedItem(li.data("item-id"));

View File

@ -85,6 +85,12 @@ export class SoSActor extends Actor {
this.saveDeck(); this.saveDeck();
} }
/* -------------------------------------------- */
discardEdge( cardName ) {
this.cardDeck.discardEdge( cardName );
this.saveDeck();
}
/* -------------------------------------------- */ /* -------------------------------------------- */
resetDeck( ) { resetDeck( ) {
this.cardDeck.resetDeck(); this.cardDeck.resetDeck();
@ -221,7 +227,8 @@ export class SoSActor extends Actor {
modifierList: SoSUtility.fillRange(-10, +10), modifierList: SoSUtility.fillRange(-10, +10),
tnList: SoSUtility.fillRange(6, 20), tnList: SoSUtility.fillRange(6, 20),
consequencesList: duplicate( this.getApplicableConsequences() ), consequencesList: duplicate( this.getApplicableConsequences() ),
malusConsequence: 0 malusConsequence: 0,
bonusConsequence: 0
} }
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/dialog-flip.html', flipData); let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/dialog-flip.html', flipData);
new SoSFlipDialog(flipData, html).render(true); new SoSFlipDialog(flipData, html).render(true);
@ -238,7 +245,8 @@ export class SoSActor extends Actor {
actor: this, actor: this,
modifierList: SoSUtility.fillRange(-10, +10), modifierList: SoSUtility.fillRange(-10, +10),
tnList: SoSUtility.fillRange(6, 20), tnList: SoSUtility.fillRange(6, 20),
malusConsequence: 0 malusConsequence: 0,
bonusConsequence: 0
} }
flipData.statList['nostat'] = { label: "No stat (ie defaulting skills)", value: 0, cardsuit: "none" } flipData.statList['nostat'] = { label: "No stat (ie defaulting skills)", value: 0, cardsuit: "none" }
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/dialog-flip.html', flipData); let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/dialog-flip.html', flipData);

View File

@ -76,6 +76,13 @@ export class SoSCardDeck {
} }
} }
/* -------------------------------------------- */
discardEdge( cardName ) {
let newEdge = this.data.cardEdge.filter( card => card.cardName != cardName);
this.data.cardEdge = newEdge; // New edge list
this.data.discard.push( { cardName: cardName }); // And push in the discard pile
}
/* -------------------------------------------- */ /* -------------------------------------------- */
drawEdge( edgeNumber = 1 ) { drawEdge( edgeNumber = 1 ) {
for (let i=0; i<edgeNumber; i++) { for (let i=0; i<edgeNumber; i++) {
@ -159,6 +166,10 @@ export class SoSCardDeck {
flipData.isJoker = false; flipData.isJoker = false;
flipData.fullTrump = false; flipData.fullTrump = false;
if ( flipData.edgeLuck ) {
flipData.cardOrigin == "Deck"; // Force Deck
}
// Select card origin // Select card origin
if ( flipData.cardOrigin == "Deck") { if ( flipData.cardOrigin == "Deck") {
flipData.cardSlot[0].card1 = this.drawFromDeck(); flipData.cardSlot[0].card1 = this.drawFromDeck();
@ -190,7 +201,7 @@ export class SoSCardDeck {
// Trump check // Trump check
flipData.cardSlot[0].cardsuit = cardsuit; flipData.cardSlot[0].cardsuit = cardsuit;
if ( ! flipData.isJoker && cardsuit == flipData.stat.cardsuit ) { if ( !flipData.isJoker && ( cardsuit == flipData.stat.cardsuit || flipData.edgeLuck) ) {
// This is a trump ! // This is a trump !
flipData.cardSlot[1] = { total: 0 }; flipData.cardSlot[1] = { total: 0 };
flipData.isTrump = true; flipData.isTrump = true;
@ -293,6 +304,15 @@ export class SoSCardDeck {
return html; return html;
} }
/* -------------------------------------------- */
getEdgeHTMLForFlip( ) {
let html = "";
for (let edge of this.data.cardEdge) {
html += `<a class='view-edge'><img class='flip-card edge-card' data-edge-card='${edge.cardName}' src='systems/foundryvtt-shadows-over-sol/img/cards/${edge.cardName}.webp' /></a>`
}
return html;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
getDiscardTopHTML( ) { getDiscardTopHTML( ) {
let html = ""; let html = "";

View File

@ -36,6 +36,7 @@ export class SoSFlipDialog extends Dialog {
scoreBase = this.flipData.stat.value; scoreBase = this.flipData.stat.value;
} }
scoreBase += this.flipData.malusConsequence; scoreBase += this.flipData.malusConsequence;
scoreBase += this.flipData.bonusConsequence;
$('#score-base').text( scoreBase); $('#score-base').text( scoreBase);
} }
@ -46,7 +47,7 @@ export class SoSFlipDialog extends Dialog {
$("#view-deck").append(await flipData.actor.cardDeck.getDeckHTML()); $("#view-deck").append(await flipData.actor.cardDeck.getDeckHTML());
$('.view-edge').remove(); $('.view-edge').remove();
$("#view-edge").append(await flipData.actor.cardDeck.getEdgeHTML()); $("#view-edge").append(await flipData.actor.cardDeck.getEdgeHTMLForFlip());
this.updateScoreBase(); this.updateScoreBase();
@ -55,6 +56,7 @@ export class SoSFlipDialog extends Dialog {
flipData.modifier = $('#modifier').val(); flipData.modifier = $('#modifier').val();
flipData.tn = (flipData.target) ? flipData.target.actor.data.data.scores.defense.value : $('#tn').val(); flipData.tn = (flipData.target) ? flipData.target.actor.data.data.scores.defense.value : $('#tn').val();
flipData.edgeName = event.currentTarget.attributes['data-edge-card'].value; flipData.edgeName = event.currentTarget.attributes['data-edge-card'].value;
flipData.edgeLuck = $('#edge-luck').is(":checked");
flipData.cardOrigin = "Edge"; flipData.cardOrigin = "Edge";
if ( flipData.mode == 'skill' || flipData.mode == 'weapon') { if ( flipData.mode == 'skill' || flipData.mode == 'weapon') {
flipData.stat = duplicate( flipData.statList[ $('#statSelect').val() ] ); flipData.stat = duplicate( flipData.statList[ $('#statSelect').val() ] );
@ -67,8 +69,8 @@ export class SoSFlipDialog extends Dialog {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
updateConsequence(event) { updateConsequenceMalus(event) {
this.flipData.consequencesSelected = $('#consequenceSelect').val(); this.flipData.consequencesSelected = $('#consequenceSelectMalus').val();
let malusConsequence = 0; let malusConsequence = 0;
for (let consequenceId of this.flipData.consequencesSelected) { for (let consequenceId of this.flipData.consequencesSelected) {
let consequence = this.flipData.consequencesList.find( item => item._id == consequenceId); let consequence = this.flipData.consequencesList.find( item => item._id == consequenceId);
@ -80,6 +82,20 @@ export class SoSFlipDialog extends Dialog {
this.updateScoreBase(); this.updateScoreBase();
} }
/* -------------------------------------------- */
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();
}
/* -------------------------------------------- */ /* -------------------------------------------- */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
@ -90,9 +106,6 @@ export class SoSFlipDialog extends Dialog {
function onLoad() { function onLoad() {
let flipData = dialog.flipData; let flipData = dialog.flipData;
//RdDItemSort.setCoutReveReel(rollData.selectedSort);
//$("#diffLibre").val(Misc.toInt(rollData.diffLibre));
//$("#diffConditions").val(Misc.toInt(rollData.diffConditions));
dialog.updateFlip(flipData); dialog.updateFlip(flipData);
} }
@ -103,8 +116,11 @@ export class SoSFlipDialog extends Dialog {
this.updateFlip(dialog.flipData ); this.updateFlip(dialog.flipData );
} ); } );
html.find('#consequenceSelect').change((event) => { html.find('#consequenceSelectMalus').change((event) => {
this.updateConsequence( event ); this.updateConsequenceMalus( event );
} );
html.find('#consequenceSelectBonus').change((event) => {
this.updateConsequenceBonus( event );
} ); } );
html.find('.class-view-deck').click((event) => { html.find('.class-view-deck').click((event) => {

View File

@ -4,6 +4,8 @@ import { SoSDialogCombatActions } from "./sos-dialog-combat-actions.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
const severity2malus = { "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 extends Entity { export class SoSUtility extends Entity {
@ -98,6 +100,10 @@ export class SoSUtility extends Entity {
static getConsequenceMalus(severity) { static getConsequenceMalus(severity) {
return severity2malus[severity] ?? 0; return severity2malus[severity] ?? 0;
} }
/* -------------------------------------------- */
static getConsequenceBonus(severity) {
return severity2bonus[severity] ?? 0;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeEncumbrance( items) { static computeEncumbrance( items) {

View File

@ -1022,6 +1022,24 @@ ul, li {
font-weight: bold; font-weight: bold;
} }
.card-button {
box-shadow: inset 0px 1px 0px 0px #a6827e;
background: linear-gradient(to bottom, #21374afc 5%, #152833ab 100%);
background-color: #7d5d3b00;
border-radius: 3px;
border: 2px ridge #846109;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Neuropol;
font-size: 0.7rem;
padding: 4px 12px 0px 12px;
text-decoration: none;
text-shadow: 0px 1px 0px #4d3534;
position: relative;
margin:2px;
}
.chat-card-button { .chat-card-button {
box-shadow: inset 0px 1px 0px 0px #a6827e; box-shadow: inset 0px 1px 0px 0px #a6827e;
background: linear-gradient(to bottom, #21374afc 5%, #152833ab 100%); background: linear-gradient(to bottom, #21374afc 5%, #152833ab 100%);
@ -1032,7 +1050,7 @@ ul, li {
cursor: pointer; cursor: pointer;
color: #ffffff; color: #ffffff;
font-family: Neuropol; font-family: Neuropol;
font-size: 0.9rem; font-size: 0.8rem;
padding: 4px 12px 0px 12px; padding: 4px 12px 0px 12px;
text-decoration: none; text-decoration: none;
text-shadow: 0px 1px 0px #4d3534; text-shadow: 0px 1px 0px #4d3534;
@ -1040,10 +1058,12 @@ ul, li {
margin:5px; margin:5px;
} }
.card-button:hover,
.chat-card-button:hover { .chat-card-button:hover {
background: linear-gradient(to bottom, #800000 5%, #3e0101 100%); background: linear-gradient(to bottom, #800000 5%, #3e0101 100%);
background-color: red; background-color: red;
} }
.card-button:active,
.chat-card-button:active { .chat-card-button:active {
position:relative; position:relative;
top:1px; top:1px;

View File

@ -71,18 +71,23 @@
</div> </div>
</div> </div>
<div class="flexrow"> <div class="flexcol">
<span class="flexcol"> <h3 class="edge-name">Current deck size : {{data.deckSize}} cards</h3>
<h3 class="edge-name">Current deck size : {{data.deckSize}} cards</h3> <div class="flexrow">
<span class="edge-name"><a class="reset-deck-full">Reset full deck and edges</a></span> <span class="edge-name"><a class="card-button reset-deck-full">Reset full deck and edges</a></span>
<span class="edge-name"><a class="draw-new-edge">Draw a new Edge card</a></span> <span class="edge-name"><a class="card-button draw-new-edge">Draw a new Edge card</a></span>
<span class="edge-name"><a class="reset-deck">Reset deck only (ie after a Joker)</a></span> <span class="edge-name"><a class="card-button reset-deck">Reset deck only (ie after a Joker)</a></span>
</span> </div>
<span class="edge-name"> <span class="edge-name">
<h3 class="edge-name">Edge cards : </h3> <h3 class="edge-name">Edge cards : </h3>
{{#each data.edgecard as |card key|}} <div class="flexrow">
<img class="card-img" src="{{card.path}}" data-edit="img" title="{{card.cardName}}" /> {{#each data.edgecard as |card key|}}
{{/each}} <div class="flexcol">
<img class="card-img" src="{{card.path}}" data-edit="img" title="{{card.cardName}}" />
<span class="edge-name"><a class="card-button discard-card" data-discard="{{card.cardName}}">Discard</a></span>
</div>
{{/each}}
</div>
</span> </span>
</div> </div>

View File

@ -2,47 +2,57 @@
<h2 class="compdialog" id="statSkillFlip">Flip Dialog !</h2> <h2 class="compdialog" id="statSkillFlip">Flip Dialog !</h2>
<div class="grid grid-2col"> <div class="flexrow">
<div class="flexcol">
<div class="flex-group-left flexcol skill-column"> {{#if (eq mode 'stat')}}
{{#if (eq mode 'stat')}} <h3 class="skill-label" id="flipSubTitle">
<h3 class="skill-label" id="flipSubTitle"> Stat Only Flip : {{localize stat.label}} : {{stat.value}} - <img class="cardsuit-img" src="systems/foundryvtt-shadows-over-sol/img/cards/{{stat.cardsuit}}.webp"/>
Stat Only Flip : {{localize stat.label}} : {{stat.value}} - <img class="cardsuit-img" src="systems/foundryvtt-shadows-over-sol/img/cards/{{stat.cardsuit}}.webp"/> </h3>
</h3> <span>
<span> <h3 class="skill-label" id="flipSubTitle">Final Score : <span id='score-base'>0</span> </h3>
<h3 class="skill-label" id="flipSubTitle">Final Score : <span id='score-base'>0</span> </h3> </span>
</span> {{else}}
{{else}} <h3 class="skill-label" id="flipSubTitle">Select Stat</h3>
<h3 class="skill-label" id="flipSubTitle"> <select name="stat" id="statSelect" data-dtype="String">
Select Stat {{#select statList}}
<select name="stat" id="statSelect" data-dtype="String"> {{#each statList as |stat key|}}
{{#select statList}} <option value={{key}} {{#if (eq key ../selectedStat)}}selected{{/if}}>{{localize stat.label}} : {{stat.value}} - {{stat.cardsuit}} </option>
{{#each statList as |stat key|}}
<option value={{key}} {{#if (eq key ../selectedStat)}}selected{{/if}}>{{localize stat.label}} : {{stat.value}} - {{stat.cardsuit}} </option>
{{/each}}
{{/select}}
</select>
</h3>
<span>
<h3 class="skill-label" id="flipSubTitle">Skill Flip : {{skill.name}} ({{skill.data.value}}) </h3>
<h3 class="skill-label" id="flipSubTitle">Final Score : <span id='score-base'>0</span> </h3>
</span>
{{/if}}
</div>
<div class="flex-group-left flexcol skill-column">
<div class="tab" data-group="primary">
<select name="consequenceSelect" id="consequenceSelect" data-dtype="String" multiple size="5" width="200">
{{#select consequencesList}}
{{#each consequencesList as |consequence key|}}
<option value={{consequence._id}}>{{localize consequence.name}} - {{consequence.data.severity}}</option>
{{/each}} {{/each}}
{{/select}} {{/select}}
</select> </select>
<h3 class="skill-label" id="flipConsequenceMalus">Consequences malus : <span id='consequence-malus'>0</span> </h3> <span>
<h3 class="skill-label" id="flipSubTitle">Skill Flip : {{skill.name}} ({{skill.data.value}}) </h3>
<h3 class="skill-label" id="flipSubTitle">Final Score : <span id='score-base'>0</span> </h3>
</span>
{{/if}}
</div>
<div class="flexcol">
<div class="tab" data-group="primary">
<select name="consequenceSelect" id="consequenceSelectMalus" data-dtype="String" multiple size="5" width="200">
{{#select consequencesList}}
{{#each consequencesList as |consequence key|}}
<option value={{consequence._id}}>{{localize consequence.name}} - {{consequence.data.severity}}</option>
{{/each}}
{{/select}}
</select>
<h3 class="skill-label" id="flipConsequenceMalus">Consequences Malus : <span id='consequence-malus'>0</span> </h3>
</div>
</div>
<div class="flexcol">
<div class="tab" data-group="primary">
<select name="consequenceSelect" id="consequenceSelectBonus" data-dtype="String" multiple size="5" width="200">
{{#select consequencesList}}
{{#each consequencesList as |consequence key|}}
<option value={{consequence._id}}>{{localize consequence.name}} - {{consequence.data.severity}}</option>
{{/each}}
{{/select}}
</select>
<h3 class="skill-label" id="flipConsequenceMalus">Consequences Bonus : <span id='consequence-bonus'>0</span> </h3>
</div>
</div> </div>
</div> </div>
</div> </div>
<hr>
{{#if target}} {{#if target}}
<div> <div>
<h4>Target : {{target.actor.name}} - Defense : {{target.actor.data.data.scores.defense.value}}/{{target.actor.data.data.scores.defense.critical}}</h4> <h4>Target : {{target.actor.name}} - Defense : {{target.actor.data.data.scores.defense.value}}/{{target.actor.data.data.scores.defense.critical}}</h4>
@ -64,9 +74,7 @@
{{/select}} {{/select}}
</select> </select>
{{/if}} {{/if}}
</div> <label for="categorie" class="generic-label"> Flip Modifier (GM bonus/malus)</label>
<div class="flexrow">
<label for="categorie" class="generic-label">Flip Modifier</label>
<select name="modifier" id="modifier" data-dtype="number"> <select name="modifier" id="modifier" data-dtype="number">
{{#select modifier}} {{#select modifier}}
{{#each modifierList as |key|}} {{#each modifierList as |key|}}
@ -76,14 +84,19 @@
</select> </select>
</div> </div>
</div> </div>
<div id="flexrow"> <hr>
<div class="flexcol">
<label class="generic-label">Click on deck to flip from deck, or click on the relevant Edge card to flip from it!</label> <label class="generic-label">Click on deck to flip from deck, or click on the relevant Edge card to flip from it!</label>
<label class="generic-label flexrow">Discard Edge for Luck (ie force Trump) when clicking :
<span class="attribute-value checkbox"><input type="checkbox" name="edge-luck" id="edge-luck"/></span>
</label>
</div> </div>
<div id="flexrow"> <div class="flexrow">
<span class="class-view-deck" id="view-deck"></span> <span class="class-view-deck" id="view-deck"></span>
<span class="class-view-edge" id="view-edge"></span> <span class="class-view-edge" id="view-edge"></span>
</div> </div>
<div id="flexrow"> <div class="flexrow">
<label class="generic-label"></label> <label class="generic-label"></label>
</div> </div>
</section> </section>