Feast 2.0!
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

31 lines
847 B

  1. import { Creature } from './creature'
  2. import { Encounter } from './combat'
  3. import { LogEntry } from './interface'
  4. export interface AI {
  5. name: string;
  6. decide (actor: Creature, encounter: Encounter): LogEntry;
  7. }
  8. export class NoAI implements AI {
  9. name = "No AI"
  10. decide (actor: Creature, encounter: Encounter): LogEntry {
  11. throw new Error("This AI cannot be used.")
  12. }
  13. }
  14. /**
  15. * The RandomAI is **COMPLETELY** random. Good luck.
  16. */
  17. export class RandomAI implements AI {
  18. name = "Random AI"
  19. decide (actor: Creature, encounter: Encounter): LogEntry {
  20. const actions = encounter.combatants.flatMap(enemy => actor.validActions(enemy).map(action => ({
  21. target: enemy,
  22. action: action
  23. })))
  24. const chosen = actions[Math.floor(Math.random() * actions.length)]
  25. return chosen.action.execute(actor, chosen.target)
  26. }
  27. }