Removed trailing whitespaces and CRLFs
[getmangos.git] / sql / updates / 0.9 / 4781_mangos_gameobject_loot_template.sql
blobba803c4e0886b337643692c4f5e7f054169030d7
1 -- Addgo command change
2 DELETE FROM `command` WHERE `name`='addgo';
3 INSERT INTO `command` (`name`,`security`,`help`) VALUES
4  ('addgo',2,'Syntax: .addgo #id <spawntimeSecs>\r\n\r\nAdd a game object from game object templates to the world at your current location using the #id.\r\nspawntimesecs sets the spawntime, it is optional.\r\n\r\nNote: this is a copy of .gameobject.');
6 -- Creation of first temp table
7 DROP TABLE IF EXISTS `goloot`;
8 CREATE TABLE `goloot` (
9   `entry` int(11) unsigned NOT NULL default '0',
10   `loot` int(11) unsigned NOT NULL default '0',
11   `sound1` int(11) unsigned NOT NULL default '0',
12   PRIMARY KEY  (`entry`),
13   INDEX `idx_loot` (`loot`)
14 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Go Loot Errors';
16 -- Filling table
17 INSERT IGNORE INTO `goloot` (`entry`,`loot`,`sound1`) SELECT `entry`,`entry`,`sound1` FROM `gameobject_template` WHERE `type` IN (3,25); -- AND `sound1`!=0;
18 UPDATE `goloot` a,`gameobject` b SET a.`loot`=b.`loot` WHERE a.`entry`=b.`id` AND b.`loot`!=0;
20 -- Second temp table
21 DROP TABLE IF EXISTS `goloot2`;
22 CREATE TABLE `goloot2` (
23   `sound1` int(11) unsigned NOT NULL default '0',
24   `loot` int(11) unsigned NOT NULL default '0',
25   PRIMARY KEY  (`sound1`)
26 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Temp Table';
28 -- Put data into
29 INSERT INTO `goloot2` (`sound1`,`loot`) SELECT DISTINCT `sound1`,MIN(`loot`) FROM `goloot` WHERE `loot`!=0 AND `sound1`!=0 AND `loot` IN (SELECT DISTINCT `entry` FROM `gameobject_loot_template`) GROUP BY `sound1`;
31 -- Now update gameobject_loot_template with new ids
32 UPDATE IGNORE `gameobject_loot_template` a,`goloot2` b SET a.`entry`=b.`sound1`+1000000 WHERE a.`entry`=b.`loot`;
34 -- Now remove remaining loots not binded (conflits in several update or just garbage)
35 DELETE FROM `gameobject_loot_template` WHERE `entry` NOT IN (SELECT DISTINCT `sound1`+1000000 FROM `goloot2` UNION SELECT DISTINCT `loot` FROM `goloot` WHERE `sound1`=0);
36 UPDATE `gameobject_loot_template` SET `entry`=`entry`-1000000 WHERE `entry`>1000000;
38 -- Cleanup but let bad sound1 entries for later correction
39 DELETE FROM `goloot` WHERE `sound1`!=0;
40 DELETE FROM `goloot` WHERE `loot` NOT IN (SELECT DISTINCT `entry` FROM `gameobject_loot_template`);
42 --      Inverse comments in following 3 lines to see generated errors on conversion for gameobjects type 3 with sound1=0
43 -- DROP TABLE IF EXISTS `gameobject_loot_errors`;
44 -- RENAME TABLE `goloot` TO `gameobject_loot_errors`;
45 DROP TABLE IF EXISTS `goloot`;
47 -- Remove second temp table
48 DROP TABLE IF EXISTS `goloot2`;
49 -- Remove now not usefull loot column
50 ALTER TABLE `gameobject` DROP COLUMN `loot`;