Feast 2.0!
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

112 строки
3.0 KiB

  1. import { Decider } from '@/game/ai'
  2. import { Encounter, Action, Consequence, CompositionAction } from '@/game/combat'
  3. import { Creature } from '@/game/creature'
  4. import { PassAction, ReleaseAction, RubAction } from '@/game/combat/actions'
  5. import { StatusConsequence } from '@/game/combat/consequences'
  6. import { SurrenderEffect } from '@/game/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. /* eslint-disable-next-line */
  44. constructor (private consequenceType: new (...args: any) => T, private weight: number) {
  45. }
  46. decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
  47. if (action instanceof CompositionAction) {
  48. if (action.consequences.some(
  49. consequence => consequence instanceof this.consequenceType
  50. )) {
  51. return this.weight
  52. } else {
  53. return 1
  54. }
  55. } else {
  56. return 1
  57. }
  58. }
  59. }
  60. /**
  61. * Adjusts the weights for [[CompositionAction]]s, using the provided function to make the choice.
  62. */
  63. export class ConsequenceFunctionDecider implements Decider {
  64. constructor (private func: (encounter: Encounter, user: Creature, target: Creature, action: CompositionAction) => number) {
  65. }
  66. decide (encounter: Encounter, user: Creature, target: Creature, action: Action): number {
  67. if (action instanceof CompositionAction) {
  68. return this.func(encounter, user, target, action)
  69. } else {
  70. return 1
  71. }
  72. }
  73. }
  74. export class NoSurrenderDecider extends ConsequenceFunctionDecider {
  75. constructor () {
  76. super(
  77. (encounter, user, target, action) => {
  78. return action.consequences.some(
  79. consequence => {
  80. if (consequence instanceof StatusConsequence) {
  81. return (consequence.statusMaker(user, target) instanceof SurrenderEffect)
  82. }
  83. }
  84. ) ? 0 : 1
  85. }
  86. )
  87. }
  88. }
  89. /**
  90. * Favors [[RubAction]]s
  91. */
  92. export class FavorRubDecider implements Decider {
  93. decide (encounter: Encounter, user: Creature, target: Creature, action: Action) {
  94. if (action instanceof RubAction) {
  95. return 5
  96. } else {
  97. return 1
  98. }
  99. }
  100. }