Skip to content

Move creature min/max level check to objectmgr #3015

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

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions sql/migrations/20250418172108_world.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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`='20250418172108');
IF v = 0 THEN
INSERT INTO `migrations` VALUES ('20250418172108');
-- Add your query below.

-- Correct levelrange for Morbent Fel Pre 1.6

UPDATE `creature_template` SET `level_max`=35 WHERE `entry`=1200 AND `patch`=0;

-- End of migration.
END IF;
END??
DELIMITER ;
CALL add_migration();
DROP PROCEDURE IF EXISTS add_migration;
6 changes: 6 additions & 0 deletions src/game/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,12 @@ void ObjectMgr::CheckCreatureTemplate(CreatureInfo* cInfo)
sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Creature (Entry: %u) with despawn instantly flag has skinning loot assigned. It will never be lootable.", cInfo->entry);
}

if (cInfo->level_min > cInfo->level_max)
{
std::swap(cInfo->level_min, cInfo->level_max);
sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Creature (Entry: %u) has level_min (%u) greater than level_max (%u), values have been swapped.", cInfo->entry, cInfo->level_max, cInfo->level_min);
}

ConvertCreatureAurasField<CreatureInfo>(cInfo, "creature_template", "Entry", cInfo->entry);
}

Expand Down
4 changes: 2 additions & 2 deletions src/game/Objects/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,8 +1703,8 @@ void Creature::SelectLevel(float percentHealth, float percentMana)
CreatureInfo const* cinfo = GetCreatureInfo();

// level
uint32 const minLevel = std::min(cinfo->level_max, cinfo->level_min);
uint32 const maxLevel = std::max(cinfo->level_max, cinfo->level_min);
uint32 const minLevel = cinfo->level_min;
uint32 const maxLevel = cinfo->level_max;
uint32 const level = minLevel == maxLevel ? minLevel : urand(minLevel, maxLevel);

SetLevel(level);
Expand Down