diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 4ac9dca8b..eb94ba3ff 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -1105,20 +1105,22 @@ namespace Game.Entities { CreatureTemplate cInfo = GetCreatureTemplate(); + // level + byte minlevel = (byte)Math.Min(cInfo.Maxlevel, cInfo.Minlevel); + byte maxlevel = (byte)Math.Max(cInfo.Maxlevel, cInfo.Minlevel); + byte level = (byte)(minlevel == maxlevel ? minlevel : RandomHelper.URand(minlevel, maxlevel)); + SetLevel(level); + if (!HasScalableLevels()) { - // level - byte minlevel = (byte)Math.Min(cInfo.Maxlevel, cInfo.Minlevel); - byte maxlevel = (byte)Math.Max(cInfo.Maxlevel, cInfo.Minlevel); - byte level = (byte)(minlevel == maxlevel ? minlevel : RandomHelper.URand(minlevel, maxlevel)); - SetLevel(level); - } - else - { - SetLevel(cInfo.levelScaling.Value.MaxLevel); SetUInt32Value(UnitFields.ScalingLevelMin, cInfo.levelScaling.Value.MinLevel); SetUInt32Value(UnitFields.ScalingLevelMax, cInfo.levelScaling.Value.MaxLevel); - SetUInt32Value(UnitFields.ScalingLevelDelta, (uint)cInfo.levelScaling.Value.DeltaLevel); + + int mindelta = Math.Min(cInfo.levelScaling.Value.DeltaLevelMax, cInfo.levelScaling.Value.DeltaLevelMin); + int maxdelta = Math.Max(cInfo.levelScaling.Value.DeltaLevelMax, cInfo.levelScaling.Value.DeltaLevelMin); + int delta = mindelta == maxdelta ? mindelta : RandomHelper.IRand(mindelta, maxdelta); + + SetInt32Value(UnitFields.ScalingLevelDelta, delta); } UpdateLevelDependantStats(); @@ -2368,7 +2370,7 @@ namespace Game.Entities // between UNIT_FIELD_SCALING_LEVEL_MIN and UNIT_FIELD_SCALING_LEVEL_MAX if (HasScalableLevels()) { - uint targetLevelWithDelta = (uint)(unitTarget.getLevel() + GetCreatureTemplate().levelScaling.Value.DeltaLevel); + uint targetLevelWithDelta = (uint)(unitTarget.getLevel() + GetInt32Value(UnitFields.ScalingLevelDelta)); if (target.IsPlayer()) targetLevelWithDelta += target.GetUInt32Value(PlayerFields.ScalingLevelDelta); diff --git a/Source/Game/Entities/Creature/CreatureData.cs b/Source/Game/Entities/Creature/CreatureData.cs index 2e7ff9551..f581b2f21 100644 --- a/Source/Game/Entities/Creature/CreatureData.cs +++ b/Source/Game/Entities/Creature/CreatureData.cs @@ -397,6 +397,7 @@ namespace Game.Entities { public ushort MinLevel; public ushort MaxLevel; - public short DeltaLevel; + public short DeltaLevelMin; + public short DeltaLevelMax; } } diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index f4150d0ef..da19ebb75 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -2307,8 +2307,8 @@ namespace Game { uint oldMSTime = Time.GetMSTime(); - // 0 1 2 3 - SQLResult result = DB.World.Query("SELECT Entry, LevelScalingMin, LevelScalingMax, LevelScalingDelta FROM creature_template_scaling"); + // 0 1 2 3 4 + SQLResult result = DB.World.Query("SELECT Entry, LevelScalingMin, LevelScalingMax, LevelScalingDeltaMin, LevelScalingDeltaMax FROM creature_template_scaling"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 creature template scaling definitions. DB table `creature_template_scaling` is empty."); @@ -2330,7 +2330,8 @@ namespace Game CreatureLevelScaling creatureLevelScaling; creatureLevelScaling.MinLevel = result.Read(1); creatureLevelScaling.MaxLevel = result.Read(2); - creatureLevelScaling.DeltaLevel = result.Read(3); + creatureLevelScaling.DeltaLevelMin = result.Read(3); + creatureLevelScaling.DeltaLevelMax = result.Read(3); template.levelScaling.Set(creatureLevelScaling); ++count; diff --git a/Source/Game/Network/Packets/SpellPackets.cs b/Source/Game/Network/Packets/SpellPackets.cs index a5f15d8d4..f6d0d7a5d 100644 --- a/Source/Game/Network/Packets/SpellPackets.cs +++ b/Source/Game/Network/Packets/SpellPackets.cs @@ -1168,7 +1168,7 @@ namespace Game.Network.Packets Class = (byte)creatureTemplate.UnitClass; TargetMinScalingLevel = (byte)creatureTemplate.levelScaling.Value.MinLevel; TargetMaxScalingLevel = (byte)creatureTemplate.levelScaling.Value.MaxLevel; - TargetScalingLevelDelta = (sbyte)creatureTemplate.levelScaling.Value.DeltaLevel; + TargetScalingLevelDelta = (sbyte)attacker.GetInt32Value(UnitFields.ScalingLevelDelta); return true; } @@ -1184,13 +1184,14 @@ namespace Game.Network.Packets Class = (byte)creatureTemplate.UnitClass; TargetMinScalingLevel = (byte)creatureTemplate.levelScaling.Value.MinLevel; TargetMaxScalingLevel = (byte)creatureTemplate.levelScaling.Value.MaxLevel; - TargetScalingLevelDelta = (sbyte)creatureTemplate.levelScaling.Value.DeltaLevel; + TargetScalingLevelDelta = (sbyte)target.GetInt32Value(UnitFields.ScalingLevelDelta); return true; } bool GenerateDataCreatureToCreature(Creature attacker, Creature target) { - CreatureTemplate creatureTemplate = target.HasScalableLevels() ? target.GetCreatureTemplate() : attacker.GetCreatureTemplate(); + Creature accessor = target.HasScalableLevels() ? target : attacker; + CreatureTemplate creatureTemplate = accessor.GetCreatureTemplate(); Type = SandboxScalingDataType.CreatureToCreatureDamage; PlayerLevelDelta = 0; @@ -1200,7 +1201,7 @@ namespace Game.Network.Packets Class = (byte)creatureTemplate.UnitClass; TargetMinScalingLevel = (byte)creatureTemplate.levelScaling.Value.MinLevel; TargetMaxScalingLevel = (byte)creatureTemplate.levelScaling.Value.MaxLevel; - TargetScalingLevelDelta = (sbyte)creatureTemplate.levelScaling.Value.DeltaLevel; + TargetScalingLevelDelta = (sbyte)accessor.GetInt32Value(UnitFields.ScalingLevelDelta); return true; } diff --git a/sql/updates/world/master/2018_04_12_00_world.sql b/sql/updates/world/master/2018_04_12_00_world.sql new file mode 100644 index 000000000..caef73a3d --- /dev/null +++ b/sql/updates/world/master/2018_04_12_00_world.sql @@ -0,0 +1,5 @@ +ALTER TABLE `creature_template_scaling` + CHANGE `LevelScalingDelta` `LevelScalingDeltaMin` smallint(5) NOT NULL DEFAULT '0' AFTER `LevelScalingMax`, + ADD `LevelScalingDeltaMax` smallint(5) NOT NULL DEFAULT '0' AFTER `LevelScalingDeltaMin`; + +UPDATE `creature_template_scaling` SET `LevelScalingDeltaMax`=`LevelScalingDeltaMin`;