DELIMITER $$

DROP FUNCTION IF EXISTS `GetSpellTypeDescriptionToken`;

-- This function converts numeric spell type description ids to a string label based on server code designations
--
-- example:
-- SELECT `id`, `name`, GetSpellTypeDescriptionToken(`typedescnum`) FROM `spells_new` WHERE `id` IN ('16', '42', '23214');
CREATE FUNCTION `GetSpellTypeDescriptionToken` (`type_description_id` INT(11)) RETURNS VARCHAR(256)
BEGIN
	DECLARE `token` VARCHAR(256) DEFAULT '';
	
	CASE `type_description_id`
		WHEN '1' THEN SET `token` = 'Aegolism';
		WHEN '2' THEN SET `token` = 'Agility';
		WHEN '3' THEN SET `token` = 'Alliance';
		WHEN '4' THEN SET `token` = 'Animal';
		WHEN '5' THEN SET `token` = 'Antonica';
		WHEN '6' THEN SET `token` = 'Armor_Class';
		WHEN '7' THEN SET `token` = 'Attack';
		WHEN '8' THEN SET `token` = 'Bane';
		WHEN '9' THEN SET `token` = 'Blind';
		WHEN '10' THEN SET `token` = 'Block';
		WHEN '11' THEN SET `token` = 'Calm';
		WHEN '12' THEN SET `token` = 'Charisma';
		WHEN '13' THEN SET `token` = 'Charm';
		WHEN '14' THEN SET `token` = 'Cold';
		WHEN '15' THEN SET `token` = 'Combat_Abilities';
		WHEN '16' THEN SET `token` = 'Combat_Innates';
		WHEN '17' THEN SET `token` = 'Conversions';
		WHEN '18' THEN SET `token` = 'Create_Item';
		WHEN '19' THEN SET `token` = 'Cure';
		WHEN '20' THEN SET `token` = 'Damage_Over_Time';
		WHEN '21' THEN SET `token` = 'Damage_Shield';
		WHEN '22' THEN SET `token` = 'Defensive';
		WHEN '23' THEN SET `token` = 'Destroy';
		WHEN '24' THEN SET `token` = 'Dexterity';
		WHEN '25' THEN SET `token` = 'Direct_Damage';
		WHEN '26' THEN SET `token` = 'Disarm_Traps';
		WHEN '27' THEN SET `token` = 'Disciplines';
		WHEN '28' THEN SET `token` = 'Discord';
		WHEN '29' THEN SET `token` = 'Disease';
		WHEN '30' THEN SET `token` = 'Disempowering';
		WHEN '31' THEN SET `token` = 'Dispel';
		WHEN '32' THEN SET `token` = 'Duration_Heals';
		WHEN '33' THEN SET `token` = 'Duration_Tap';
		WHEN '34' THEN SET `token` = 'Enchant_Metal';
		WHEN '35' THEN SET `token` = 'Enthrall';
		WHEN '36' THEN SET `token` = 'Faydwer';
		WHEN '37' THEN SET `token` = 'Fear';
		WHEN '38' THEN SET `token` = 'Fire';
		WHEN '39' THEN SET `token` = 'Fizzle_Rate';
		WHEN '40' THEN SET `token` = 'Fumble';
		WHEN '41' THEN SET `token` = 'Haste';
		WHEN '42' THEN SET `token` = 'Heals';
		WHEN '43' THEN SET `token` = 'Health';
		WHEN '44' THEN SET `token` = 'Health_Mana';
		WHEN '45' THEN SET `token` = 'HP_Buffs';
		WHEN '46' THEN SET `token` = 'HP_type_one';
		WHEN '47' THEN SET `token` = 'HP_type_two';
		WHEN '48' THEN SET `token` = 'Illusion_Other';
		WHEN '49' THEN SET `token` = 'Illusion_Player';
		WHEN '50' THEN SET `token` = 'Imbue_Gem';
		WHEN '51' THEN SET `token` = 'Invisibility';
		WHEN '52' THEN SET `token` = 'Invulnerability';
		WHEN '53' THEN SET `token` = 'Jolt';
		WHEN '54' THEN SET `token` = 'Kunark';
		WHEN '55' THEN SET `token` = 'Levitate';
		WHEN '56' THEN SET `token` = 'Life_Flow';
		WHEN '57' THEN SET `token` = 'Luclin';
		WHEN '58' THEN SET `token` = 'Magic';
		WHEN '59' THEN SET `token` = 'Mana';
		WHEN '60' THEN SET `token` = 'Mana_Drain';
		WHEN '61' THEN SET `token` = 'Mana_Flow';
		WHEN '62' THEN SET `token` = 'Melee_Guard';
		WHEN '63' THEN SET `token` = 'Memory_Blur';
		WHEN '64' THEN SET `token` = 'Misc';
		WHEN '65' THEN SET `token` = 'Movement';
		WHEN '66' THEN SET `token` = 'Objects';
		WHEN '67' THEN SET `token` = 'Odus';
		WHEN '68' THEN SET `token` = 'Offensive';
		WHEN '69' THEN SET `token` = 'Pet';
		WHEN '70' THEN SET `token` = 'Pet_Haste';
		WHEN '71' THEN SET `token` = 'Pet_Misc_Buffs';
		WHEN '72' THEN SET `token` = 'Physical';
		WHEN '73' THEN SET `token` = 'Picklock';
		WHEN '74' THEN SET `token` = 'Plant';
		WHEN '75' THEN SET `token` = 'Poison';
		WHEN '76' THEN SET `token` = 'Power_Tap';
		WHEN '77' THEN SET `token` = 'Quick_Heal';
		WHEN '78' THEN SET `token` = 'Reflection';
		WHEN '79' THEN SET `token` = 'Regen';
		WHEN '80' THEN SET `token` = 'Resist_Buff';
		WHEN '81' THEN SET `token` = 'Resist_Debuffs';
		WHEN '82' THEN SET `token` = 'Resurrection';
		WHEN '83' THEN SET `token` = 'Root';
		WHEN '84' THEN SET `token` = 'Rune';
		WHEN '85' THEN SET `token` = 'Sense_Trap';
		WHEN '86' THEN SET `token` = 'Shadowstep';
		WHEN '87' THEN SET `token` = 'Shielding';
		WHEN '88' THEN SET `token` = 'Slow';
		WHEN '89' THEN SET `token` = 'Snare';
		WHEN '90' THEN SET `token` = 'Special';
		WHEN '91' THEN SET `token` = 'Spell_Focus';
		WHEN '92' THEN SET `token` = 'Spell_Guard';
		WHEN '93' THEN SET `token` = 'Spellshield';
		WHEN '94' THEN SET `token` = 'Stamina';
		WHEN '95' THEN SET `token` = 'Statistic_Buffs';
		WHEN '96' THEN SET `token` = 'Strength';
		WHEN '97' THEN SET `token` = 'Stun';
		WHEN '98' THEN SET `token` = 'Sum_Air';
		WHEN '99' THEN SET `token` = 'Sum_Animation';
		WHEN '100' THEN SET `token` = 'Sum_Earth';
		WHEN '101' THEN SET `token` = 'Sum_Familiar';
		WHEN '102' THEN SET `token` = 'Sum_Fire';
		WHEN '103' THEN SET `token` = 'Sum_Undead';
		WHEN '104' THEN SET `token` = 'Sum_Warder';
		WHEN '105' THEN SET `token` = 'Sum_Water';
		WHEN '106' THEN SET `token` = 'Summon_Armor';
		WHEN '107' THEN SET `token` = 'Summon_Focus';
		WHEN '108' THEN SET `token` = 'Summon_Food_Water';
		WHEN '109' THEN SET `token` = 'Summon_Utility';
		WHEN '110' THEN SET `token` = 'Summon_Weapon';
		WHEN '111' THEN SET `token` = 'Summoned';
		WHEN '112' THEN SET `token` = 'Symbol';
		WHEN '113' THEN SET `token` = 'Taelosia';
		WHEN '114' THEN SET `token` = 'Taps';
		WHEN '115' THEN SET `token` = 'Techniques';
		WHEN '116' THEN SET `token` = 'The_Planes';
		WHEN '117' THEN SET `token` = 'Timer_1';
		WHEN '118' THEN SET `token` = 'Timer_2';
		WHEN '119' THEN SET `token` = 'Timer_3';
		WHEN '120' THEN SET `token` = 'Timer_4';
		WHEN '121' THEN SET `token` = 'Timer_5';
		WHEN '122' THEN SET `token` = 'Timer_6';
		WHEN '123' THEN SET `token` = 'Transport';
		WHEN '124' THEN SET `token` = 'Undead';
		WHEN '125' THEN SET `token` = 'Utility_Beneficial';
		WHEN '126' THEN SET `token` = 'Utility_Detrimental';
		WHEN '127' THEN SET `token` = 'Velious';
		WHEN '128' THEN SET `token` = 'Visages';
		WHEN '129' THEN SET `token` = 'Vision';
		WHEN '130' THEN SET `token` = 'Wisdom_Intelligence';
		WHEN '131' THEN SET `token` = 'Traps';
		WHEN '132' THEN SET `token` = 'Auras';
		WHEN '133' THEN SET `token` = 'Endurance';
		WHEN '134' THEN SET `token` = 'Serpent\'s_Spine';
		WHEN '135' THEN SET `token` = 'Corruption';
		WHEN '136' THEN SET `token` = 'Learning';
		WHEN '137' THEN SET `token` = 'Chromatic';
		WHEN '138' THEN SET `token` = 'Prismatic';
		WHEN '139' THEN SET `token` = 'Sum_Swarm';
		WHEN '140' THEN SET `token` = 'Delayed';
		WHEN '141' THEN SET `token` = 'Temporary';
		WHEN '142' THEN SET `token` = 'Twincast';
		WHEN '143' THEN SET `token` = 'Sum_Bodyguard';
		WHEN '144' THEN SET `token` = 'Humanoid';
		WHEN '145' THEN SET `token` = 'Haste_Spell_Focus';
		WHEN '146' THEN SET `token` = 'Timer_7';
		WHEN '147' THEN SET `token` = 'Timer_8';
		WHEN '148' THEN SET `token` = 'Timer_9';
		WHEN '149' THEN SET `token` = 'Timer_10';
		WHEN '150' THEN SET `token` = 'Timer_11';
		WHEN '151' THEN SET `token` = 'Timer_12';
		WHEN '152' THEN SET `token` = 'Hatred';
		WHEN '153' THEN SET `token` = 'Fast';
		WHEN '154' THEN SET `token` = 'Illusion_Special';
		WHEN '155' THEN SET `token` = 'Timer_13';
		WHEN '156' THEN SET `token` = 'Timer_14';
		WHEN '157' THEN SET `token` = 'Timer_15';
		WHEN '158' THEN SET `token` = 'Timer_16';
		WHEN '159' THEN SET `token` = 'Timer_17';
		WHEN '160' THEN SET `token` = 'Timer_18';
		WHEN '161' THEN SET `token` = 'Timer_19';
		WHEN '162' THEN SET `token` = 'Timer_20';
		WHEN '163' THEN SET `token` = 'Alaris';
		ELSE SET `token` = 'unk';
	END CASE;
	
	SET `token` = CONCAT(`token`, '(', `type_description_id`, ')');
	
	RETURN `token`;
END$$

DELIMITER ;
