From 59db2eeea0a35028779fd76372ae06cc98c8086f Mon Sep 17 00:00:00 2001 From: r00ty-tc Date: Sun, 7 May 2017 21:48:41 +0100 Subject: Dynamic Creature/Go spawning: - True blizzlike creature spawn/respawn behavior - new creature = new object - Toggleable spawn groups (with C++/SAI/command options to use them) - Custom feature: dynamic spawn rate scaling. Accelerates respawn rate based on players in the zone. - Backward compatibility mode (set via group and for summons) to support creatures/gos that currently don't work well with this (this should be removed once the exceptions are fixed) Fixes and closes #2858 Tags #8661 as fixable. Fixes and closes #13787 Fixes #15222. --- src/server/game/Scripting/ScriptMgr.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/server/game/Scripting/ScriptMgr.cpp') diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 9f42ded8cc6..cfc64b83005 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1566,16 +1566,32 @@ bool ScriptMgr::OnCastItemCombatSpell(Player* player, Unit* victim, SpellInfo co return tmpscript->OnCastItemCombatSpell(player, victim, spellInfo, item); } -bool ScriptMgr::CanSpawn(ObjectGuid::LowType spawnId, uint32 entry, CreatureTemplate const* actTemplate, CreatureData const* cData, Map const* map) +bool ScriptMgr::CanSpawn(ObjectGuid::LowType spawnId, uint32 entry, CreatureData const* cData, Map const* map) { - ASSERT(actTemplate); - + ASSERT(map); CreatureTemplate const* baseTemplate = sObjectMgr->GetCreatureTemplate(entry); - if (!baseTemplate) - baseTemplate = actTemplate; + ASSERT(baseTemplate); + + // find out which template we'd be using + CreatureTemplate const* actTemplate = baseTemplate; + for (uint8 diff = uint8(map->GetSpawnMode()); diff > 0;) + { + if (uint32 diffEntry = baseTemplate->DifficultyEntry[diff - 1]) + if (CreatureTemplate const* diffTemplate = sObjectMgr->GetCreatureTemplate(diffEntry)) + { + actTemplate = diffTemplate; + break; + } + if (diff >= RAID_DIFFICULTY_10MAN_HEROIC && map->IsRaid()) + diff -= 2; + else + diff -= 1; + } + uint32 scriptId = baseTemplate->ScriptID; - if (cData && cData->ScriptId) - scriptId = cData->ScriptId; + if (cData && cData->scriptId) + scriptId = cData->scriptId; + GET_SCRIPT_RET(CreatureScript, scriptId, tmpscript, true); return tmpscript->CanSpawn(spawnId, entry, baseTemplate, actTemplate, cData, map); } -- cgit v1.2.3