ContentMoleculeFucking.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///<reference path="../ContentMolecule.ts"/>
  2. class ContentMoleculeFucking extends ContentMolecule {
  3. protected say : Say | ((relevantAtoms : Array<ContentAtomFucking>) => Say);
  4. protected saidTimes = 0;
  5. public constructor (description : Say | ((relevantAtoms : Array<ContentAtomFucking>) => Say)) {
  6. super();
  7. this.say = description;
  8. ContentMoleculeFucking.MOLECULES.push(this);
  9. }
  10. public getSay(specificMolecule : ContentMolecule, relevantAtoms : Array<ContentAtomFucking>) {
  11. this.saidTimes++;
  12. if (this.say instanceof Say) {
  13. return this.say;
  14. } else {
  15. //let relevantAtoms = specificMolecule.findMatches([this.fuckingAtom])
  16. //let fuckingAtom = <ContentAtomFucking>(specificMolecule.getAtoms()[0]);
  17. return this.say(relevantAtoms);
  18. }
  19. }
  20. public getWeight () {
  21. // TODO: Check if this implementation is good enough.
  22. let weight = -this.saidTimes;
  23. this.atoms.forEach(value => {
  24. weight += value.getAtomPriority()
  25. });
  26. return weight;
  27. }
  28. protected static MOLECULES : Array<ContentMoleculeFucking> = [];
  29. /**
  30. * Searches for Fucking molecules that describe the specificMolecule given. Assumes atoms are of the Fucking variety.
  31. * @param specificMolecule
  32. */
  33. public static getSay (specificMolecule : ContentMolecule) {
  34. // Randomize the array to prevent the same message from showing up every time
  35. let many : Array<ContentMoleculeFucking> = new Shuffler(ContentMoleculeFucking.MOLECULES).getShuffled();
  36. // Order the array placing higher priority messages on top, but messages with same priority are still randomized
  37. many.sort((a, b) => {
  38. return b.getWeight() - a.getWeight()
  39. });
  40. let matches = specificMolecule.findMatches(many);
  41. if (matches.length == 0) {
  42. let say = new Say("Unable to find match for this sexual passage.");
  43. specificMolecule.getAtoms().forEach((atom : ContentAtomFucking) => {
  44. say.add(Say.LINE_BREAK, "Fucker: ", atom.fucker,
  45. ". Fucked: ", atom.fucked,
  46. ". Stick: ", atom.stick,
  47. ". Hole: ", atom.hole,
  48. ". Markers: ", ...(atom.markers.getNouns()),
  49. ". Please report for fixing."
  50. );
  51. });
  52. Elements.CurrentTurnHandler.printAsError(say);
  53. return new Say();
  54. } else {
  55. let finalSay = new Say();
  56. matches.forEach((idx : number) => {
  57. let value = ContentMoleculeFucking.MOLECULES[idx];
  58. finalSay.add(
  59. value.getSay(
  60. specificMolecule, specificMolecule.findMatches([value], true)
  61. )
  62. );
  63. finalSay.add(" ");
  64. });
  65. return finalSay;
  66. }
  67. }
  68. }