SET @GUID                            := 303059;

/* NPCs */
-- Ahune
SET @NPC_AHUNE                       := 25740;
SET @NPC_FROZENCORE                  := 25865;
-- Bunnys
SET @NPC_SPANKTARGETBUNNY            := 26190;
SET @NPC_SLIPPERYFLOORBUNNY          := 25952;
SET @NPC_ICESPEARBUNNY               := 25985;
-- Ahunite Adds
SET @NPC_AHUNITE_FROSTWIND           := 25757;
SET @NPC_AHUNITE_COLD_WIND           := 25756;
SET @NPC_AHUNITE_HAILSTONE           := 25755;

/* Spells */
-- Ahune
SET @SPELL_SLIPPERY_FLOOR            := 46320;
SET @SPELL_BUNNY_KNOCK_OUT           := 46735;
SET @SPELL_COLD_SLAP                 := 46145;
SET @SPELL_SPANK_KNOCK_TO            := 46734;
-- Ahunite Adds
SET @SPELL_LIGHTNING_SHIELD          := 51620;
SET @SPELL_WIND_BUFFET               := 46568;
SET @SPELL_BITTER_BLAST              := 46406;
SET @SPELL_CHILLING_AURA             := 46542;
SET @SPELL_PULVERIZE                 := 2676;

/* Gameobjects */
SET @GO_ICE_SPEAR                    := 188077;
SET @GO_ICE_STONE                    := 187882;

/* Items */
SET @ITEM_POCKET_FULL_OF_SNOW        := 35512;
-- DF Reward
SET @ITEM_SATCHEL_OF_CHILLED_GOODS   := 54536;
-- Satchel of Chilled Goods Loot
SET @ITEM_ICE_CHIP                   := 53641;
SET @ITEM_FROSTSCYTHE                := 35514; -- Level 80: 54806
-- Chest Loot
SET @ITEM_ICEBOUND_CLOAK             := 35496; -- Level 80: 54801
SET @ITEM_FROST_LORDS_WAR_CLOAK      := 35495; -- Level 80: 54802
-- SET @ITEM_FROST_LORDS_BATTLE_SHROUD  := 54803;
SET @ITEM_SHROUD_OF_WINTERS_CHILL    := 35494; -- Level 80: 54804
SET @ITEM_CLOAK_OF_THE_FRIGID_WINDS  := 35497; -- Level 80: 54805
SET @ITEM_SHARDS_OF_AHUNE            := 35723;
SET @ITEM_HUGE_SNOWBALL              := 35557;
SET @ITEM_LORDS_PRIVATE_LABEL        := 35720;
SET @ITEM_FORMULA_DEATHFROST         := 35498;
-- Pocket Full of Snow
SET @ITEM_SNOWBALL                   := 17202;

/* Quests */
SET @QUEST_WORLD_EVENT_DUNGEON_AHUNE := 25484;

-- ToDo: Move some Earthen Ring Npc
/*
UPDATE `creature` SET `orientation`=4.5618 WHERE `guid`=202734;
UPDATE `creature` SET `position_x`=-127.463, `position_y`=-130.762, `position_z`=-2.06541, `orientation`=4.90899 WHERE `guid`=202735;
UPDATE `creature` SET `position_x`=-141.138, `position_y`=-136.834, `position_z`=-1.59055, `orientation`=5.24279 WHERE `guid`=202736;
UPDATE `creature` SET `position_x`=-136.327, `position_y`=-132.425, `position_z`=-1.80894, `orientation`=5.06608 WHERE `guid`=202737;
UPDATE `creature` SET `position_x`=-138.054, `position_y`=-139.024, `position_z`=-1.67183, `orientation`=5.04643 WHERE `guid`=202738;
UPDATE `creature` SET `position_x`=-131.929, `position_y`=-135.194, `position_z`=-1.94897, `orientation`=4.99538 WHERE `guid`=202739;
*/

