All user data for FoundryVTT. Includes worlds, systems, modules, and any asset in the "foundryuserdata" directory. Does NOT include the FoundryVTT installation itself.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.5 KiB

  1. /** Equivalent to the VisionLevel enum in the Pathfinder 2e system */
  2. class VisionLevelPF2e {
  3. static BLINDED = 0;
  4. static NORMAL = 1;
  5. static LOW_LIGHT_VISION = 2;
  6. static DARKVISION = 3;
  7. }
  8. Hooks.on(
  9. "init",
  10. () => {
  11. // Calculate the NPCs vision level from its sense field. The field is a free-text string, so we have to do a bit of
  12. // maniplulation and make some assumptions about the data.
  13. libWrapper.register(
  14. "pf2e-rules-based-npc-vision",
  15. "CONFIG.PF2E.Actor.documentClasses.npc.prototype.visionLevel",
  16. function npcVisionLevel() {
  17. const senses = (this.system.traits.senses.value ?? "").split(",").map(s => s.replace(/[\s-]+/g, '').toLowerCase());
  18. return this.getCondition("blinded") ? VisionLevelPF2e.BLINDED
  19. : senses.some(sense => ["darkvision", "greaterdarkvision"].includes(sense))
  20. ? VisionLevelPF2e.DARKVISION
  21. : senses.includes("lowlightvision")
  22. ? VisionLevelPF2e.LOW_LIGHT_VISION
  23. : VisionLevelPF2e.NORMAL;
  24. },
  25. "OVERRIDE"
  26. );
  27. libWrapper.register(
  28. "pf2e-rules-based-npc-vision",
  29. "CONFIG.Token.documentClass.prototype.rulesBasedVision",
  30. function npcRulesBasedVision() {
  31. return !!(this.sight.enabled && this.actor?.isOfType("character", "familiar", "npc") && this.scene?.rulesBasedVision);
  32. },
  33. "OVERRIDE"
  34. );
  35. }
  36. );