|
Spells
While most typical Units (i.e. creatures) will automatically generate their own spawning spell with a range of 1 and a chance and balance based on their Unit definition's properties, all other spells will be specified as a function for maximum flexibility. If a spell is defined with the same name as a Unit, the spell definition will replace the automatically generated Default Spawning Spell. chance Number(0.1-1)? base casting probability strength Number(1-10)? multiCast Number? if set, will allow the spell effect to be repeated times rangne Number? lineOfSight Boolean? balance Number e.g. -1 chaotic, 0 neutral, 1 lawful etc. validTargets Array(String) e.g. "self", "friendlymob", "friendlystatic", "enemymob", "enemystatic", "enemywizard", "emptytile", "allmobs", "allstatics", "undead", "living", "dead", "invulnerable" noExpend Boolean? does not remove spell from spellbook on casting (i.e. disbelieve) effect Function AccessThe effect function will have access to several helper functions which provide access to most of the current game's data. This allows spells to potentially be very flexible, and potentially very powerful. The function will only be called if the chance roll succeeds and if the target is valid. The spell will only be considered successful if the effect returns true. All helper functions are designed to chain, and will return false if unsuccessful. NOTE: Properties must not be set directly by spell effects, they must be set via AlterProperties and/or AlterStatus Helper functions include: Caster() Piece The casting Unit CurrentSpell() Spell The spell currently being cast Selected() Piece, Tile The Tile or Piece a spell was cast upon Owner() Player Returns the caster, or if chained with a Piece object, will return that Piece's owner Spells() Array(Spell) Returns the caster's spells, or if chained with a Player object, will return that Player's spells PiecesInRange(r Number) Array(Piece) Returns all Pieces in radius r of caster or chained Tile/Piece. If r is not specified, will use the spell's range property. If r == -1, will return all Pieces. Returned array is sorted nearest to furthest in a clockwise spiral TilesInRange(r Number) Array(Tile) As above, only returns Tiles instead of Pieces LoS(l Tile/Piece) Boolean Can the chained Piece see Tile or Piece l? Players() Array(Player) Returns all Players Roll(p String, s Number) Piece Rolls against property p with a strength of s against chained Piece. If s is not specified, will use the spell's strength property. For example, a basic attack against a Unit would be Roll("defense"). Returns the targetted Unit if roll was successful Kill() Piece Attempts to kill or destroy (where applicable) the chained Unit. Returns the killed Unit if successful. Alias of AlterStatus({"dead": true}) AlterProperties(p Object) Piece Changes the property/properties of chained Piece by merging and overwriting its current properties with the supplied object p. Properties can be set with a number, or altered relatively with a string. For example, AlterProperties({"defense": 1, "combat": "-2"}) will set the chained Unit's defense to 1, and reduce its combat by 2. Returns the modified Piece on success AlterBoard(p Object) Board Change board properties as above. For example AlterProperties({"balance": "+2"}) will increase the lawfulness of the board by 2 AlterStatus(s Object) Piece Adds or removes statuses to a Piece via the supplied object s. For example, AlterStatus({"undead": true, "mount": false}) will make a Piece undead, but remove its ability to accept a mount. Returns the modified Piece on success AlterOwner(p Player) Piece Changes chained piece's owner Spawn(u Unit, t Tile) Piece Creates a new Unit u for the current caster's owner (or the chained owner) at Tile t ExamplesA few possible examples of spell effects: Subversionfunction() {
if (Selected().Roll("resistance").AlterOwner(Owner())) {
return true;
}
}Magic Boltfunction() {
if (Selected().Roll("defense").Kill()) {
return true;
}
}Magic Woodfunction() {
var i = CurrentSpell().strength // use strength to determine amount of trees, as multiCast would result in non-automated casting
for each(var t in Caster().TilesInRange()) {
if (!t.piece && Caster().LoS(t)) { // tile must be empty and within line of sight of caster
if (t.PiecesInRange(1).filter(function(piece) {
if (piece.tree == true) {
return true;
}
}).length == 0) { // tile must not have adjacent trees
if (i > 0) {
Spawn("Magic Wood", t);
i--;
}
}
}
}
if (i < CurrentSpell().strength) { // consider the spell successful if at least one tree was cast
return true;
}
} Chaosfunction() {
if (AlterBoard({"balance": "-2"})) {
return true;
}
}Raise Deadfunction() {
if (Selected().AlterStatus({"dead": false}).AlterOwner(Owner())) {
return true
}
}Default Spawning SpellThis spell template will be applied to all standard mobile Units: "Unit Name": {
"chance": Unit.chance,
"range": 1,
"balance": Unit.balance,
"validTargets": [
"emptytile"
],
"effect": "function() { if (Spawn(\"Unit Name\", Selected())) { return true; } }"
}
|