diff --git a/sql/migrations/20190816210511_world.sql b/sql/migrations/20190816210511_world.sql new file mode 100644 index 000000000..f9d00bcda --- /dev/null +++ b/sql/migrations/20190816210511_world.sql @@ -0,0 +1,129 @@ +DROP PROCEDURE IF EXISTS add_migration; +delimiter ?? +CREATE PROCEDURE `add_migration`() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20190816210511'); +IF v=0 THEN +INSERT INTO `migrations` VALUES ('20190816210511'); +-- Add your query below. + + +-- Spawn position for Justin. +UPDATE `creature` SET `position_x`=-8582.03, `position_y`=633.634, `position_z`=96.338, `orientation`=4.98933 WHERE `guid`=79815; + +-- Spawn position for Brandon. +UPDATE `creature` SET `position_x`=-8580.092, `position_y`=634.187, `position_z`=96.338, `orientation`=5.129, `MovementType`=0 WHERE `guid`=79817; +DELETE FROM `creature_movement` WHERE `id`=79817; + +-- Spawn position for Roman. +UPDATE `creature` SET `position_x`=-8583.88, `position_y`=633.127, `position_z`=96.338, `orientation`=4.98933, `MovementType`=0 WHERE `guid`=79816; +DELETE FROM `creature_movement` WHERE `id`=79816; + +-- Events list for Justin +DELETE FROM `creature_ai_events` WHERE `creature_id`=1368; +INSERT INTO `creature_ai_events` (`id`, `creature_id`, `condition_id`, `event_type`, `event_inverse_phase_mask`, `event_chance`, `event_flags`, `event_param1`, `event_param2`, `event_param3`, `event_param4`, `action1_script`, `action2_script`, `action3_script`, `comment`) VALUES (136801, 1368, 0, 1, 0, 100, 1, 35000, 60000, 35000, 60000, 136801, 0, 0, 'Justin - Say Text OOC'); +DELETE FROM `creature_ai_scripts` WHERE `id`=136801; +INSERT INTO `creature_ai_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136801, 0, 39, 136801, 136802, 0, 0, 0, 0, 0, 0, 50, 50, 0, 0, 0, 0, 0, 0, 0, 'Justin - Say Text'); +INSERT INTO `creature_ai_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136801, 0, 39, 136803, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 'Brandon and Roman - Say Text'); +DELETE FROM `event_scripts` WHERE `id`=136801; +INSERT INTO `event_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136801, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 149, 150, 151, 152, 0, 0, 0, 0, 0, 'Justin - Say Text'); +DELETE FROM `event_scripts` WHERE `id`=136802; +INSERT INTO `event_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136802, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 154, 155, 156, 0, 0, 0, 0, 0, 'Justin - Say Text'); +DELETE FROM `event_scripts` WHERE `id`=136803; +INSERT INTO `event_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136803, 2, 39, 136804, 136805, 0, 0, 79817, 0, 9, 2, 50, 50, 0, 0, 0, 0, 0, 0, 0, 'Brandon - Say Text'); +INSERT INTO `event_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136803, 10, 39, 136806, 136807, 0, 0, 79816, 0, 9, 2, 50, 50, 0, 0, 0, 0, 0, 0, 0, 'Roman - Say Text'); +DELETE FROM `event_scripts` WHERE `id`=136804; +INSERT INTO `event_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136804, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 147, 157, 158, 166, 0, 0, 0, 0, 0, 'Brandon - Say Text'); +DELETE FROM `event_scripts` WHERE `id`=136805; +INSERT INTO `event_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136805, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 167, 168, 169, 170, 0, 0, 0, 0, 0, 'Brandon - Say Text'); +DELETE FROM `event_scripts` WHERE `id`=136806; +INSERT INTO `event_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136806, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 171, 172, 173, 174, 0, 0, 0, 0, 0, 'Roman - Say Text'); +DELETE FROM `event_scripts` WHERE `id`=136807; +INSERT INTO `event_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (136807, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 175, 176, 177, 0, 0, 0, 0, 0, 0, 'Roman - Say Text'); +UPDATE `creature_template` SET `ai_name`='EventAI' WHERE `entry`=1368; + +-- Waypoints for Justin. +DELETE FROM `creature_movement` WHERE `id`=79815; +INSERT INTO `creature_movement` (`id`, `point`, `position_x`, `position_y`, `position_z`, `waittime`, `wander_distance`, `script_id`, `textid1`, `textid2`, `textid3`, `textid4`, `textid5`, `emote`, `spell`, `orientation`, `model1`, `model2`) VALUES +(79815, 1, -8582.03, 633.634, 96.3386, 1800000, 0, 7981501, 0, 0, 0, 0, 0, 0, 0, 5.02218, 0, 0), +(79815, 2, -8582.03, 633.634, 96.3386, 1000, 0, 7981502, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 3, -8592.9, 656.706, 98.215, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 4, -8603.73, 656.529, 98.667, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 5, -8616.8, 653.192, 98.877, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 6, -8638.93, 656.882, 101.093, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 7, -8652.71, 660.539, 100.896, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 8, -8663.02, 670.676, 100.304, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 9, -8669.88, 678.648, 99.344, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 10, -8675.11, 685.278, 98.608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 11, -8693.1, 707.655, 97.018, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 12, -8704.13, 721.515, 97.017, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 13, -8715.06, 737.284, 97.807, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 14, -8725.33, 751.855, 98.203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 15, -8730.63, 759.914, 98.186, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 16, -8729.58, 773.227, 98.045, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 17, -8719.73, 787.05, 97.497, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 18, -8717.58, 797.687, 97.095, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 19, -8725.29, 811.882, 97.227, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 20, -8727.36, 825.57, 96.71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 21, -8724.79, 839.923, 96.092, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 22, -8714.8, 851.813, 96.761, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 23, -8708.47, 858.245, 97.006, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 24, -8698.47, 866.606, 97.081, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 25, -8691.03, 872.861, 97.017, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 26, -8680.25, 880.963, 97.017, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 27, -8660.5, 897.437, 97.581, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 28, -8660.09, 905.128, 97.394, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 29, -8667.05, 913.248, 96.338, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 30, -8673.76, 909.402, 96.338, 0, 0, 7981530, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 31, -8675.49, 909.244, 96.3384, 1800000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.80119, 0, 0), +(79815, 32, -8675.49, 909.244, 96.3384, 1000, 0, 7981502, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 33, -8667.05, 913.248, 96.338, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 34, -8660.09, 905.128, 97.394, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 35, -8660.5, 897.437, 97.581, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 36, -8680.25, 880.963, 97.017, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 37, -8691.03, 872.861, 97.017, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 38, -8698.47, 866.606, 97.081, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 39, -8708.47, 858.245, 97.006, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 40, -8714.8, 851.813, 96.761, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 41, -8724.79, 839.923, 96.092, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 42, -8727.36, 825.57, 96.71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 43, -8725.29, 811.882, 97.227, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 44, -8717.58, 797.687, 97.095, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 45, -8719.73, 787.05, 97.497, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 46, -8729.58, 773.227, 98.045, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 47, -8730.63, 759.914, 98.186, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 48, -8725.33, 751.855, 98.203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 49, -8715.06, 737.284, 97.807, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 50, -8704.13, 721.515, 97.017, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 51, -8693.1, 707.655, 97.018, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 52, -8675.11, 685.278, 98.608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 53, -8669.88, 678.648, 99.344, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 54, -8663.02, 670.676, 100.304, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 55, -8652.71, 660.539, 100.896, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 56, -8638.93, 656.882, 101.093, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 57, -8616.8, 653.192, 98.877, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 58, -8603.73, 656.529, 98.667, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +(79815, 59, -8592.9, 656.706, 98.215, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + +-- Waypoint scripts for Justin. +DELETE FROM `creature_movement_scripts` WHERE `id`=7981501; +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981501, 0, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Justin - Disband Creature Group'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981501, 1, 3, 0, 0, 66, 2, 79817, 0, 9, 2, 0, 0, 0, 0, -8580.092, 634.187, 96.338, 5.129, 0, 'Brandon - Move to point'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981501, 1, 3, 0, 0, 66, 2, 79816, 0, 9, 2, 0, 0, 0, 0, -8583.88, 633.127, 96.338, 4.98933, 0, 'Roman - Move to point'); +DELETE FROM `creature_movement_scripts` WHERE `id`=7981502; +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981502, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1090, 0, 0, 0, 0, 0, 0, 0, 0, 'Justin - Say Text'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981502, 0, 78, 1, 0, 0, 0, 79817, 0, 9, 2, 0, 0, 0, 0, 2.19769, 0, 0, 1.9, 0, 'Brandon - Follow Justin'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981502, 0, 78, 1, 0, 0, 0, 79816, 0, 9, 2, 0, 0, 0, 0, 2.19769, 0, 0, 4.50248, 0, 'Roman - Follow Justin'); +DELETE FROM `creature_movement_scripts` WHERE `id`=7981530; +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981530, 0, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Justin - Disband Creature Group'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981530, 1, 3, 0, 0, 66, 2, 79816, 0, 9, 2, 0, 0, 0, 0, -8673.38, 911.824, 96.3384, 2.25631, 0, 'Roman - Move to point'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (7981530, 1, 3, 0, 0, 66, 2, 79817, 0, 9, 2, 0, 0, 0, 0, -8674.68, 910.761, 96.3384, 2.25631, 0, 'Brandon - Move to poin'); + + +-- End of migration. +END IF; +END?? +delimiter ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/src/game/CreatureGroups.cpp b/src/game/CreatureGroups.cpp index 10c2829ea..4653fb717 100644 --- a/src/game/CreatureGroups.cpp +++ b/src/game/CreatureGroups.cpp @@ -170,6 +170,26 @@ void CreatureGroup::RemoveMember(ObjectGuid guid) } } +void CreatureGroup::DisbandGroup(Creature* pMember) +{ + if (Creature* pLeader = pMember->GetMap()->GetCreature(GetLeaderGuid())) + pLeader->SetCreatureGroup(nullptr); + + for (auto& it : _members) + { + if (Creature* pOtherMember = pMember->GetMap()->GetCreature(it.first)) + { + pOtherMember->SetCreatureGroup(nullptr); + if (IsFormation() && pOtherMember->isAlive()) + pOtherMember->GetMotionMaster()->Initialize(); + } + + delete it.second; + } + + _members.clear(); +} + void CreatureGroup::DeleteFromDb() { WorldDatabase.PExecute("DELETE FROM creature_groups WHERE leader_guid=%u", _leaderGuid.GetCounter()); diff --git a/src/game/CreatureGroups.h b/src/game/CreatureGroups.h index 7ee1d0771..71ed17f3e 100644 --- a/src/game/CreatureGroups.h +++ b/src/game/CreatureGroups.h @@ -36,6 +36,8 @@ enum OptionFlags OPTION_INFORM_MEMBERS_ON_ANY_DIED = 0x080, }; +#define ALL_CREATURE_GROUP_OPTIONS (OPTION_FORMATION_MOVE | OPTION_AGGRO_TOGETHER | OPTION_EVADE_TOGETHER | OPTION_RESPAWN_TOGETHER | OPTION_RESPAWN_ALL_ON_MASTER_EVADE | OPTION_RESPAWN_ALL_ON_ANY_EVADE | OPTION_INFORM_LEADER_ON_MEMBER_DIED | OPTION_INFORM_MEMBERS_ON_ANY_DIED) + struct CreatureGroupMember { bool ComputeRelativePosition(float leaderAngle, float &x, float &y) const; @@ -52,6 +54,7 @@ class CreatureGroup } CreatureGroupMember* AddMember(ObjectGuid guid, float followDist, float followAngle, uint32 memberFlags = (OPTION_FORMATION_MOVE|OPTION_AGGRO_TOGETHER)); void RemoveMember(ObjectGuid guid); + void DisbandGroup(Creature* pMember); void DeleteFromDb(); void SaveToDb(); diff --git a/src/game/Maps/Map.h b/src/game/Maps/Map.h index a52f158ec..957487a13 100644 --- a/src/game/Maps/Map.h +++ b/src/game/Maps/Map.h @@ -894,6 +894,8 @@ class MANGOS_DLL_SPEC Map : public GridRefManager, public MaNGOS::Obj bool ScriptCommand_AddThreat(const ScriptInfo& script, WorldObject* source, WorldObject* target); bool ScriptCommand_SummonObject(const ScriptInfo& script, WorldObject* source, WorldObject* target); bool ScriptCommand_SetFly(const ScriptInfo& script, WorldObject* source, WorldObject* target); + bool ScriptCommand_JoinCreatureGroup(const ScriptInfo& script, WorldObject* source, WorldObject* target); + bool ScriptCommand_LeaveCreatureGroup(const ScriptInfo& script, WorldObject* source, WorldObject* target); // Add any new script command functions to the array. const ScriptCommandFunction m_ScriptCommands[SCRIPT_COMMAND_MAX] = @@ -976,6 +978,8 @@ class MANGOS_DLL_SPEC Map : public GridRefManager, public MaNGOS::Obj &Map::ScriptCommand_AddThreat, // 75 &Map::ScriptCommand_SummonObject, // 76 &Map::ScriptCommand_SetFly, // 77 + &Map::ScriptCommand_JoinCreatureGroup, // 78 + &Map::ScriptCommand_LeaveCreatureGroup, // 79 }; public: diff --git a/src/game/Maps/ScriptCommands.cpp b/src/game/Maps/ScriptCommands.cpp index 2511ff9d9..7991e45dd 100644 --- a/src/game/Maps/ScriptCommands.cpp +++ b/src/game/Maps/ScriptCommands.cpp @@ -2139,5 +2139,45 @@ bool Map::ScriptCommand_SetFly(const ScriptInfo& script, WorldObject* source, Wo pSource->SetFly(script.setFly.enabled); + return false; +} + +// SCRIPT_COMMAND_JOIN_CREATURE_GROUP (78) +bool Map::ScriptCommand_JoinCreatureGroup(const ScriptInfo& script, WorldObject* source, WorldObject* target) +{ + Creature* pSource = ToCreature(source); + + if (!pSource) + { + sLog.outError("SCRIPT_COMMAND_JOIN_CREATURE_GROUP (script id %u) call for a NULL or non-creature source (TypeId: %u), skipping.", script.id, source ? source->GetTypeId() : 0); + return ShouldAbortScript(script); + } + + Creature* pTarget = ToCreature(target); + + if (!pTarget) + { + sLog.outError("SCRIPT_COMMAND_JOIN_CREATURE_GROUP (script id %u) call for a NULL or non-creature target (TypeId: %u), skipping.", script.id, target ? target->GetTypeId() : 0); + return ShouldAbortScript(script); + } + + pSource->JoinCreatureGroup(pTarget, script.x, script.o, script.joinCreatureGroup.options); + + return false; +} + +// SCRIPT_COMMAND_LEAVE_CREATURE_GROUP (79) +bool Map::ScriptCommand_LeaveCreatureGroup(const ScriptInfo& script, WorldObject* source, WorldObject* target) +{ + Creature* pSource = ToCreature(source); + + if (!pSource) + { + sLog.outError("SCRIPT_COMMAND_LEAVE_CREATURE_GROUP (script id %u) call for a NULL or non-creature source (TypeId: %u), skipping.", script.id, source ? source->GetTypeId() : 0); + return ShouldAbortScript(script); + } + + pSource->LeaveCreatureGroup(); + return false; } \ No newline at end of file diff --git a/src/game/Objects/Creature.cpp b/src/game/Objects/Creature.cpp index 5dde6c36a..98db7c367 100644 --- a/src/game/Objects/Creature.cpp +++ b/src/game/Objects/Creature.cpp @@ -3767,6 +3767,23 @@ void Creature::JoinCreatureGroup(Creature* leader, float dist, float angle, uint GetMotionMaster()->Initialize(); } +void Creature::LeaveCreatureGroup() +{ + if (CreatureGroup* pGroup = GetCreatureGroup()) + { + if (pGroup->GetLeaderGuid() == GetObjectGuid()) + { + pGroup->DisbandGroup(this); + delete pGroup; + } + else + { + pGroup->RemoveMember(GetObjectGuid()); + SetCreatureGroup(nullptr); + } + } +} + bool Creature::HasWeapon() const { uint8 itemClass = GetByteValue(UNIT_VIRTUAL_ITEM_INFO + (0 * 2) + 0, VIRTUAL_ITEM_INFO_0_OFFSET_CLASS); diff --git a/src/game/Objects/Creature.h b/src/game/Objects/Creature.h index 761b83e5d..ec59d608c 100644 --- a/src/game/Objects/Creature.h +++ b/src/game/Objects/Creature.h @@ -494,6 +494,7 @@ class MANGOS_DLL_SPEC Creature : public Unit CreatureGroup* GetCreatureGroup() const { return _creatureGroup; } void SetCreatureGroup(CreatureGroup* group) { _creatureGroup = group; } void JoinCreatureGroup(Creature* leader, float dist, float angle, uint32 options); + void LeaveCreatureGroup(); uint32 GetSpawnFlags() const; // Fonctions utilisees par les links, et appelle CreatureAI. diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index e070e6e6e..6edfe2832 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -29,6 +29,7 @@ #include "ScriptLoader.h" #include "Conditions.h" #include "GameEventMgr.h" +#include "CreatureGroups.h" typedef std::vector ScriptVector; int num_sc_scripts; @@ -1195,6 +1196,16 @@ void ScriptMgr::LoadScripts(ScriptMapMap& scripts, const char* tablename) } break; } + case SCRIPT_COMMAND_JOIN_CREATURE_GROUP: + { + if (tmp.joinCreatureGroup.options & ~ALL_CREATURE_GROUP_OPTIONS) + { + sLog.outErrorDb("Table `%s` using unknown option in datalong (%u) in SCRIPT_COMMAND_JOIN_CREATURE_GROUP for script id %u", + tablename, tmp.joinCreatureGroup.options, tmp.id); + continue; + } + break; + } } if (scripts.find(tmp.id) == scripts.end()) diff --git a/src/game/ScriptMgr.h b/src/game/ScriptMgr.h index e767e5022..c04a9db76 100644 --- a/src/game/ScriptMgr.h +++ b/src/game/ScriptMgr.h @@ -317,6 +317,12 @@ enum eScriptCommand // x/y/z/o = coordinates SCRIPT_COMMAND_SET_FLY = 77, // source = Unit // datalong = (bool) 0 = off, 1 = on + SCRIPT_COMMAND_JOIN_CREATURE_GROUP = 78, // source = Creature + // target = Creature + // datalong = OptionFlags + // x = distance + // o = angle + SCRIPT_COMMAND_LEAVE_CREATURE_GROUP = 79, // source = Creature SCRIPT_COMMAND_MAX, SCRIPT_COMMAND_DISABLED = 9999 // Script action was disabled during loading. @@ -972,6 +978,13 @@ struct ScriptInfo uint32 enabled; // datalong } setFly; + struct // SCRIPT_COMMAND_JOIN_CREATURE_GROUP (78) + { + uint32 options; // datalong + } joinCreatureGroup; + + // SCRIPT_COMMAND_LEAVE_CREATURE_GROUP (79) + struct { uint32 data[9];