From c6186f17bdd0c8fbb50b8b70d12bcdce64366946 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 7 Jan 2022 09:33:54 -0500 Subject: [PATCH] Core/Creature: Use proper name for wander distance. Port From (https://github.com/TrinityCore/TrinityCore/commit/72093e98e1bdbd3b83d8030d1cb50306bb04b028) --- Source/Framework/Constants/Language.cs | 2 +- .../Database/Databases/WorldDatabase.cs | 6 ++--- Source/Game/Chat/Commands/NPCCommands.cs | 10 ++++----- .../Game/Entities/Creature/Creature.Fields.cs | 2 +- Source/Game/Entities/Creature/Creature.cs | 16 +++++++------- Source/Game/Entities/Creature/CreatureData.cs | 2 +- Source/Game/Globals/ObjectManager.cs | 22 +++++++++---------- .../Generators/RandomMovementGenerator.cs | 2 +- Source/Game/Movement/MotionMaster.cs | 4 ++-- ...021_12_21_15_world_2020_02_16_01_world.sql | 7 ++++++ 10 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 sql/updates/world/master/2021_12_21_15_world_2020_02_16_01_world.sql diff --git a/Source/Framework/Constants/Language.cs b/Source/Framework/Constants/Language.cs index d2face90c..bd8670209 100644 --- a/Source/Framework/Constants/Language.cs +++ b/Source/Framework/Constants/Language.cs @@ -361,7 +361,7 @@ namespace Framework.Constants // 296 free // End - CommandSpawndist = 297, + CommandWanderDistance = 297, CommandSpawntime = 298, CommandModifyHonor = 299, diff --git a/Source/Framework/Database/Databases/WorldDatabase.cs b/Source/Framework/Database/Databases/WorldDatabase.cs index c4cfb1e08..6490a889b 100644 --- a/Source/Framework/Database/Databases/WorldDatabase.cs +++ b/Source/Framework/Database/Databases/WorldDatabase.cs @@ -40,7 +40,7 @@ namespace Framework.Database PrepareStatement(WorldStatements.UPD_CREATURE_FACTION, "UPDATE creature_template SET faction = ? WHERE entry = ?"); PrepareStatement(WorldStatements.UPD_CREATURE_NPCFLAG, "UPDATE creature_template SET npcflag = ? WHERE entry = ?"); PrepareStatement(WorldStatements.UPD_CREATURE_POSITION, "UPDATE creature SET position_x = ?, position_y = ?, position_z = ?, orientation = ? WHERE guid = ?"); - PrepareStatement(WorldStatements.UPD_CREATURE_SPAWN_DISTANCE, "UPDATE creature SET spawndist = ?, MovementType = ? WHERE guid = ?"); + PrepareStatement(WorldStatements.UPD_CREATURE_WANDER_DISTANCE, "UPDATE creature SET wander_distance = ?, MovementType = ? WHERE guid = ?"); PrepareStatement(WorldStatements.UPD_CREATURE_SPAWN_TIME_SECS, "UPDATE creature SET spawntimesecs = ? WHERE guid = ?"); PrepareStatement(WorldStatements.INS_CREATURE_FORMATION, "INSERT INTO creature_formations (leaderGUID, memberGUID, dist, angle, groupAI) VALUES (?, ?, ?, ?, ?)"); PrepareStatement(WorldStatements.INS_WAYPOINT_DATA, "INSERT INTO waypoint_data (id, point, position_x, position_y, position_z, orientation) VALUES (?, ?, ?, ?, ?, ?)"); @@ -80,7 +80,7 @@ namespace Framework.Database PrepareStatement(WorldStatements.SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?"); PrepareStatement(WorldStatements.SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_"); PrepareStatement(WorldStatements.SEL_CREATURE_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM creature WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_"); - PrepareStatement(WorldStatements.INS_CREATURE, "INSERT INTO creature (guid, id , map, spawnDifficulties, PhaseId, PhaseGroup, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, unit_flags2, unit_flags3, dynamicflags) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + PrepareStatement(WorldStatements.INS_CREATURE, "INSERT INTO creature (guid, id , map, spawnDifficulties, PhaseId, PhaseGroup, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, wander_distance, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, unit_flags2, unit_flags3, dynamicflags) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); PrepareStatement(WorldStatements.DEL_GAME_EVENT_CREATURE, "DELETE FROM game_event_creature WHERE guid = ?"); PrepareStatement(WorldStatements.DEL_GAME_EVENT_MODEL_EQUIP, "DELETE FROM game_event_model_equip WHERE guid = ?"); PrepareStatement(WorldStatements.INS_GAMEOBJECT, "INSERT INTO gameobject (guid, id, map, spawnDifficulties, PhaseId, PhaseGroup, position_x, position_y, position_z, orientation, rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); @@ -116,7 +116,7 @@ namespace Framework.Database UPD_CREATURE_FACTION, UPD_CREATURE_NPCFLAG, UPD_CREATURE_POSITION, - UPD_CREATURE_SPAWN_DISTANCE, + UPD_CREATURE_WANDER_DISTANCE, UPD_CREATURE_SPAWN_TIME_SECS, INS_CREATURE_FORMATION, INS_WAYPOINT_DATA, diff --git a/Source/Game/Chat/Commands/NPCCommands.cs b/Source/Game/Chat/Commands/NPCCommands.cs index e2922ce2d..d0bfea445 100644 --- a/Source/Game/Chat/Commands/NPCCommands.cs +++ b/Source/Game/Chat/Commands/NPCCommands.cs @@ -1403,8 +1403,8 @@ namespace Game.Chat return true; } - [Command("spawndist", RBACPermissions.CommandNpcSetSpawndist)] - static bool HandleNpcSetSpawnDistCommand(StringArguments args, CommandHandler handler) + [Command("wanderdistance", RBACPermissions.CommandNpcSetSpawndist)] + static bool HandleNpcSetWanderDistanceCommand(StringArguments args, CommandHandler handler) { if (args.Empty()) return false; @@ -1428,7 +1428,7 @@ namespace Game.Chat else return false; - creature.SetRespawnRadius(option); + creature.SetWanderDistance(option); creature.SetDefaultMovementType(mtype); creature.GetMotionMaster().Initialize(); if (creature.IsAlive()) // dead creature will reset movement generator at respawn @@ -1437,14 +1437,14 @@ namespace Game.Chat creature.Respawn(); } - PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_SPAWN_DISTANCE); + PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.UPD_CREATURE_WANDER_DISTANCE); stmt.AddValue(0, option); stmt.AddValue(1, (byte)mtype); stmt.AddValue(2, guidLow); DB.World.Execute(stmt); - handler.SendSysMessage(CypherStrings.CommandSpawndist, option); + handler.SendSysMessage(CypherStrings.CommandWanderDistance, option); return true; } diff --git a/Source/Game/Entities/Creature/Creature.Fields.cs b/Source/Game/Entities/Creature/Creature.Fields.cs index 1fdd6048c..9f2fe3919 100644 --- a/Source/Game/Entities/Creature/Creature.Fields.cs +++ b/Source/Game/Entities/Creature/Creature.Fields.cs @@ -79,7 +79,7 @@ namespace Game.Entities long m_respawnTime; // (secs) time of next respawn uint m_respawnDelay; // (secs) delay between corpse disappearance and respawning uint m_corpseDelay; // (secs) delay between death and corpse disappearance - float m_respawnradius; + float m_wanderDistance; uint m_boundaryCheckTime; // (msecs) remaining time for next evade boundary check uint m_combatPulseTime; // (msecs) remaining time for next zone-in-combat pulse uint m_combatPulseDelay; // (secs) how often the creature puts the entire zone in combat (only works in dungeons) diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 5d2121559..8c613bbdd 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -314,7 +314,7 @@ namespace Game.Entities // checked at loading DefaultMovementType = (MovementGeneratorType)(data != null ? data.movementType : cInfo.MovementType); - if (m_respawnradius == 0 && DefaultMovementType == MovementGeneratorType.Random) + if (m_wanderDistance == 0 && DefaultMovementType == MovementGeneratorType.Random) DefaultMovementType = MovementGeneratorType.Idle; for (byte i = 0; i < SharedConst.MaxCreatureSpells; ++i) @@ -1267,12 +1267,12 @@ namespace Game.Entities data.spawntimesecs = (int)m_respawnDelay; // prevent add data integrity problems - data.spawndist = GetDefaultMovementType() == MovementGeneratorType.Idle ? 0.0f : m_respawnradius; + data.WanderDistance = GetDefaultMovementType() == MovementGeneratorType.Idle ? 0.0f : m_wanderDistance; data.currentwaypoint = 0; data.curhealth = (uint)GetHealth(); data.curmana = (uint)GetPower(PowerType.Mana); // prevent add data integrity problems - data.movementType = (byte)(m_respawnradius == 0 && GetDefaultMovementType() == MovementGeneratorType.Random + data.movementType = (byte)(m_wanderDistance == 0 && GetDefaultMovementType() == MovementGeneratorType.Random ? MovementGeneratorType.Idle : GetDefaultMovementType()); data.spawnDifficulties = spawnDifficulties; data.npcflag = npcflag; @@ -1309,7 +1309,7 @@ namespace Game.Entities stmt.AddValue(index++, GetPositionZ()); stmt.AddValue(index++, GetOrientation()); stmt.AddValue(index++, m_respawnDelay); - stmt.AddValue(index++, m_respawnradius); + stmt.AddValue(index++, m_wanderDistance); stmt.AddValue(index++, 0); stmt.AddValue(index++, GetHealth()); stmt.AddValue(index++, GetPower(PowerType.Mana)); @@ -2455,7 +2455,7 @@ namespace Game.Entities if (m_creatureData != null) { m_creatureData.SpawnPoint.GetPosition(out x, out y, out z, out ori); - dist = m_creatureData.spawndist; + dist = m_creatureData.WanderDistance; } else { @@ -3160,7 +3160,7 @@ namespace Game.Entities m_spawnId = spawnId; m_respawnCompatibilityMode = data.spawnGroupData.flags.HasAnyFlag(SpawnGroupFlags.CompatibilityMode); m_creatureData = data; - m_respawnradius = data.spawndist; + m_wanderDistance = data.WanderDistance; m_respawnDelay = (uint)data.spawntimesecs; if (!Create(map.GenerateLowGuid(HighGuid.Creature), map, data.Id, data.SpawnPoint, data, 0, !m_respawnCompatibilityMode)) @@ -3246,8 +3246,8 @@ namespace Game.Entities public uint GetRespawnDelay() { return m_respawnDelay; } public void SetRespawnDelay(uint delay) { m_respawnDelay = delay; } - public float GetRespawnRadius() { return m_respawnradius; } - public void SetRespawnRadius(float dist) { m_respawnradius = dist; } + public float GetWanderDistance() { return m_wanderDistance; } + public void SetWanderDistance(float dist) { m_wanderDistance = dist; } public void DoImmediateBoundaryCheck() { m_boundaryCheckTime = 0; } uint GetCombatPulseDelay() { return m_combatPulseDelay; } diff --git a/Source/Game/Entities/Creature/CreatureData.cs b/Source/Game/Entities/Creature/CreatureData.cs index 491717f61..aa1c609b3 100644 --- a/Source/Game/Entities/Creature/CreatureData.cs +++ b/Source/Game/Entities/Creature/CreatureData.cs @@ -332,7 +332,7 @@ namespace Game.Entities { public uint displayid; public sbyte equipmentId; - public float spawndist; + public float WanderDistance; public uint currentwaypoint; public uint curhealth; public uint curmana; diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 81b291f00..9f5880a65 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -3366,7 +3366,7 @@ namespace Game var time = Time.GetMSTime(); // 0 1 2 3 4 5 6 7 8 9 10 - SQLResult result = DB.World.Query("SELECT creature.guid, id, map, position_x, position_y, position_z, orientation, modelid, equipment_id, spawntimesecs, spawndist, " + + SQLResult result = DB.World.Query("SELECT creature.guid, id, map, position_x, position_y, position_z, orientation, modelid, equipment_id, spawntimesecs, wander_distance, " + //11 12 13 14 15 16 17 18 19 20 21 "currentwaypoint, curhealth, curmana, MovementType, spawnDifficulties, eventEntry, poolSpawnId, creature.npcflag, creature.unit_flags, creature.unit_flags2, creature.unit_flags3, " + //22 23 24 25 26 27 @@ -3415,7 +3415,7 @@ namespace Game data.displayid = result.Read(7); data.equipmentId = result.Read(8); data.spawntimesecs = result.Read(9); - data.spawndist = result.Read(10); + data.WanderDistance = result.Read(10); data.currentwaypoint = result.Read(11); data.curhealth = result.Read(12); data.curmana = result.Read(13); @@ -3477,25 +3477,25 @@ namespace Game "but creature are not in instance.", guid, data.Id); } - if (data.spawndist < 0.0f) + if (data.WanderDistance < 0.0f) { - Log.outError(LogFilter.Sql, "Table `creature` have creature (GUID: {0} Entry: {1}) with `spawndist`< 0, set to 0.", guid, data.Id); - data.spawndist = 0.0f; + Log.outError(LogFilter.Sql, "Table `creature` have creature (GUID: {0} Entry: {1}) with `wander_distance`< 0, set to 0.", guid, data.Id); + data.WanderDistance = 0.0f; } else if (data.movementType == (byte)MovementGeneratorType.Random) { - if (MathFunctions.fuzzyEq(data.spawndist, 0.0f)) + if (MathFunctions.fuzzyEq(data.WanderDistance, 0.0f)) { - Log.outError(LogFilter.Sql, "Table `creature` have creature (GUID: {0} Entry: {1}) with `MovementType`=1 (random movement) but with `spawndist`=0, replace by idle movement type (0).", guid, data.Id); + Log.outError(LogFilter.Sql, "Table `creature` have creature (GUID: {0} Entry: {1}) with `MovementType`=1 (random movement) but with `wander_distance`=0, replace by idle movement type (0).", guid, data.Id); data.movementType = (byte)MovementGeneratorType.Idle; } } else if (data.movementType == (byte)MovementGeneratorType.Idle) { - if (data.spawndist != 0.0f) + if (data.WanderDistance != 0.0f) { - Log.outError(LogFilter.Sql, "Table `creature` have creature (GUID: {0} Entry: {1}) with `MovementType`=0 (idle) have `spawndist`<>0, set to 0.", guid, data.Id); - data.spawndist = 0.0f; + Log.outError(LogFilter.Sql, "Table `creature` have creature (GUID: {0} Entry: {1}) with `MovementType`=0 (idle) have `wander_distance`<>0, set to 0.", guid, data.Id); + data.WanderDistance = 0.0f; } } @@ -3620,7 +3620,7 @@ namespace Game data.equipmentId = 0; data.spawntimesecs = (int)spawntimedelay; - data.spawndist = 0; + data.WanderDistance = 0; data.currentwaypoint = 0; data.curhealth = (uint)(Global.DB2Mgr.EvaluateExpectedStat(ExpectedStatType.CreatureHealth, level, cInfo.HealthScalingExpansion, scaling.ContentTuningID, (Class)cInfo.UnitClass) * cInfo.ModHealth * cInfo.ModHealthExtra); data.curmana = stats.GenerateMana(cInfo); diff --git a/Source/Game/Movement/Generators/RandomMovementGenerator.cs b/Source/Game/Movement/Generators/RandomMovementGenerator.cs index 1cd8ff01d..a4f5d0628 100644 --- a/Source/Game/Movement/Generators/RandomMovementGenerator.cs +++ b/Source/Game/Movement/Generators/RandomMovementGenerator.cs @@ -47,7 +47,7 @@ namespace Game.Movement owner.StopMoving(); if (_wanderDistance == 0f) - _wanderDistance = owner.GetRespawnRadius(); + _wanderDistance = owner.GetWanderDistance(); // Retail seems to let a creature walk 2 up to 10 splines before triggering a pause _wanderSteps = RandomHelper.URand(2, 10); diff --git a/Source/Game/Movement/MotionMaster.cs b/Source/Game/Movement/MotionMaster.cs index c8a748eeb..87db7d39c 100644 --- a/Source/Game/Movement/MotionMaster.cs +++ b/Source/Game/Movement/MotionMaster.cs @@ -536,10 +536,10 @@ namespace Game.Movement Add(new FollowMovementGenerator(target, SharedConst.PetFollowDist, new ChaseAngle(SharedConst.PetFollowAngle))); } - public void MoveRandom(float spawndist = 0.0f) + public void MoveRandom(float wanderDistance = 0.0f) { if (_owner.IsTypeId(TypeId.Unit)) - Add(new RandomMovementGenerator(spawndist)); + Add(new RandomMovementGenerator(wanderDistance), MovementSlot.Default); } public void MoveFollow(Unit target, float dist, float angle = 0.0f, MovementSlot slot = MovementSlot.Active) { MoveFollow(target, dist, new ChaseAngle(angle), slot); } diff --git a/sql/updates/world/master/2021_12_21_15_world_2020_02_16_01_world.sql b/sql/updates/world/master/2021_12_21_15_world_2020_02_16_01_world.sql new file mode 100644 index 000000000..9252ade82 --- /dev/null +++ b/sql/updates/world/master/2021_12_21_15_world_2020_02_16_01_world.sql @@ -0,0 +1,7 @@ +-- Use more appropriate name for distance used by random movement generator. +ALTER TABLE `creature` + CHANGE COLUMN `spawndist` `wander_distance` FLOAT NOT NULL DEFAULT '0' AFTER `spawntimesecs`; + +-- Update name used by chat command. +UPDATE `trinity_string` SET `content_default`='Wander distance changed to: %f' WHERE `entry`=297; +UPDATE `command` SET `name`='npc set wanderdistance', `help`='Syntax: .npc set wanderdistance #dist\r\n\r\nAdjust wander distance of selected creature to dist.' WHERE `name`='npc set spawndist';