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

96 строки
2.4 KiB

  1. import { DamageType, Damage, Combatant, Stats, Action, Vigor } from './combat'
  2. import { Noun, Pronoun } from './language'
  3. import { Pred, Prey, Container, VoreType } from './vore'
  4. export enum POV {First, Third}
  5. export interface Entity {
  6. name: Noun;
  7. pronouns: Pronoun;
  8. perspective: POV;
  9. }
  10. export interface Mortal extends Entity {
  11. vigors: {[key in Vigor]: number};
  12. maxVigors: {[key in Vigor]: number};
  13. resistances: Map<DamageType, number>;
  14. takeDamage: (damage: Damage) => void;
  15. stats: Stats;
  16. status: string;
  17. }
  18. export class Creature implements Mortal, Pred, Prey, Combatant {
  19. vigors = {
  20. [Vigor.Health]: 100,
  21. [Vigor.Stamina]: 100,
  22. [Vigor.Willpower]: 100
  23. }
  24. maxVigors = {
  25. [Vigor.Health]: 100,
  26. [Vigor.Stamina]: 100,
  27. [Vigor.Willpower]: 100
  28. }
  29. resistances: Map<DamageType, number> = new Map()
  30. perspective: POV = POV.Third
  31. containers: Array<Container> = []
  32. actions: Array<Action> = [];
  33. private baseBulk: number;
  34. get bulk (): number {
  35. return this.baseBulk
  36. }
  37. containedIn: Container|null = null;
  38. constructor (public name: Noun, public pronouns: Pronoun, public stats: Stats, public preyPrefs: Set<VoreType>, public predPrefs: Set<VoreType>, bulk: number) {
  39. this.baseBulk = bulk
  40. }
  41. toString (): string {
  42. return this.name.toString()
  43. }
  44. takeDamage (damage: Damage): void {
  45. damage.damages.forEach(instance => {
  46. const resistance: number|undefined = this.resistances.get(instance.type)
  47. if (resistance !== undefined) {
  48. this.vigors[instance.target] -= instance.amount * resistance
  49. } else {
  50. this.vigors[instance.target] -= instance.amount
  51. }
  52. })
  53. }
  54. get status (): string {
  55. if (this.vigors[Vigor.Health] < 0) {
  56. return "DEAD"
  57. }
  58. if (this.vigors[Vigor.Stamina] < 0) {
  59. return "Unconscious"
  60. }
  61. if (this.vigors[Vigor.Willpower] < 0) {
  62. return "Too horny"
  63. }
  64. if (this.containedIn !== null) {
  65. return "Devoured"
  66. }
  67. return "Normal"
  68. }
  69. validActions (target: Creature): Array<Action> {
  70. let choices = this.actions.concat(this.containers.flatMap(container => container.actions))
  71. if (this.containedIn !== null) {
  72. choices = choices.concat(this.containedIn.actions)
  73. }
  74. return choices.filter(action => {
  75. return action.allowed(this, target)
  76. })
  77. }
  78. }