//include("SpellCast.js"); include("Utils.js"); // We depend on the Utils module. // Create the global symbol "SpellCast" as our namespace if it doesn't exist. // Throw an error if it does exist but is not an object. var SpellCast; if (!SpellCast) { SpellCast = {}; } else if (typeof SpellCast != "object") { throw new Error("SpellCast.js: SpellCast already exists and is not an object."); } /** * Releases all mana, held mana spells, and preparing spells. */ SpellCast.releaseAll = function() { SpellCast.release("all"); } /** * Releases a currently prepared/preparing spell. */ SpellCast.releasePrep = function() { if (spell != "None") { SpellCast.release("spell"); } } /** * Releases some or all held mana. * Param manaNum Optional. The amount of mana to release. * If not provided, defaults to all mana. */ SpellCast.releaseMana = function(/*optional*/ manaNum) { if (!manaNum) { SpellCast.release("mana"); } else if (isNaN(parseInt(manaNum))) { // Not a number, do nothing. return; } else { SpellCast.release(manaNum + " mana"); } } /** * Attempts to release whatever is passed as a parameter. * Used as the back end for all the more specific release methods. * When releasing mana, if more mana is specified than is currently held * It will attempt to release all held mana. * Param relString Optional. What we should attempt to release. * If not provided, a generic release will be tried. */ SpellCast.release = function(/*optional*/ relString) { if (!relString) { var relString = ""; } // The huge match table is so we can guarantee a successful release // Unfortunately, this means we need every possible string. WIP. var matches = new MatchList(); matches.match("Type RELEASE HELP for more options.", _end); matches.match("Release what?", _end); matches.match("You let your concentration lapse", _end); matches.match("You aren't preparing a spell.", _end); matches.match("You release", _end); matches.match("You aren't holding any mana.", _end); matches.match("You gesture, completing the pattern to unravel", _end); matches.match("That would be a neat trick. Try finding a", _end); matches.match("Shadow Servant disappears.", _end); matches.match("You don't have a Shadow Servant.", _end); matches.match("You release the Refractive Field spell.", _end); matches.match("That spell isn't in effect on you.", _end); matches.match("You release your Distant Gaze spell.", _end); matches.match("You do not have a Distant Gaze spell in effect.", _end); matches.match("You aren't holding that much mana.", SpellCast.releaseMana); Utils.matchPut("release " + relString, matches); function _end() {} } /** * Prepares a spell. Releases any currently preparing spell in favor * of this one. * Param spellName Name of the spell to prepare. * Param manaNum Optional. Amount of mana to prepare the spell at. * Returns A string containing the preparing spell or "None" if no * spell was prepped. */ SpellCast.prep = function(spellName, /*optional*/ manaNum) { if (!spellName) { throw new Error("SpellCast.js: SpellCast.prep requires a spell name."); } if (!manaNum || isNaN(parseInt(manaNum))) { manaNum = 1; } // Release any currently preparing spell SpellCast.releasePrep(); var matches = new MatchList(); matches.match("That is not a spell you can cast."); // Bad spell name matches.match("You do not know how to cast that spell."); // You haven't learned this spell matches.match("You stop, convinced that there's no way"); // Too much mana (>499) matches.matchRe( "You struggle against your bindings to prepare|" + // Prep while webbed "You raise your arms skyward, chanting the words|" + // Moon Mage - Default "Your eyes and skin darken to black as a starless night|" + // Moon Mage - Exclusive Library "Smiling slyly, you murmur the words|" + // Moon Mage - Tezirite "You trace an arcane sigil in the air|" + // War Mage - Default "Icy blue frost crackles up your arms|" + // War Mage - Exclusive Library "Heatless orange flames blaze between your|" + // War Mage - Exclusive Library "Tiny tendrils of lightning jolt between your|" + // War Mage - Exclusive Library "You close your eyes and breathe deeply, gathering|" + // Empath/Ranger - Default "You begin chanting a prayer to invoke|" + // Cleric - Default? "You bow your head and chant a prayer|" + // Cleric - Default? "The wailing of lost souls accompanies your preparations|" + // Cleric - Exclusive Library "Your skin briefly withers and tightens, becoming gaunt"); // Necromancer - Exclusive Library Utils.matchPut("prepare " + spellName + " " + manaNum, matches); } /** * Casts a pre prepared spell. * Param target Optional. The target of the spell. * Returns true if the spell was successfully cast, otherwise false * Casting while out of mana still counts as success. */ SpellCast.cast = function(/*optional*/ target) { matches = new MatchList(); var success = matches.matchRe( "You sweep your right hand across the spell pattern|" + // energy bolt "You gesture\\.|" + // regular cast "(You steeple your fingers together|Using your (left|right) hand, you channel)"); // whole displacement var failure = matches.matchRe( "I could not find what you were referring to\\.|" + // bad target "You must cast this spell on a constellation\\.|" + // bad target - starlight sphere "Your secondary spell pattern|" + // dead target - TM "on yourself!|" + // not a self cast spell "You don't have a spell"); // no spell prepped if (target) { var matched = Utils.matchPut("cast " + target, matches); } else { var matched = Utils.matchPut("cast", matches); } if (matched == success) { return true; } else if (matched == failure) { return false; } } /** * Harness some mana * Param amount Amount to harness per try * Param times Optional. Times to harness amount. Default is one * Returns Total number of mana sucessfully harnessed. */ SpellCast.harness = function(amount, /*optional*/ times) { if (!amount || isNaN(parseInt(amount))) { throw new Error("SpellCast.js: " +amount +"is not a valid amount for SpellCast.harness"); } if (!times) { times = 1; } if (isNaN(parseInt(times))) { throw new Error("SpellCast.js: SpellCast.harness second argument is optional but must be a number"); } for (var i = 0; i < times; i++) { matches = new MatchList(); matches.match("You tap into the mana"); var failure = matches.match("You strain, but cannot"); Utils.matchPut("harness " + amount, matches); if (failure == matches) { break; } } return i * amount; } /** * Charge a cambrinth item * Param item Cambrinth item to charge * Param amount Amount to charge * Returns true if any mana was successfuly charged. false otherwise. */ SpellCast.charge = function(item, amount) { if (!item || !amount || isNaN(parseInt(amount))) { throw new Error("SpellCast.js: Usage: SpellCast.charge(cambrinth_item, charge_amount);"); } matches = new MatchList(); var failure = matches.matchRe("Don't be rediculous.|That cannot be charged\\.|You strain, but cannot|I could not find what"); var success = matches.match("Roundtime:"); var matched = Utils.matchPut("charge " +item +" " +amount, matches); if (matched == failure) { return false; } else if (matched == success) { return true; } } /** * Focus on an item, usually cambrinth * Param item Item to focus on * Param amount Optional. Amount to focus. (for runestones) */ SpellCast.focus = function(item, /*optional*/amount) { if (!item) { throw new Error("SpellCast.js: SpellCast.focus requires an item parameter."); } matches = new MatchList(); var retry = matches.matchRe("Try though you may,|magical link, but fail\\."); var end = matches.matchRe("dim, almost magically|readying it for your|Your link to|Roundtime:|You must have both hands free|I could not find what you"); if (!amount || isNaN(parseInt(amount))) { var matched = Utils.matchPut("focus my " +item, matches); } else { var matched = Utils.matchPut("foucs my " +item +" " +amount, matches); } if (matched == retry) { SpellCast.focus(item, amount); } else if (matched == end) { return; } } SpellCast.prep("cv"); SpellCast.charge("armband", 11); SpellCast.focus("armband"); SpellCast.cast();