Want to make an Elements tool but can't be bothered writing out all the different properties of every single card that you need? No problem! The Ultimate Elements PHP/Javascript Library is here to help for your client-side and server-side needs.
>> The Ultimate Elements PHP/Javascript Library <<You can find the library here in text format. Simply change the file extension to .php, upload it to your server and access it like so in PHP:
require_once('elements_lib.php');
To use the library in Javascript, go to elements_lib.php?jsupdate. This will automatically create a file called elements_lib.js and populate it. You should do this whenever you update your library. Access it like so:
<script src='elements_lib.js'></script>
To change the path of the Javascript file to write to, find the variable $jsfile and change it. You can also have a dynamic Javascript file outputted by elements_lib.php?js. Note that the Javascript will automatically be compressed by
JSCompress. To see the raw Javascript, add a nocompress parameter to the URL, as in elements_lib.php?js&nocompress.
Can't be bothered uploading it to your server? Want to try it out first? No problem!
PHP:
eval('?>' . file_get_contents('http://elementscommunity.org/tools/elements_lib.txt') . '<?php;');
Javascript:
<script src='http://elementscommunity.org/tools/elements_lib.js'></script>
You are free to use the library in any of your tools without credit, as long as the tool is exclusive to the Elements community. If you plan to use it somewhere else for whatever reason, mention my name and provide a link to this topic.
How to use the libraryBefore we use the library, we need to understand how the game and library stores and references cards. Basically, each element is given a number, like so:
Other: 0
Entropy: 1
Death: 2
Gravity: 3
Earth: 4
Life: 5
Fire: 6
Water: 7
Light: 8
Air: 9
Time: 10
Darkness: 11
Aether: 12
Yes, this is the order of elements in the deck building screen and Bazaar.
Each card is stored as a number too. This number for non-upgraded cards is equal to the number of the element multiplied by 100 plus an arbitrary number:
Card number = element number * 100 + x
x is 0 for pillars, 20 for nymphs and 50 for pendulums. For other cards, it is merely the order in which they were added to the game.
So, Amethyst Pillar is 100, Black Nymph is 1120, Heal is 506, etc. There is one exception to this pattern - Quantum Pillar is 2, not 0.
Upgraded cards are simply the non-upgraded card + 2000. So, Amethyst Pillar is 2100, Dark Nymph is 3120, Quantum Tower is 2002, etc.
The library uses a standard format for decks. Each deck is an array of these card numbers (2, 2002, 1450, etc.). They also have a 'mark' index which stores the element number of the deck's mark. Some decks also have a 'name' index.
Card DataNow that that's out of the way, we can look at the main feature of the library, which is the array called $__cardData.
$__cardData is essentially an array of objects. Each object represents a card, and can be accessed by cardData(card number). For example, Amethyst Pillar's object is cardData(100).
Each card object has a number of different properties. Each object has the following properties:
nameThe name of the card.
ctypeThis can take upon one of the following values:
- 'creature' - Any creature except Chimera.
- 'spell' - All spells and Chimera.
- 'pillar' - All pillars, pendulums and marks.
- 'shard' - All permanent shards.
- 'weapon' - All weapons.
- 'shield' - All shields.
- 'permanent' - All other permanents.
atkThe ATK of a creature or damage a weapon deals. Set to 0 for everything else.
defThe HP of a creature, damage reduction of a shield or amount healed per turn by Purify. Set to 0 for everything else.
skillThe name of a card's skill.
Spoiler for List of skills:
* means that the skill is not present on both non-upgraded and upgraded cards.
'ablaze': Fire Spirit, Graviton Fire Eater
'acceleration': Acceleration*
'accretion': Shard of Focus
'adrenaline': Adrenaline, Green Nymph
'aflatoxin': Aflatoxin, Grey Nymph
'air': Dragonfly
'antimatter': Antimatter, Purple Nymph
'armor': Plate Armor*
'berserk': Rage Elixir*, Fire Nymph*
'black hole': Black Hole, Amber Nymph
'blessing': Blessing
'blitz': Sky Blitz
'bones': Bone Wall
'boneyard': Boneyard
'bow': Short Bow
'bravery': Shard of Bravery
'burrow': Antlion, Shrieker, Devourer
'butterfly': Butterfly Effect
'catapult': Catapult
'chaos': Chaos Seed*
'chaos power': Chaos Power*
'cloak': Cloak
'congeal': Congeal*, Arctic Octopus*
'cremation': Cremation*
'dagger': Dagger
'dead/alive': Schrödinger's cat
'deadly poison': Deadly Poison*
'deadly venom': Deathstalker
'deja vu': Deja Vu
'delay': Procrastination
'destroy': Deflagration, Pulverizer
'devour': Otyugh, Scarab
'dissipation': Dissipation Field*
'dive': Wyrm, Pegasus
'divineshield': Seraph
'drain life': Drain Life
'duality': Mindgate
'dusk': Dusk Mantle
'earth': Gnome Rider
'earthquake': Earthquake
'eclipse': Eclipse*
'edissipation': Dissipation Shield*
'empathy': Empathic Bond
'enchant': Enchant Artifact
'endow': Crusader
'evolve': Graboid
'fiery': Fahrenheit
'fire': Brimstone Eater*, Elite Firefly*
'fire bolt': Fire Bolt
'firewall': Fire Shield
'flood': Flooding
'flying': Flying Weapon
'fog': Fog Shield
'fractal': Fractal
'freedom': Shard of Freedom
'freeze': Freeze*, Arctic Squid*
'golem': Shard Golem
'gratitude': Shard of Gratitude
'gravity pull': Gravity Pull
'growth': Lava Golem, Forest Spirit
'guard': Iridium Warden
'hammer': Hammer
'hasten': Golden Hourglass, Sundial
'hatch': Fate Egg
'heal': Guardian Angel
'healp': Heal
'heavy armor': Heavy Armor*
'holy light': Holy Light
'hope': Hope
'ice': Ice Shield
'icebolt': Ice Bolt
'ignite': Unstable Gas
'immaterial': Immortal, Phase Dragon, Morning Star
'immolate': Immolation*
'immortality': Quintessence, Anubis, Turquoise Nymph
'improve': Improved Mutation*, Fallen Druid*
'infect': Virus*
'infection': Parasite, Toadfish*
'infest': Malignant Cell
'integrity': Shard of Integrity
'light': Ray of Light*, Firefly*
'lightning': Lightning
'liquid shadow': Liquid Shadow, Black Nymph
'lobotomize': Lobotomizer, Mind Flayer
'luciferin': Luciferin, Light Nymph
'lycanthropy': Lycanthrope
'miracle': Miracle
'mitosis': Mitosis
'momentum': Momentum, Sapphire Charger, Titan
'moo': Holy Cow
'mutation': Mutation*, Fallen Elf*
'neurotoxin': Dune Scorpion
'nightfall': Nightfall*
'nightmare': Nightmare
'none': Weapon (slot), Shield (slot)
'nova': Nova*
'nymph': Nymph's Tears, Nymph Queen
'overdrive': Overdrive*
'pandemonium': Pandemonium
'paradox': Maxwell's Demon
'parallel universe': Parallel Universe
'patience': Shard of Patience
'petrify': Basilisk's Blood, Auburn Nymph
'phaseshift': Dimensional Shield
'phoenix': Phoenix
'photosynthesis': Rustler
'plague': Plague, Retrovirus*
'poison': Poison
'precognition': Precognition, Golden Nymph
'queen': Firefly Queen
'rage': Rage Potion*, Red Nymph*
'rain of fire': Rain of Fire
'readiness': Shard of Readiness
'rebirth': Ash
'reflect': Reflective Shield, Emerald Shield
'regenerate': Druidic Staff
'reverse time': Reverse Time, Eternity
'sacrifice': Shard of Sacrifice
'sanctuary': Sanctuary
'scarab': Pharaoh
'scavenger': Vulture
'scramble': Discord
'serendipity': Shard of Serendipity
'shard': Shard of Divinity
'shield': Shield, Titanium Shield
'shockwave': Shockwave
'silence': Silence
'singularity': Singularity
'sniper': Owl's Eye
'solar': Solar Shield
'soul catch': Soul Catcher
'spines': Thorn Carapace
'steal': Steal
'steam': Steam Machine
'stone form': Gargoyle
'stoneskin': Stone Skin
'supernova': Supernova*
'sword': Short Sword
'thunderstorm': Thunderstorm
'tsunami': Trident
'unholy': Skull Shield
'unstable gas': Blue Nymph
'vampire': Minor Vampire, Vampire Stiletto
'venom': Arsenic, Forest Scorpion, Puffer Fish*
'void': Shard of Void
'web': Flesh Spider, Phase Spider
'weight': Gravity Shield
'wings': Wings
'wisdom': Shard of Wisdom
' ': Pendulums (yeah, that's right - a space)
skillcostThe cost of a skill. An empty string if the skill is not active and manually activated.
skillelementThe number of the element used to pay for a skill. Usually an empty string if the skill is not active and manually activated.
costThe casting cost of a card.
costelementThe number of the element used to pay for a card. 0 if the card can be paid for with any quanta (Animate Weapon, etc.)
rarityThe 'tier' of a card, used in buying and selling cost calculations.
They may also have:
passiveThe name of a card's passive skill.
passive2The name of a card's second passive skill. Right now this can only be 'airborne', or an empty string for weapons.
AI DecksGetting random AI decks are made easy by this simple function:
array AIDeck(int $level, string $name = '')Level is a number from 0 to 5, the AI level for which you want a deck to be generated. Name can be specified when level is 5 to get a specific False God deck.
One can also access the $AIDecks array, which stores AI2, AI3 and AI5 decks.
FunctionsAll these functions can be used the same way in both PHP and Javascript. Examples given are for PHP.
Spoiler for getDeck:
array getDeck(string $deck_code)Takes a deck import code as an input. Returns an array containing the numbers of each card. Returns false if the deck code is invalid.
Spoiler for Example:
$deck = getDeck("6rq 6rq 6rq 6rq 6u3 6u3 6u3 6u3 6u3 6u3 74g 7ap 7n9 7q0 7q0 7q0 7q0 7q0 7q0 7q5 7q5 7q5 7q5 7q6 7q9 7q9 7q9 7q9 7q9 7q9 8pj");
echo $deck['mark'];
echo implode(", ", $deck);
Output:
1
2034, 2034, 2034, 2034, 2107, 2107, 2107, 2107, 2107, 2107, 2312, 2513, 2913, 3000, 3000, 3000, 3000, 3000, 3000, 3005, 3005, 3005, 3005, 3006, 3009, 3009, 3009, 3009, 3009, 3009
Spoiler for outputDeck:
string outputDeck(array $deck)Returns the deck import code of a deck array.
Spoiler for Example:
$deck = array(2034, 2034, 2034, 2034, 2107, 2107, 2107, 2107, 2107, 2107, 2312, 2513, 2913, 3000, 3000, 3000, 3000, 3000, 3000, 3005, 3005, 3005, 3005, 3006, 3009, 3009, 3009, 3009, 3009, 3009);
$deck['mark'] = 1;
echo outputDeck($deck);
Output:
6rq 6rq 6rq 6rq 6u3 6u3 6u3 6u3 6u3 6u3 74g 7ap 7n9 7q0 7q0 7q0 7q0 7q0 7q0 7q5 7q5 7q5 7q5 7q6 7q9 7q9 7q9 7q9 7q9 7q9 8pj
Spoiler for compressDeckCode:
string compressDeckCode(mixed $deck_code)This compresses a deck code by removing all spaces and replacing repeating instances of a card code with z{number of copies - 1}{card code}. Accepts a deck import code or deck array as an input. Useful for things like passing deck codes as get parameters. You can also use it to link a deck image like so: <img src='
http://elementscommunity.org/tools/deck/?redirect&deck={compressed code}' />.
ExamplesLet's write a quick program to calculate the cost of a deck.
In PHP ($_GET['deck'] is the input):
<?php
require_once("elements_lib.php");
$deck = getDeck($_GET['deck']);
$cost = 0;
function buy_price($card) {
return 6 * pow(cardData($card)->rarity, 2) + cardData($card)->cost;
}
foreach (cards($deck) as $card) {
$cost += buy_price($card);
}
echo "Cost of deck: " . $cost;
?>
That was easy, wasn't it? Let's try the same thing in Javascript:
<script src='elements_lib.js'></script>
<script>
deck = getDeck(prompt("Enter a deck code"));
cost = 0;
function buy_price(card) {
return 6 * Math.pow(cardData(card).rarity, 2) + cardData(card).cost;
}
for (i in cards(deck)) {
cost += buy_price(deck[i]);
}
alert("Cost of deck: " + cost);
</script>
This is just the tip of the iceberg. The library can be used and extended to fit virtually any needs you may have for your tool. Now get coding!