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') { if (data.type == 'creature') {
const skills = await HawkmoonUtility.loadCompendium("fvtt-hawkmoon-cyd.skills-creatures") const skills = await HawkmoonUtility.loadCompendium("fvtt-hawkmoon-cyd.skills-creatures")
data.items = skills.map(i => i.toObject()) 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 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 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); return super.create(data, options);
@ -71,7 +71,7 @@ export class HawkmoonActor extends Actor {
let combat = this.getCombatValues() let combat = this.getCombatValues()
if (arme.system.typearme == "contact" || arme.system.typearme == "contactjet") { if (arme.system.typearme == "contact" || arme.system.typearme == "contactjet") {
let bonusDefense = this.getBonusDefenseFromTalents() 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.attrKey = "pui"
arme.system.totalDegats = arme.system.degats + "+" + combat.bonusDegatsTotal arme.system.totalDegats = arme.system.degats + "+" + combat.bonusDegatsTotal
arme.system.totalOffensif = this.system.attributs.pui.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff 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() { getWeapons() {
let armes = [] let armes = []
for (let arme of this.items) { for (let arme of this.items) {
@ -98,55 +103,37 @@ export class HawkmoonActor extends Actor {
armes.push(this.prepareArme(arme)) armes.push(this.prepareArme(arme))
} }
} }
HawkmoonUtility.sortArrayObjectsByName(armes)
return armes return armes
} }
/* -------------------------------------------- */
getMonnaies() { 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() { getEquipments() {
return this.items.filter(item => item.type == "equipement") return this.getItemSorted(["equipement"])
} }
/* ----------------------- --------------------- */
getArtefacts() { getArtefacts() {
return this.items.filter(item => item.type == "artefact") return this.getItemSorted(["artefact"])
} }
/* ----------------------- --------------------- */
getMonnaies() {
return this.items.filter(item => item.type == "monnaie")
}
/* -------------------------------------------- */
getArmors() { getArmors() {
return this.items.filter(item => item.type == "protection") return this.getItemSorted(["protection"])
} }
getHistoriques() { getHistoriques() {
return this.items.filter(item => item.type == "historique") return this.getItemSorted(["historique"])
} }
getProfils() { getProfils() {
return this.items.filter(item => item.type == "profil") return this.getItemSorted(["profil"])
} }
getTalents() { getTalents() {
return this.items.filter(item => item.type == "talent") return this.getItemSorted(["talent"])
} }
getRessources() { getRessources() {
return this.items.filter(item => item.type == "ressource") return this.getItemSorted(["ressource"])
} }
getContacts() { getContacts() {
return this.items.filter(item => item.type == "contact") return this.getItemSorted(["contact"])
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getSkills() { getSkills() {
let comp = [] let comp = []
@ -167,17 +154,19 @@ export class HawkmoonActor extends Actor {
comp.push(item) comp.push(item)
} }
} }
return comp.sort(function (a, b) { HawkmoonUtility.sortArrayObjectsByName(comp)
let fa = a.name.toLowerCase(), return comp
fb = b.name.toLowerCase(); }
if (fa < fb) {
return -1; /* ----------------------- --------------------- */
} addMember(actorId) {
if (fa > fb) { let members = duplicate(this.system.members)
return 1; members.push({ id: actorId })
} this.update({ 'system.members': members })
return 0; }
}) 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() { getProtection() {
let equipProtection = 0 let equipProtection = 0
for(let armor in this.items) { for (let armor in this.items) {
if (armor.type == "protection" && armor.system.equipped) { if (armor.type == "protection" && armor.system.equipped) {
equipProtection += Number(armor.system.protection) equipProtection += Number(armor.system.protection)
} }
@ -213,7 +202,7 @@ export class HawkmoonActor extends Actor {
vitesseBase: this.getVitesseBase(), vitesseBase: this.getVitesseBase(),
vitesseTotal: this.getVitesseBase() + this.system.combat.vitessebonus, vitesseTotal: this.getVitesseBase() + this.system.combat.vitessebonus,
defenseBase: this.getDefenseBase(), defenseBase: this.getDefenseBase(),
protection : this.getProtection(), protection: this.getProtection(),
defenseTotal: this.getDefenseBase() + this.system.combat.defensebonus + this.getProtection() - this.getTotalAdversite() defenseTotal: this.getDefenseBase() + this.system.combat.defensebonus + this.getProtection() - this.getTotalAdversite()
} }
return combat return combat
@ -448,25 +437,25 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
computeRichesse() { computeRichesse() {
let valueSC = 0 let valueSC = 0
for(let monnaie of this.items) { for (let monnaie of this.items) {
if (monnaie.type == "monnaie") { 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() { computeValeurEquipement() {
let valueSC = 0 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") { if (equip.type == "equipement" || equip.type == "arme" || equip.type == "protection") {
valueSC += Number(equip.system.prixsc) * Number(equip.system.quantite ?? 1) 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.prixca) * Number(equip.system.quantite ?? 1)) * 20
valueSC += (Number(equip.system.prixpo) * Number(equip.system.quantite ?? 1)) * 400 valueSC += (Number(equip.system.prixpo) * Number(equip.system.quantite ?? 1)) * 400
} }
} }
return HawkmoonUtility.computeMonnaieDetails( valueSC) return HawkmoonUtility.computeMonnaieDetails(valueSC)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -494,7 +483,7 @@ export class HawkmoonActor extends Actor {
let maxDef = 0 let maxDef = 0
let bestArme let bestArme
for (let arme of defenseList) { for (let arme of defenseList) {
if (arme.type == "arme" ) { if (arme.type == "arme") {
arme = this.prepareArme(arme) arme = this.prepareArme(arme)
} }
if (arme.system.totalDefensif > maxDef) { if (arme.system.totalDefensif > maxDef) {
@ -569,7 +558,7 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollAttribut(attrKey, isInit = false) { async rollAttribut(attrKey, isInit = false) {
let rollData = this.getCommonRollData(attrKey) let rollData = this.getCommonRollData(attrKey)
rollData.multiplier = (isInit)? 1 : 2 rollData.multiplier = (isInit) ? 1 : 2
rollData.isInit = isInit rollData.isInit = isInit
let rollDialog = await HawkmoonRollDialog.create(this, rollData) let rollDialog = await HawkmoonRollDialog.create(this, rollData)
rollDialog.render(true) rollDialog.render(true)
@ -605,7 +594,7 @@ export class HawkmoonActor extends Actor {
arme = this.prepareArme(arme) arme = this.prepareArme(arme)
} }
console.log("DEGATS", 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")); await HawkmoonUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode"));
let nbEtatPerdus = 0 let nbEtatPerdus = 0
if (targetVigueur) { if (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() { static getModificateurOptions() {
let opt = [] let opt = []
@ -309,8 +316,8 @@ export class HawkmoonUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeMonnaieDetails(valueSC) { static computeMonnaieDetails(valueSC) {
let po = Math.floor(valueSC / 400) let po = Math.floor(valueSC / 400)
let pa = Math.floor((valueSC - (po*400)) / 20) let pa = Math.floor((valueSC - (po * 400)) / 20)
let sc = valueSC - (po*400) - (pa*20) let sc = valueSC - (po * 400) - (pa * 20)
return { return {
po: po, pa: pa, sc: sc, valueSC: valueSC po: po, pa: pa, sc: sc, valueSC: valueSC
} }

View File

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