import React from 'react';

import Analyzer from 'Parser/Core/Analyzer';
import SPELLS from 'common/SPELLS';
import SpellIcon from 'common/SpellIcon';
import { formatPercentage } from 'common/format';

import StatisticBox from 'Main/StatisticBox';

import Garothi from 'Raids/AntorusTheBurningThrone/GarothiWorldbreaker';
import Felhounds from 'Raids/AntorusTheBurningThrone/FelhoundsOfSargeras';
import Council from 'Raids/AntorusTheBurningThrone/AntoranHighCommand';
import Eonar from 'Raids/AntorusTheBurningThrone/EonarLifebinder';
import PKeeper from 'Raids/AntorusTheBurningThrone/PortalKeeperHasabel';
import Imonar from 'Raids/AntorusTheBurningThrone/ImonarTheSoulhunter';
import KG from 'Raids/AntorusTheBurningThrone/Kingaroth';
import Vari from 'Raids/AntorusTheBurningThrone/Varimathras';
import Coven from 'Raids/AntorusTheBurningThrone/TheCovenOfShivarra';
import Agg from 'Raids/AntorusTheBurningThrone/Aggramar';
import Argus from 'Raids/AntorusTheBurningThrone/ArgusTheUnmaker';

const mitigationBuffs = {'Paladin' : [SPELLS.SHIELD_OF_THE_RIGHTEOUS_BUFF.id,
                                      SPELLS.ARDENT_DEFENDER.id,
                                      SPELLS.GUARDIAN_OF_ANCIENT_KINGS.id]};

const mitigationChecks = new Map([
  [Garothi.id, Object.values(Garothi.fight.softMitigationChecks)],
  [Felhounds.id, Object.values(Felhounds.fight.softMitigationChecks)],
  [Council.id, Object.values(Council.fight.softMitigationChecks)],
  [Eonar.id, Object.values(Eonar.fight.softMitigationChecks)],
  [PKeeper.id, Object.values(PKeeper.fight.softMitigationChecks)],
  [Imonar.id, Object.values(Imonar.fight.softMitigationChecks)],
  [KG.id, Object.values(KG.fight.softMitigationChecks)],
  [Vari.id, Object.values(Vari.fight.softMitigationChecks)],
  [Coven.id, Object.values(Coven.fight.softMitigationChecks)],
  [Agg.id, Object.values(Agg.fight.softMitigationChecks)],
  [Argus.id, Object.values(Argus.fight.softMitigationChecks)],
]);


class MitigationCheck extends Analyzer{
  static checks;
  static buffCheck;
  static checksPassed = 0;
  static checksFailed = 0;


  constructor(...args) {
    super(...args);
    const boss = this.owner.boss;
    this.checks = mitigationChecks.get(boss.id);
    if(typeof this.checks === "undefined"){
      this.checks = [];
    }
    this.buffCheck = mitigationBuffs[this.owner.player.type];
    this.checksPassed = 0;
    this.checksFailed = 0;
  }


  on_toPlayer_damage(event){
    if(this.checks.includes(event.ability.guid)){
      if(this.buffCheck.some((e) => this.selectedCombatant.hasBuff(e))){
        this.checksPassed += 1;
      } else {
        this.checksFailed += 1;
      }
    }
  }


  statistic(){
    if(this.checksPassed + this.checksFailed === 0){
      return null;
    }
    return (
      <StatisticBox icon={<SpellIcon id={this.buffCheck[0]} />}
        value={`${formatPercentage(this.checksPassed/(this.checksPassed+this.checksFailed))} %`}
        label={`Soft mitigation checks passed.`}
        tooltip={`${this.checksPassed}/${this.checksPassed+this.checksFailed} of tank-targeted abilities were mitigated.`} />
    );
  }

}


export default MitigationCheck;

import React from 'react';

import Analyzer from 'Parser/Core/Analyzer';
import SPELLS from 'common/SPELLS';
import SpellIcon from 'common/SpellIcon';
import { formatPercentage } from 'common/format';

import StatisticBox from 'Main/StatisticBox';

import {findByBossId} from 'Raids';

const mitigationBuffs = {'Paladin' : [SPELLS.SHIELD_OF_THE_RIGHTEOUS_BUFF.id,
                                      SPELLS.ARDENT_DEFENDER.id,
                                      SPELLS.GUARDIAN_OF_ANCIENT_KINGS.id]};


class MitigationCheck extends Analyzer{

  static checks;
  static buffCheck;
  static checksPassed;
  static checksFailed;


  constructor(...args) {
    super(...args);
    this.checksPassed = 0;
    this.checksFailed = 0;
    const boss = findByBossId(this.owner.boss.id);
    if(boss !== null && boss.fight.hasOwnProperty('softMitigationChecks')){
      this.checks = Object.values(boss.fight.softMitigationChecks);
      if(typeof this.checks === "undefined"){
        this.checks = [];
      }
      this.buffCheck = mitigationBuffs[this.owner.player.type];
    }else{
      this.checks = [];
      this.buffCheck = [];
    }

  }


  on_toPlayer_damage(event){
    if(this.checks.includes(event.ability.guid)){
      if(this.buffCheck.some((e) => this.selectedCombatant.hasBuff(e))){
        this.checksPassed += 1;
      } else {
        this.checksFailed += 1;
      }
    }
  }


  statistic(){
    if(this.checksPassed + this.checksFailed === 0){
      return null;
    }
    return (
      <StatisticBox icon={<SpellIcon id={this.buffCheck[0]} />}
        value={`${formatPercentage(this.checksPassed/(this.checksPassed+this.checksFailed))} %`}
        label={`Soft mitigation checks passed.`}
        tooltip={`${this.checksPassed}/${this.checksPassed+this.checksFailed} of tank-targeted abilities were mitigated.`} />
    );
  }

}


export default MitigationCheck;

Change to get boss info via findByBossId rather than having to add each boss to MitigationCheck manually.