Core/Movement: Allow using run when moving randomly (#23081)

* Allow run when moving randomly

(cherry picked from commit 34cfa69efd)
This commit is contained in:
Sorikoff
2019-03-03 18:54:07 +00:00
committed by Shauren
parent ace33a464f
commit a57ca5cea2
6 changed files with 71 additions and 29 deletions

View File

@@ -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';

View File

@@ -78,7 +78,7 @@ void WorldDatabaseConnection::DoPrepareStatements()
PrepareStatement(WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID, "SELECT id FROM waypoint_scripts WHERE guid = ?", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_CREATURE, "DELETE FROM creature WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(WORLD_SEL_COMMANDS, "SELECT name, permission, help FROM command", CONNECTION_SYNCH);
PrepareStatement(WORLD_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 = ?", CONNECTION_SYNCH);
PrepareStatement(WORLD_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 = ?", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_WAYPOINT_SCRIPT_BY_ID, "SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = ?", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?", CONNECTION_SYNCH);
PrepareStatement(WORLD_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_", CONNECTION_SYNCH);

View File

@@ -61,13 +61,15 @@ std::string CreatureMovementData::ToString() const
char const* const GroundStates[] = { "None", "Run", "Hover" };
char const* const FlightStates[] = { "None", "DisableGravity", "CanFly" };
char const* const ChaseStates[] = { "Run", "CanWalk", "AlwaysWalk" };
char const* const RandomStates[] = { "Walk", "CanRun", "AlwaysRun" };
std::ostringstream str;
str << std::boolalpha
<< "Ground: " << GroundStates[AsUnderlyingType(Ground)]
<< ", Swim: " << Swim
<< ", Flight: " << FlightStates[AsUnderlyingType(Flight)]
<< ", Chase: " << ChaseStates[AsUnderlyingType(Chase)];
<< ", Chase: " << ChaseStates[AsUnderlyingType(Chase)]
<< ", Random: " << RandomStates[AsUnderlyingType(Random)];
if (Rooted)
str << ", Rooted";

View File

@@ -327,16 +327,27 @@ enum class CreatureChaseMovementType : uint8
Max
};
enum class CreatureRandomMovementType : uint8
{
Walk,
CanRun,
AlwaysRun,
Max
};
struct TC_GAME_API CreatureMovementData
{
CreatureMovementData() : Ground(CreatureGroundMovementType::Run), Flight(CreatureFlightMovementType::None),
Swim(true), Rooted(false), Chase(CreatureChaseMovementType::Run) { }
Swim(true), Rooted(false), Chase(CreatureChaseMovementType::Run),
Random(CreatureRandomMovementType::Walk) { }
CreatureGroundMovementType Ground;
CreatureFlightMovementType Flight;
bool Swim;
bool Rooted;
CreatureChaseMovementType Chase;
CreatureRandomMovementType Random;
bool IsGroundAllowed() const { return Ground != CreatureGroundMovementType::None; }
bool IsSwimAllowed() const { return Swim; }
@@ -344,6 +355,7 @@ struct TC_GAME_API CreatureMovementData
bool IsRooted() const { return Rooted; }
CreatureChaseMovementType GetChase() const { return Chase; }
CreatureRandomMovementType GetRandom() const { return Random; }
std::string ToString() const;
};

View File

@@ -359,13 +359,13 @@ void ObjectMgr::LoadCreatureTemplates()
// "type_flags, type_flags2, lootid, pickpocketloot, skinloot, resistance1, resistance2, resistance3, resistance4, resistance5, resistance6, "
// 47 48 49 50 51 52 53 54 55 56 57 58 59
// "spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, VehicleId, mingold, maxgold, AIName, MovementType, "
// 60 61 62 63 64 65 66 67 68 69 70 71 72
// "ctm.Ground, ctm.Swim, ctm.Flight, ctm.Rooted, ctm.Chase, HoverHeight, HealthModifier, HealthModifierExtra, ManaModifier, ManaModifierExtra, ArmorModifier, DamageModifier, ExperienceModifier, "
// 73 74 75 76 77 78
// 60 61 62 63 64 65 66 67 68 69 70 71 72 73
// "ctm.Ground, ctm.Swim, ctm.Flight, ctm.Rooted, ctm.Chase, ctm.Random, HoverHeight, HealthModifier, HealthModifierExtra, ManaModifier, ManaModifierExtra, ArmorModifier, DamageModifier, ExperienceModifier, "
// 74 75 76 77 78 79
// "RacialLeader, movementId, CreatureDifficultyID, WidgetSetID, WidgetSetUnitConditionID, RegenHealth, "
// 79 80 81
// 80 81 82
// "mechanic_immune_mask, spell_school_immune_mask, flags_extra, "
// 82
// 83
// "ScriptName FROM creature_template WHERE entry = ? OR 1 = ?");
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_TEMPLATE);
@@ -469,26 +469,29 @@ void ObjectMgr::LoadCreatureTemplate(Field* fields)
creatureTemplate.Movement.Rooted = fields[63].GetBool();
if (!fields[64].IsNull())
creatureTemplate.Movement.Chase = static_cast<CreatureChaseMovementType>(fields[64].GetUInt8());
creatureTemplate.Movement.Chase = static_cast<CreatureChaseMovementType>(fields[64].GetUInt8());
creatureTemplate.HoverHeight = fields[65].GetFloat();
creatureTemplate.ModHealth = fields[66].GetFloat();
creatureTemplate.ModHealthExtra = fields[67].GetFloat();
creatureTemplate.ModMana = fields[68].GetFloat();
creatureTemplate.ModManaExtra = fields[69].GetFloat();
creatureTemplate.ModArmor = fields[70].GetFloat();
creatureTemplate.ModDamage = fields[71].GetFloat();
creatureTemplate.ModExperience = fields[72].GetFloat();
creatureTemplate.RacialLeader = fields[73].GetBool();
creatureTemplate.movementId = fields[74].GetUInt32();
creatureTemplate.CreatureDifficultyID = fields[75].GetInt32();
creatureTemplate.WidgetSetID = fields[76].GetInt32();
creatureTemplate.WidgetSetUnitConditionID = fields[77].GetInt32();
creatureTemplate.RegenHealth = fields[78].GetBool();
creatureTemplate.MechanicImmuneMask = fields[79].GetUInt32();
creatureTemplate.SpellSchoolImmuneMask = fields[80].GetUInt32();
creatureTemplate.flags_extra = fields[81].GetUInt32();
creatureTemplate.ScriptID = GetScriptId(fields[82].GetString());
if (!fields[65].IsNull())
creatureTemplate.Movement.Random = static_cast<CreatureRandomMovementType>(fields[65].GetUInt8());
creatureTemplate.HoverHeight = fields[66].GetFloat();
creatureTemplate.ModHealth = fields[67].GetFloat();
creatureTemplate.ModHealthExtra = fields[68].GetFloat();
creatureTemplate.ModMana = fields[69].GetFloat();
creatureTemplate.ModManaExtra = fields[70].GetFloat();
creatureTemplate.ModArmor = fields[71].GetFloat();
creatureTemplate.ModDamage = fields[72].GetFloat();
creatureTemplate.ModExperience = fields[73].GetFloat();
creatureTemplate.RacialLeader = fields[74].GetBool();
creatureTemplate.movementId = fields[75].GetUInt32();
creatureTemplate.CreatureDifficultyID = fields[76].GetInt32();
creatureTemplate.WidgetSetID = fields[77].GetInt32();
creatureTemplate.WidgetSetUnitConditionID = fields[78].GetInt32();
creatureTemplate.RegenHealth = fields[79].GetBool();
creatureTemplate.MechanicImmuneMask = fields[80].GetUInt32();
creatureTemplate.SpellSchoolImmuneMask = fields[81].GetUInt32();
creatureTemplate.flags_extra = fields[82].GetUInt32();
creatureTemplate.ScriptID = GetScriptId(fields[83].GetString());
}
void ObjectMgr::LoadCreatureTemplateModels()
@@ -1063,6 +1066,13 @@ void ObjectMgr::CheckCreatureMovement(char const* table, uint64 id, CreatureMove
table, uint32(creatureMovement.Chase), id);
creatureMovement.Chase = CreatureChaseMovementType::Run;
}
if (creatureMovement.Random >= CreatureRandomMovementType::Max)
{
TC_LOG_ERROR("sql.sql", "`%s`.`Random` wrong value (%u) for Id " UI64FMTD ", setting to Walk.",
table, uint32(creatureMovement.Random), id);
creatureMovement.Random = CreatureRandomMovementType::Walk;
}
}
void ObjectMgr::LoadCreatureAddons()
@@ -1410,7 +1420,8 @@ void ObjectMgr::LoadCreatureMovementOverrides()
_creatureMovementOverrides.clear();
QueryResult result = WorldDatabase.Query("SELECT SpawnId, Ground, Swim, Flight, Rooted, Chase from creature_movement_override");
QueryResult result = WorldDatabase.Query("SELECT SpawnId, Ground, Swim, Flight, Rooted, Chase, Random from creature_movement_override");
if (!result)
{
TC_LOG_INFO("server.loading", ">> Loaded 0 creature movement overrides. DB table `creature_movement_override` is empty!");
@@ -1433,6 +1444,7 @@ void ObjectMgr::LoadCreatureMovementOverrides()
movement.Flight = static_cast<CreatureFlightMovementType>(fields[3].GetUInt8());
movement.Rooted = fields[4].GetBool();
movement.Chase = static_cast<CreatureChaseMovementType>(fields[5].GetUInt8());
movement.Random = static_cast<CreatureRandomMovementType>(fields[6].GetUInt8());
CheckCreatureMovement("creature_movement_override", spawnId, movement);
}

View File

@@ -115,9 +115,22 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
owner->AddUnitState(UNIT_STATE_ROAMING_MOVE);
bool walk = true;
switch (owner->GetMovementTemplate().GetRandom())
{
case CreatureRandomMovementType::CanRun:
walk = owner->IsWalking();
break;
case CreatureRandomMovementType::AlwaysRun:
walk = false;
break;
default:
break;
}
Movement::MoveSplineInit init(owner);
init.MovebyPath(_path->GetPath());
init.SetWalk(true);
init.SetWalk(walk);
int32 traveltime = init.Launch();
_timer.Reset(traveltime + resetTimer);