Alpha sort

This commit is contained in:
LeRatierBretonnien 2023-03-19 18:58:28 +01:00
parent 22ae4fb588
commit 0e5be07fb9
3 changed files with 63 additions and 67 deletions

View File

@ -44,8 +44,8 @@ export class HawkmoonActor extends Actor {
if (data.type == 'creature') {
const skills = await HawkmoonUtility.loadCompendium("fvtt-hawkmoon-cyd.skills-creatures")
data.items = skills.map(i => i.toObject())
data.items.push( { name: "Arme naturelle 1", type: 'arme', img: "systems/fvtt-hawkmoon-cyd/assets/icons/melee.webp", system: { typearme: "contact", bonusmaniementoff: 0, seuildefense: 0, degats: "0"} } )
data.items.push( { name: "Arme naturelle 2", type: 'arme', img: "systems/fvtt-hawkmoon-cyd/assets/icons/melee.webp", system: { typearme: "contact", bonusmaniementoff: 0, seuildefense: 0, degats: "0"} } )
data.items.push({ name: "Arme naturelle 1", type: 'arme', img: "systems/fvtt-hawkmoon-cyd/assets/icons/melee.webp", system: { typearme: "contact", bonusmaniementoff: 0, seuildefense: 0, degats: "0" } })
data.items.push({ name: "Arme naturelle 2", type: 'arme', img: "systems/fvtt-hawkmoon-cyd/assets/icons/melee.webp", system: { typearme: "contact", bonusmaniementoff: 0, seuildefense: 0, degats: "0" } })
}
return super.create(data, options);
@ -71,7 +71,7 @@ export class HawkmoonActor extends Actor {
let combat = this.getCombatValues()
if (arme.system.typearme == "contact" || arme.system.typearme == "contactjet") {
let bonusDefense = this.getBonusDefenseFromTalents()
arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée") )
arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée"))
arme.system.attrKey = "pui"
arme.system.totalDegats = arme.system.degats + "+" + combat.bonusDegatsTotal
arme.system.totalOffensif = this.system.attributs.pui.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff
@ -91,6 +91,11 @@ export class HawkmoonActor extends Actor {
}
/* -------------------------------------------- */
getItemSorted(types) {
let items = this.items.filter(item => types.includes(item.type)) || []
HawkmoonUtility.sortArrayObjectsByName(items)
return items
}
getWeapons() {
let armes = []
for (let arme of this.items) {
@ -98,55 +103,37 @@ export class HawkmoonActor extends Actor {
armes.push(this.prepareArme(arme))
}
}
HawkmoonUtility.sortArrayObjectsByName(armes)
return armes
}
/* -------------------------------------------- */
getMonnaies() {
return this.items.filter( it => it.type == "monnaie")
return this.getItemSorted(["monnaie"])
}
/* ----------------------- --------------------- */
addMember( actorId) {
let members = duplicate(this.system.members)
members.push( {id: actorId} )
this.update ({'system.members': members})
}
async removeMember(actorId) {
let members = this.system.members.filter(it => it.id != actorId )
this.update ({'system.members': members})
}
/* ----------------------- --------------------- */
getEquipments() {
return this.items.filter(item => item.type == "equipement")
return this.getItemSorted(["equipement"])
}
/* ----------------------- --------------------- */
getArtefacts() {
return this.items.filter(item => item.type == "artefact")
}
/* ----------------------- --------------------- */
getMonnaies() {
return this.items.filter(item => item.type == "monnaie")
}
/* -------------------------------------------- */
return this.getItemSorted(["artefact"])
}
getArmors() {
return this.items.filter(item => item.type == "protection")
return this.getItemSorted(["protection"])
}
getHistoriques() {
return this.items.filter(item => item.type == "historique")
return this.getItemSorted(["historique"])
}
getProfils() {
return this.items.filter(item => item.type == "profil")
return this.getItemSorted(["profil"])
}
getTalents() {
return this.items.filter(item => item.type == "talent")
return this.getItemSorted(["talent"])
}
getRessources() {
return this.items.filter(item => item.type == "ressource")
return this.getItemSorted(["ressource"])
}
getContacts() {
return this.items.filter(item => item.type == "contact")
return this.getItemSorted(["contact"])
}
/* -------------------------------------------- */
getSkills() {
let comp = []
@ -167,17 +154,19 @@ export class HawkmoonActor extends Actor {
comp.push(item)
}
}
return comp.sort(function (a, b) {
let fa = a.name.toLowerCase(),
fb = b.name.toLowerCase();
if (fa < fb) {
return -1;
}
if (fa > fb) {
return 1;
}
return 0;
})
HawkmoonUtility.sortArrayObjectsByName(comp)
return comp
}
/* ----------------------- --------------------- */
addMember(actorId) {
let members = duplicate(this.system.members)
members.push({ id: actorId })
this.update({ 'system.members': members })
}
async removeMember(actorId) {
let members = this.system.members.filter(it => it.id != actorId)
this.update({ 'system.members': members })
}
/* -------------------------------------------- */
@ -192,7 +181,7 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
getProtection() {
let equipProtection = 0
for(let armor in this.items) {
for (let armor in this.items) {
if (armor.type == "protection" && armor.system.equipped) {
equipProtection += Number(armor.system.protection)
}
@ -213,7 +202,7 @@ export class HawkmoonActor extends Actor {
vitesseBase: this.getVitesseBase(),
vitesseTotal: this.getVitesseBase() + this.system.combat.vitessebonus,
defenseBase: this.getDefenseBase(),
protection : this.getProtection(),
protection: this.getProtection(),
defenseTotal: this.getDefenseBase() + this.system.combat.defensebonus + this.getProtection() - this.getTotalAdversite()
}
return combat
@ -386,7 +375,7 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
getBonusDegats() {
return 0;
return 0;
}
/* -------------------------------------------- */
@ -448,27 +437,27 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
computeRichesse() {
let valueSC = 0
for(let monnaie of this.items) {
for (let monnaie of this.items) {
if (monnaie.type == "monnaie") {
valueSC += Number(monnaie.system.prixsc) * Number(monnaie.system.quantite)
valueSC += Number(monnaie.system.prixsc) * Number(monnaie.system.quantite)
}
}
return HawkmoonUtility.computeMonnaieDetails( valueSC)
return HawkmoonUtility.computeMonnaieDetails(valueSC)
}
/* -------------------------------------------- */
computeValeurEquipement() {
let valueSC = 0
for(let equip of this.items) {
for (let equip of this.items) {
if (equip.type == "equipement" || equip.type == "arme" || equip.type == "protection") {
valueSC += Number(equip.system.prixsc) * Number(equip.system.quantite ?? 1)
valueSC += (Number(equip.system.prixca) * Number(equip.system.quantite ?? 1)) * 20
valueSC += (Number(equip.system.prixpo) * Number(equip.system.quantite ?? 1)) * 400
valueSC += Number(equip.system.prixsc) * Number(equip.system.quantite ?? 1)
valueSC += (Number(equip.system.prixca) * Number(equip.system.quantite ?? 1)) * 20
valueSC += (Number(equip.system.prixpo) * Number(equip.system.quantite ?? 1)) * 400
}
}
return HawkmoonUtility.computeMonnaieDetails( valueSC)
return HawkmoonUtility.computeMonnaieDetails(valueSC)
}
/* -------------------------------------------- */
getCompetence(compId) {
return this.items.get(compId)
@ -494,7 +483,7 @@ export class HawkmoonActor extends Actor {
let maxDef = 0
let bestArme
for (let arme of defenseList) {
if (arme.type == "arme" ) {
if (arme.type == "arme") {
arme = this.prepareArme(arme)
}
if (arme.system.totalDefensif > maxDef) {
@ -568,8 +557,8 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
async rollAttribut(attrKey, isInit = false) {
let rollData = this.getCommonRollData(attrKey)
rollData.multiplier = (isInit)? 1 : 2
let rollData = this.getCommonRollData(attrKey)
rollData.multiplier = (isInit) ? 1 : 2
rollData.isInit = isInit
let rollDialog = await HawkmoonRollDialog.create(this, rollData)
rollDialog.render(true)
@ -605,9 +594,9 @@ export class HawkmoonActor extends Actor {
arme = this.prepareArme(arme)
}
console.log("DEGATS", arme)
let roll = new Roll( "1d10+"+arme.system.totalDegats).roll({ async: false })
let roll = new Roll("1d10+" + arme.system.totalDegats).roll({ async: false })
await HawkmoonUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode"));
let nbEtatPerdus = 0
let nbEtatPerdus = 0
if (targetVigueur) {
nbEtatPerdus = Math.floor(roll.total / targetVigueur)
}

View File

@ -61,6 +61,13 @@ export class HawkmoonUtility {
}
/* -------------------------------------------- */
static sortArrayObjectsByName(myArray) {
myArray.sort((a, b) => {
return a.name.localeCompare(b.name);
})
}
/* -------------------------------------------- */
static getModificateurOptions() {
let opt = []
@ -309,13 +316,13 @@ export class HawkmoonUtility {
/* -------------------------------------------- */
static computeMonnaieDetails(valueSC) {
let po = Math.floor(valueSC / 400)
let pa = Math.floor((valueSC - (po*400)) / 20)
let sc = valueSC - (po*400) - (pa*20)
let pa = Math.floor((valueSC - (po * 400)) / 20)
let sc = valueSC - (po * 400) - (pa * 20)
return {
po: po, pa: pa, sc: sc, valueSC: valueSC
po: po, pa: pa, sc: sc, valueSC: valueSC
}
}
/* -------------------------------------------- */
static computeResult(rollData) {
rollData.diceResult = rollData.roll.terms[0].results[0].result

View File

@ -1,7 +1,7 @@
{
"id": "fvtt-hawkmoon-cyd",
"description": "Hawkmoon RPG for FoundryVTT (CYD system - French)",
"version": "10.1.10",
"version": "10.1.11",
"authors": [
{
"name": "Uberwald/LeRatierBretonnien",
@ -35,7 +35,7 @@
"gridUnits": "m",
"license": "LICENSE.txt",
"manifest": "https://www.uberwald.me/gitea/public/fvtt-hawkmoon-cyd/raw/branch/master/system.json",
"download": "https://www.uberwald.me/gitea/public/fvtt-hawkmoon-cyd/archive/fvtt-hawkmoon-cyd-10.1.10.zip",
"download": "https://www.uberwald.me/gitea/public/fvtt-hawkmoon-cyd/archive/fvtt-hawkmoon-cyd-10.1.11.zip",
"languages": [
{
"lang": "fr",