Feast 2.0!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

114 lines
3.0 KiB

  1. import { Decider } from '../ai'
  2. import { Encounter, Action, Consequence, CompositionAction } from '../combat'
  3. import { Creature } from '../creature'
  4. import { PassAction, ReleaseAction, DigestAction } from '../combat/actions'
  5. import { StatusConsequence } from '../combat/consequences'
  6. import { SurrenderEffect } from '../combat/effects'
  7. /**
  8. * Specifically avoids using a [[PassAction]]
  9. */
  10. export class NoPassDecider implements Decider {
  11. decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
  12. if (action instanceof PassAction) {
  13. return 0
  14. } else {
  15. return 1
  16. }
  17. }
  18. }
  19. /**
  20. * Specifically avoids using a [[ReleaseAction]]
  21. */
  22. export class NoReleaseDecider implements Decider {
  23. decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
  24. if (action instanceof ReleaseAction) {
  25. return 0
  26. } else {
  27. return 1
  28. }
  29. }
  30. }
  31. /**
  32. * Weights actions based on how likely they are to succeed
  33. */
  34. export class ChanceDecider implements Decider {
  35. decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
  36. return action.odds(user, target)
  37. }
  38. }
  39. /**
  40. * Adjusts the weights for [[CompositionAction]]s that contain the specified consequence
  41. */
  42. export class ConsequenceDecider<T extends Consequence> implements Decider {
  43. constructor (private consequenceType: new (...args: any) => T, private weight: number) {
  44. }
  45. decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
  46. if (action instanceof CompositionAction) {
  47. if (action.consequences.some(
  48. consequence => consequence instanceof this.consequenceType
  49. )) {
  50. return this.weight
  51. } else {
  52. return 1
  53. }
  54. } else {
  55. return 1
  56. }
  57. }
  58. }
  59. /**
  60. * Adjusts the weights for [[CompositionAction]]s, using the provided function to make the choice.
  61. */
  62. export class ConsequenceFunctionDecider implements Decider {
  63. constructor (private func: (encounter: Encounter, user: Creature, target: Creature, action: CompositionAction) => number) {
  64. }
  65. decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
  66. if (action instanceof CompositionAction) {
  67. return this.func(encounter, user, target, action)
  68. } else {
  69. return 1
  70. }
  71. }
  72. }
  73. /**
  74. * A [[ConsequenceFunctionDecider]] that filters out status effects
  75. */
  76. export class NoSurrenderDecider extends ConsequenceFunctionDecider {
  77. constructor () {
  78. super(
  79. (encounter, user, target, action) => {
  80. return action.consequences.some(
  81. consequence => {
  82. if (consequence instanceof StatusConsequence) {
  83. return (consequence.statusMaker(user, target) instanceof SurrenderEffect)
  84. }
  85. }
  86. ) ? 0 : 1
  87. }
  88. )
  89. }
  90. }
  91. /**
  92. * Favors [[DigestAction]]s
  93. */
  94. export class FavorDigestDecider implements Decider {
  95. decide (encounter: Encounter, user: Creature, target: Creature, action: Action) {
  96. if (action instanceof DigestAction) {
  97. return 5
  98. } else {
  99. return 1
  100. }
  101. }
  102. }