From 6d8af38985a9182d2e29a05e7ec75a556bd850fc Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Fri, 7 Aug 2020 11:05:23 -0400 Subject: [PATCH] Add armor --- src/App.vue | 5 ++--- src/game/combat/effects.ts | 2 +- src/game/creature.ts | 19 ++++++++++++----- src/game/creatures/player.ts | 12 +++++++++-- src/game/items.ts | 40 +++++++++++++++++++++++++++++++++--- 5 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/App.vue b/src/App.vue index 7b8e960..c6c3c4a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -64,14 +64,13 @@ export default class App extends Vue { } created () { - const player = new Creatures.Wolf() + const player = new Creatures.Player() player.perspective = POV.Second player.side = Side.Heroes player.equipment.set(Items.EquipmentSlot.MainHand, new Items.Sword()) - player.items.push(new Items.Sword()) + player.equipment.set(Items.EquipmentSlot.Head, new Items.Helmet()) player.items.push(new Items.Mace()) player.items.push(new Items.Dagger()) - player.items.push(new Items.Sword()) this.$data.world = new World(player) player.location = Town() diff --git a/src/game/combat/effects.ts b/src/game/combat/effects.ts index 4474641..80cebd4 100644 --- a/src/game/combat/effects.ts +++ b/src/game/combat/effects.ts @@ -74,7 +74,7 @@ export class DamageTypeResistanceEffect extends StatusEffect { modResistance (type: DamageType, factor: number) { if (this.damageTypes.includes(type)) { - return factor * (1 - this.amount) + return factor * this.amount } else { return factor } diff --git a/src/game/creature.ts b/src/game/creature.ts index 7c5db97..fbccea3 100644 --- a/src/game/creature.ts +++ b/src/game/creature.ts @@ -1,4 +1,4 @@ -import { Damage, Combatant, Stats, Action, Vigor, Side, GroupAction, VisibleStatus, ImplicitStatus, StatusEffect, DamageType } from './combat' +import { Damage, Combatant, Stats, Action, Vigor, Side, GroupAction, VisibleStatus, ImplicitStatus, StatusEffect, DamageType, Effective } from './combat' import { Noun, Pronoun } from './language' import { LogEntry, LogLines } from './interface' import { Vore, VoreContainer, VoreType } from './vore' @@ -10,7 +10,16 @@ export class Creature extends Vore implements Combatant { actions: Array = []; containedIn: VoreContainer | null = null; desc = "Some creature"; - effects: Array = []; + + get effects (): Array { + return (this.statusEffects as Effective[]).concat( + Array.from(this.equipment.values()).flatMap( + item => item.effects + ) + ) + } + + statusEffects: Array = []; groupActions: Array = []; items: Array = []; otherActions: Array = []; @@ -35,7 +44,7 @@ export class Creature extends Vore implements Combatant { * Determines how much damage an attack would do */ effectiveDamage (damage: Damage): Damage { - const preDamage = this.effects.reduce((modifiedDamage: Damage, effect: StatusEffect) => { + const preDamage = this.effects.reduce((modifiedDamage: Damage, effect: Effective) => { return effect.preDamage(this, modifiedDamage) }, damage) return super.effectiveDamage(preDamage) @@ -61,7 +70,7 @@ export class Creature extends Vore implements Combatant { } removeEffect (effect: StatusEffect): LogEntry { - this.effects = this.effects.filter(eff => eff !== effect) + this.statusEffects = this.statusEffects.filter(eff => eff !== effect) return effect.onRemove(this) } @@ -81,7 +90,7 @@ export class Creature extends Vore implements Combatant { results.push(new ImplicitStatus('Eaten', 'Devoured by ' + this.containedIn.owner.name, 'fas fa-drumstick-bite')) } - this.effects.forEach(effect => { + this.statusEffects.forEach(effect => { results.push(effect) }) return results diff --git a/src/game/creatures/player.ts b/src/game/creatures/player.ts index 58970c0..8fc0a1d 100644 --- a/src/game/creatures/player.ts +++ b/src/game/creatures/player.ts @@ -1,12 +1,20 @@ import { Creature } from "../creature" import { ProperNoun, TheyPronouns, ImproperNoun, POV } from '../language' import { Damage, DamageType, Vigor, ConstantDamageFormula } from '../combat' -import { Stomach, Bowels, VoreType } from '../vore' +import { Stomach, Bowels, VoreType, anyVore } from '../vore' import { AttackAction } from '../combat/actions' export class Player extends Creature { constructor () { - super(new ProperNoun('The Dude'), new ImproperNoun('player', 'players'), TheyPronouns, { Toughness: 20, Power: 20, Speed: 20, Willpower: 20, Charm: 20 }, new Set([VoreType.Oral, VoreType.Anal]), new Set([VoreType.Oral, VoreType.Anal]), 50) + super( + new ProperNoun('Player'), + new ImproperNoun('player', 'players'), + TheyPronouns, + { Toughness: 25, Power: 25, Speed: 25, Willpower: 25, Charm: 25 }, + anyVore, + anyVore, + 50 + ) this.actions.push(new AttackAction(new ConstantDamageFormula(new Damage({ type: DamageType.Pierce, amount: 20, target: Vigor.Health }, { type: DamageType.Pierce, amount: 20, target: Vigor.Stamina })))) diff --git a/src/game/items.ts b/src/game/items.ts index 24e0f9e..ee35850 100644 --- a/src/game/items.ts +++ b/src/game/items.ts @@ -1,6 +1,8 @@ import { TextLike, LiveText, DynText, Word, ImproperNoun, Verb } from './language' -import { Actionable, Action, DamageFormula, ConstantDamageFormula, Damage, DamageType, Vigor, StatDamageFormula, Stat } from './combat' +import { Actionable, Action, DamageFormula, ConstantDamageFormula, Damage, DamageType, Vigor, StatDamageFormula, Stat, Effective } from './combat' import { AttackAction } from './combat/actions' +import { Resistances } from './entity' +import { DamageTypeResistanceEffect } from './combat/effects' export enum ItemKind { Key = "Key Item", @@ -15,9 +17,10 @@ export const ItemKindIcons: {[key in ItemKind]: string} = { } export abstract class Item implements Actionable { - abstract kind: ItemKind; - abstract actions: Array; + actions: Array = [] + effects: Array = [] + abstract kind: ItemKind constructor (public name: Word, public desc: TextLike) { } @@ -105,3 +108,34 @@ export class Mace extends Weapon { ) } } + +export abstract class Armor extends Equipment { + constructor (name: Word, desc: TextLike, public slot: EquipmentSlot, resistances: Partial) { + super(name, desc) + Object.entries(resistances).forEach(([damageType, value]) => { + if (value !== undefined) { + this.effects.push( + new DamageTypeResistanceEffect( + [damageType as DamageType], + value + ) + ) + } + }) + } +} + +export class Helmet extends Armor { + constructor () { + super( + new ImproperNoun('helmet'), + 'A helmet', + EquipmentSlot.Head, + { + Slash: 0.75, + Pierce: 0.5, + Crush: 0.9 + } + ) + } +}