Fix rpg game objects quest accept and reward (#1080)

This commit is contained in:
Yunfan Li
2025-03-16 00:50:00 +08:00
committed by GitHub
parent 38912d4a8a
commit 0fabf174c0
5 changed files with 33 additions and 33 deletions

View File

@@ -227,27 +227,27 @@ bool NewRpgMoveRandomAction::Execute(Event event)
bool NewRpgMoveNpcAction::Execute(Event event)
{
NewRpgInfo& info = botAI->rpgInfo;
if (!info.near_npc.npc)
if (!info.near_npc.npcOrGo)
{
// No npc can be found, switch to IDLE
ObjectGuid npc = ChooseNpcOrGameObjectToInteract();
if (npc.IsEmpty())
ObjectGuid npcOrGo = ChooseNpcOrGameObjectToInteract();
if (npcOrGo.IsEmpty())
{
info.ChangeToIdle();
return true;
}
info.near_npc.npc = npc;
info.near_npc.npcOrGo = npcOrGo;
info.near_npc.lastReach = 0;
return true;
}
Unit* unit = botAI->GetUnit(info.near_npc.npc);
if (unit && bot->GetDistance(unit) <= INTERACTION_DISTANCE)
WorldObject* object = ObjectAccessor::GetWorldObject(*bot, info.near_npc.npcOrGo);
if (object && bot->CanInteractWithQuestGiver(object))
{
if (!info.near_npc.lastReach)
{
info.near_npc.lastReach = getMSTime();
InteractWithNpcOrGameObjectForQuest(info.near_npc.npc);
InteractWithNpcOrGameObjectForQuest(info.near_npc.npcOrGo);
return true;
}
@@ -255,12 +255,12 @@ bool NewRpgMoveNpcAction::Execute(Event event)
return false;
// has reached the npc for more than `npcStayTime`, select the next target
info.near_npc.npc = ObjectGuid();
info.near_npc.npcOrGo = ObjectGuid();
info.near_npc.lastReach = 0;
}
else
{
return MoveNpcTo(info.near_npc.npc);
return MoveWorldObjectTo(info.near_npc.npcOrGo);
}
return true;
}

View File

@@ -110,37 +110,37 @@ bool NewRpgBaseAction::MoveFarTo(WorldPosition dest)
return false;
}
bool NewRpgBaseAction::MoveNpcTo(ObjectGuid guid, float distance)
bool NewRpgBaseAction::MoveWorldObjectTo(ObjectGuid guid, float distance)
{
if (IsWaitingForLastMove(MovementPriority::MOVEMENT_NORMAL))
{
return false;
}
Unit* unit = botAI->GetUnit(guid);
if (!unit)
WorldObject* object = botAI->GetWorldObject(guid);
if (!object)
return false;
float x = unit->GetPositionX();
float y = unit->GetPositionY();
float z = unit->GetPositionZ();
float mapId = unit->GetMapId();
float x = object->GetPositionX();
float y = object->GetPositionY();
float z = object->GetPositionZ();
float mapId = object->GetMapId();
float angle = 0.f;
if (!unit->isMoving())
angle = unit->GetAngle(bot) + (M_PI * irand(-25, 25) / 100.0); // Closest 45 degrees towards the target
if (!object->ToUnit() || !object->ToUnit()->isMoving())
angle = object->GetAngle(bot) + (M_PI * irand(-25, 25) / 100.0); // Closest 45 degrees towards the target
else
angle = unit->GetOrientation() +
angle = object->GetOrientation() +
(M_PI * irand(-25, 25) / 100.0); // 45 degrees infront of target (leading it's movement)
float rnd = rand_norm();
x += cos(angle) * distance * rnd;
y += sin(angle) * distance * rnd;
if (!unit->GetMap()->CheckCollisionAndGetValidCoords(unit, unit->GetPositionX(), unit->GetPositionY(),
unit->GetPositionZ(), x, y, z))
if (!object->GetMap()->CheckCollisionAndGetValidCoords(object, object->GetPositionX(), object->GetPositionY(),
object->GetPositionZ(), x, y, z))
{
x = unit->GetPositionX();
y = unit->GetPositionY();
z = unit->GetPositionZ();
x = object->GetPositionX();
y = object->GetPositionY();
z = object->GetPositionZ();
}
return MoveTo(mapId, x, y, z, false, false, false, true);
}
@@ -453,16 +453,16 @@ bool NewRpgBaseAction::OrganizeQuestLog()
bool NewRpgBaseAction::SearchQuestGiverAndAcceptOrReward()
{
OrganizeQuestLog();
if (ObjectGuid npc = ChooseNpcOrGameObjectToInteract(true, 80.0f))
if (ObjectGuid npcOrGo = ChooseNpcOrGameObjectToInteract(true, 80.0f))
{
const WorldObject* object = ObjectAccessor::GetWorldObject(*bot, npc);
if (bot->GetDistance(object) <= INTERACTION_DISTANCE)
WorldObject* object = ObjectAccessor::GetWorldObject(*bot, npcOrGo);
if (bot->CanInteractWithQuestGiver(object))
{
InteractWithNpcOrGameObjectForQuest(npc);
InteractWithNpcOrGameObjectForQuest(npcOrGo);
ForceToWait(5000);
return true;
}
return MoveNpcTo(npc);
return MoveWorldObjectTo(npcOrGo);
}
return false;
}

View File

@@ -28,7 +28,7 @@ public:
protected:
// MOVEMENT RELATED
bool MoveFarTo(WorldPosition dest);
bool MoveNpcTo(ObjectGuid guid, float distance = INTERACTION_DISTANCE);
bool MoveWorldObjectTo(ObjectGuid guid, float distance = INTERACTION_DISTANCE);
bool MoveRandomNear(float moveStep = 50.0f, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
bool ForceToWait(uint32 duration, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);

View File

@@ -90,9 +90,9 @@ std::string NewRpgInfo::ToString()
break;
case RPG_NEAR_NPC:
out << "NEAR_NPC";
out << "\nnpcEntry: " << near_npc.npc.GetCounter();
out << "\nnpcOrGoEntry: " << near_npc.npcOrGo.GetCounter();
out << "\nlastNearNpc: " << startT;
out << "\nlastReachNpc: " << near_npc.lastReach;
out << "\nlastReachNpcOrGo: " << near_npc.lastReach;
break;
case RPG_NEAR_RANDOM:
out << "NEAR_RANDOM";

View File

@@ -46,7 +46,7 @@ struct NewRpgInfo
// RPG_NEAR_NPC
struct NearNpc {
NearNpc() = default;
ObjectGuid npc{};
ObjectGuid npcOrGo{};
uint32 lastReach{0};
};
// RPG_NEAR_RANDOM