///
class ContentMoleculeCombat extends ContentMolecule {
protected say : Say | ((attacker : any, target : any, weapons : Array, markers : Array) => Say);
protected saidTimes = 0;
public constructor (description : Say | ((attacker : any, target : any, weapons : Array, markers : Array) => Say)) {
super();
this.say = description;
ContentMoleculeCombat.MOLECULES.push(this);
console.warn(this);
}
public getSay(specificMolecule : ContentMolecule) {
this.saidTimes++;
if (this.say instanceof Say) {
return this.say;
} else {
let combatAtom = (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 : Array = [];
/**
* Searches for Combat molecules that describe the specificMolecule given. Assumes Atoms are of the Combat variety. Assumes there is always a single Atom.
* @param specificMolecule
*/
public static getSay (specificMolecule : ContentMolecule) {
// Randomize the array to prevent the same message from showing up every time
let many : Array = 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 = 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."
)
);
return new Say();
} else {
let finalSay = new Say();
matches.forEach((idx : number) => {
finalSay.add(ContentMoleculeCombat.MOLECULES[idx].getSay(specificMolecule));
finalSay.add(" ");
});
return finalSay;
}
}
}