Skip to content
DasSauerkraut edited this page May 5, 2020 · 10 revisions

Macro Repository

Add Armor Set

This macro adds the selected armor set to all target tokens.

let armorVal = 1; //Enter Wanted AP.
//1 = Leather, 2 = Chain, 3 = Plate
 
let pack = game.packs.find(p => p.metadata.label == "Trappings")
if (armorVal > 0 && armorVal < 4) {
  let armorType = "";
  let ignore = "";
  switch (armorVal) {
    case 1:
      armorType = "softLeather";
      ignore = "Leather Jerkin"
      break;
    case 2:
      armorType = "mail";
      ignore = "Mail Shirt"
      break;
    case 3:
      armorType = "plate";
      ignore = "Open Plate Helm"
      break;
  }
 
  let addItem = async (target, armorList) => {
    for (const armor of armorList) {
      let junk = await target.actor.createOwnedItem(armor.data)
      console.log(`Added ${armor.data.name}`)
    }
  }
 
  pack.getContent().then(items => {
    let armorList = items.filter(i => i.type == "armour" && i.data.data.armorType.value == armorType && i.data.name != ignore)
    game.user.targets.forEach(target => {
      addItem(target, armorList);
    })
  })
}

Add XP

Adds an amount of XP to all target tokens, outputting info to chat

let XP = 58; //Enter Wanted XP.
game.user.targets.forEach(target => {
  console.log(target.actor.data.data.details.experience.total)
   target.actor.update({
      "data.details.experience.total": target.actor.data.data.details.experience.total + XP
    })
 
    let chatContent = `Adding ${XP} XP to ${target.data.name}. <hr> Total  XP:  
     ${target.actor.data.data.details.experience.total} -> ${target.actor.data.data.details.experience.total + XP} | Current XP: ${target.actor.data.data.details.experience.current} -> ${target.actor.data.data.details.experience.current + XP}`;
let chatData = {
      user: game.user._id,
      speaker: ChatMessage.getSpeaker(),
      content: chatContent
    };
    ChatMessage.create(chatData, {});  
console.log(target.actor.data.data.details.experience.total + XP)
  console.log(target.actor.data.data.details.experience.total)
})

Timed Skill Increase Macro

Increases specified skill by 10, then resets after 10 rounds(36 seconds). This affects all targeted tokens. This macro is called from any chat macro via the syntax of /macroname macroAbbrev characteristic duration 'Fancy Macro Name'. ex: /pray bobMacro ws 36 'Myrmidias Blessing of Battle'. The macro abbreviation should be unique to its use, IE don't have a Blessing of Battle macro and a Runic Item macro both use the 'genericMacro' abbreviation. Duration is in seconds, and it's assumed that there's 6 seconds to a round. If duration is < 0, the macro will persist until toggled again. This macro requires the about-time module by tposney as well as the Furnace module by KaKaRoTo to function.

let enabled = false;
let chatContent = ''
let macroAbbrev = args[0];
let modChar = args[1];
let macroDur = args[2];

let macroName = "Characteristic Increase"
if(args[3])
  macroName = args[3]

let disableMacro = (target) => {
  if (target.actor.data.flags.bobMacro !== null && target.actor.data.flags.bobMacro !== undefined) {
    chatContent = `${macroName} on ${target.name} has ended. <br> ${modChar}:  
     ${eval(`target.actor.data.data.characteristics.${modChar}.initial`)} -> ${eval(`target.actor.data.flags.${macroAbbrev}`)}`;
    let obj = {}
    obj[`flags.${macroAbbrev}`] = null;
    let updateStr = `data.characteristics.${modChar}.initial`
    target.actor.update({
      [updateStr]: eval(`target.actor.data.data.characteristics.${modChar}.initial`) - 10
    })
    target.actor.update(obj)
    let chatData = {
      user: game.user._id,
      speaker: ChatMessage.getSpeaker(),
      content: chatContent
    };
    ChatMessage.create(chatData, {});
  }
}

game.user.targets.forEach(target => {
  if (eval(`target.actor.data.flags.${macroAbbrev}`) !== null && eval(`target.actor.data.flags.${macroAbbrev}`) !== undefined) {
    enabled = true;
  }
  if (!enabled) {
    chatContent = `Casting ${macroName} on ${target.name} <br> ${modChar}: 
    ${eval(`target.actor.data.data.characteristics.${modChar}.initial`)} -> ${parseInt(eval(`target.actor.data.data.characteristics.${modChar}.initial`) + 10)}`;
    let obj = {}
    obj[`flags.${macroAbbrev}`] = eval(`target.actor.data.data.characteristics.${modChar}.initial`);
    let updateStr = `data.characteristics.${modChar}.initial`
    target.actor.update({
      [updateStr]: eval(`target.actor.data.data.characteristics.${modChar}.initial`) + 10
    })
    target.actor.update(obj)
    
    if(macroDur > 0){
    	game.Gametime.doIn(game.Gametime.DMf({
      	seconds: macroDur
    	}), disableMacro, target)
    }
    let chatData = {
      user: game.user._id,
      speaker: ChatMessage.getSpeaker(),
      content: chatContent
    };
    ChatMessage.create(chatData, {});
  } else {
    disableMacro(target);
  }
})

EXPERIMENTAL Weapon Length Toggle

Toggle -10 to WS, used for if a character is outranged and you're using the weapon length optional rule

