
Good morning! <3 I'd like to share with you the code for the first two spells I have coded into my Campaign so far: Bless and Color Spray . To begin with, the casting of spells is accomplished through the API chat message, using the command "!cast" in an Ability. It is assumed in this code that a Token representing a Character is currently Selected (all spell casting Abilities should be Token Actions). The syntax for my API call is such that the first parameter is ALWAYS "!cast", the second parameter is ALWAYS a string representing a spell's name, the third parameter is ALWAYS the Token ID of the selected Token (who is the spell caster), and the fourth parameter is ALWAYS a STRING matching the name of an Attribute defined for the Character that the selected Token represents. Certain spells may require additional parameters, such as the ID of the Targeted token, etc. Bless: This is the first spell I coded. It is pretty simple. The spell turns on a bluish-white aura around the caster, at a radius equal to the spell's range (in this case, 50 feet). Then, the code searches all the Tokens on the caster's Page, and if the Token represents a Character controlled by a Player, AND that token is within the spell's range, the Script marks that Token with a BLUE status marker, if it does not already have one. (The functionality that applies the +1 morale bonus to attacks and fear saves has not been written yet... for now, just remember that a BLUE status marker represents a Bless effect. In the future, I will expand this to allow NPCs to cast Bless affecting the player characters' enemies.) I chose not to set a numeric value on the status marker since the Bless spell's duration is measured in minutes, not rounds. /me holds aloft Selûne's moon mote pendant. The radiant white light of the Moonmaiden illuminates you all. "Blessed Be!"
!cast Bless @{selected|token_id} Wisdom Color Spray: This spell is a fair bit more complicated. The macro will prompt the caster to enter an angle measurement, from 0 to 359 degrees. Once that is entered, the Scrpit creates a graphic Token with the Color Spray image, rotates it according to the angle measurement entered, and moves it to the front of its Layer. THEN, the Script loops through all the other tokens on the page, selecting those that are within the spell's effect. Note that the code does NOT check for an intersection between the graphic Tokens; rather, it uses the JavaScript Math library's arctangent function to calculate the distance AND angle from the point of origin, i.e. the caster's coordinates. The values for the spell's range (spellEffectiveDistance) and the cone's angle (spellEffectiveAngle) are currently hard-coded into the spell_ColorSpray function, although eventually, the spell's range will be level dependent. The dimensions of the Color Spray rainbow graphic are calculated based on the spellEffectiveDistance. /me extends her arm and shouts, "KALLISTI!" A kaleidoscopic flash bursts from her outstretched hand.
!cast ColorSpray @{selected|token_id} Charisma ?{Enter an angle rotation from 0-359 degrees: 0 = up, 90 = right, 180 = down, and 270 = left.|0} Once a Token has been determined to be within the spell's area of effect, that Token's Character is allowed a Will saving throw against the spell's Difficulty Class (which is calculated in the API event and passed as an Integer to the spell_ColorSpray function). (If the Token in question is NOT represented by a Character, the Will save bonus should default to 0.) If the target fails its Will save, the spell effect is applied. Since the spell's effect varies based on the target's level or Hit Dice, the function checks that and uses a /desc chat message to describe the effect. Finally, affected targets who fail their save are given a RED status marker with a number on it equal to the number of rounds they are unconscious, blinded, or whatever. Here is the PNG image file for the rainbow-colored 60° cone. You have to load it into your graphic library in order for it to work, and then you will have to change the imgsrc parameter for the createObj() function inside of spell_ColorSpray() to match the URL for the graphic in your library. Note that it is porportioned so that the apex of the cone falls exactly in the center of the file. This is important because the image will be given the caster's top and left coordinates, and then rotated around its center. I created this in Adobe Photoshop using the gradient tool, with opacity set to 65%. Finally, here is a link to the Gist which contains the source for the case: "cast" portion of my on ('chat:message') API routine, followed by my (separate) Script file containing the spell definition functions for Bless and Color Spray. <script src=" <a href="https://gist.github.com/Aeristan/e3214ec8c0b18b6e35b8.js"></script" rel="nofollow">https://gist.github.com/Aeristan/e3214ec8c0b18b6e35b8.js"></script</a>
> Thank you very much, I hope you enjoy this and find it useful in all of your Campaigns. Blessed Be!