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.
 
 
 
 
 

150 line
4.2 KiB

  1. import { Consequence, DamageFormula, Condition, StatusEffect, Damage, DamageType } 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. * Deals damage to the target and heals the user
  75. */
  76. export class DrainConsequence extends Consequence {
  77. constructor (private damageFormula: DamageFormula, conditions: Condition[] = []) {
  78. super(conditions)
  79. }
  80. apply (user: Creature, target: Creature): LogEntry {
  81. const damage = this.damageFormula.calc(user, target)
  82. const heal = new Damage(...damage.damages.map(instance => ({ amount: instance.amount, type: DamageType.Heal, target: instance.target })))
  83. console.log(heal)
  84. return new LogLines(
  85. new LogLine(`${user.name.capital} ${user.name.conjugate(new Verb("drain"))} `, damage.renderShort(), ` from ${target.name.objective}.`),
  86. target.takeDamage(damage),
  87. user.takeDamage(heal)
  88. )
  89. }
  90. describe (user: Creature, target: Creature): LogEntry {
  91. return new LogLine(
  92. this.damageFormula.describe(user, target)
  93. )
  94. }
  95. }
  96. /**
  97. * Applies a status effect
  98. */
  99. export class StatusConsequence extends Consequence {
  100. constructor (public statusMaker: (user: Creature, target: Creature) => StatusEffect, conditions: Condition[] = []) {
  101. super(conditions)
  102. }
  103. apply (user: Creature, target: Creature): LogEntry {
  104. return target.applyEffect(this.statusMaker(user, target))
  105. }
  106. describe (user: Creature, target: Creature): LogEntry {
  107. return new LogLine(
  108. `Applies a `,
  109. this.statusMaker(user, target).name.toString(),
  110. ` effect.`
  111. )
  112. }
  113. }
  114. /**
  115. * Consumes the target
  116. */
  117. export class ConsumeConsequence extends Consequence {
  118. constructor (public container: Container, conditions: Condition[] = []) {
  119. super(conditions)
  120. }
  121. apply (user: Creature, target: Creature): LogEntry {
  122. return this.container.consume(target)
  123. }
  124. describe (user: Creature, target: Creature): LogEntry {
  125. return new LogLine(
  126. `${this.container.consumeVerb.singular.capital} ${target.name.objective}, sending ${target.pronouns.objective} ${this.container.consumePreposition} ${user.name.possessive} ${this.container.name}.`
  127. )
  128. }
  129. }