<commit_before>import SPELLS from 'common/SPELLS';

import Analyzer from 'Parser/Core/Analyzer';
import Abilities from 'Parser/Core/Modules/Abilities';
import SpellUsable from 'Parser/Core/Modules/SpellUsable';

const HEALTHSTONE_SPELLS = [
  SPELLS.HEALTHSTONE,
  SPELLS.ANCIENT_HEALING_POTION,
  SPELLS.ASTRAL_HEALING_POTION,
];

const ONE_HOUR_MS = 3600000; // one hour
const COOLDOWN_MS = 60000; // one minute

/**
* Healthstone/health pot cooldown is one minute, but only starts when the 
* actor is out of combat or dead.
*/

class Healthstone extends Analyzer {
  static dependencies = {
    abilities: Abilities,
    spellUsable: SpellUsable,
  };

  maxCasts = 1;
  lastDeathWithHealthstoneReady = null;

  on_initialized() {
    this.abilities.add({
      spell: HEALTHSTONE_SPELLS,
      category: Abilities.SPELL_CATEGORIES.DEFENSIVE,
      cooldown: ONE_HOUR_MS / 1000, // The cooldown does not start while in combat so setting it to one hour.
      castEfficiency: {
        suggestion: true,
        recommendedEfficiency: 0.5,
        maxCasts: (cooldown, fightDuration, getAbility, parser) => {
          return this.maxCasts;
        },
      },
    });
  }

  on_toPlayer_death(event) {
    if (!this.spellUsable.isOnCooldown(SPELLS.HEALTHSTONE.id)){
      // If Healthstone was not on cooldown, only increase maxCasts if it would have been ready again since the previous death.
      if (this.lastDeathWithHealthstoneReady){
        const timeSince = event.timestamp - this.lastDeathWithHealthstoneReady;
        if (timeSince < COOLDOWN_MS){ // Healthstone would not have been ready if used on previous death
          return;
        }
      }
      // Healthstone was ready for this death so increase maxCasts and save timestamp
      this.lastDeathWithHealthstoneReady = event.timestamp;
      this.increaseMaxCasts(event);
      return;
    }
    const cooldownRemaining = this.spellUsable.cooldownRemaining(SPELLS.HEALTHSTONE.id);
    // Only start cooldown if not already started.
    if (cooldownRemaining < COOLDOWN_MS){
      return;
    }
    this.spellUsable.reduceCooldown(SPELLS.HEALTHSTONE.id, cooldownRemaining - COOLDOWN_MS);
    this.increaseMaxCasts(event);
  }

  increaseMaxCasts(event){
    // If the death starts the cooldown and there is less than 60 seconds remaining of the encounter another cast was possible.
    const nextAvailableHealthstoneCast = event.timestamp + COOLDOWN_MS;
    if (nextAvailableHealthstoneCast < this.owner.fight.end_time){
      this.maxCasts += 1;
    }
  }

}

export default Healthstone;
<commit_msg>updated efficiency thresholds<commit_after>import SPELLS from 'common/SPELLS';

import Analyzer from 'Parser/Core/Analyzer';
import Abilities from 'Parser/Core/Modules/Abilities';
import SpellUsable from 'Parser/Core/Modules/SpellUsable';

const HEALTHSTONE_SPELLS = [
  SPELLS.HEALTHSTONE,
  SPELLS.ANCIENT_HEALING_POTION,
  SPELLS.ASTRAL_HEALING_POTION,
];

const ONE_HOUR_MS = 3600000; // one hour
const COOLDOWN_MS = 60000; // one minute

/**
* Healthstone/health pot cooldown is one minute, but only starts when the 
* actor is out of combat or dead.
*/

class Healthstone extends Analyzer {
  static dependencies = {
    abilities: Abilities,
    spellUsable: SpellUsable,
  };

  maxCasts = 1;
  lastDeathWithHealthstoneReady = null;

  on_initialized() {
    this.abilities.add({
      spell: HEALTHSTONE_SPELLS,
      category: Abilities.SPELL_CATEGORIES.DEFENSIVE,
      cooldown: ONE_HOUR_MS / 1000, // The cooldown does not start while in combat so setting it to one hour.
      castEfficiency: {
        suggestion: true,
        recommendedEfficiency: 0.6,
          averageIssueEfficiency: 0.4,
          majorIssueEfficiency: 0.1,
        maxCasts: (cooldown, fightDuration, getAbility, parser) => {
          return this.maxCasts;
        },
      },
    });
  }

  on_toPlayer_death(event) {
    if (!this.spellUsable.isOnCooldown(SPELLS.HEALTHSTONE.id)){
      // If Healthstone was not on cooldown, only increase maxCasts if it would have been ready again since the previous death.
      if (this.lastDeathWithHealthstoneReady){
        const timeSince = event.timestamp - this.lastDeathWithHealthstoneReady;
        if (timeSince < COOLDOWN_MS){ // Healthstone would not have been ready if used on previous death
          return;
        }
      }
      // Healthstone was ready for this death so increase maxCasts and save timestamp
      this.lastDeathWithHealthstoneReady = event.timestamp;
      this.increaseMaxCasts(event);
      return;
    }
    const cooldownRemaining = this.spellUsable.cooldownRemaining(SPELLS.HEALTHSTONE.id);
    // Only start cooldown if not already started.
    if (cooldownRemaining < COOLDOWN_MS){
      return;
    }
    this.spellUsable.reduceCooldown(SPELLS.HEALTHSTONE.id, cooldownRemaining - COOLDOWN_MS);
    this.increaseMaxCasts(event);
  }

  increaseMaxCasts(event){
    // If the death starts the cooldown and there is less than 60 seconds remaining of the encounter another cast was possible.
    const nextAvailableHealthstoneCast = event.timestamp + COOLDOWN_MS;
    if (nextAvailableHealthstoneCast < this.owner.fight.end_time){
      this.maxCasts += 1;
    }
  }

}

export default Healthstone;

{'fraction_non_alphanumeric': 0.08237986270022883, 'fraction_numerical': 0.009153318077803204, 'mean_word_length': 3.316872427983539, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6072078', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1660, 'n_words': 426}