|
- import { Damage, Combatant, Stats, Action, Vigor, Side, GroupAction, VisibleStatus, ImplicitStatus, StatusEffect, DamageType } from './combat'
- import { Noun, Pronoun } from './language'
- import { LogEntry, LogLines } from './interface'
- import { Vore, VoreContainer, VoreType } from './vore'
- import { Item } from './items'
- import { PassAction } from './combat/actions'
-
- export class Creature extends Vore implements Combatant {
- actions: Array<Action> = [];
- containedIn: VoreContainer | null = null;
- desc = "Some creature";
- effects: Array<StatusEffect> = [];
- groupActions: Array<GroupAction> = [];
- items: Array<Item> = [];
- otherActions: Array<Action> = [];
- side: Side;
- title = "Lv. 1 Creature";
-
- constructor (name: Noun, kind: Noun, pronouns: Pronoun, stats: Stats, preyPrefs: Set<VoreType>, predPrefs: Set<VoreType>, mass: number) {
- super(name, kind, pronouns, stats, preyPrefs, predPrefs, mass)
-
- this.actions.push(new PassAction())
- this.side = Side.Heroes
- }
-
- applyEffect (effect: StatusEffect): LogEntry {
- this.effects.push(effect)
- return effect.onApply(this)
- }
-
- /**
- * Determines how much damage an attack would do
- */
- effectiveDamage (damage: Damage): Damage {
- const preDamage = this.effects.reduce((modifiedDamage: Damage, effect: StatusEffect) => {
- return effect.preDamage(this, modifiedDamage)
- }, damage)
- return super.effectiveDamage(preDamage)
- }
-
- resistanceTo (damageType: DamageType) {
- const base = super.resistanceTo(damageType)
-
- const modified = this.effects.reduce((resist, effect) => effect.modResistance(damageType, resist), base)
- return modified
- }
-
- executeAction (action: Action, target: Creature): LogEntry {
- const preActionResults = this.effects.map(effect => effect.preAction(this))
- const preReceiveActionResults = target.effects.map(effect => effect.preReceiveAction(target, this))
-
- const blocking = preActionResults.concat(preReceiveActionResults).filter(result => result.prevented)
- if (blocking.length > 0) {
- return new LogLines(...blocking.map(result => result.log))
- } else {
- return action.execute(this, target)
- }
- }
-
- removeEffect (effect: StatusEffect): LogEntry {
- this.effects = this.effects.filter(eff => eff !== effect)
- return effect.onRemove(this)
- }
-
- get status (): Array<VisibleStatus> {
- const results: Array<VisibleStatus> = []
-
- if (this.vigors[Vigor.Health] <= 0) {
- results.push(new ImplicitStatus('Dead', 'Out of health', 'fas fa-heart'))
- }
- if (this.vigors[Vigor.Stamina] <= 0) {
- results.push(new ImplicitStatus('Unconscious', 'Out of stamina', 'fas fa-bolt'))
- }
- if (this.vigors[Vigor.Resolve] <= 0) {
- results.push(new ImplicitStatus('Broken', 'Out of resolve', 'fas fa-brain'))
- }
- if (this.containedIn !== null) {
- results.push(new ImplicitStatus('Eaten', 'Devoured by ' + this.containedIn.owner.name, 'fas fa-drumstick-bite'))
- }
-
- this.effects.forEach(effect => {
- results.push(effect)
- })
- return results
- }
-
- validActions (target: Creature): Array<Action> {
- let choices = this.actions.concat(
- this.containers.flatMap(container => container.actions)
- ).concat(
- target.otherActions.concat(
- this.otherContainers.flatMap(container => container.actions).concat(
- this.items.flatMap(item => item.actions)
- )
- )
- )
-
- if (this.containedIn !== null) {
- choices = choices.concat(this.containedIn.actions)
- }
-
- return choices.filter(action => {
- return action.allowed(this, target)
- })
- }
-
- validGroupActions (targets: Array<Creature>): Array<GroupAction> {
- const choices = this.groupActions
-
- return choices.filter(action => {
- return targets.some(target => action.allowed(this, target))
- })
- }
- }
|