ContentAtomCombat.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ///<reference path="../ContentAtom.ts"/>
  2. ///<reference path="../ContentNounSimple.ts"/>
  3. /**
  4. * This atom should be used in place of the default atom when handling Combat.
  5. */
  6. class ContentAtomCombat extends ContentAtom {
  7. /**
  8. * Only one of the following markers appears at once.
  9. */
  10. public static HIT = new ContentNounSimple("HIT");
  11. public static MISS = new ContentNounSimple("MISS");
  12. public static CRITICAL = new ContentNounSimple("CRITICAL");
  13. /**
  14. * Only one of the following markers appears at once.
  15. */
  16. public static KNOCKED = new ContentNounSimple("KNOCKED");
  17. public static KNOCKED_OFF = new ContentNounSimple("KNOCKED_OFF");
  18. public static KILLED = new ContentNounSimple("KILLED");
  19. public attacker : any;
  20. public target : any;
  21. public weapons : ContentAtom = new ContentAtom();
  22. public markers : ContentAtom = new ContentAtom();
  23. constructor (attacker : any, target : any, weapons : Array<any> = [], markers : Array<ContentNounSimple | ContentNoun> = []) {
  24. super();
  25. this.attacker = attacker;
  26. this.target = target;
  27. this.weapons.addNoun(...weapons);
  28. this.markers.addNoun(...markers);
  29. }
  30. public compareAgainst (other : ContentAtom) {
  31. if (other instanceof ContentAtomCombat) {
  32. console.warn(
  33. ContentAtom.compareNoun(this.attacker, other.attacker) &&
  34. ContentAtom.compareNoun(this.target, other.target) &&
  35. this.weapons.compareAgainst(other.weapons) &&
  36. this.markers.compareAgainst(other.markers),
  37. );
  38. return (
  39. ContentAtom.compareNoun(this.attacker, other.attacker) &&
  40. ContentAtom.compareNoun(this.target, other.target) &&
  41. this.weapons.compareAgainst(other.weapons) &&
  42. this.markers.compareAgainst(other.markers)
  43. );
  44. }
  45. return false;
  46. }
  47. public getAtomPriority () {
  48. return (
  49. ContentAtom.weightNoun(this.attacker) +
  50. ContentAtom.weightNoun(this.target) +
  51. this.weapons.getAtomPriority() +
  52. this.markers.getAtomPriority()
  53. );
  54. }
  55. }
  56. //new ContentAtomCombat(WorldState.player, OrcDebugger, [HumanoidHands], [ContentAtomCombat.HIT]);
  57. //Looks good.