<commit_before>import React from 'react';
import Analyzer, { SELECTED_PLAYER } from 'parser/core/Analyzer';
import SPELLS from 'common/SPELLS';
import Statistic from 'interface/statistics/Statistic';
import BoringSpellValueText from 'interface/statistics/components/BoringSpellValueText';
import Events, { ApplyDebuffEvent, ApplyDebuffStackEvent, CastEvent, EventType, RemoveDebuffEvent } from 'parser/core/Events';
import STATISTIC_CATEGORY from 'interface/others/STATISTIC_CATEGORY';
import { currentStacks } from 'parser/shared/modules/helpers/Stacks';

/**
 * Steady Shot increases the damage of your next Aimed Shot against the target by X, stacking up to 5 times.
 *
 * Example:
 * https://www.warcraftlogs.com/reports/wPdQLfFnhTVYRyJm#fight=12&type=damage-done&source=640
 */

const MAX_STACKS = 5;
const MS_BUFFER = 100;

class SteadyAim extends Analyzer {

  constructor(options: any) {
    super(options);
    this.active = this.selectedCombatant.hasTrait(SPELLS.STEADY_AIM.id);
    this.addEventListener(Events.cast.by(SELECTED_PLAYER).spell(SPELLS.AIMED_SHOT), this.onAimedShot);
    this.addEventListener(Events.cast.by(SELECTED_PLAYER).spell(SPELLS.STEADY_SHOT), this.onSteadyShot);
    this.addEventListener(Events.applydebuff.by(SELECTED_PLAYER).spell(SPELLS.STEADY_AIM_DEBUFF), this.onDebuffChange);
    this.addEventListener(Events.applydebuffstack.by(SELECTED_PLAYER).spell(SPELLS.STEADY_AIM_DEBUFF), this.onDebuffChange);
    this.addEventListener(Events.removedebuff.by(SELECTED_PLAYER).spell(SPELLS.STEADY_AIM_DEBUFF), this.onDebuffChange);
  }

  applications = 0;
  _stacks = 0;
  aimedShotStacks = 0;
  aimedShots = 0;
  maxPossible = 0;
  wasted = 0;
  utilised = 0;
  removeDebuffTimestamp: number = 0;

  onAimedShot(event: CastEvent) {
    this.aimedShots += 1;
    if (this.aimedShotStacks > 0 && event.timestamp + MS_BUFFER > this.removeDebuffTimestamp) {
      this.utilised += this.aimedShotStacks;
      this.aimedShotStacks = 0;
    }
  }

  onSteadyShot() {
    this.maxPossible += 1;
    if (this._stacks === MAX_STACKS) {
      this.wasted += 1;
    }
  }

  onDebuffChange(event: ApplyDebuffEvent | ApplyDebuffStackEvent | RemoveDebuffEvent) {
    if (event.type === EventType.RemoveDebuff) {
      this.removeDebuffTimestamp = event.timestamp;
      this.aimedShotStacks = this._stacks;
    } else {
      this.applications += 1;
    }
    this._stacks = currentStacks(event);
  }

  get averageStacksPerAimed() {<commit_msg>update SteadyAim to stricter eventlistener<commit_after>import React from 'react';
import Analyzer, { SELECTED_PLAYER } from 'parser/core/Analyzer';
import SPELLS from 'common/SPELLS';
import Statistic from 'interface/statistics/Statistic';
import BoringSpellValueText from 'interface/statistics/components/BoringSpellValueText';
import Events, { ApplyDebuffEvent, ApplyDebuffStackEvent, CastEvent, EventType, RemoveDebuffEvent } from 'parser/core/Events';
import STATISTIC_CATEGORY from 'interface/others/STATISTIC_CATEGORY';
import { currentStacks } from 'parser/shared/modules/helpers/Stacks';

/**
 * Steady Shot increases the damage of your next Aimed Shot against the target by X, stacking up to 5 times.
 *
 * Example:
 * https://www.warcraftlogs.com/reports/wPdQLfFnhTVYRyJm#fight=12&type=damage-done&source=640
 */

const MAX_STACKS = 5;
const MS_BUFFER = 100;

class SteadyAim extends Analyzer {

  constructor(options: any) {
    super(options);
    this.active = this.selectedCombatant.hasTrait(SPELLS.STEADY_AIM.id);
    this.addEventListener(Events.cast.by(SELECTED_PLAYER).spell(SPELLS.AIMED_SHOT), this.onAimedShot);
    this.addEventListener(Events.cast.by(SELECTED_PLAYER).spell(SPELLS.STEADY_SHOT), this.onSteadyShot);
    this.addEventListener(Events.applydebuff.by(SELECTED_PLAYER).spell(SPELLS.STEADY_AIM_DEBUFF), this.onDebuffChange);
    this.addEventListener(Events.applydebuffstack.by(SELECTED_PLAYER).spell(SPELLS.STEADY_AIM_DEBUFF), this.onDebuffChange);
    this.addEventListener(Events.removedebuff.by(SELECTED_PLAYER).spell(SPELLS.STEADY_AIM_DEBUFF), this.onDebuffChange);
  }

  applications = 0;
  _stacks = 0;
  aimedShotStacks = 0;
  aimedShots = 0;
  maxPossible = 0;
  wasted = 0;
  utilised = 0;
  removeDebuffTimestamp: number = 0;

  onAimedShot(event: CastEvent) {
    this.aimedShots += 1;
    if (this.aimedShotStacks > 0 && event.timestamp + MS_BUFFER > this.removeDebuffTimestamp) {
      this.utilised += this.aimedShotStacks;
      this.aimedShotStacks = 0;
    }
  }

  onSteadyShot() {
    this.maxPossible += 1;
    if (this._stacks === MAX_STACKS) {
      this.wasted += 1;
    }
  }

  onDebuffChange(event: ApplyDebuffEvent & ApplyDebuffStackEvent & RemoveDebuffEvent) {
    if (event.type === EventType.RemoveDebuff) {
      this.removeDebuffTimestamp = event.timestamp;
      this.aimedShotStacks = this._stacks;
    } else {
      this.applications += 1;
    }
    this._stacks = currentStacks(event);
  }

  get averageStacksPerAimed() {
{'fraction_non_alphanumeric': 0.11171607178866708, 'fraction_numerical': 0.009679370840895343, 'mean_word_length': 4.734104046242774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1892597', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1745, 'n_words': 288}