Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Core) Dynamic Creature/GameObject #14893

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5d6b19a
temp
Feb 6, 2023
70c5e8b
new fixes
Feb 6, 2023
57dfd72
new fixes
Feb 7, 2023
3c48e97
final core fixes
Feb 7, 2023
185c05a
other fixes
Feb 7, 2023
c260041
New builds fixes & Remove SAVE_RESPAWN_TIME_IMMEDIATELY
Feb 7, 2023
0460efc
fix builds compile with Create()
Feb 8, 2023
2810a38
fix build compile with GuidWarning() and GuidAlert()
Feb 8, 2023
86d8df0
new fixes
Feb 8, 2023
b2f0dad
final build fixes and codestyle
Feb 8, 2023
4d944b4
fix gcc/clang and cli build
Feb 8, 2023
7559239
try new fix
Feb 8, 2023
ddff700
fix build, important new modifications for cs_npc, and strings for dy…
Feb 8, 2023
b42411a
remove unused variable and _DespawnAtEvade()
Feb 8, 2023
5adeaeb
.
Feb 8, 2023
82a7e9e
simplify the method for now
Feb 8, 2023
1d52016
.
Feb 8, 2023
33526b5
.
Feb 8, 2023
44a5b30
missing WorldMock
Feb 9, 2023
38a3156
remove unused variable, and some other improvements
Feb 10, 2023
07634fd
fix id naming, and allow to keep 3 ids for creautres
Feb 10, 2023
917ba95
remove some sql lines waiting to implement new commands
Feb 10, 2023
07655af
import last change in commands and restore sql strings
Feb 10, 2023
a1834f6
.
Feb 10, 2023
adb7818
Revert "."
Feb 11, 2023
49611d3
try a new fix
Feb 11, 2023
717f606
Merge branch 'master' into dynamic-crea-go
Feb 11, 2023
69a3e5a
remove list respawn and fix codestyle
Feb 11, 2023
fa5cd8f
fix last commit
Feb 11, 2023
36d6e22
build fix
Feb 11, 2023
17f1a26
Merge branch 'dynamic-crea-go' of https://github.com/Maelthyrr/Person…
Feb 11, 2023
206bc29
codestyle
Feb 12, 2023
a57c42d
update from master branch
Feb 12, 2023
90cfc34
Merge branch 'azerothcore:master' into dynamic-crea-go
Feb 15, 2023
6d408cc
remove unused method
Feb 15, 2023
e6f1752
Merge branch 'dynamic-crea-go' of https://github.com/Maelthyrr/Person…
Feb 15, 2023
9aa8fe6
fix few LOG_ERROR in Creatures.cpp
Feb 15, 2023
87a5e16
Merge branch 'azerothcore:master' into dynamic-crea-go
Feb 21, 2023
ec5cbdd
Merge branch 'azerothcore:master' into dynamic-crea-go
Feb 26, 2023
97a46bb
already present in AC
Feb 26, 2023
4a2184e
use GetGameTime in CheckRespawn()
Feb 26, 2023
1bf4497
update from master
Mar 11, 2023
dfb9151
use ftm in some log
Mar 11, 2023
71cbc47
fix with last commit
Mar 11, 2023
ac5cb76
new fixes
Mar 11, 2023
e8e16e4
few restore changes and fix some other things
Mar 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 228 additions & 0 deletions data/sql/updates/pending_db_world/rev_1675639737114759100.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
-- Create databases for spawn group template, and spawn group membership
-- Current flags
-- 0x01 Legacy Spawn Mode (spawn using legacy spawn system)
-- 0x02 Manual Spawn (don't automatically spawn, instead spawned by core as part of script)
DROP TABLE IF EXISTS `spawn_group_template`;
CREATE TABLE `spawn_group_template` (
`groupId` INT UNSIGNED NOT NULL,
`groupName` varchar(100) NOT NULL,
`groupFlags` INT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`groupId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

DROP TABLE IF EXISTS `spawn_group`;
CREATE TABLE `spawn_group` (
`groupId` INT UNSIGNED NOT NULL,
`spawnType` tinyint(10) unsigned NOT NULL,
`spawnId` INT UNSIGNED NOT NULL,
PRIMARY KEY (`groupId`,`spawnType`,`spawnId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Create the default groups
INSERT INTO `spawn_group_template` (`groupId`, `groupName`, `groupFlags`) VALUES
(0, 'Default Group', 0x01),
(1, 'Legacy Group', (0x01|0x02)),
(2, 'Dynamic Scaling (Quest objectives)', (0x01|0x08)),
(3, 'Dynamic Scaling (Escort NPCs)', (0x01|0x08|0x10)),
(4, 'Dynamic Scaling (Gathering nodes)', (0x01|0x08));

-- Create creature dynamic spawns group (creatures with quest items, or subjects of quests with less than 30min spawn time)
DROP TABLE IF EXISTS `creature_temp_group`;
CREATE TEMPORARY TABLE `creature_temp_group`
(
`creatureId` INT UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `creature_temp_group`
SELECT `guid`
FROM `creature` C
INNER JOIN `creature_questitem` ON `CreatureEntry` = C.`id1`
WHERE `spawntimesecs` < 1800
AND `map` IN (0, 1, 530, 571);

INSERT INTO `creature_temp_group`
SELECT `guid`
FROM `creature` C
INNER JOIN `quest_template` ON `RequiredNpcOrGo1` = C.`id1`
WHERE `spawntimesecs` < 1800
AND `map` IN (0, 1, 530, 571);

INSERT INTO `creature_temp_group`
SELECT `guid`
FROM `creature` C
INNER JOIN `quest_template` ON `RequiredNpcOrGo2` = C.`id1`
WHERE `spawntimesecs` < 1800
AND `map` IN (0, 1, 530, 571);

INSERT INTO `creature_temp_group`
SELECT `guid`
FROM `creature` C
INNER JOIN `quest_template` ON `RequiredNpcOrGo3` = C.`id1`
WHERE `spawntimesecs` < 1800
AND `map` IN (0, 1, 530, 571);

INSERT INTO `creature_temp_group`
SELECT `guid`
FROM `creature` C
INNER JOIN `quest_template` ON `RequiredNpcOrGo4` = C.`id1`
WHERE `spawntimesecs` < 1800
AND `map` IN (0, 1, 530, 571);

INSERT INTO `spawn_group` (`groupId`, `spawnType`, `spawnId`)
SELECT DISTINCT 2, 0, `creatureId`
FROM `creature_temp_group`;

DROP TABLE `creature_temp_group`;

-- Create gameobject dynamic spawns group (gameobjects with quest items, or subjects of quests with less than 30min spawn time)
DROP TABLE IF EXISTS `gameobject_temp_group`;
CREATE TEMPORARY TABLE `gameobject_temp_group`
(
`gameobjectId` INT UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

DROP TABLE IF EXISTS `gameobject_temp_group_ids`;
CREATE TEMPORARY TABLE `gameobject_temp_group_ids`
(
`entryid` INT NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `gameobject_temp_group_ids` ADD INDEX (`entryid`);

INSERT INTO `gameobject_temp_group`
SELECT `guid`
FROM `gameobject` G
INNER JOIN `gameobject_questitem` ON `GameObjectEntry` = G.`id`
WHERE `spawntimesecs` < 1800
AND `map` IN (0, 1, 530, 571);

INSERT INTO `gameobject_temp_group_ids` (`entryid`)
SELECT DISTINCT `RequiredNpcOrGo1` * -1
FROM `quest_template`;

INSERT INTO `gameobject_temp_group_ids` (`entryid`)
SELECT DISTINCT `RequiredNpcOrGo2` * -1
FROM `quest_template`;

INSERT INTO `gameobject_temp_group_ids` (`entryid`)
SELECT DISTINCT `RequiredNpcOrGo3` * -1
FROM `quest_template`;

INSERT INTO `gameobject_temp_group_ids` (`entryid`)
SELECT DISTINCT `RequiredNpcOrGo4` * -1
FROM `quest_template`;

INSERT INTO `gameobject_temp_group`
SELECT `guid`
FROM `gameobject` G
INNER JOIN `gameobject_temp_group_ids` ON `entryid` = G.`id`
WHERE `spawntimesecs` < 1800
AND `map` IN (0, 1, 530, 571);

INSERT INTO `spawn_group` (`groupId`, `spawnType`, `spawnId`)
SELECT DISTINCT 2, 1, `gameobjectId`
FROM `gameobject_temp_group`;

DROP TABLE `gameobject_temp_group`;
ALTER TABLE `gameobject_temp_group_ids` DROP INDEX `entryid`;
DROP TABLE `gameobject_temp_group_ids`;

-- Add mining nodes/herb nodes to profession node group
INSERT INTO `spawn_group` (`groupId`, `spawnType`, `spawnId`)
SELECT 4, 1, `guid`
FROM `gameobject` g
INNER JOIN `gameobject_template` gt
ON gt.`entry` = g.`id`
WHERE `type` = 3
AND `Data0` IN (2, 8, 9, 10, 11, 18, 19, 20, 21, 22, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40, 41, 42, 45, 47, 48, 49, 50, 51, 379, 380, 399, 400, 439, 440, 441, 442, 443, 444, 519, 521, 719, 939, 1119, 1120,
1121, 1122, 1123, 1124, 1632, 1639, 1641, 1642, 1643, 1644, 1645, 1646, 1649, 1650, 1651, 1652, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789, 1790, 1791, 1792, 1793, 1800, 1860);

-- Add Escort NPCs
INSERT INTO `spawn_group` (`groupId`, `spawnType`, `spawnId`) VALUES
(3, 0, 10873),
(3, 0, 17874),
(3, 0, 40210),
(3, 0, 11348),
(3, 0, 93301),
(3, 0, 93194),
(3, 0, 19107),
(3, 0, 21692),
(3, 0, 21584),
(3, 0, 23229),
(3, 0, 24268),
(3, 0, 21594),
(3, 0, 14387),
(3, 0, 50381),
(3, 0, 15031),
(3, 0, 26987),
(3, 0, 29241),
(3, 0, 32333),
(3, 0, 33115),
(3, 0, 37085),
(3, 0, 41759),
(3, 0, 84459),
(3, 0, 78685),
(3, 0, 62090),
(3, 0, 72388),
(3, 0, 86832),
(3, 0, 67040),
(3, 0, 78781),
(3, 0, 65108),
(3, 0, 63688),
(3, 0, 59383),
(3, 0, 63625),
(3, 0, 70021),
(3, 0, 82071),
(3, 0, 117903),
(3, 0, 111075),
(3, 0, 101136),
(3, 0, 101303),
(3, 0, 122686),
(3, 0, 117065),
(3, 0, 202337),
(3, 0, 2017),
(3, 0, 132683);

-- remove potential duplicates
DELETE FROM `spawn_group` WHERE `groupId` != 3 AND `spawnType`=0 AND `spawnId` IN (SELECT `spawnId` FROM (SELECT `spawnId` FROM `spawn_group` WHERE `groupId`=3 AND `spawnType`=0) as `temp`);
DELETE FROM `spawn_group` WHERE `groupId` != 4 AND `spawnType`=1 AND `spawnId` IN (SELECT `spawnId` FROM (SELECT `spawnId` FROM `spawn_group` WHERE `groupId`=4 AND `spawnType`=1) as `temp`);

-- Add new NPC/Gameobject commands
DELETE FROM `command` WHERE `name` IN ('npc spawngroup', 'npc despawngroup', 'gobject spawngroup', 'gobject despawngroup', 'list respawns');
INSERT INTO `command` (`name`, `security`, `help`) VALUES
('npc spawngroup', 3, 'Syntax: .npc spawngroup $groupId [ignorerespawn] [force]'),
('npc despawngroup', 3, 'Syntax: .npc despawngroup $groupId [removerespawntime]'),
('gobject spawngroup', 3, 'Syntax: .gobject spawngroup $groupId [ignorerespawn] [force]'),
('gobject despawngroup', 3, 'Syntax: .gobject despawngroup $groupId [removerespawntime]');

-- Update Acore strings for various cs_list strings, to support showing spawn ID and guid.
UPDATE `acore_string`
SET `content_default` = '%d (Entry: %d) - |cffffffff|Hgameobject:%d|h[%s X:%f Y:%f Z:%f MapId:%d]|h|r %s %s'
WHERE `entry` = 517;

UPDATE `acore_string`
SET `content_default` = '%d - |cffffffff|Hcreature:%d|h[%s X:%f Y:%f Z:%f MapId:%d]|h|r %s %s'
WHERE `entry` = 515;

UPDATE `acore_string`
SET `content_default` = '%d - %s X:%f Y:%f Z:%f MapId:%d %s %s'
WHERE `entry` = 1111;

UPDATE `acore_string`
SET `content_default` = '%d - %s X:%f Y:%f Z:%f MapId:%d %s %s'
WHERE `entry` = 1110;

-- Add new Acore strings for extra npc/gobject info lines
DELETE FROM `acore_string` WHERE `entry` BETWEEN 5087 AND 5097;
INSERT INTO `acore_string` (`entry`, `content_default`) VALUES
(5087, 'Spawn group: %s (ID: %u, Flags: %u, Active: %u)'),
(5088, 'Compatibility Mode: %u'),
(5089, 'GUID: %s'),
(5090, 'SpawnID: %u, location (%f, %f, %f)'),
(5091, 'Distance from player %f'),
(5092, 'Spawn group %u not found'),
(5093, 'Spawned a total of %zu objects:'),
(5094, 'SpawnID | Entry | GridXY| Zone | Respawn time (Full)'),
(5095, 'overdue'),
(5096, 'creatures'),
(5097, 'gameobjects');
5 changes: 5 additions & 0 deletions data/sql/updates/pending_db_world/rev_1675863321192995800.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Cherry-pick: https://github.com/TrinityCore/TrinityCore/commit/3d4bebd8d9210fbb84f8fc75742e248071192b09
-- (Co-authored-by: Treeston <treeston@users.noreply.github.com>)
DELETE FROM `spawn_group` WHERE `spawnType`=0 AND `spawnId` IN (22831,36626,23708,39059);
INSERT INTO `spawn_group` (`groupId`,`spawnType`,`spawnId`) VALUES
(3,0,22831), (3,0,36626), (3,0,23708), (3,0,39059);
124 changes: 116 additions & 8 deletions src/server/apps/worldserver/worldserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,6 @@ Compression = 1

PlayerLimit = 1000

#
# SaveRespawnTimeImmediately
# Description: Save respawn time for creatures at death and gameobjects at use/open.
# Default: 1 - (Enabled, Save respawn time immediately)
# 0 - (Disabled, Save respawn time at grid unloading)

SaveRespawnTimeImmediately = 1

#
# MaxOverspeedPings
# Description: Maximum overspeed ping count before character is disconnected.
Expand Down Expand Up @@ -1838,6 +1830,122 @@ Creatures.CustomIDs = "190010,55005,999991,25462,98888,601014,34567,34568"
#
###################################################################################################

###################################################################################################
# SPAWN/RESPAWN SETTINGS
#
# Respawn.MinCheckIntervalMS
# Description: Minimum time that needs to pass between respawn checks for any given map.
# Default: 5000 - 5 seconds

Respawn.MinCheckIntervalMS = 5000

#
# Respawn.GuidWarnLevel
# Description: The point at which the highest guid for creatures or gameobjects in any map must reach
# before the warning logic is enabled. A restart will then be queued at the next quiet time
# The maximum guid per map is 16,777,216. So, it must be less than this value.
# Default: 12000000 - 12 million

Respawn.GuidWarnLevel = 12000000

#
# Respawn.WarningMessage
# Description: This message will be periodically shown (Frequency specified by Respawn.WarningFrequency) to
# all users of the server, once the Respawn.GuidWarnLevel has been passed, and a restart scheduled.
# It's used to warn users that there will be an out of schedule server restart soon.
# Default: "There will be an unscheduled server restart at 03:00 server time. The server will be available again shortly after."

Respawn.WarningMessage = "There will be an unscheduled server restart at 03:00. The server will be available again shortly after."

#
# Respawn.WarningFrequency
# Description: The frequency (in seconds) that the warning message will be sent to users after a quiet time restart is triggered.
# The message will repeat each time this many seconds passed until the server is restarted.
# If set to 0, no warnings will be sent.
# Default: 1800 - (30 minutes)

Respawn.WarningFrequency = 1800

#
# Respawn.GuidAlertLevel
# Description: The point at which the highest guid for creatures or gameobjects in any map must reach
# before the alert logic is enabled. A restart will then be triggered for 30 mins from that
# point. The maximum guid per map is 16,777,216. So, it must be less than this value.
# Default: 16000000 - 16 million

Respawn.GuidAlertLevel = 16000000

#
# Respawn.AlertRestartReason
# Description: The shutdown reason given when the alert level is reached. The server will use a fixed time of
# 5 minutes and the reason for shutdown will be this message
# Default: "Urgent Maintenance"

Respawn.AlertRestartReason = "Urgent Maintenance"

#
# Respawn.RestartQuietTime
# Description: The hour at which the server will be restarted after the Respawn.GuidWarnLevel
# threshold has been reached. This can be between 0 and 23. 20 will be 8pm server time
# Default: 3 - 3am

Respawn.RestartQuietTime = 3

#
# Respawn.DynamicMode
# Description: Select which mode (if any) should be used to adjust respawn of creatures.
# This will only affect creatures that have dynamic spawn rate scaling enabled in
# the spawn group table (by default, gathering nodes and quest targets with respawn time <30min
# 1 - Use number of players in zone
# Default: 0 - No dynamic respawn function

Respawn.DynamicMode = 0

#
# Respawn.DynamicEscortNPC
# Description: This switch controls the dynamic respawn system for escort NPCs not in instancable maps (base maps only).
# This will cause the respawn timer to begin when an escort event begins, and potentially
# allow multiple instances of the NPC to be alive at the same time (when combined with Respawn.DynamicMode > 0)
# 1 - Enabled
# Default: 0 - Disabled

Respawn.DynamicEscortNPC = 1

#
# Respawn.DynamicRateCreature
# Description: The rate at which the respawn time is adjusted for high player counts in a zone (for creatures).
# Up to this number of players, the respawn rate is unchanged.
# At double this number in players, you get twice as many respawns, at three times this number, three times the respawns, and so forth.
# Default: 10

Respawn.DynamicRateCreature = 10

#
# Respawn.DynamicMinimumCreature
# Description: The minimum respawn time for a creature under dynamic scaling.
# Default: 10 - (10 seconds)

Respawn.DynamicMinimumCreature = 10

#
# Respawn.DynamicRateGameObject
# Description: The rate at which the respawn time is adjusted for high player counts in a zone (for gameobjects).
# Up to this number of players, the respawn rate is unchanged.
# At double this number in players, you get twice as many respawns, at three times this number, three times the respawns, and so forth.
# Default: 10

Respawn.DynamicRateGameObject = 10

#
# Respawn.DynamicMinimumGameObject
# Description: The minimum respawn time for a gameobject under dynamic scaling.
# Default: 10 - (10 seconds)

Respawn.DynamicMinimumGameObject = 10

#
###################################################################################################

###################################################################################################
# CHAT SETTINGS
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void WorldDatabaseConnection::DoPrepareStatements()
PrepareStatement(WORLD_INS_GAMEOBJECT_ADDON, "INSERT INTO gameobject_addon (guid, invisibilityType, invisibilityValue) VALUES (?, 0, 0)", CONNECTION_ASYNC);
// 0: uint8
PrepareStatement(WORLD_SEL_REQ_XP, "SELECT Experience FROM player_xp_for_level WHERE Level = ?", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_SPAWNGROUP_MEMBER, "DELETE FROM spawn_group WHERE spawnType = ? AND spawnId = ?", CONNECTION_ASYNC);
}

WorldDatabaseConnection::WorldDatabaseConnection(MySQLConnectionInfo& connInfo) : MySQLConnection(connInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ enum WorldDatabaseStatements : uint32
WORLD_UPD_GAMEOBJECT_ZONE_AREA_DATA,
WORLD_SEL_REQ_XP,
WORLD_INS_GAMEOBJECT_ADDON,
WORLD_DEL_SPAWNGROUP_MEMBER,

MAX_WORLDDATABASE_STATEMENTS
};
Expand Down
Loading