import { Grammar } from "../grammar.js";
import { RdDInitiative } from "../combat/initiative.mjs";

export class MappingCreatureArme {

  /* -------------------------------------------- */
  static setRollDataCreature(rollData) {
    const code = Grammar.toLowerCaseNoAccentNoSpace(rollData.competence.name);
    const selectedCarac = { code: code, label: rollData.competence.name, value: rollData.competence.system.carac_value };
    rollData.carac = { [code]: selectedCarac }
    rollData.competence.system.defaut_carac = code
    rollData.selectedCarac = selectedCarac
    rollData.arme = MappingCreatureArme.armeCreature(rollData.competence);
  }


  /* -------------------------------------------- */
  static armeCreature(item) {
    const categorieAttaque = item.getCategorieAttaque()
    if (categorieAttaque != undefined) {
      // cloner pour ne pas modifier la compétence
      return foundry.utils.mergeObject(item, {
        action: item.isCompetencePossession() ? 'possession' : 'attaque',
        system: {
          competence: item.name,
          cac: categorieAttaque == "naturelle" ? "naturelle" : "",
          niveau: item.system.niveau,
          initiative: RdDInitiative.getRollInitiative(item.system.carac_value, item.system.niveau),
          equipe: true,
          resistance: 100,
          dommagesReels: item.system.dommages,
          penetration: 0,
          force: 0,
          rapide: true,
        }
      }, { inplace: false, });
    }
    return undefined;
  }

}