-- Spawn Ahune + Bunnies
DELETE FROM `creature` WHERE `id` IN (@NPC_AHUNE,@NPC_SPANKTARGETBUNNY);
INSERT INTO `creature` (`guid`, `id`, `map`, `spawnMask`, `phaseMask`, `modelid`, `equipment_id`, `position_x`, `position_y`, `position_z`, `orientation`, `spawntimesecs`, `spawndist`, `currentwaypoint`, `curhealth`, `curmana`, `MovementType`, `npcflag`, `unit_flags`, `dynamicflags`) VALUES
(@GUID,@NPC_AHUNE,547,1,1,0,0,-97.407,-238.3,-1.26481,1.43332,10,0,0,539000,0,0,0,0,0),
(@GUID+1,@NPC_SPANKTARGETBUNNY,547,1,1,0,0,-85.6774,-197.35,25.3171,4.4867,30,0,0,57,0,0,0,33554432,0),
(@GUID+2,@NPC_SPANKTARGETBUNNY,547,1,1,0,0,-121.318,-199.329,26.6837,5.17001,30,0,0,57,0,0,0,33554432,0),
(@GUID+3,@NPC_SPANKTARGETBUNNY,547,1,1,0,0,-105.895,-194.285,26.6837,4.98152,30,0,0,57,0,0,0,33554432,0),
(@GUID+4,@NPC_SPANKTARGETBUNNY,547,1,1,0,0,-96.5971,-195.524,26.6837,4.46316,30,0,0,57,0,0,0,33554432,0);


DELETE FROM `game_event_creature` WHERE `guid` BETWEEN @GUID AND @GUID+4;
INSERT INTO `game_event_creature` (`eventEntry`, `guid`) VALUES
(1,@GUID),
(1,@GUID+1),
(1,@GUID+2),
(1,@GUID+3),
(1,@GUID+4);

-- ToDo: Update Templates
/*
UPDATE `creature_template` SET `minlevel`=82, `maxlevel`=82, `exp`=2, `faction_A`=14, `faction_H`=14 WHERE `entry` IN (@NPC_AHUNE,@NPC_FROZENCORE);
UPDATE `creature_template` SET `minlevel`=82, `maxlevel`=82 WHERE `entry`=@NPC_SLIPPERYFLOORBUNNY;
UPDATE `creature_template` SET `minlevel`=82, `maxlevel`=82, `flags_extra`=128 WHERE `entry`=@NPC_ICESPEARBUNNY;
UPDATE `creature_template` SET `minlevel`=80, `maxlevel`=80, `exp`=2, `faction_A`=14, `faction_H`=14 WHERE `entry` IN (@NPC_AHUNITE_HAILSTONE,@NPC_AHUNITE_COLD_WIND,@NPC_AHUNITE_FROSTWIND);
UPDATE `creature_template` SET `mindmg`=417, `maxdmg`=582, `dmg_multiplier`=2 WHERE `entry` IN (@NPC_AHUNITE_COLD_WIND,@NPC_AHUNITE_FROSTWIND);
UPDATE `creature_template` SET `mindmg`=417, `maxdmg`=582, `dmg_multiplier`=5 WHERE `entry`=@NPC_AHUNITE_HAILSTONE;
*/
-- Factions & HP
UPDATE `creature_template` SET `exp`=2, `faction_A`=14, `faction_H`=14 WHERE `entry` IN (@NPC_AHUNE,@NPC_FROZENCORE);
UPDATE `creature_template` SET `exp`=2, `faction_A`=14, `faction_H`=14 WHERE `entry` IN (@NPC_AHUNITE_HAILSTONE,@NPC_AHUNITE_COLD_WIND,@NPC_AHUNITE_FROSTWIND);
-- Damage
UPDATE `creature_template` SET `mindmg`=417, `maxdmg`=582, `dmg_multiplier`=2 WHERE `entry` IN (@NPC_AHUNITE_COLD_WIND,@NPC_AHUNITE_FROSTWIND);
UPDATE `creature_template` SET `mindmg`=417, `maxdmg`=582, `dmg_multiplier`=5 WHERE `entry`=@NPC_AHUNITE_HAILSTONE;
-- Bunny Flags
UPDATE `creature_template` SET `flags_extra`=128 WHERE `entry`=@NPC_ICESPEARBUNNY;
-- InhabitType: Air Only and flags_extra CREATURE_FLAG_EXTRA_TRIGGER
UPDATE `creature_template` SET `InhabitType`=4, `flags_extra`=128 WHERE `entry`=@NPC_SPANKTARGETBUNNY;
-- Mechanic Immune Mask and Frost Immunity
UPDATE `creature_template` SET `mechanic_immune_mask`=650854239 WHERE `entry` IN (@NPC_AHUNE,@NPC_FROZENCORE);
-- Quest 'Summon Ahune': Add Flags DungeonFinder & Repeatable
UPDATE `quest_template` SET `SpecialFlags`=9 WHERE `entry`=@QUEST_WORLD_EVENT_DUNGEON_AHUNE;
-- Set Ice Spear GO Flag GO_FLAG_NOT_SELECTABLE
UPDATE `gameobject_template` SET `flags`=16 WHERE `entry`=@GO_ICE_SPEAR;
-- Root Frozen Core
UPDATE `creature_template` SET `unit_flags`=4 WHERE `entry`=@NPC_FROZENCORE;
-- Scriptnames
UPDATE `creature_template` SET `ScriptName`='npc_frostlord_ahune' WHERE `entry`=@NPC_AHUNE;
UPDATE `creature_template` SET `ScriptName`='npc_ahune_ice_spear' WHERE `entry`=@NPC_ICESPEARBUNNY;
UPDATE `creature_template` SET `AIName`='SmartAI' WHERE `entry` IN (@NPC_AHUNITE_FROSTWIND,@NPC_AHUNITE_COLD_WIND,@NPC_AHUNITE_HAILSTONE);
UPDATE `gameobject_template` SET `ScriptName`='go_ahune_ice_stone' WHERE `entry`=@GO_ICE_STONE;

