Fix de régressions, stabilisation #575
@@ -15,21 +15,15 @@ export class TMRRencontres {
 | 
			
		||||
   * @param {*} forcedRoll 
 | 
			
		||||
   */
 | 
			
		||||
  static async rollRencontre(terrain, forcedRoll) {
 | 
			
		||||
    // TODO: recherche parmi les types de terrains + mauvaise, rejet si plusieurs choix
 | 
			
		||||
    const codeTerrain = Grammar.toLowerCaseNoAccent(terrain);
 | 
			
		||||
    if (!terrain) {
 | 
			
		||||
      ChatMessage.create({
 | 
			
		||||
        user: game.user.id,
 | 
			
		||||
        whisper: [game.user.id],
 | 
			
		||||
        content: "Un type de case doit être indiqué (par exemple sanctuaire, desert ou cité)"
 | 
			
		||||
      });
 | 
			
		||||
      return false;
 | 
			
		||||
    terrain = TMRUtility.findTMRLike(terrain);
 | 
			
		||||
    if (terrain == undefined) {
 | 
			
		||||
      return undefined;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if (forcedRoll && (forcedRoll <= 0 || forcedRoll > 100)) {
 | 
			
		||||
      forcedRoll = undefined;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    const codeTerrain = Grammar.toLowerCaseNoAccent(terrain)
 | 
			
		||||
    const table = await TMRRencontres.$buildTableRencontre(codeTerrain);
 | 
			
		||||
    const [selected, roll] = await TMRRencontres.$selectRencontre(codeTerrain, table, forcedRoll);
 | 
			
		||||
    const rencontre = await TMRRencontres.createRencontre(selected.rencontre);
 | 
			
		||||
@@ -40,7 +34,7 @@ export class TMRRencontres {
 | 
			
		||||
  /* -------------------------------------------- */
 | 
			
		||||
  static async $buildTableRencontre(codeTerrain) {
 | 
			
		||||
    let max = 0;
 | 
			
		||||
    const items = await SystemCompendiums.getItems('rencontres');
 | 
			
		||||
    const items = await SystemCompendiums.getItems('rencontres', 'rencontre');
 | 
			
		||||
    const filtreMauvaise = codeTerrain == 'mauvaise' ? it => it.system.mauvaiseRencontre : it => !it.system.mauvaiseRencontre;
 | 
			
		||||
    const rencontres = items.filter(it => it.type == 'rencontre')
 | 
			
		||||
      .filter(filtreMauvaise)
 | 
			
		||||
 
 | 
			
		||||
@@ -286,6 +286,23 @@ export class TMRUtility {
 | 
			
		||||
    const tmr = TMRMapping[coord];
 | 
			
		||||
    return Grammar.articleDetermine(tmr.type) + ' ' + tmr.label;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  static findTMRLike(type, options = {inclusMauvaise:true}) {
 | 
			
		||||
    const choix = [...Object.values(TMRType)]
 | 
			
		||||
    if (options.inclusMauvaise){
 | 
			
		||||
      choix.push({name: 'Mauvaise'});
 | 
			
		||||
    }
 | 
			
		||||
    const selection = Misc.findAllLike(type, choix).map(it => it.name);
 | 
			
		||||
    if (selection.length == 0) {
 | 
			
		||||
      ui.notifications.warn(`Un type de TMR doit être indiqué, '${type}' n'est pas trouvé dans ${choix}`);
 | 
			
		||||
      return undefined;
 | 
			
		||||
    }
 | 
			
		||||
    if (selection.length > 1) {
 | 
			
		||||
      ui.notifications.warn(`Plusieurs types de TMR pourraient correspondre à '${type}': ${selection}`);
 | 
			
		||||
      return undefined;
 | 
			
		||||
    }
 | 
			
		||||
    return selection[0];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static typeTmrName(type) {
 | 
			
		||||
    return Misc.upperFirst(TMRType[Grammar.toLowerCaseNoAccent(type)].name);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user