Core/Movement: Allow using run when moving randomly
Port From (https://github.com/TrinityCore/TrinityCore/commit/a57ca5cea2d13bc5d5ddee11e7b8100c7afd68e1)
This commit is contained in:
@@ -407,6 +407,15 @@ namespace Framework.Constants
|
||||
Max
|
||||
}
|
||||
|
||||
public enum CreatureRandomMovementType
|
||||
{
|
||||
Walk,
|
||||
CanRun,
|
||||
AlwaysRun,
|
||||
|
||||
Max
|
||||
}
|
||||
|
||||
public enum VendorInventoryReason
|
||||
{
|
||||
None = 0,
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Framework.Database
|
||||
PrepareStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_ID_BY_GUID, "SELECT id FROM waypoint_scripts WHERE guid = ?");
|
||||
PrepareStatement(WorldStatements.DEL_CREATURE, "DELETE FROM creature WHERE guid = ?");
|
||||
PrepareStatement(WorldStatements.SEL_COMMANDS, "SELECT name, permission, help FROM command");
|
||||
PrepareStatement(WorldStatements.SEL_CREATURE_TEMPLATE, "SELECT entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, name, femaleName, subname, TitleAlt, IconName, gossip_menu_id, minlevel, maxlevel, HealthScalingExpansion, RequiredExpansion, VignetteID, faction, npcflag, speed_walk, speed_run, scale, `rank`, dmgschool, BaseAttackTime, RangeAttackTime, BaseVariance, RangeVariance, unit_class, unit_flags, unit_flags2, unit_flags3, dynamicflags, family, trainer_class, type, type_flags, type_flags2, lootid, pickpocketloot, skinloot, resistance1, resistance2, resistance3, resistance4, resistance5, resistance6, spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, VehicleId, mingold, maxgold, AIName, MovementType, ctm.Ground, ctm.Swim, ctm.Flight, ctm.Rooted, ctm.Chase, HoverHeight, HealthModifier, HealthModifierExtra, ManaModifier, ManaModifierExtra, ArmorModifier, DamageModifier, ExperienceModifier, RacialLeader, movementId, CreatureDifficultyID, WidgetSetID, WidgetSetUnitConditionID, RegenHealth, mechanic_immune_mask, spell_school_immune_mask, flags_extra, ScriptName FROM creature_template ct LEFT JOIN creature_template_movement ctm ON ct.entry = ctm.CreatureId WHERE entry = ? OR 1 = ?");
|
||||
PrepareStatement(WorldStatements.SEL_CREATURE_TEMPLATE, "SELECT entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, name, femaleName, subname, TitleAlt, IconName, gossip_menu_id, minlevel, maxlevel, HealthScalingExpansion, RequiredExpansion, VignetteID, faction, npcflag, speed_walk, speed_run, scale, `rank`, dmgschool, BaseAttackTime, RangeAttackTime, BaseVariance, RangeVariance, unit_class, unit_flags, unit_flags2, unit_flags3, dynamicflags, family, trainer_class, type, type_flags, type_flags2, lootid, pickpocketloot, skinloot, resistance1, resistance2, resistance3, resistance4, resistance5, resistance6, spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, VehicleId, mingold, maxgold, AIName, MovementType, ctm.Ground, ctm.Swim, ctm.Flight, ctm.Rooted, ctm.Chase, ctm.Random, HoverHeight, HealthModifier, HealthModifierExtra, ManaModifier, ManaModifierExtra, ArmorModifier, DamageModifier, ExperienceModifier, RacialLeader, movementId, CreatureDifficultyID, WidgetSetID, WidgetSetUnitConditionID, RegenHealth, mechanic_immune_mask, spell_school_immune_mask, flags_extra, ScriptName FROM creature_template ct LEFT JOIN creature_template_movement ctm ON ct.entry = ctm.CreatureId WHERE entry = ? OR 1 = ?");
|
||||
PrepareStatement(WorldStatements.SEL_WAYPOINT_SCRIPT_BY_ID, "SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = ?");
|
||||
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_");
|
||||
|
||||
@@ -353,6 +353,7 @@ namespace Game.Entities
|
||||
public bool Swim;
|
||||
public bool Rooted;
|
||||
public CreatureChaseMovementType Chase;
|
||||
public CreatureRandomMovementType Random;
|
||||
|
||||
public CreatureMovementData()
|
||||
{
|
||||
@@ -368,10 +369,11 @@ namespace Game.Entities
|
||||
public bool IsRooted() { return Rooted; }
|
||||
|
||||
public CreatureChaseMovementType GetChase() { return Chase; }
|
||||
public CreatureRandomMovementType GetRandom() { return Random; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Ground: {Ground}, Swim: {Swim}, Flight: {Flight} {(Rooted ? ", Rooted" : "")}, Chase: {Chase}";
|
||||
return $"Ground: {Ground}, Swim: {Swim}, Flight: {Flight} {(Rooted ? ", Rooted" : "")}, Chase: {Chase}, Random: {Random}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1832,24 +1832,27 @@ namespace Game
|
||||
if (!fields.IsNull(64))
|
||||
creature.Movement.Chase = (CreatureChaseMovementType)fields.Read<byte>(64);
|
||||
|
||||
creature.HoverHeight = fields.Read<float>(65);
|
||||
creature.ModHealth = fields.Read<float>(66);
|
||||
creature.ModHealthExtra = fields.Read<float>(67);
|
||||
creature.ModMana = fields.Read<float>(68);
|
||||
creature.ModManaExtra = fields.Read<float>(69);
|
||||
creature.ModArmor = fields.Read<float>(70);
|
||||
creature.ModDamage = fields.Read<float>(71);
|
||||
creature.ModExperience = fields.Read<float>(72);
|
||||
creature.RacialLeader = fields.Read<bool>(73);
|
||||
creature.MovementId = fields.Read<uint>(74);
|
||||
creature.CreatureDifficultyID = fields.Read<int>(75);
|
||||
creature.WidgetSetID = fields.Read<int>(76);
|
||||
creature.WidgetSetUnitConditionID = fields.Read<int>(77);
|
||||
creature.RegenHealth = fields.Read<bool>(78);
|
||||
creature.MechanicImmuneMask = fields.Read<uint>(79);
|
||||
creature.SpellSchoolImmuneMask = fields.Read<uint>(80);
|
||||
creature.FlagsExtra = (CreatureFlagsExtra)fields.Read<uint>(81);
|
||||
creature.ScriptID = GetScriptId(fields.Read<string>(82));
|
||||
if (!fields.IsNull(65))
|
||||
creature.Movement.Random = (CreatureRandomMovementType)fields.Read<byte>(65);
|
||||
|
||||
creature.HoverHeight = fields.Read<float>(66);
|
||||
creature.ModHealth = fields.Read<float>(67);
|
||||
creature.ModHealthExtra = fields.Read<float>(68);
|
||||
creature.ModMana = fields.Read<float>(69);
|
||||
creature.ModManaExtra = fields.Read<float>(70);
|
||||
creature.ModArmor = fields.Read<float>(71);
|
||||
creature.ModDamage = fields.Read<float>(72);
|
||||
creature.ModExperience = fields.Read<float>(73);
|
||||
creature.RacialLeader = fields.Read<bool>(74);
|
||||
creature.MovementId = fields.Read<uint>(75);
|
||||
creature.CreatureDifficultyID = fields.Read<int>(76);
|
||||
creature.WidgetSetID = fields.Read<int>(77);
|
||||
creature.WidgetSetUnitConditionID = fields.Read<int>(78);
|
||||
creature.RegenHealth = fields.Read<bool>(79);
|
||||
creature.MechanicImmuneMask = fields.Read<uint>(80);
|
||||
creature.SpellSchoolImmuneMask = fields.Read<uint>(81);
|
||||
creature.FlagsExtra = (CreatureFlagsExtra)fields.Read<uint>(82);
|
||||
creature.ScriptID = GetScriptId(fields.Read<string>(83));
|
||||
|
||||
creatureTemplateStorage[entry] = creature;
|
||||
}
|
||||
@@ -2252,7 +2255,7 @@ namespace Game
|
||||
|
||||
creatureMovementOverrides.Clear();
|
||||
|
||||
SQLResult result = DB.World.Query("SELECT SpawnId, Ground, Swim, Flight, Rooted, Chase from creature_movement_override");
|
||||
SQLResult result = DB.World.Query("SELECT SpawnId, Ground, Swim, Flight, Rooted, Chase, Random from creature_movement_override");
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 creature movement overrides. DB table `creature_movement_override` is empty!");
|
||||
@@ -2274,6 +2277,7 @@ namespace Game
|
||||
movement.Flight = (CreatureFlightMovementType)result.Read<byte>(3);
|
||||
movement.Rooted = result.Read<bool>(4);
|
||||
movement.Chase = (CreatureChaseMovementType)result.Read<byte>(5);
|
||||
movement.Random = (CreatureRandomMovementType)result.Read<byte>(6);
|
||||
|
||||
CheckCreatureMovement("creature_movement_override", spawnId, movement);
|
||||
|
||||
@@ -2750,6 +2754,12 @@ namespace Game
|
||||
Log.outError(LogFilter.Sql, $"`{table}`.`Chase` wrong value ({creatureMovement.Chase}) for Id {id}, setting to Run.");
|
||||
creatureMovement.Chase = CreatureChaseMovementType.Run;
|
||||
}
|
||||
|
||||
if (creatureMovement.Random >= CreatureRandomMovementType.Max)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"`{table}`.`Random` wrong value ({creatureMovement.Random}) for Id {id}, setting to Walk.");
|
||||
creatureMovement.Random = CreatureRandomMovementType.Walk;
|
||||
}
|
||||
}
|
||||
public void LoadLinkedRespawn()
|
||||
{
|
||||
|
||||
@@ -138,9 +138,22 @@ namespace Game.Movement
|
||||
|
||||
owner.AddUnitState(UnitState.RoamingMove);
|
||||
|
||||
bool walk = true;
|
||||
switch (owner.GetMovementTemplate().GetRandom())
|
||||
{
|
||||
case CreatureRandomMovementType.CanRun:
|
||||
walk = owner.IsWalking();
|
||||
break;
|
||||
case CreatureRandomMovementType.AlwaysRun:
|
||||
walk = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
MoveSplineInit init = new(owner);
|
||||
init.MovebyPath(_path.GetPath());
|
||||
init.SetWalk(true);
|
||||
init.SetWalk(walk);
|
||||
int traveltime = init.Launch();
|
||||
_timer.Reset(traveltime + resetTimer);
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
--
|
||||
ALTER TABLE `creature_template_movement` ADD `Random` tinyint(3) UNSIGNED NOT NULL DEFAULT '0';
|
||||
ALTER TABLE `creature_movement_override` ADD `Random` tinyint(3) UNSIGNED NOT NULL DEFAULT '0';
|
||||
Reference in New Issue
Block a user