From edc918db4473c406dace7da307667bd46c91254f Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 13 Aug 2020 15:13:17 -0400 Subject: [PATCH] Make DeciderAI the only kind of AI; remove AI pickers --- src/components/Combat.vue | 2 +- src/components/Statblock.vue | 10 +--------- src/game/ai.ts | 31 ++----------------------------- src/game/creature.ts | 4 ++-- src/game/creatures/werewolf.ts | 1 + src/game/maps/town.ts | 4 ++-- 6 files changed, 9 insertions(+), 43 deletions(-) diff --git a/src/components/Combat.vue b/src/components/Combat.vue index 1deadd0..f001662 100644 --- a/src/components/Combat.vue +++ b/src/components/Combat.vue @@ -210,7 +210,7 @@ export default class Combat extends Vue { } }) - if (!(this.encounter.currentMove.ai instanceof NoAI)) { + if (!(this.encounter.currentMove.ai === null)) { if (this.encounter.currentMove.side === Side.Heroes) { this.executedLeft(this.encounter.currentMove.ai.decide(this.encounter.currentMove, this.encounter)) } else { diff --git a/src/components/Statblock.vue b/src/components/Statblock.vue index 0d964bc..4d7c07d 100644 --- a/src/components/Statblock.vue +++ b/src/components/Statblock.vue @@ -60,9 +60,6 @@ - @@ -71,7 +68,6 @@ import { Component, Prop, Vue, Watch, Emit } from 'vue-property-decorator' import { Creature } from '@/game/creature' import { POV } from '@/game/language' -import { NoAI, RandomAI, VoreAI, AI } from '@/game/ai' import { Stats, Stat, StatIcons, StatDescs, Vigor, VigorIcons, VigorDescs, VoreStatDescs, VoreStatIcons, VisibleStatus } from '@/game/combat' import ContainerView from './ContainerView.vue' import tippy, { delegate, createSingleton } from 'tippy.js' @@ -83,8 +79,7 @@ import 'tippy.js/dist/tippy.css' }, data () { return { - POV: POV, - ais: [new NoAI(), new RandomAI(), new VoreAI()] + POV: POV } }, methods: { @@ -156,9 +151,6 @@ export default class Statblock extends Vue { createSingleton(tippyInstances, { delay: 500, touch: ["hold", 500] }) this.statusChanged([]) - - const picker = this.$el.querySelector(".ai-picker") as HTMLSelectElement - picker.selectedIndex = this.$data.ais.findIndex((ai: AI) => ai.name === this.subject.ai.name) } } diff --git a/src/game/ai.ts b/src/game/ai.ts index 7012491..88dde55 100644 --- a/src/game/ai.ts +++ b/src/game/ai.ts @@ -6,18 +6,6 @@ import { NoPassDecider, NoReleaseDecider, ChanceDecider, ConsequenceDecider, Con import { SurrenderEffect } from './combat/effects' import { StatusConsequence, DamageConsequence } from './combat/consequences' -export interface AI { - name: string; - decide (actor: Creature, encounter: Encounter): LogEntry; -} - -export class NoAI implements AI { - name = "No AI" - decide (actor: Creature, encounter: Encounter): LogEntry { - throw new Error("This AI cannot be used.") - } -} - /** * A Decider determines how favorable an action is to perform. */ @@ -25,7 +13,7 @@ export interface Decider { decide: (encounter: Encounter, user: Creature, target: Creature, action: Action) => number; } -export class DeciderAI implements AI { +export class AI { constructor (public name: string, private deciders: Decider[]) { } @@ -74,25 +62,10 @@ export class DeciderAI implements AI { } } -/** - * The RandomAI is **COMPLETELY** random. Good luck. - */ -export class RandomAI implements AI { - name = "Random AI" - decide (actor: Creature, encounter: Encounter): LogEntry { - const actions = encounter.combatants.flatMap(enemy => actor.validActions(enemy).map(action => ({ - target: enemy, - action: action - }))) - const chosen = actions[Math.floor(Math.random() * actions.length)] - return chosen.action.try(actor, chosen.target) - } -} - /** * The VoreAI tries to eat opponents, but only if the odds are good enough */ -export class VoreAI extends DeciderAI { +export class VoreAI extends AI { constructor () { super( "Vore AI", diff --git a/src/game/creature.ts b/src/game/creature.ts index f1a500b..381f98d 100644 --- a/src/game/creature.ts +++ b/src/game/creature.ts @@ -4,7 +4,7 @@ import { LogEntry, LogLines, LogLine } from './interface' import { VoreContainer, VoreType, Container } from './vore' import { Item, EquipmentSlot, Equipment, ItemKind, Currency } from './items' import { PassAction } from './combat/actions' -import { AI, NoAI } from './ai' +import { AI } from './ai' import { Mortal } from './entity' export class Creature extends Mortal { @@ -34,7 +34,7 @@ export class Creature extends Mortal { side: Side; title = "Lv. 1 Creature"; equipment: {[key in EquipmentSlot]?: Equipment } = {} - ai: AI = new NoAI() + ai: AI|null = null constructor (name: Noun, kind: Noun, pronouns: Pronoun, stats: Stats, public preyPrefs: Set, public predPrefs: Set, private baseMass: number) { super(name, kind, pronouns, stats) diff --git a/src/game/creatures/werewolf.ts b/src/game/creatures/werewolf.ts index 0db31c4..465cb2f 100644 --- a/src/game/creatures/werewolf.ts +++ b/src/game/creatures/werewolf.ts @@ -27,6 +27,7 @@ export class Werewolf extends Creature { ) this.ai = new VoreAI() + this.side = Side.Monsters const stomach = new Stomach(this, 2, new ConstantDamageFormula(new Damage( diff --git a/src/game/maps/town.ts b/src/game/maps/town.ts index d57384b..01df436 100644 --- a/src/game/maps/town.ts +++ b/src/game/maps/town.ts @@ -8,7 +8,7 @@ import { Creature } from '../creature' import { DevourAction } from '../combat/actions' import { SurrenderEffect } from '../combat/effects' import moment from 'moment' -import { RandomAI, VoreAI } from '../ai' +import { VoreAI } from '../ai' function makeParty (): Creature[] { const fighter = new Creatures.Human(new ProperNoun("Redgar"), MalePronouns, { @@ -244,7 +244,7 @@ export const Town = (): Place => { (world, executor) => { const enemy = new Creatures.Human(new ProperNoun("Nerd"), TheyPronouns) enemy.side = Side.Monsters - enemy.ai = new RandomAI() + enemy.ai = new VoreAI() const encounter = new Encounter( { name: "Fight some nerd",