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.

67 lines
2.7 KiB

1 year ago
  1. Hooks.on("createChatMessage", async (chatMessage) => {
  2. try{
  3. if(game.system.id != "dnd5e")return;
  4. if (!chatMessage.isAuthor || !game.settings.get(AECONSTS.MN, "enableautomations")) return;
  5. const messageContent = $(chatMessage.content);
  6. if(!messageContent.length)return;
  7. const actorId = messageContent[0].dataset.actorId;
  8. const itemId = messageContent[0].dataset.itemId;
  9. const spellLevel = parseInt(messageContent[0].dataset.spellLevel);
  10. const tokenId = messageContent[0].dataset.tokenId;
  11. const token = tokenId ? await fromUuid(tokenId) : null;
  12. const actor = token?.actor ?? game.actors.get(actorId);
  13. if(!actor) return;
  14. const spellName = actor?.items?.get(itemId)?.name;
  15. let system = game.automatedevocations[game.system.id];
  16. if (!system) return;
  17. if (system[spellName]) {
  18. //attempt to get spell level
  19. let summonData = [];
  20. const data = {level:spellLevel}
  21. const creatures = typeof system[spellName] === "function" ? system[spellName](data) : system[spellName];
  22. for (let creature of creatures) {
  23. if (creature.level && spellLevel && creature.level >= spellLevel)
  24. continue;
  25. let actor = game.actors.getName(creature.creature);
  26. if (actor) {
  27. summonData.push({
  28. id: actor.id,
  29. number: creature.number,
  30. animation: creature.animation,
  31. });
  32. }
  33. }
  34. new SimpleCompanionManager(summonData,spellLevel,canvas.tokens.get(chatMessage?.data?.speaker?.token)?.actor).render(true);
  35. }
  36. }catch(e){}
  37. });
  38. Hooks.on("createChatMessage", async (chatMessage) => {
  39. if(game.system.id != "pf2e")return;
  40. if (chatMessage.user !== game.user.id || !game.settings.get(AECONSTS.MN, "enableautomations")) return;
  41. const item = await fromUuid(chatMessage.flags.pf2e.origin.uuid)
  42. const spellName = item.document.name;
  43. let system = game.automatedevocations[game.system.id];
  44. if (!system) return;
  45. if (system[spellName]) {
  46. let summonData = [];
  47. const spellLevel = $(chatMessage.content)?.data("spell-lvl")
  48. const data = {level:item, spellLevel:spellLevel}
  49. //const data = {level:item}
  50. const creatures = typeof system[spellName] === "function" ? system[spellName](data) : system[spellName];
  51. for (let creature of creatures) {
  52. if (creature.level && spellLevel && creature.level >= spellLevel)
  53. continue;
  54. let actor = game.actors.getName(creature.creature);
  55. if (actor) {
  56. summonData.push({
  57. id: actor.id,
  58. number: creature.number,
  59. animation: creature.animation,
  60. });
  61. }
  62. }
  63. new SimpleCompanionManager(summonData,spellLevel,canvas.tokens.get(chatMessage?.data?.speaker?.token)?.actor).render(true);
  64. }
  65. });