1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- ///<reference path="../ContentMolecule.ts"/>
- class ContentMoleculeCombat extends ContentMolecule {
- protected say : Say | ((attacker : any, target : any, weapons : Array<any>, markers : Array<ContentNounSimple>) => Say);
- protected saidTimes = 0;
- public constructor (description : Say | ((attacker : any, target : any, weapons : Array<any>, markers : Array<ContentNounSimple>) => Say)) {
- super();
- this.say = description;
- ContentMoleculeCombat.MOLECULES.push(this);
- }
- public getSay(specificMolecule : ContentMolecule) {
- this.saidTimes++;
- if (this.say instanceof Say) {
- return this.say;
- } else {
- let combatAtom = <ContentAtomCombat>(specificMolecule.getAtoms()[0]);
- return this.say(combatAtom.attacker, combatAtom.target, combatAtom.weapons.getNouns(), combatAtom.markers.getNouns());
- }
- }
- public getWeight () {
- // TODO: Check if this implementation is good enough.
- let weight = -this.saidTimes;
- this.atoms.forEach(value => {
- weight += value.getAtomPriority()
- });
- return weight;
- }
- protected static MOLECULES = [];
- /**
- * Returns an array of ContentMoleculeCombat that fulfill ContentMolecule given.
- * @param specificMolecule
- */
- public static getSay (specificMolecule : ContentMolecule) {
- // Randomize the array to prevent the same message from showing up every time
- let many : Array<ContentMoleculeCombat> = new Shuffler(ContentMoleculeCombat.MOLECULES).getShuffled();
- // Order the array placing higher priority messages on top, but messages with same priority are still randomized
- many.sort((a, b) => {
- return b.getWeight() - a.getWeight()
- });
- let matches = specificMolecule.findMatches(many);
- if (matches.length == 0) {
- let atom = <ContentAtomCombat> specificMolecule.getAtoms()[0];
- Elements.CurrentTurnHandler.printAsError(
- new Say(
- "Unable to find match for this combat passage. Attacker: ", atom.attacker,
- ". Target: ", atom.target,
- ". Weapons used:", ...(atom.weapons.getNouns()),
- ". Markers: ", ...(atom.markers.getNouns()),
- ". Please report for fixing."
- )
- );
- } else {
- let finalSay = new Say();
- matches.forEach((value : ContentMoleculeCombat) => {
- finalSay.add(value.getSay(specificMolecule));
- });
- return finalSay;
- }
- }
- }
- // new ContentMoleculeCombat(
- // (attacker, target, weapons, markers) => {
- // return new Say("Woohoo");
- // }
- // ).addAtom(
- // new ContentAtomCombat(
- // Person,
- // Person,
- // [Thing],
- // [new ContentNoun(ContentAtomCombat.HIT, ContentAtomCombat.CRITICAL).setType(ContentNounType.FULLY_ADAPTIVE), ContentAtomCombat.KNOCKED_OFF]
- // )
- // );
- // Definitely tons saner than the current implementation
|