Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

4ePowerCards

From Roll20 Wiki

Revision as of 13:08, 20 February 2014 by HoneyBadger (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
==== Code ====
on("chat:message", function(msg) {	// Exit if not an api command	if (msg.type != "api") return;		// Get the API Chat Command	msg.who = msg.who.replace(" (GM)", "");	msg.content = msg.content.replace("(GM) ", "");	var n = msg.content.split(" ");	var command = n[0].toLowerCase();		if (command == "!power") {		// Create the PowerCard object array		var n = msg.content.split(" --");		var inlinerolls = msg.inlinerolls;		var NumberOfAttacks = 1;		var PowerCard = {};		var key = "";		var i = 1;		while (n[i]) {			key = n[i].substring(0, n[i].indexOf(" "));			if (key.substring(0, 6).toLowerCase() == "attack") {				NumberOfAttacks = parseInt(key.substring(6));				if(NumberOfAttacks === 0 || !NumberOfAttacks) NumberOfAttacks = 1;				key = "attack";			}			PowerCard[key] = n[i].substring(n[i].indexOf(" ")+1);			i++;		}			// Default PowerCard Variables		var TitleStyle     = " color: #FFF; font-size: large; font-weight: bold; font-family: Times; text-align: center; padding: 4px 0px 0px 0px;";		var AtWill         = " background-color: #060;";		var Encounter      = " background-color: #600;";		var Daily          = " background-color: #666;";		var Odd            = " background-color: #CEC7B6;";		var Even           = " background-color: #B6AB91;";		var RowStyle       = " padding: 5px;";		var RowBackground  = Odd;		var RowNumber      = 1;		var InlineStyle    = " width: 1.75em; padding: 0px; font-weight: bold; cursor: crosshair; text-align: center; vertical-align: middle; background-color: #fef68e;";		var InlineBorder   = " border: 3px solid #fef68e;";		var CritHitBorder  = " border: 3px solid #0C0;";		var CritMissBorder = " border: 3px solid #C00;";		var Count          = 0;			// TITLE BACKGROUND - Set the background color of the title card based on PowerCard.usage		if (PowerCard.usage !== undefined) {			if (PowerCard.usage.toLowerCase() == "daily") { TitleStyle += Daily; }			else if (PowerCard.usage.toLowerCase() == "encounter") { TitleStyle += Encounter; }			else { TitleStyle += AtWill; }		} else {			TitleStyle += AtWill;			PowerCard.usage = "At-Will";		}				// TITLE		var DisplayCard  = "<div style='" + TitleStyle + "'>" + PowerCard.name + "<br><span style='font-family: Verdana; font-size: 0.5em; font-weight: normal; color: #FFF;'>" + PowerCard.usage +  " • " + PowerCard.action + "</span></div>";				// KEYWORDS		if (PowerCard.keywords !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>Keyword(s):</b> " + PowerCard.keywords + "</div>";		}				// RANGE		if (PowerCard.range !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>Range:</b> " + PowerCard.range + "</div>";		}				// REQUIRE		if (PowerCard.require !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>Requirement:</b> " + PowerCard.require + "</div>";		}				// TRIGGER		if (PowerCard.trigger !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>Trigger:</b> " + PowerCard.trigger + "</div>";		}				// TARGET		if (PowerCard.target !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>Target:</b> " + PowerCard.target + "</div>";		}				// ATTACK		if (PowerCard.attack !== undefined) {			var AttackRolls = 1;			var CriticalHitMessage = "";			var AttackNumber = parseInt(PowerCard.attack.substring(3).replace("]]", ""));			var AttackTotal = msg.inlinerolls[AttackNumber].results.total;			var AttackRolled = msg.inlinerolls[AttackNumber].results.rolls[0].results[0].v;			var AttackBonus =  AttackTotal - AttackRolled;			var AttackTooltip = msg.inlinerolls[AttackNumber].expression.replace("1d20", "[1d20]");			while (AttackRolls <= NumberOfAttacks) {				RowBackground = (RowNumber%2 == 1) ? Odd : Even;								// Make an attack roll and check for critical hit or miss...				var AttackRoll = randomInteger(20);				if (AttackRoll == 20) {					CriticalHitMessage = " (Critical hit!)";					InlineBorder = CritHitBorder;				} else if (AttackRoll == 1) {					CriticalHitMessage = " (Critical miss!)";					InlineBorder = CritMissBorder;				} else {					CriticalHitMessage = "";					InlineBorder = " border: 3px solid #fef68e;";				}						// Add the attack roll to the DisplayCard construct...			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><table style='width: 100%;'><tr><td style='width: 1.75em;'><div style='" + InlineStyle + InlineBorder + "' title='" + AttackRoll + " " + AttackTooltip + "'>" + (AttackRoll + AttackBonus) + "</div></td><td style='padding-left: 5px;'> vs " + PowerCard.defense + CriticalHitMessage + "</td></tr></table></div>";   						// Increment row number and the number of attack rolls completed...			RowNumber += 1;			AttackRolls += 1;			}		}				// DAMAGE		if (PowerCard.damage !== undefined) {			var dmg = PowerCard.damage.substring(3).replace("]]", "");			var PowerDamageTotal = msg.inlinerolls[dmg].results.total;			var PowerDamageRoll  = msg.inlinerolls[dmg].expression;			var DamageRollBorder = "#fef68e";			// Alternates the background color...			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;						// Adds the damage line to the DisplayCard			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><table width='100%'><tr><td style='width: 1.75em;'><div style='width: 1.75em; text-align: center; vertical-align: middle; background-color: #fef68e; border: 3px solid " + DamageRollBorder + "; padding: 0px; font-weight: bold; cursor: crosshair;' title='" + PowerDamageRoll + "'>" + PowerDamageTotal + "</div></td><td style='text-align: left; padding-left: 5px;'>" + PowerCard.dmgtype + " damage</td></tr></table></div>";		}				// ONHIT		if (PowerCard.onhit !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>On Hit:</b> " + PowerCard.onhit + "</div>";		}				// ONMISS		if (PowerCard.onmiss !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>On Miss:</b> " + PowerCard.onmiss + "</div>";		}				// EFFECT		if (PowerCard.effect !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>Effect:</b> " + PowerCard.effect + "</div>";		}				// SPECIAL		if (PowerCard.special !== undefined) {			RowBackground = (RowNumber%2 == 1) ? Odd : Even;			RowNumber += 1;			DisplayCard += "<div style='" + RowStyle + RowBackground + "'><b>Special:</b> " + PowerCard.special + "</div>";		}				// INLINE ROLLS REPLACEMENT		while (Count < msg.inlinerolls.length) {			// Replace inline roll placeholder in DisplayCard			var RollTotal = msg.inlinerolls[Count].results.total;			var RollTooltip = msg.inlinerolls[Count].expression;			var InlineRoll = "<div style='display: inline-block; border: 3px solid #fef68e;" + InlineStyle + "' title='" + RollTooltip + "'>" + RollTotal + "</div>";			DisplayCard = DisplayCard.replace("$[[" + Count + "]]", InlineRoll);			Count += 1;		}				// SEND OUTPUT TO CHAT		/* var Token = getObj("graphic", msg.selected[0]._id);		var Represents = getObj("character", Token.get("represents")); 		var CharacterID = "character|" + Represents.id;		var PlayerID = "player|" + msg.playerid; */		if (PowerCard.emote !== undefined) sendChat(msg.who, "/emas " + PowerCard.emote);		sendChat("", "/direct " + DisplayCard);	}});