-- Frozen Core Hitbox
UPDATE `creature_model_info` SET `bounding_radius`=0.45, `combat_reach`=10 WHERE `modelid`=23447;

-- Cold Slap targets
DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=13 AND `SourceEntry` IN (@SPELL_SLIPPERY_FLOOR,@SPELL_BUNNY_KNOCK_OUT);
INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceEntry`,`ConditionTypeOrReference`,`ConditionValue1`,`ConditionValue2`) VALUES
(13,@SPELL_SLIPPERY_FLOOR,18,1,0),
(13,@SPELL_BUNNY_KNOCK_OUT,18,1,@NPC_SPANKTARGETBUNNY);

-- Cold Slap related Script Effects
DELETE FROM `spell_scripts` WHERE `id` IN (@SPELL_SLIPPERY_FLOOR,@SPELL_BUNNY_KNOCK_OUT);
INSERT INTO `spell_scripts` (`id`, `effIndex`, `delay`, `command`, `datalong`, `datalong2`, `dataint`, `x`, `y`, `z`, `o`) VALUES
(@SPELL_SLIPPERY_FLOOR,0,0,15,@SPELL_COLD_SLAP,0,0,0,0,0,0),
(@SPELL_BUNNY_KNOCK_OUT,0,0,15,@SPELL_SPANK_KNOCK_TO,3,0,0,0,0,0);

-- Ice Chest - Loot
DELETE FROM `gameobject_loot_template` WHERE `entry`=28682;
INSERT INTO `gameobject_loot_template` (`entry`, `item`, `ChanceOrQuestChance`, `lootmode`, `groupid`, `mincountOrRef`, `maxcount`) VALUES
-- Cloaks
(28682,@ITEM_ICEBOUND_CLOAK,0,1,1,1,1),
(28682,@ITEM_FROST_LORDS_WAR_CLOAK,0,1,1,1,1),
-- (28682,@ITEM_FROST_LORDS_BATTLE_SHROUD,0,1,1,1,1),
(28682,@ITEM_SHROUD_OF_WINTERS_CHILL,0,1,1,1,1),
(28682,@ITEM_CLOAK_OF_THE_FRIGID_WINDS,0,1,1,1,1),
-- Shards of Ahune
(28682,@ITEM_SHARDS_OF_AHUNE,100,1,0,1,1),
-- Huge Snowball
(28682,@ITEM_HUGE_SNOWBALL,28,1,0,2,2),
-- Lord of Frost Private Label
(28682,@ITEM_LORDS_PRIVATE_LABEL,3,1,0,6,6),
-- Formula: Enchant Weapon - Deathfrost
(28682,@ITEM_FORMULA_DEATHFROST,3,1,0,1,1);

-- Pocket Full of Snow - Loot
DELETE FROM `item_loot_template` WHERE `entry`=@ITEM_POCKET_FULL_OF_SNOW;
INSERT INTO `item_loot_template` (`entry`, `item`, `ChanceOrQuestChance`, `lootmode`, `groupid`, `mincountOrRef`, `maxcount`) VALUES
(@ITEM_POCKET_FULL_OF_SNOW,@ITEM_SNOWBALL,100,1,0,2,5);

-- Ahnuite Adds SAI
DELETE FROM `smart_scripts` WHERE `entryorguid` IN (@NPC_AHUNITE_FROSTWIND,@NPC_AHUNITE_COLD_WIND,@NPC_AHUNITE_HAILSTONE) AND `source_type`=0;
INSERT INTO `smart_scripts` (`entryorguid`, `source_type`, `id`, `link`, `event_type`, `event_phase_mask`, `event_chance`, `event_flags`, `event_param1`, `event_param2`, `event_param3`, `event_param4`, `action_type`, `action_param1`, `action_param2`, `action_param3`, `action_param4`, `action_param5`, `action_param6`, `target_type`, `target_param1`, `target_param2`, `target_param3`, `target_x`, `target_y`, `target_z`, `target_o`, `comment`) VALUES
(@NPC_AHUNITE_FROSTWIND,0,0,0,25,0,100,0,0,0,0,0,75,@SPELL_LIGHTNING_SHIELD,0,0,0,0,0,1,0,0,0,0,0,0,0, 'Ahunite Frostwind - Add Lightning Shield on Reset'),
(@NPC_AHUNITE_FROSTWIND,0,1,0,0,0,100,0,5000,5000,7000,7000,11,@SPELL_WIND_BUFFET,0,0,0,0,0,17,8,25,0,0,0,0,0, 'Ahunite Frostwind - Cast Wind Buffet'),
(@NPC_AHUNITE_COLD_WIND,0,0,0,0,0,100,0,1000,5000,4000,5000,11,@SPELL_BITTER_BLAST,0,0,0,0,0,5,0,0,0,0,0,0,0,'Ahunite Coldwave - Cast Bitter Blast'),
(@NPC_AHUNITE_HAILSTONE,0,0,0,25,0,100,0,0,0,0,0,75,@SPELL_CHILLING_AURA,0,0,0,0,0,1,0,0,0,0,0,0,0, 'Ahunite Hailstone - Add Chilling Aura on Reset'),
(@NPC_AHUNITE_HAILSTONE,0,1,0,0,0,100,0,2500,5000,6000,7000,11,@SPELL_PULVERIZE,2,0,0,0,0,1,0,0,0,0,0,0,0, 'Ahunite Hailstone - Cast Pulverize');

-- Satchel of Chilled Goods - loot
DELETE FROM `item_loot_template` WHERE `entry`=@ITEM_SATCHEL_OF_CHILLED_GOODS;
INSERT INTO `item_loot_template` (`entry`, `item`, `ChanceOrQuestChance`, `lootmode`, `groupid`, `mincountOrRef`, `maxcount`) VALUES
-- Ice Chip
(@ITEM_SATCHEL_OF_CHILLED_GOODS,@ITEM_ICE_CHIP,3,1,0,1,1),
-- Frostscythe of Lord Ahune (Level 70 Version)
(@ITEM_SATCHEL_OF_CHILLED_GOODS,@ITEM_FROSTSCYTHE,6,1,0,1,1);

-- Ice Stone gossip menu
DELETE FROM `gossip_menu` WHERE `entry`=11389;
INSERT INTO `gossip_menu` (`entry`, `text_id`) VALUES
(11389,15864);