Initial system development

This commit is contained in:
2021-01-18 22:05:02 +01:00
parent ca29af6b61
commit e78b2ac67d
15 changed files with 481 additions and 363 deletions

View File

@ -16,14 +16,17 @@ export class SoSActorSheet extends ActorSheet {
width: 640,
//height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }]
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editStatSkill: false
});
}
/* -------------------------------------------- */
getData() {
let data = super.getData();
data.data.edgecard = this.actor.getEdgesCard();
data.data.editStatSkill = this.options.editStatSkill;
console.log("stats", data);
//data.stats = duplicate(this.actor.stats);
//data.scores = duplicate(this.actor.scores);
@ -58,6 +61,21 @@ export class SoSActorSheet extends ActorSheet {
const li = $(ev.currentTarget).parents(".item");
RdDUtility.confirmerSuppression(this, li);
});
html.find('.stat-label a').click((event) => {
let statName = event.currentTarget.attributes.name.value;
this.actor.rollStat(statName);
});
html.find('.edge-draw').click((event) => {
this.actor.drawEdge();
this.render(true);
});
html.find('.lock-unlock-sheet').click((event) => {
this.options.editStatSkill = !this.options.editStatSkill;
this.render(true);
});
}
/* -------------------------------------------- */

View File

@ -1,3 +1,4 @@
import { SoSCardDeck } from "./sos-card-deck.js";
import { SoSUtility } from "./sos-utility.js";
@ -36,18 +37,95 @@ export class SoSActor extends Actor {
}
/* -------------------------------------------- */
prepareData() {
async prepareData() {
super.prepareData();
const actorData = this.data;
if ( !this.cardDeck ) {
this.cardDeck = new SoSCardDeck();
this.cardDeck.initCardDeck( this );
}
this.controlScores();
}
/* -------------------------------------------- */
getEdgesCard( ) {
let edgesCard = duplicate(this.cardDeck.data.cardEdge);
for (let edge of edgesCard) {
edge.path = `systems/foundryvtt-shadows-over-sol/img/cards/${edge.cardName}.webp`
}
return edgesCard;
}
/* -------------------------------------------- */
drawEdge( ) {
this.cardDeck.drawEdge();
}
/* -------------------------------------------- */
/**
* Prepare Character type specific data
*/
async _prepareCharacterData(actorData) {
// Initialize empty items
getDefense( ) {
return this.data.data.scores.defense;
}
/* -------------------------------------------- */
computeDefense() {
return { value: Math.ceil((this.data.data.stats.speed.value + this.data.data.stats.perception.value + this.data.data.stats.dexterity.value) / 2),
critical: this.data.data.stats.speed.value + this.data.data.stats.perception.value + this.data.data.stats.dexterity.value
}
}
/* -------------------------------------------- */
getEdge( ) {
return this.data.data.scores.edge.value;
}
/* -------------------------------------------- */
getEncumbrance( ) {
return this.data.data.scores.encumbrance.value;
}
/* -------------------------------------------- */
computeEdge( ) {
return Math.ceil( (this.data.data.stats.intelligence.value + this.data.data.stats.charisma.value) / 2);
}
/* -------------------------------------------- */
getShock( ) {
return this.data.data.scores.shock.value;
}
computeShock() {
return Math.ceil( this.data.data.stats.endurance.value + this.data.data.stats.determination.value + this.data.data.scores.dr.value);
}
/* -------------------------------------------- */
getWound( ) {
return this.data.data.scores.wound.value;
}
computeWound() {
return Math.ceil( (this.data.data.stats.strength.value + this.data.data.stats.endurance.value) / 2);
}
/* -------------------------------------------- */
async controlScores() {
// Defense check
let defenseData = this.getDefense();
let newDefenseData = this.computeDefense();
if ( defenseData.value != newDefenseData.value || defenseData.critical != newDefenseData.critical) {
await this.update( {'data.scores.defense': newDefenseData});
}
// Edge check
if ( this.getEdge() != this.computeEdge() ) {
await this.update( {'data.scores.edge.value': this.computeEdge()});
}
// Encumbrance
if ( this.getEncumbrance() != this.data.data.stats.strength.value ) {
await this.update( {'data.scores.encumbrance.value': this.data.data.stats.strength.value });
}
// Shock
if ( this.getShock() != this.computeShock() ) {
await this.update( {'data.scores.shock.value': this.computeShock() });
}
// Wounds
if ( this.getWound() != this.computeWound() ) {
await this.update( {'data.scores.wound.value': this.computeWound() });
}
}
/* -------------------------------------------- */
rollStat( statKey ) {
console.log("STAT", this);
let result = this.cardDeck.doFlipStat( duplicate(this.data.data.stat[statKey]) );
}
}

View File

@ -4,45 +4,66 @@ const NB_POKER_CARD = 54;
const IDX2CARDFAMILY = ['c', 'd', 'h', 's'];
/* -------------------------------------------- */
export class SoSCardDeck extends Application {
export class SoSCardDeck {
/* -------------------------------------------- */
static async create(data, options) {
data.deck = [];
data.discard = [];
data.cardState = [];
return super.create(data, options);
initCardDeck(actor) {
this.data = {};
this.data.deck = [];
this.data.discard = [];
this.data.cardState = [];
this.data.cardEdge = [];
this.data.actor = actor;
this.shuffleDeck();
}
/* -------------------------------------------- */
shuffleDeck() {
this.cleanCardList();
// Randomize deck
while (data.deck.length != NB_POKER_CARD) {
while (this.data.deck.length != NB_POKER_CARD) {
let idx = new Roll("1d54").roll().total;
if (!this.data.cardState[idx - 1]) {
if (idx == 53) { // Red Joker
data.deck.push = { cardName: 'jr' }
this.data.deck.push( { cardName: 'jr' } );
} else if (idx == 54) { // Black Joker
data.deck.push = { cardName: 'jb' }
this.data.deck.push({ cardName: 'jb' });
} else {
let familyIdx = idx % 4;
let cardName = IDX2CARDFAMILY[familyIdx] + String((idx % 13) + 1);
data.deck.push = { cardName: cardName }
let cardIdx = String( (idx % 13) + 1);
cardIdx = (cardIdx.length < 2) ? "0"+cardIdx: cardIdx;
let cardName = IDX2CARDFAMILY[familyIdx] + cardIdx;
this.data.deck.push( { cardName: cardName } );
}
this.data.cardState[idx - 1] = true;
}
}
}
}
/* -------------------------------------------- */
drawEdge() {
this.data.cardEdge.push( this.data.deck.pop() );
this.data.cardEdge.push( this.data.deck.pop() );
console.log("DRAW EDGE", this.data.cardEdge);
}
/* -------------------------------------------- */
cleanCardList() {
data.discard = []; // Reinit discard pile
data.deck = [];
this.data.discard = []; // Reinit discard pile
this.data.deck = [];
for (let i = 0; i < NB_POKER_CARD; i++) {
data.cardState[i] = false;
this.data.cardState[i] = false;
}
}
/* -------------------------------------------- */
doFlipStat( statData ) {
let card = this.data.deck.pop();
this.data.discard.push( card );
console.log("CARD IS : ", card, this.data.deck.length );
}
}