123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- ///<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));
- finalSay.add(" ");
- });
- 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
|