From ac646801dbdb7ddeafef546e9bf1b5d146cfd3b1 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Mon, 17 Aug 2020 11:07:36 -0400 Subject: [PATCH] Add a basic perk system The perks aren't visible yet. There's only one perk: Ravenous, which makes the dire wolf even better at eating you. --- src/game/combat.ts | 15 +++++++++++++++ src/game/combat/perks.ts | 27 +++++++++++++++++++++++++++ src/game/combat/tests.ts | 4 ++-- src/game/creature.ts | 6 +++++- src/game/creatures/wolves.ts | 3 +++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/game/combat/perks.ts diff --git a/src/game/combat.ts b/src/game/combat.ts index b825714..c9223de 100644 --- a/src/game/combat.ts +++ b/src/game/combat.ts @@ -3,6 +3,7 @@ import { TextLike, DynText, ToBe, LiveText, PairLineArgs, PairLine } from './lan import { LogEntry, LogLines, FAElem, LogLine, FormatEntry, FormatOpt, PropElem, nilLog, Newline } from './interface' import { Resistances } from './entity' import { World } from './world' +import { TestCategory } from './combat/tests' export enum DamageType { Pierce = "Pierce", @@ -555,6 +556,20 @@ export class Effective { scale (scale: number): number { return scale } + + /** + * Additively modifies a creature's score for an offensive test + */ + modTestOffense (attacker: Creature, defender: Creature, kind: TestCategory): number { + return 0 + } + + /** + * Additively modifies a creature's score for a defensive test + */ + modTestDefense (defender: Creature, attacker: Creature, kind: TestCategory): number { + return 0 + } } /** * A displayable status effect diff --git a/src/game/combat/perks.ts b/src/game/combat/perks.ts new file mode 100644 index 0000000..9e5a139 --- /dev/null +++ b/src/game/combat/perks.ts @@ -0,0 +1,27 @@ +import { Effective } from '../combat' +import { TextLike } from '../language' +import { Creature } from '../creature' +import { TestCategory } from './tests' + +export abstract class Perk extends Effective { + constructor (name: TextLike, desc: TextLike) { + super() + } +} + +export class RavenousPerk extends Perk { + constructor () { + super( + "Ravenous", + "+10 to your score when eating someone if you have no prey in you." + ) + } + + modTestOffense (user: Creature, target: Creature, kind: TestCategory): number { + if (user.voreStats["Prey Count"] === 0 && kind === TestCategory.Vore) { + return 10 + } else { + return 0 + } + } +} diff --git a/src/game/combat/tests.ts b/src/game/combat/tests.ts index b5a7a68..8dd94df 100644 --- a/src/game/combat/tests.ts +++ b/src/game/combat/tests.ts @@ -60,8 +60,8 @@ export class OpposedStatTest extends RandomTest { } odds (user: Creature, target: Creature): number { - const userScore = this.getScore(user, this.userStats) - const targetScore = this.getScore(target, this.targetStats) + const userScore = this.getScore(user, this.userStats) + user.effects.reduce((total, effect) => total + effect.modTestOffense(user, target, this.category), 0) + const targetScore = this.getScore(target, this.targetStats) + target.effects.reduce((total, effect) => total + effect.modTestDefense(target, user, this.category), 0) return this.f(userScore - targetScore + this.bias) } diff --git a/src/game/creature.ts b/src/game/creature.ts index ef12f21..d53dcbe 100644 --- a/src/game/creature.ts +++ b/src/game/creature.ts @@ -6,6 +6,7 @@ import { Item, EquipmentSlot, Equipment, ItemKind, Currency } from './items' import { PassAction } from './combat/actions' import { AI } from './ai' import { Mortal } from './entity' +import { Perk } from './combat/perks' export class Creature extends Mortal { containers: Array = [] @@ -22,11 +23,14 @@ export class Creature extends Mortal { return (this.statusEffects as Effective[]).concat( Object.values(this.equipment).filter(item => item !== undefined).flatMap( item => (item as Equipment).effects - ) + ), + this.perks ) } statusEffects: Array = []; + perks: Array = []; + groupActions: Array = []; items: Array = []; /* eslint-disable-next-line */ diff --git a/src/game/creatures/wolves.ts b/src/game/creatures/wolves.ts index 11b6a32..491d457 100644 --- a/src/game/creatures/wolves.ts +++ b/src/game/creatures/wolves.ts @@ -4,6 +4,7 @@ import { MalePronouns, ImproperNoun, FemalePronouns, TheyPronouns, Verb } from ' import { Stomach, Bowels, anyVore } from '../vore' import { AttackAction, TransferAction } from '../combat/actions' import { VoreAI } from '../ai' +import { RavenousPerk } from '../combat/perks' export class Wolf extends Creature { constructor () { @@ -54,6 +55,8 @@ export class DireWolf extends Creature { this.side = Side.Monsters this.ai = new VoreAI() + this.perks.push(new RavenousPerk()) + this.actions.push( new AttackAction( new StatDamageFormula([