|
- import { Decider } from '../ai'
- import { Encounter, Action, Consequence, CompositionAction } from '../combat'
- import { Creature } from '../creature'
- import { PassAction, ReleaseAction, DigestAction } from '../combat/actions'
- import { StatusConsequence } from '../combat/consequences'
- import { SurrenderEffect } from '../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 {
- 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
- }
- }
- }
-
- /**
- * A [[ConsequenceFunctionDecider]] that filters out status effects
- */
- 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 [[DigestAction]]s
- */
- export class FavorDigestDecider implements Decider {
- decide (encounter: Encounter, user: Creature, target: Creature, action: Action) {
- if (action instanceof DigestAction) {
- return 5
- } else {
- return 1
- }
- }
- }
|