Feast 2.0!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

124 行
3.4 KiB

  1. import { Consequence, DamageFormula, Condition, StatusEffect } from '@/game/combat'
  2. import { Creature } from '@/game/creature'
  3. import { LogEntry, LogLines, LogLine, nilLog } from '@/game/interface'
  4. import { Verb, PairLine } from '@/game/language'
  5. import { Container } from '@/game/vore'
  6. /**
  7. * Takes a function, and thus can do anything.
  8. */
  9. export class ArbitraryConsequence extends Consequence {
  10. constructor (
  11. public apply: (user: Creature, target: Creature) => LogEntry,
  12. public describe: (user: Creature, target: Creature) => LogEntry,
  13. conditions: Condition[] = []
  14. ) {
  15. super(conditions)
  16. }
  17. }
  18. /**
  19. * Renders some text.
  20. */
  21. export class LogConsequence extends Consequence {
  22. constructor (private line: PairLine<Creature>, conditions: Condition[] = []) {
  23. super(conditions)
  24. }
  25. apply (user: Creature, target: Creature): LogEntry {
  26. return this.line(user, target)
  27. }
  28. describe (user: Creature, target: Creature): LogEntry {
  29. return nilLog
  30. }
  31. }
  32. /**
  33. * Deals damage.
  34. */
  35. export class DamageConsequence extends Consequence {
  36. constructor (private damageFormula: DamageFormula, conditions: Condition[] = []) {
  37. super(conditions)
  38. }
  39. apply (user: Creature, target: Creature): LogEntry {
  40. const damage = this.damageFormula.calc(user, target)
  41. return new LogLines(
  42. new LogLine(`${target.name.capital} ${target.name.conjugate(new Verb('take'))} `, damage.renderShort(), ` damage!`),
  43. target.takeDamage(damage)
  44. )
  45. }
  46. describe (user: Creature, target: Creature): LogEntry {
  47. return new LogLine(
  48. this.damageFormula.describe(user, target)
  49. )
  50. }
  51. }
  52. /**
  53. * Same as [[DamageConsequence]], but it has healing text
  54. */
  55. export class HealingConsequence extends Consequence {
  56. constructor (private damageFormula: DamageFormula, conditions: Condition[] = []) {
  57. super(conditions)
  58. }
  59. apply (user: Creature, target: Creature): LogEntry {
  60. const damage = this.damageFormula.calc(user, target)
  61. return new LogLines(
  62. new LogLine(`${target.name.capital} ${target.name.conjugate(new Verb('heal'))} `, damage.renderShort(), `!`),
  63. target.takeDamage(damage)
  64. )
  65. }
  66. describe (user: Creature, target: Creature): LogEntry {
  67. return new LogLine(
  68. `Heals for `,
  69. this.damageFormula.describe(user, target)
  70. )
  71. }
  72. }
  73. /**
  74. * Applies a status effect
  75. */
  76. export class StatusConsequence extends Consequence {
  77. constructor (public statusMaker: (user: Creature, target: Creature) => StatusEffect, conditions: Condition[] = []) {
  78. super(conditions)
  79. }
  80. apply (user: Creature, target: Creature): LogEntry {
  81. return target.applyEffect(this.statusMaker(user, target))
  82. }
  83. describe (user: Creature, target: Creature): LogEntry {
  84. return new LogLine(
  85. `Applies a `,
  86. this.statusMaker(user, target).name.toString(),
  87. ` effect.`
  88. )
  89. }
  90. }
  91. /**
  92. * Consumes the target
  93. */
  94. export class ConsumeConsequence extends Consequence {
  95. constructor (public container: Container, conditions: Condition[] = []) {
  96. super(conditions)
  97. }
  98. apply (user: Creature, target: Creature): LogEntry {
  99. return this.container.consume(target)
  100. }
  101. describe (user: Creature, target: Creature): LogEntry {
  102. return new LogLine(
  103. `${this.container.consumeVerb.singular.capital} ${target.name.objective}, sending ${target.pronouns.objective} ${this.container.consumePreposition} ${user.name.possessive} ${this.container.name}.`
  104. )
  105. }
  106. }