import { PART_JEU, RollPartJeu } from "./roll-part-jeu.mjs"
import { RollType } from "./roll-type.mjs"
import { DIFF,  ROLL_TYPE_JEU, RollConstants } from "./roll-constants.mjs"
import { Apprecier } from "../moral/apprecier.mjs"


export class RollTypeJeu extends RollType {
  get code() { return ROLL_TYPE_JEU }
  get name() { return `Jouer` }

  visible(rollData) {
    return rollData.active.actor.isPersonnage()
      && RollConstants.findCompetence(rollData, 'Jeu')
  }

  isOpposed(rollData) { return rollData.opponent != undefined  }


  title(rollData) {
    if (rollData.opponent) {
      return `joue contre`
    }
    return `joue: ${rollData.current[PART_JEU].label}`
  }

  onSelect(rollData) {
    this.setDiffType(rollData, DIFF.LIBRE)
    RollPartJeu.forceCompJeu(rollData)
  }

  getResult(rollData, impacts) {
    const current = rollData.current[PART_JEU]
    return Apprecier.getAppreciation(current.qualite, current.jeu, rollData, current.comp)
  }
}
