fix(Scripts/SmartAI): Rewrite ACTION_MOVE_TO_POS (#19190)

* init

* Update SmartScript.cpp

* combatReach

* Update SmartScript.cpp
This commit is contained in:
Gultask
2024-07-05 15:07:56 -03:00
committed by GitHub
parent 172f73db92
commit 89a6996628
3 changed files with 69 additions and 42 deletions
@@ -0,0 +1,25 @@
--
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1367 AND `source_type` = 0 AND `id` = 1;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1367 AND `source_type` = 0 AND `id` = 3;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1367 AND `source_type` = 0 AND `id` = 5;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1368 AND `source_type` = 0 AND `id` = 1;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1368 AND `source_type` = 0 AND `id` = 3;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1371 AND `source_type` = 0 AND `id` = 2;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1371 AND `source_type` = 0 AND `id` = 4;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1414 AND `source_type` = 0 AND `id` = 4;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1415 AND `source_type` = 0 AND `id` = 3;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2470 AND `source_type` = 0 AND `id` = 0;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 137300 AND `source_type` = 9 AND `id` = 20;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 137300 AND `source_type` = 9 AND `id` = 19;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 1043900 AND `source_type` = 9 AND `id` = 2;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2129100 AND `source_type` = 9 AND `id` = 1;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2129100 AND `source_type` = 9 AND `id` = 13;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2711300 AND `source_type` = 9 AND `id` = 1;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2711300 AND `source_type` = 9 AND `id` = 3;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2711400 AND `source_type` = 9 AND `id` = 1;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2711400 AND `source_type` = 9 AND `id` = 3;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2711500 AND `source_type` = 9 AND `id` = 1;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2711500 AND `source_type` = 9 AND `id` = 3;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2731600 AND `source_type` = 9 AND `id` = 2;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 2731600 AND `source_type` = 9 AND `id` = 3;
UPDATE `smart_scripts` SET `target_type` = 8 WHERE `entryorguid` = 3019000 AND `source_type` = 9 AND `id` = 13;
+28 -27
View File
@@ -1744,8 +1744,21 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
WorldObject* target = nullptr; WorldObject* target = nullptr;
if (e.GetTargetType() == SMART_TARGET_RANDOM_POINT) switch (e.GetTargetType())
{ {
case SMART_TARGET_POSITION:
{
G3D::Vector3 dest(e.target.x, e.target.y, e.target.z);
if (e.action.moveToPos.transport)
if (TransportBase* trans = me->GetDirectTransport())
trans->CalculatePassengerPosition(dest.x, dest.y, dest.z);
me->GetMotionMaster()->MovePoint(e.action.moveToPos.pointId, dest.x, dest.y, dest.z, true, true,
isControlled ? MOTION_SLOT_CONTROLLED : MOTION_SLOT_ACTIVE, e.target.o);
break;
}
case SMART_TARGET_RANDOM_POINT:
if (me) if (me)
{ {
float range = (float)e.target.randomPoint.range; float range = (float)e.target.randomPoint.range;
@@ -1760,44 +1773,32 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
true, true,
isControlled ? MOTION_SLOT_CONTROLLED : MOTION_SLOT_ACTIVE isControlled ? MOTION_SLOT_CONTROLLED : MOTION_SLOT_ACTIVE
); );
}
break; break;
} }
// Can use target floats as offset
/*if (e.GetTargetType() == SMART_TARGET_CREATURE_RANGE || e.GetTargetType() == SMART_TARGET_CREATURE_GUID || default:
e.GetTargetType() == SMART_TARGET_CREATURE_DISTANCE || e.GetTargetType() == SMART_TARGET_GAMEOBJECT_RANGE ||
e.GetTargetType() == SMART_TARGET_GAMEOBJECT_GUID || e.GetTargetType() == SMART_TARGET_GAMEOBJECT_DISTANCE ||
e.GetTargetType() == SMART_TARGET_CLOSEST_CREATURE || e.GetTargetType() == SMART_TARGET_CLOSEST_GAMEOBJECT ||
e.GetTargetType() == SMART_TARGET_OWNER_OR_SUMMONER || e.GetTargetType() == SMART_TARGET_ACTION_INVOKER ||
e.GetTargetType() == SMART_TARGET_CLOSEST_ENEMY || e.GetTargetType() == SMART_TARGET_CLOSEST_FRIENDLY ||
e.GetTargetType() == SMART_TARGET_SELF || e.GetTargetType() == SMART_TARGET_STORED)) */
{ {
// we want to move to random element // we want to move to random element
if (!targets.empty()) if (targets.empty())
return;
else
target = Acore::Containers::SelectRandomContainerElement(targets); target = Acore::Containers::SelectRandomContainerElement(targets);
}
if (!target)
{
G3D::Vector3 dest(e.target.x, e.target.y, e.target.z);
if (e.action.moveToPos.transport)
if (TransportBase* trans = me->GetDirectTransport())
trans->CalculatePassengerPosition(dest.x, dest.y, dest.z);
me->GetMotionMaster()->MovePoint(e.action.moveToPos.pointId, dest.x, dest.y, dest.z, true, true,
isControlled ? MOTION_SLOT_CONTROLLED : MOTION_SLOT_ACTIVE, e.target.o);
}
else // Xinef: we can use dest.x, dest.y, dest.z to make offset
{
float x, y, z; float x, y, z;
target->GetPosition(x, y, z); target->GetPosition(x, y, z);
if (e.action.moveToPos.ContactDistance > 0)
{ if (e.action.moveToPos.combatReach)
target->GetNearPoint(me, x, y, z, target->GetCombatReach() + e.action.moveToPos.ContactDistance, 0, target->GetAngle(me));
else if (e.action.moveToPos.ContactDistance)
target->GetNearPoint(me, x, y, z, e.action.moveToPos.ContactDistance, 0, target->GetAngle(me)); target->GetNearPoint(me, x, y, z, e.action.moveToPos.ContactDistance, 0, target->GetAngle(me));
}
me->GetMotionMaster()->MovePoint(e.action.moveToPos.pointId, x + e.target.x, y + e.target.y, z + e.target.z, true, true, isControlled ? MOTION_SLOT_CONTROLLED : MOTION_SLOT_ACTIVE); me->GetMotionMaster()->MovePoint(e.action.moveToPos.pointId, x + e.target.x, y + e.target.y, z + e.target.z, true, true, isControlled ? MOTION_SLOT_CONTROLLED : MOTION_SLOT_ACTIVE);
break;
} }
}
break; break;
} }
case SMART_ACTION_MOVE_TO_POS_TARGET: case SMART_ACTION_MOVE_TO_POS_TARGET:
@@ -1202,6 +1202,7 @@ struct SmartAction
SAIBool transport; SAIBool transport;
uint32 controlled; uint32 controlled;
uint32 ContactDistance; uint32 ContactDistance;
uint32 combatReach;
} moveToPos; } moveToPos;
struct struct