Fatigue management, ongoing work

This commit is contained in:
LeRatierBretonnien 2020-05-27 23:47:49 +02:00
parent a6b46cb4ad
commit 63e4e6f91a
5 changed files with 101 additions and 9 deletions

View File

@ -54,7 +54,7 @@ export class RdDActorSheet extends ActorSheet {
list.push(item);
}
}
data.data.fatigueHTML = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.fatigue.max ).html() +"</table>";
data.data.materiel = this._checkNull(data.itemsByType['objet']);
data.data.armes = this._checkNull(data.itemsByType['arme']);
data.data.armures = this._checkNull(data.itemsByType['armure']);
@ -62,6 +62,8 @@ export class RdDActorSheet extends ActorSheet {
data.data.potions = this._checkNull(data.itemsByType['potions']);
data.data.competenceByCategory = data.competenceByCategory;
console.log("HTML", data.data.fatigueHTML);
return data;
}
@ -93,6 +95,7 @@ export class RdDActorSheet extends ActorSheet {
let compName = event.currentTarget.text;
this.actor.rollCompetence( compName);
});
// On carac change
$(".competence-value").change((event) => {
let caracName = event.currentTarget.name.replace(".value", "").replace("data.carac.", "");

View File

@ -39,9 +39,37 @@ const levelDown = [ { "level": -11, "score": 1, "part": 0, "epart": 2, "etotal":
{ "level": -13, "score": 1, "part": 0, "epart": 2, "etotal": 50 },
{ "level": -14, "score": 1, "part": 0, "epart": 2, "etotal": 30 },
{ "level": -15, "score": 1, "part": 0, "epart": 2, "etotal": 10 },
{ "level": -16, "score": 1, "part": 0, "epart": 2, "etotal": 2 },
{ "level": -16, "score": 1, "part": 0, "epart": 2, "etotal": 2 }
];
const fatigueMatrix = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // Dummy filler for the array.
[2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3 ],
[2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3 ],
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ],
[3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 4 ],
[3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4 ],
[3, 3, 4, 3, 4, 4, 3, 3, 4, 3, 4, 4 ],
[3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4 ],
[3, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4 ],
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ],
[4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 5 ],
[4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5 ],
[4, 4, 5, 4, 5, 5, 4, 4, 5, 4, 5, 5 ],
[4, 5, 5, 4, 5, 5, 4, 5, 5, 4, 5, 5 ],
[4, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5 ],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ] ];
const fatigueMalus = [ 0, 0, 0, -1, -1, -1, -2, -3, -4, -5, -6, -7 ]; // Provides the malus for each segment of fatigue
const fatigueLineSize = [ 3, 6, 7, 8, 9, 10, 11, 12];
const fatigueTemplate = "<table>\
<th><tdid=1><td/><td/><td/><td/> <td/> <td/><td/><td/><td/><td/> <td/> <td/><td/><td/><td/><td/></tr>\
<th><td/><td/><td/><td/><td/> <td/> <td/><td/><td/><td/><td/> <td/> <td/><td/><td/><td/><td/></tr>\
<th><td/><td/><td/><td/><td/></tr>\
<th><td/><td/><td/><td/><td/></tr>\
<th><td/><td/><td/><td/><td/></tr>\
<th><td/><td/><td/><td/><td/></tr>\
<th><td/><td/><td/><td/><td/></tr>\
<th><td/><td/><td/><td/><td/></tr>\
</table>"
export class RdDUtility {
/* -------------------------------------------- */
@ -213,6 +241,42 @@ export class RdDUtility {
data.attributs.sust.value = 3;
}
/* -------------------------------------------- */
static makeHTMLfatigueMatrix( value, max )
{
max = (max < 16) ? 16 : max;
max = (max > 30) ? 30 : max;
value = (value > max) ? max : value;
let fatigueTab = fatigueMatrix[max];
let idx = 0; // Current fatigue slot
let remFatigue = value;
while ( remFatigue >= fatigueTab[idx] ) { // computes the fatigue segment consumed
remFatigue = remFatigue - fatigueTab[idx];
idx = idx + 1;
}
// At this point, we have the segment id in idx and the remaing fatigue points for the next segment in remFatigue
let table = $("<table/>").addClass('table-fatigue');
let segmentIdx = 0;
for (var line=0; line < fatigueLineSize.length; line++) {
let row = $("<tr/>");
let segmentsPerLine = fatigueLineSize[line];
while (segmentIdx < segmentsPerLine) {
let freeSize = fatigueTab[segmentIdx];
for (let col=0; col <5; col++) {
if ( col < freeSize )
row.append("<td class='fatigue-free'/>");
else
row.append("<td class='fatigue-none'/>");
}
row.append("<td class='fatigue-separator'/>");
segmentIdx = segmentIdx + 1;
}
table.append(row);
}
console.log("fatigue", table);
return table;
}
/* -------------------------------------------- */
static findCompetence(compList, compName)

View File

@ -305,9 +305,30 @@
background-color: lightblue;
}
/* ======================================== */
/* Global UI elements */
select {
font-family: "GoudyAcc", sans-serif;
}
button {
font-family: "GoudyAcc", sans-serif;
}
/* ======================================== */
/* Fatigue CSS */
.table-fatigue {
table-layout: fixed;
}
.table-fatigue td {
table-layout: fixed;
width: 8px;
height: 8px;
}
.table-fatigue .fatigue-none {
background-color: black;
border: 1px solid #999;
}
.table-fatigue .fatigue-free {
border: 1px solid #999;
}

View File

@ -147,21 +147,21 @@
"type": "number",
"max": 10,
"value": 10,
"label": "Points de Vie",
"label": "Vie",
"derivee": true
},
"endurance": {
"type": "number",
"max": 10,
"value": 10,
"label": "Points d'Endurance",
"label": "Endurance",
"derivee": true
},
"fatigue": {
"type": "number",
"max": 40,
"value": 10,
"label": "Points de Fatigue",
"max": 0,
"value": 0,
"label": "Fatigue",
"derivee": true
},
"legeres": {

View File

@ -5,7 +5,7 @@
<img class="profile-img" src="{{actor.img}}" data-edit="img" title="{{actor.name}}" height="100" width="100"/>
<div class="header-fields">
<h1 class="charname"><input name="name" type="text" value="{{actor.name}}" placeholder="Name"/></h1>
<div class="grid grid-2col">
<div class="grid grid-3col">
<div class="flex-group-center">
Vie
<input class="resource-content flexrow flex-center flex-between" type="text" name="data.sante.vie.value" value="{{data.sante.vie.value}}" data-dtype="Number"/>/{{data.sante.vie.max}}
@ -14,6 +14,10 @@
Endurance
<input class="resource-content flexrow flex-center flex-between" type="text" name="data.sante.fatigue.value" value="{{data.sante.fatigue.value}}" data-dtype="Number"/>/{{data.sante.fatigue.max}}
</div>
<div class="flex-group-center">
Fatigue
<span>{{{data.fatigueHTML}}}</span>
</div>
</div>
</div>
</header>