Feast 2.0!
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

52 řádky
1.7 KiB

  1. import { Creature } from './creature'
  2. import { Encounter } from './combat'
  3. import { LogEntry } from './interface'
  4. import { ReleaseAction, TransferAction } from './combat/actions'
  5. export interface AI {
  6. name: string;
  7. decide (actor: Creature, encounter: Encounter): LogEntry;
  8. }
  9. export class NoAI implements AI {
  10. name = "No AI"
  11. decide (actor: Creature, encounter: Encounter): LogEntry {
  12. throw new Error("This AI cannot be used.")
  13. }
  14. }
  15. /**
  16. * The RandomAI is **COMPLETELY** random. Good luck.
  17. */
  18. export class RandomAI implements AI {
  19. name = "Random AI"
  20. decide (actor: Creature, encounter: Encounter): LogEntry {
  21. const actions = encounter.combatants.flatMap(enemy => actor.validActions(enemy).map(action => ({
  22. target: enemy,
  23. action: action
  24. })))
  25. const chosen = actions[Math.floor(Math.random() * actions.length)]
  26. return chosen.action.execute(actor, chosen.target)
  27. }
  28. }
  29. /**
  30. * The VoreAI tries to perform moves from its containers
  31. */
  32. export class VoreAI extends RandomAI {
  33. name = "Vore AI"
  34. decide (actor: Creature, encounter: Encounter): LogEntry {
  35. const actions = encounter.combatants.flatMap(enemy => actor.validActions(enemy).map(action => ({
  36. target: enemy,
  37. action: action
  38. })))
  39. const voreActions = actions.filter(action => actor.otherContainers.concat(actor.containers).some(container => container.actions.includes(action.action) || action instanceof TransferAction))
  40. const aggressiveActions = voreActions.filter(action => !(action.action instanceof ReleaseAction))
  41. const chosen = aggressiveActions[Math.floor(Math.random() * aggressiveActions.length)]
  42. if (chosen === undefined) {
  43. return super.decide(actor, encounter)
  44. }
  45. return chosen.action.execute(actor, chosen.target)
  46. }
  47. }