|
|
|
@@ -1,8 +1,12 @@ |
|
|
|
import { TextLike, LiveText, DynText, Word, ImproperNoun, Verb } from './language' |
|
|
|
import { Actionable, Action, DamageFormula, ConstantDamageFormula, Damage, DamageType, Vigor, StatDamageFormula, Stat, Effective } from './combat' |
|
|
|
import { Actionable, Action, DamageFormula, ConstantDamageFormula, Damage, DamageType, Vigor, StatDamageFormula, Stat, Effective, CompositionAction, Condition } from './combat' |
|
|
|
import { AttackAction } from './combat/actions' |
|
|
|
import { Resistances } from './entity' |
|
|
|
import { DamageTypeResistanceEffect } from './combat/effects' |
|
|
|
import { DamageConsequence, LogConsequence, HealingConsequence } from './combat/consequences' |
|
|
|
import { SoloCondition } from './combat/conditions' |
|
|
|
import { LogLine, LogEntry } from './interface' |
|
|
|
import { Creature } from './creature' |
|
|
|
|
|
|
|
export enum ItemKind { |
|
|
|
Key = "Key Item", |
|
|
|
@@ -19,6 +23,7 @@ export const ItemKindIcons: {[key in ItemKind]: string} = { |
|
|
|
export abstract class Item implements Actionable { |
|
|
|
actions: Array<Action> = [] |
|
|
|
effects: Array<Effective> = [] |
|
|
|
consumed = false |
|
|
|
|
|
|
|
abstract kind: ItemKind |
|
|
|
constructor (public name: Word, public desc: TextLike) { |
|
|
|
@@ -139,3 +144,64 @@ export class Helmet extends Armor { |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class ItemAction extends Action { |
|
|
|
constructor (name: TextLike, desc: TextLike, private item: Item, private action: Action) { |
|
|
|
super(name, desc, action.conditions) |
|
|
|
} |
|
|
|
|
|
|
|
execute (user: Creature, target: Creature): LogEntry { |
|
|
|
this.item.consumed = true |
|
|
|
return this.action.execute(user, target) |
|
|
|
} |
|
|
|
|
|
|
|
describe (user: Creature, target: Creature): LogEntry { |
|
|
|
return this.action.describe(user, target) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class Consumable extends Item { |
|
|
|
kind = ItemKind.Consumable |
|
|
|
|
|
|
|
constructor (name: Word, desc: TextLike, onUse: Action) { |
|
|
|
super(name, desc) |
|
|
|
this.actions.push(new ItemAction( |
|
|
|
onUse.name, |
|
|
|
onUse.desc, |
|
|
|
this, |
|
|
|
onUse |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class HealthPotion extends Consumable { |
|
|
|
constructor () { |
|
|
|
super( |
|
|
|
new ImproperNoun("health potion"), |
|
|
|
"Restores all of your vigors", |
|
|
|
new CompositionAction( |
|
|
|
"Drink Potion", |
|
|
|
"Heals your vigors", |
|
|
|
{ |
|
|
|
conditions: [ |
|
|
|
new SoloCondition() |
|
|
|
], |
|
|
|
consequences: [ |
|
|
|
new LogConsequence( |
|
|
|
(user, target) => new LogLine(`${user.name.capital} ${user.name.conjugate(new Verb('drink'))} a potion.`) |
|
|
|
), |
|
|
|
new HealingConsequence( |
|
|
|
new ConstantDamageFormula( |
|
|
|
new Damage( |
|
|
|
{ amount: 100, target: Vigor.Health, type: DamageType.Heal }, |
|
|
|
{ amount: 100, target: Vigor.Stamina, type: DamageType.Heal }, |
|
|
|
{ amount: 100, target: Vigor.Resolve, type: DamageType.Heal } |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
] |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |