[8451] Implement talent 47236 and ranks.
[getmangos.git] / sql / updates / 0.8 / 4501.sql
blob7380a0ff7c459b003afa3d3f8066739c988d4cbf
1 -- Add definitly a very usefull index to this creature table
2 -- If this sql file fails because the index already exists, comment the following line
3 ALTER TABLE `creature` ADD INDEX `index_id` (id);
5 -- Add suport to creature table for equipment and model overwritting
6 ALTER TABLE `creature`
7     ADD COLUMN `equipment_id` int(11) NOT NULL default '0' AFTER `map`,
8     ADD COLUMN `modelid` int(11) unsigned default '0' AFTER `map`;
10 -- Creation of creature_model_info table
11 DROP TABLE IF EXISTS `creature_model_info`;
12 CREATE TABLE `creature_model_info` (
13   `modelid` int(11) unsigned NOT NULL default '0',
14   `bounding_radius` float NOT NULL default '0',
15   `combat_reach` float NOT NULL default '0',
16   `gender` tinyint(2) unsigned NOT NULL default '2',
17   `modelid_other_gender` int(11) unsigned NOT NULL default '0',
18   PRIMARY KEY  (`modelid`)
19 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Creature System (Model related info)';
21 -- Correct possible db problems
22 UPDATE `creature_template` SET `bounding_radius`=0 WHERE `bounding_radius` IS NULL;
23 UPDATE `creature_template` SET `combat_reach`=0 WHERE `combat_reach` IS NULL;
24 UPDATE `creature_template` SET `modelid_m`=0 WHERE `modelid_m` IS NULL;
25 UPDATE `creature_template` SET `modelid_f`=0 WHERE `modelid_f` IS NULL;
27 -- All models defined in creature_template are used to build the table
28 INSERT IGNORE INTO `creature_model_info` (`modelid`) SELECT DISTINCT `modelid_m` FROM `creature_template`;
29 INSERT IGNORE INTO `creature_model_info` (`modelid`) SELECT DISTINCT `modelid_f` FROM `creature_template`;
31 -- Copy the data from creature_template to creature_model_info
32 UPDATE `creature_model_info`,`creature_template` SET
33     `creature_model_info`.`bounding_radius`=`creature_template`.`bounding_radius`,
34     `creature_model_info`.`combat_reach`=`creature_template`.`combat_reach`,
35     `creature_model_info`.`modelid_other_gender`=`creature_template`.`modelid_f`
36     WHERE `creature_model_info`.`modelid`=`creature_template`.`modelid_m`;
38 UPDATE `creature_model_info`,`creature_template` SET
39     `creature_model_info`.`bounding_radius`=`creature_template`.`bounding_radius`,
40     `creature_model_info`.`combat_reach`=`creature_template`.`combat_reach`,
41     `creature_model_info`.`modelid_other_gender`=`creature_template`.`modelid_m`
42     WHERE `creature_model_info`.`modelid`=`creature_template`.`modelid_f`;
44 -- Some changes in fields of creature_template
45 ALTER TABLE `creature_template`
46     CHANGE `modelid_m` `modelid_A` int(11) unsigned NOT NULL default '0',
47     CHANGE `modelid_f` `modelid_H` int(11) unsigned NOT NULL default '0',
48     ADD COLUMN `faction_H` int(4) unsigned NOT NULL default '0' AFTER `faction`,
49     ADD COLUMN `equipment_id` int(11) unsigned NOT NULL default '0' AFTER `RacialLeader`,
50     ADD COLUMN `RegenHealth` tinyint(1) unsigned NOT NULL default '1' AFTER `RacialLeader`,
51     DROP COLUMN `bounding_radius`,
52     DROP COLUMN `combat_reach`,
53     -- This index is temporary and enable the population of creature_equip_template to be fast
54     ADD INDEX `idx_tmp` (`equipmodel1`,`equipmodel2`,`equipmodel3`,`equipinfo1`,`equipinfo2`,`equipinfo3`,`equipslot1`,`equipslot2`,`equipslot3`);
56 ALTER TABLE `creature_template`
57     CHANGE `faction` `faction_A` int(4) unsigned NOT NULL default '0';
59 -- Create table creature_equip_template with temporary auto-increment key
60 DROP TABLE IF EXISTS `creature_equip_template`;
61 CREATE TABLE `creature_equip_template` (
62   `entry` int(11) unsigned NOT NULL auto_increment COMMENT 'Unique entry',
63   `equipmodel1` int(11) unsigned NOT NULL default '0',
64   `equipmodel2` int(11) unsigned NOT NULL default '0',
65   `equipmodel3` int(11) unsigned NOT NULL default '0',
66   `equipinfo1` int(11) unsigned NOT NULL default '0',
67   `equipinfo2` int(11) unsigned NOT NULL default '0',
68   `equipinfo3` int(11) unsigned NOT NULL default '0',
69   `equipslot1`  int(11) NOT NULL default '0',
70   `equipslot2`  int(11) NOT NULL default '0',
71   `equipslot3`  int(11) NOT NULL default '0',
72   PRIMARY KEY  (`entry`)
73 ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='Creature System (Equipment)';
75 -- Fill the creature_equip_template table with values from creature_template
76 INSERT INTO `creature_equip_template` (`equipmodel1`,`equipmodel2`,`equipmodel3`,`equipinfo1`,`equipinfo2`,`equipinfo3`,`equipslot1`,`equipslot2`,`equipslot3`)
77     (SELECT DISTINCT `equipmodel1`,`equipmodel2`,`equipmodel3`,`equipinfo1`,`equipinfo2`,`equipinfo3`,`equipslot1`,`equipslot2`,`equipslot3` FROM `creature_template` WHERE `equipmodel1`<>0 OR `equipmodel2`<>0 OR `equipmodel3`<>0);
79 -- Then add to creature_template the id generated for equipements
80 UPDATE `creature_template`,`creature_equip_template` SET
81     `creature_template`.`equipment_id`=`creature_equip_template`.`entry`
82     WHERE `creature_template`.`equipmodel1`=`creature_equip_template`.`equipmodel1` AND
83         `creature_template`.`equipmodel2`=`creature_equip_template`.`equipmodel2` AND
84         `creature_template`.`equipmodel3`=`creature_equip_template`.`equipmodel3` AND
85         `creature_template`.`equipinfo1`=`creature_equip_template`.`equipinfo1` AND
86         `creature_template`.`equipinfo2`=`creature_equip_template`.`equipinfo2` AND
87         `creature_template`.`equipinfo3`=`creature_equip_template`.`equipinfo3` AND
88         `creature_template`.`equipslot1`=`creature_equip_template`.`equipslot1` AND
89         `creature_template`.`equipslot2`=`creature_equip_template`.`equipslot2` AND
90         `creature_template`.`equipslot3`=`creature_equip_template`.`equipslot3`;
92 -- Remove all equipment fields from creature_template, this will remove the temporary index
93 ALTER TABLE `creature_template`
94     DROP COLUMN `equipmodel1`,
95     DROP COLUMN `equipmodel2`,
96     DROP COLUMN `equipmodel3`,
97     DROP COLUMN `equipinfo1`,
98     DROP COLUMN `equipinfo2`,
99     DROP COLUMN `equipinfo3`,
100     DROP COLUMN `equipslot1`,
101     DROP COLUMN `equipslot2`,
102     DROP COLUMN `equipslot3`;
104 -- Make all modelid and faction fields filled
105 UPDATE `creature_template` SET `modelid_A`=`modelid_H` WHERE `modelid_A`=0 AND `modelid_H`<>0;
106 UPDATE `creature_template` SET `modelid_H`=`modelid_A` WHERE `modelid_H`=0 AND `modelid_A`<>0;
107 UPDATE `creature_template` SET `faction_A`=`faction_H` WHERE `faction_A`=0 AND `faction_H`<>0;
108 UPDATE `creature_template` SET `faction_H`=`faction_A` WHERE `faction_H`=0 AND `faction_A`<>0;
110 -- Finaly remove the no more necessary auto-increment from creature_equip_template
111 ALTER TABLE `creature_equip_template`
112     CHANGE `entry` `entry` int(11) unsigned NOT NULL default '0' COMMENT 'Unique entry';