let enabled = false;
if (actor.data.flags.atBayMacro !== null && actor.data.flags.atBayMacro !== undefined) {
   enabled = true;
 }
 if (!enabled) {
this.data.name = "Kept at Bay!"
 this.data.img = "icons/svg/circle.svg"
 this.update({"data.name" : "Kept at Bay!"});
   let obj = {}
   obj['flags.atBayMacro'] = actor.data.data.characteristics.ws.initial;
  actor.update({
     "data.characteristics.ws.initial": actor.data.data.characteristics.ws.initial - 10
   })
  actor.update(obj)
} else {
 this.data.name = "Same Length!"
 this.data.img = "icons/svg/combat.svg"
 this.update({"data.name" : "Same Length!"});
let obj = {}
   obj['flags.atBayMacro'] = null;
  actor.update({
     "data.characteristics.ws.initial": actor.data.data.characteristics.ws.initial + 10
 })
  actor.update(obj)
}

Generate Item Qualities

Generates minimum of 1 item flaw, with a 50% chance for a second item flaw. There is a 5% chance of the item also gaining a quality. It then outputs these flaws and qualities to chat.

let flaws = [{
    name: 'Ugly',
    desc: 'Crafted without any aesthetic awareness whatsoever, Ugly items attract negative attention, and related Fellowship Tests might even suffer a –10 penalty.'
  },
  {
    name: 'Shoddy',
    desc: 'Hastily crafted by an amateur or fraudster. The item breaks when used in any failed Test rolling a double. Similarly, Shoddy armour breaks if any Critical Hit is sustained to a Hit Location it protects.'
  },
  {
    name: 'Unreliable',
    desc: 'Crafted without attention to functionality, a failed test using this item receives –1 SL. Further, penalties for wearing Unreliable armour are doubled. '
  },
  {
    name: 'Bulky',
    desc: 'An awkward design crafted clumsily. Increase Encumbrance by +1 (small trinkets cannot normally have this flaw). Bulky clothing and armour are Enc 1 even when worn, and Fatigue penalties for armour are doubled.'
  },
]

let qualities = [{
    name: 'Fine',
    desc: 'Meticulously crafted to please the eye. This Quality is a sign of social status and can be taken multiple times. The higher the quality, the more impressive it seems.'
  },
  {
    name: 'Durable',
    desc: 'Laboriously crafted using strong materials, the item can take +Durable Damage points before it suffers any negatives (see Weapon Damage and Armour Damage on pages 296 and 299) and gains a saving throw of 9+ on a 1d10 roll against instant breakage from sources like Trap Blade (see page 298). This Quality can be taken multiple times. Each time it is taken, the saving throw improves by 1 (e.g. From 9+ to 8+).'
  },
  {
    name: 'Lightweight',
    desc: 'Cleverly crafted for ease of carrying. Reduce Encumbrance points by 1.'
  },
  {
    name: 'Practical',
    desc: 'Expertly crafted with utility in mind. A failed test using this item receives +1 SL. If the item is a piece of armour, any penalties for wearing it are reduced by one level (for example from −30 to −20).'
  },
]
let item = {flaws: [], qualities:[]};
item.flaws.push(flaws[Math.floor(Math.random() * flaws.length)])
let roll = Math.floor(Math.random() * 2) + 1
if (roll == 2) {
  console.log('Adding another flaw')
  let flag = false;
  let newFlaw = undefined
  while (!flag) {
    newFlaw = flaws[Math.floor(Math.random() * flaws.length)]
    if (item.flaws.includes(newFlaw)) {
      console.log('Duped Flaw')
    } else {
      flag = true;
    }
  }
  item.flaws.push(newFlaw)
}
roll = Math.floor(Math.random() * 20) + 1
if (roll == 20) {
  console.log('Adding a Quality')
  let newQuality = qualities[Math.floor(Math.random() * qualities.length)]
  item.qualities.push(newQuality)
}
let chatContent = `Looted item has <b> ${item.flaws.length} flaw(s) </b>.  <br>`
item.flaws.forEach( flaw => {
 chatContent = chatContent + `${flaw.name}, `
})
if(item.qualities.length != 0){
chatContent = chatContent + `<hr> Looted item has <b> ${item.qualities.length} qualities </b>.  <br>`
item.qualities.forEach( qualities=> {
 chatContent = chatContent + `${qualities.name}, `
})
}
    let chatData = {
      user: game.user._id,
      speaker: ChatMessage.getSpeaker(),
      content: chatContent
    };
    ChatMessage.create(chatData, {});

Reset Fortune

This macro resets Fortune to all target tokens, based on Fate and Luck talent advances.

game.user.targets.forEach(target => {
	console.log(target.actor.data.data.status.fortune.value);

	let startingFortune = target.actor.data.data.status.fortune.value;
	let luckNum = 0;
	let item = target.actor.items.find(i => i.data.name === "Luck")
		if(item == undefined || item.data.data.advances.value < 1) {
			luckNum = 0;
		} else { 
			for (let item of target.actor.items)
				{
				  if (item.type == "talent" && item.name == "Luck")
				  {
					luckNum += item.data.data.advances.value;
				  }
				}
		}

	target.actor.update({
		"data.status.fortune.value": target.actor.data.data.status.fate.value + luckNum
    })
 
    let chatContent = `Resetting Fortune for ${target.data.name} from ${startingFortune} to ${target.actor.data.data.status.fate.value + luckNum}.`;

	let chatData = {
		user: game.user._id,
		content: chatContent
    };

    ChatMessage.create(chatData, {});  
 	console.log(target.actor.data.data.status.fortune.value);
})