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.
 
 
 
 
 

238 lines
9.4 KiB

  1. import { Entity, Mortal, POV } from './entity'
  2. import { Damage, Actionable, Action, DevourAction, DigestAction, ReleaseAction, StruggleAction } from './combat'
  3. import { LogLines, LogEntry, CompositeLog } from './interface'
  4. import { POVSolo, POVPair, POVPairArgs } from './language'
  5. export enum VoreType {
  6. Oral = "Oral Vore",
  7. Anal = "Anal Vore",
  8. Cock = "Cock Vore",
  9. Unbirth = "Unbirthing"
  10. }
  11. export interface Prey extends Mortal {
  12. preyPrefs: Set<VoreType>;
  13. bulk: number;
  14. containedIn: Container | null;
  15. }
  16. export interface Pred extends Entity {
  17. predPrefs: Set<VoreType>;
  18. containers: Array<Container>;
  19. }
  20. export interface Container extends Actionable {
  21. name: string;
  22. owner: Pred;
  23. voreTypes: Set<VoreType>;
  24. contents: Array<Prey>;
  25. capacity: number;
  26. fullness: number;
  27. canTake: (prey: Prey) => boolean;
  28. consume: (prey: Prey) => LogEntry;
  29. release: (prey: Prey) => LogEntry;
  30. struggle: (prey: Prey) => LogEntry;
  31. tick: (dt: number) => LogEntry;
  32. describe: () => LogEntry;
  33. digest: (prey: Prey) => LogEntry;
  34. absorb: (prey: Prey) => LogEntry;
  35. dispose: (preys: Prey[]) => LogEntry;
  36. actions: Array<Action>;
  37. }
  38. abstract class NormalContainer implements Container {
  39. contents: Array<Prey>
  40. abstract consumeLines: POVPair<Pred, Prey>
  41. abstract releaseLines: POVPair<Pred, Prey>
  42. abstract struggleLines: POVPair<Prey, Pred>
  43. abstract tickLines: POVSolo<Pred>
  44. abstract digestLines: POVPair<Pred, Prey>
  45. abstract absorbLines: POVPair<Pred, Prey>
  46. abstract disposeLines: POVPair<Pred, Prey>
  47. get fullness (): number {
  48. return Array.from(this.contents.values()).reduce((total: number, prey: Prey) => total + prey.bulk, 0)
  49. }
  50. canTake (prey: Prey): boolean {
  51. const fits = this.capacity - this.fullness >= prey.bulk
  52. const permitted = Array.from(this.voreTypes).every(voreType => {
  53. return prey.preyPrefs.has(voreType)
  54. })
  55. return fits && permitted
  56. }
  57. consume (prey: Prey): LogEntry {
  58. this.contents.push(prey)
  59. prey.containedIn = this
  60. return this.consumeLines.run(this.owner, prey)
  61. }
  62. release (prey: Prey): LogEntry {
  63. prey.containedIn = null
  64. this.contents = this.contents.filter(victim => victim !== prey)
  65. return this.releaseLines.run(this.owner, prey)
  66. }
  67. struggle (prey: Prey): LogEntry {
  68. return this.struggleLines.run(prey, this.owner)
  69. }
  70. tick (dt: number): LogEntry {
  71. const digested: Array<Prey> = []
  72. const absorbed: Array<Prey> = []
  73. this.contents.forEach(prey => {
  74. const start = prey.health
  75. prey.takeDamage(this.damage.scale(dt / 3600))
  76. const end = prey.health
  77. if (start > 0 && end <= 0) {
  78. digested.push(prey)
  79. } else if (start > -100 && end <= -100) {
  80. absorbed.push(prey)
  81. }
  82. })
  83. const digestedEntries = new CompositeLog(...digested.map(prey => this.digest(prey)))
  84. const absorbedEntries = new CompositeLog(...digested.map(prey => this.absorb(prey)))
  85. this.contents = this.contents.filter(prey => {
  86. return prey.health > -100
  87. })
  88. return new CompositeLog(this.tickLines.run(this.owner), digestedEntries, absorbedEntries)
  89. }
  90. describe (): LogEntry {
  91. const lines: Array<string> = []
  92. this.contents.forEach(prey => {
  93. lines.push(prey.toString())
  94. })
  95. return new LogLines(...lines)
  96. }
  97. digest (prey: Prey): LogEntry {
  98. return this.digestLines.run(this.owner, prey)
  99. }
  100. absorb (prey: Prey): LogEntry {
  101. return this.absorbLines.run(this.owner, prey)
  102. }
  103. dispose (preys: Prey[]): LogEntry {
  104. return new CompositeLog(...preys.map(prey => this.disposeLines.run(this.owner, prey)))
  105. }
  106. actions: Array<Action>
  107. constructor (public name: string, public owner: Pred, public voreTypes: Set<VoreType>, public capacity: number, private damage: Damage) {
  108. this.contents = []
  109. this.actions = []
  110. this.actions.push(new DevourAction(this))
  111. this.actions.push(new DigestAction(this))
  112. this.actions.push(new ReleaseAction(this))
  113. this.actions.push(new StruggleAction(this))
  114. }
  115. }
  116. export class Stomach extends NormalContainer {
  117. constructor (owner: Pred, capacity: number, damage: Damage) {
  118. super('Stomach', owner, new Set([VoreType.Oral]), capacity, damage)
  119. }
  120. consumeLines = new POVPair([
  121. [[POV.First, POV.Third], (user, target) => new LogLines(`You devour ${target.name}`)],
  122. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital} munches you`)],
  123. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} munches ${target.name.capital}`)]
  124. ])
  125. releaseLines = new POVPair([
  126. [[POV.First, POV.Third], (user, target) => new LogLines(`You hork up ${target.name}`)],
  127. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital} horks you up`)],
  128. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} horks up ${target.name.capital}`)]
  129. ])
  130. struggleLines = new POVPair([
  131. [[POV.First, POV.Third], (user, target) => new LogLines(`You claw your way out of ${target.name}`)],
  132. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital} forces ${user.pronouns.possessive} way up your throat!`)],
  133. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} escapes from the gut of ${target.name}`)]
  134. ])
  135. tickLines = new POVSolo([
  136. [[POV.First], (user) => new LogLines(`Your stomach gurgles and churns`)],
  137. [[POV.Third], (user) => new LogLines(`${user.name.capital}'s gut snarls and gurgles`)]
  138. ])
  139. digestLines = new POVPair([
  140. [[POV.First, POV.Third], (user, target) => new LogLines(`Your stomach overwhelms ${target.name}`)],
  141. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital}'s stomach finishes you off`)],
  142. [[POV.Third, POV.Third], (user, target) => new LogLines(`${target.name.capital}'s squirms fade, overwhelmed by the stomach of ${user.name}`)]
  143. ])
  144. absorbLines = new POVPair([
  145. [[POV.First, POV.Third], (user, target) => new LogLines(`Your guts completely absorb ${target.name}`)],
  146. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital}'s guts soak you up like water in a sponge`)],
  147. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} finishes absorbing the remains of ${target.name}`)]
  148. ])
  149. disposeLines = new POVPair([
  150. [[POV.First, POV.Third], (user, target) => new LogLines(`Your guts completely absorb ${target.name}`)],
  151. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital}'s guts soak you up like water in a sponge`)],
  152. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} finishes absorbing the remains of ${target.name}`)]
  153. ])
  154. }
  155. export class Bowels extends NormalContainer {
  156. constructor (owner: Pred, capacity: number, damage: Damage) {
  157. super('Bowels', owner, new Set([VoreType.Anal]), capacity, damage)
  158. }
  159. consumeLines = new POVPair([
  160. [[POV.First, POV.Third], (user, target) => new LogLines(`You devour ${target.name}`)],
  161. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital} munches you`)],
  162. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} munches ${target.name.capital}`)]
  163. ])
  164. releaseLines = new POVPair([
  165. [[POV.First, POV.Third], (user, target) => new LogLines(`You hork up ${target.name}`)],
  166. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital} horks you up`)],
  167. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} horks up ${target.name.capital}`)]
  168. ])
  169. struggleLines = new POVPair([
  170. [[POV.First, POV.Third], (user, target) => new LogLines(`You claw your way out of ${target.name}`)],
  171. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital} forces ${user.pronouns.possessive} way up your throat!`)],
  172. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} escapes from the gut of ${target.name}`)]
  173. ])
  174. tickLines = new POVSolo([
  175. [[POV.First], (user) => new LogLines(`Your stomach gurgles and churns!`)],
  176. [[POV.Third], (user) => new LogLines(`${user.name.capital}'s gut snarls and gurgles`)]
  177. ])
  178. digestLines = new POVPair([
  179. [[POV.First, POV.Third], (user, target) => new LogLines(`Your stomach overwhelms ${target.name}`)],
  180. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital}'s stomach finishes you off`)],
  181. [[POV.Third, POV.Third], (user, target) => new LogLines(`${target.name.capital}'s squirms fade, overwhelmed by the stomach of ${user.name}`)]
  182. ])
  183. absorbLines = new POVPair([
  184. [[POV.First, POV.Third], (user, target) => new LogLines(`Your guts completely absorb ${target.name}`)],
  185. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital}'s guts soak you up like water in a sponge`)],
  186. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} finishes absorbing the remains of ${target.name}`)]
  187. ])
  188. disposeLines = new POVPair([
  189. [[POV.First, POV.Third], (user, target) => new LogLines(`Your guts completely absorb ${target.name}`)],
  190. [[POV.Third, POV.First], (user, target) => new LogLines(`${user.name.capital}'s guts soak you up like water in a sponge`)],
  191. [[POV.Third, POV.Third], (user, target) => new LogLines(`${user.name.capital} finishes absorbing the remains of ${target.name}`)]
  192. ])
  193. }