|  | import { Decider } from '@/game/ai'
import { Encounter, Action, Consequence, CompositionAction } from '@/game/combat'
import { Creature } from '@/game/creature'
import { PassAction, ReleaseAction, RubAction } from '@/game/combat/actions'
import { StatusConsequence } from '@/game/combat/consequences'
import { SurrenderEffect } from '@/game/combat/effects'
/**
 * Specifically avoids using a [[PassAction]]
 */
export class NoPassDecider implements Decider {
  decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
    if (action instanceof PassAction) {
      return 0
    } else {
      return 1
    }
  }
}
/**
 * Specifically avoids using a [[ReleaseAction]]
 */
export class NoReleaseDecider implements Decider {
  decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
    if (action instanceof ReleaseAction) {
      return 0
    } else {
      return 1
    }
  }
}
/**
 * Weights actions based on how likely they are to succeed
 */
export class ChanceDecider implements Decider {
  decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
    return action.odds(user, target)
  }
}
/**
 * Adjusts the weights for [[CompositionAction]]s that contain the specified consequence
 */
export class ConsequenceDecider<T extends Consequence> implements Decider {
  /* eslint-disable-next-line */
  constructor (private consequenceType: new (...args: any) => T, private weight: number) {
  }
  decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
    if (action instanceof CompositionAction) {
      if (action.consequences.some(
        consequence => consequence instanceof this.consequenceType
      )) {
        return this.weight
      } else {
        return 1
      }
    } else {
      return 1
    }
  }
}
/**
 * Adjusts the weights for [[CompositionAction]]s, using the provided function to make the choice.
 */
export class ConsequenceFunctionDecider implements Decider {
  constructor (private func: (encounter: Encounter, user: Creature, target: Creature, action: CompositionAction) => number) {
  }
  decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
    if (action instanceof CompositionAction) {
      return this.func(encounter, user, target, action)
    } else {
      return 1
    }
  }
}
export class NoSurrenderDecider extends ConsequenceFunctionDecider {
  constructor () {
    super(
      (encounter, user, target, action) => {
        return action.consequences.some(
          consequence => {
            if (consequence instanceof StatusConsequence) {
              return (consequence.statusMaker(user, target) instanceof SurrenderEffect)
            }
          }
        ) ? 0 : 1
      }
    )
  }
}
/**
 * Favors [[RubAction]]s
 */
export class FavorRubDecider implements Decider {
  decide (encounter: Encounter, user: Creature, target: Creature, action: Action) {
    if (action instanceof RubAction) {
      return 5
    } else {
      return 1
    }
  }
}
 |