#122 Gestion d'acturs liés à une fiche de perso

This commit is contained in:
2021-01-11 16:29:41 +01:00
parent e54de9f080
commit d02b5ac88c
8 changed files with 234 additions and 64 deletions

View File

@ -2506,6 +2506,77 @@ export class RdDActor extends Actor {
_alchimieResult(rollData) {
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-alchimie.html');
}
/* -------------------------------------------- */
buildVehiculesList() {
let myArray = [];
for (let vehiculeLink of this.data.data.subacteurs.vehicules) {
let vehicule = game.actors.get( vehiculeLink.id );
myArray.push( { id: vehiculeLink.id, name: vehicule.data.name, categorie: vehicule.data.data.categorie,
structure: vehicule.data.data.structure, img: vehicule.data.img } );
}
return myArray;
}
/* -------------------------------------------- */
buildSuivantsList() {
let myArray = [];
for (let suivantLink of this.data.data.subacteurs.suivants) {
let suivant = game.actors.get( suivantLink.id );
myArray.push( { id: suivantLink.id, name: suivant.data.name, img: suivant.data.img } );
}
return myArray;
}
/* -------------------------------------------- */
buildMonturesList() {
let myArray = [];
for (let montureLink of this.data.data.subacteurs.montures) {
let monture = game.actors.get( montureLink.id );
myArray.push( { id: montureLink.id, name: monture.data.name, img: monture.data.img } );
}
return myArray;
}
/* -------------------------------------------- */
async pushSubacteur( actor, dataArray, dataPath, dataName ) {
let alreadyPresent = dataArray.find( attached => attached.id == actor.data._id);
if ( !alreadyPresent ) {
let newArray = duplicate(dataArray);
newArray.push( { id: actor.data._id });
await this.update( { [dataPath]: newArray });
} else {
ui.notifications.warn(dataName+" est déja attaché à ce Personnage.");
}
}
/* -------------------------------------------- */
addSubacteur( actorId ) {
let actor = game.actors.get( actorId );
//console.log("Ajout acteur : ", actor, this);
if (actor && actor.owner ) {
if (actor.data.type == 'vehicule') {
this.pushSubacteur( actor, this.data.data.subacteurs.vehicules, 'data.subacteurs.vehicules', 'Ce Véhicule' );
} else if (actor.data.type == 'creature') {
this.pushSubacteur( actor, this.data.data.subacteurs.montures, 'data.subacteurs.montures', 'Cette Monture' );
} else if (actor.data.type == 'personnage') {
this.pushSubacteur( actor, this.data.data.subacteurs.suivants, 'data.subacteurs.suivants', 'Ce Suivant' );
}
} else {
ui.notifications.warn("Vous n'avez pas les droits sur l'acteur que vous attachez.")
}
}
/* -------------------------------------------- */
async removeSubacteur( actorId ) {
let newVehicules = this.data.data.subacteurs.vehicules.filter(function(obj, index, arr){ return obj.id != actorId } );
let newSuivants = this.data.data.subacteurs.suivants.filter(function(obj, index, arr){ return obj.id != actorId } );
let newMontures = this.data.data.subacteurs.montures.filter(function(obj, index, arr){ return obj.id != actorId } );
await this.update( { 'data.subacteurs.vehicules': newVehicules });
await this.update( { 'data.subacteurs.suivants': newSuivants });
await this.update( { 'data.subacteurs.montures': newMontures });
}
}