Skip to content

Instantly share code, notes, and snippets.

@jenthura
Last active January 24, 2022 07:35
Show Gist options
  • Save jenthura/7cf2f61d542832846b99a0de84f39921 to your computer and use it in GitHub Desktop.
Save jenthura/7cf2f61d542832846b99a0de84f39921 to your computer and use it in GitHub Desktop.
Foundry VTT macro for drawing a card from the Deck of Many Things
const cardImageURLs = [`https://i.imgur.com/IPA90hF.png`,`https://i.imgur.com/L7ZaH32.png`,`https://i.imgur.com/kkm7WFo.png`,`https://i.imgur.com/AfyefuZ.png`,`https://i.imgur.com/NDl5PRh.png`,`https://i.imgur.com/kgCkfYc.png`,`https://i.imgur.com/1QoHhca.png`,`https://i.imgur.com/60lahPl.png`,`https://i.imgur.com/ajc5X5U.png`,`https://i.imgur.com/QNPySfx.png`,`https://i.imgur.com/ufBY236.png`,`https://i.imgur.com/zH25V18.png`,`https://i.imgur.com/j4Hprzx.png`,`https://i.imgur.com/mG3DtLZ.png`,`https://i.imgur.com/QW09Ne1.png`,`https://i.imgur.com/o9pYveI.png`,`https://i.imgur.com/VmqUGQZ.png`,`https://i.imgur.com/l6rSLMN.png`,`https://i.imgur.com/o3GOJo6.png`,`https://i.imgur.com/kKZht9N.png`,`https://i.imgur.com/lQpdgAD.png`,`https://i.imgur.com/epL2BwD.png`]
const cardNames = [`Balance`,`Comet`,`Donjon`,`Euryale`,`Fates`,`Flames`,`Fool`,`Gem`,`Idiot`,`Jester`,`Key`,`Knight`,`Moon`,`Rogue`,`Ruin`,`Skull`,`Star`,`Sun`,`Talons`,`Throne`,`Vizier`,`Void`]
const cardDescriptions = [`Your mind suffers a wrenching alteration, causing your alignment to change. Lawful becomes chaotic, good becomes evil, and vice versa. If you are true neutral or unaligned, this card has no effect on you.`,`If you single-handedly defeat the next hostile monster or group of monsters you encounter, you gain experience points enough to gain one level. Otherwise, this card has no effect.`,`You disappear and become entombed in a state of suspended animation in an extradimensional sphere. Everything you were wearing and carrying stays behind in the space you occupied when you disappeared. You remain imprisoned until you are found and removed from the sphere. You can't be located by any divination magic, but a wish spell can reveal the location of your prison. You draw no more cards.`,`The card's medusa-like visage curses you. You take a −2 penalty on saving throws while cursed in this way. Only a god or the magic of The Fates card can end this curse.`,`Reality's fabric unravels and spins anew, allowing you to avoid or erase one event as if it never happened. You can use the card's magic as soon as you draw the card or at any other time before you die.`,`A powerful devil becomes your enemy. The devil seeks your ruin and plagues your life, savoring your suffering before attempting to slay you. This enmity lasts until either you or the devil dies.`,`You lose 1 level, discard this card, and draw from the deck again, counting both draws as one of your declared draws.`,`Twenty-five pieces of jewelry worth 2,000 gp each or fifty gems worth 1,000 gp each appear at your feet.`,`Permanently reduce your Intelligence by 1d4 + 1 (to a minimum score of 1). You can draw one additional card beyond your declared draws.`,`You gain 1 level, or you can draw two additional cards beyond your declared draws.`,`A rare or rarer magic weapon with which you are proficient appears in your hands. The GM chooses the weapon.`,`You gain the service of a 4th-level fighter who appears in a space you choose within 30 feet of you. The fighter is of the same race as you and serves you loyally until death, believing the fates have drawn him or her to you. You control this character.`,`You are granted the ability to cast the wish spell 1d3 times.`,`A nonplayer character of the GM's choice becomes hostile toward you. The identity of your new enemy isn't known until the NPC or someone else reveals it. Nothing less than a wish spell or divine intervention can end the NPC's hostility toward you.`,`All forms of wealth that you carry or own, other than magic items, are lost to you. Portable property vanishes. Businesses, buildings, and land you own are lost in a way that alters reality the least. Any documentation that proves you should own something lost to this card also disappears.`,`You summon an avatar of death--a ghostly humanoid skeleton clad in a tattered black robe and carrying a spectral scythe. It appears in a space of the GM's choice within 10 feet of you and attacks you, warning all others that you must win the battle alone. The avatar fights until you die or it drops to 0 hit points, whereupon it disappears. If anyone tries to help you, the helper summons its own avatar of death. A creature slain by an avatar of death can't be restored to life.`,`Increase one of your ability scores by 2. The score can exceed 20 but can't exceed 24.`,`You gain 1 level, and a wondrous item (which the GM determines randomly) appears in your hands.`,`Every magic item you wear or carry disintegrates. Artifacts in your possession aren't destroyed but do vanish.`,`You gain proficiency in the Persuasion skill, and you double your proficiency bonus on checks made with that skill. In addition, you gain rightful ownership of a small keep somewhere in the world. However, the keep is currently in the hands of monsters, which you must clear out before you can claim the keep as yours.`,`At any time you choose within one year of drawing this card, you can ask a question in meditation and mentally receive a truthful answer to that question. Besides information, the answer helps you solve a puzzling problem or other dilemma. In other words, the knowledge comes with wisdom on how to apply it.`,`This black card spells <a style = "color: red"><b>disaster</b></a>. Your soul is drawn from your body and contained in an object in a place of the GM's choice. One or more powerful beings guard the place. While your soul is trapped in this way, your body is incapacitated. <i>A wish spell can't restore your soul</i>, but the spell reveals the location of the object that holds it. You draw no more cards.`]
let choice = Math.ceil(Math.random()*22)
function drawCard() {
if (choice == 21) {
return `<div style="background-color: black"><div class="dnd5e chat-card" style="text-align: center"><header class="card-header flexrow"><h3 style="color: white" class="item-name">${cardNames[choice]}</h3></div><br><div style="text-align: center"><img width=75% height=50% src="${cardImageURLs[choice]}"</img></div><br><div style="color: white; padding: 10px"><b>${cardDescriptions[choice]}<b></div></div>`
} else {
return `<div class="dnd5e chat-card" style="text-align: center"><header class="card-header flexrow"><h3 class="item-name">${cardNames[choice]}</h3></div><br><div style="text-align: center"><img width=75% height=50% src="${cardImageURLs[choice]}"</img></div><br>${cardDescriptions[choice]}`
}
}
let message = drawCard()
let d = new Dialog({ //dialog object creates the window with all the buttons
title: "You draw...",
content: `<h2>Are you sure you want to draw a card?<h2>`,
buttons: {
one: {
label: "Yes",
callback: () => {ChatMessage.create({
user : game.user._id,
speaker: {alias: "You draw..."},
content: message
});
}
},
two: {
label: "No",
callback: () => {console.log(`Done`)}
},
},
render: html => console.log("Register interactivity in the rendered dialog"),
close: html => console.log("This always is logged no matter which option is chosen")
});
d.render(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment