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.
 
 
 
 
 

58 lines
1.5 KiB

  1. import { Consequence, DamageFormula, Condition, StatusEffect } from '../combat'
  2. import { Creature } from '../creature'
  3. import { LogEntry, LogLines, LogLine } from '../interface'
  4. import { Verb, PairLine } from '../language'
  5. /**
  6. * Takes a function, and thus can do anything.
  7. */
  8. export class ArbitraryConsequence extends Consequence {
  9. constructor (public apply: (user: Creature, target: Creature) => LogEntry, conditions: Condition[] = []) {
  10. super(conditions)
  11. }
  12. }
  13. /**
  14. * Renders some text.
  15. */
  16. export class LogConsequence extends Consequence {
  17. constructor (private line: PairLine<Creature>, conditions: Condition[] = []) {
  18. super(conditions)
  19. }
  20. apply (user: Creature, target: Creature): LogEntry {
  21. return this.line(user, target)
  22. }
  23. }
  24. /**
  25. * Deals damage.
  26. */
  27. export class DamageConsequence extends Consequence {
  28. constructor (private damageFormula: DamageFormula, conditions: Condition[] = []) {
  29. super(conditions)
  30. }
  31. apply (user: Creature, target: Creature): LogEntry {
  32. const damage = this.damageFormula.calc(user, target)
  33. return new LogLines(
  34. new LogLine(`${target.name.capital} ${target.name.conjugate(new Verb('take'))} `, damage.renderShort(), ` damage!`),
  35. target.takeDamage(damage)
  36. )
  37. }
  38. }
  39. /**
  40. * Applies a status effect
  41. */
  42. export class StatusConsequence extends Consequence {
  43. constructor (private statusMaker: () => StatusEffect, conditions: Condition[] = []) {
  44. super(conditions)
  45. }
  46. apply (user: Creature, target: Creature): LogEntry {
  47. return target.applyEffect(this.statusMaker())
  48. }
  49. }