From 0fabf174c09f7663742cc59c41e6bdc9734aa20d Mon Sep 17 00:00:00 2001 From: Yunfan Li <56597220+liyunfan1223@users.noreply.github.com> Date: Sun, 16 Mar 2025 00:50:00 +0800 Subject: [PATCH] Fix rpg game objects quest accept and reward (#1080) --- src/strategy/rpg/NewRpgAction.cpp | 18 ++++++------ src/strategy/rpg/NewRpgBaseAction.cpp | 40 +++++++++++++-------------- src/strategy/rpg/NewRpgBaseAction.h | 2 +- src/strategy/rpg/NewRpgInfo.cpp | 4 +-- src/strategy/rpg/NewRpgInfo.h | 2 +- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/strategy/rpg/NewRpgAction.cpp b/src/strategy/rpg/NewRpgAction.cpp index ebacbdb8..aee78496 100644 --- a/src/strategy/rpg/NewRpgAction.cpp +++ b/src/strategy/rpg/NewRpgAction.cpp @@ -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; } diff --git a/src/strategy/rpg/NewRpgBaseAction.cpp b/src/strategy/rpg/NewRpgBaseAction.cpp index 3fb6f2b3..3d387c17 100644 --- a/src/strategy/rpg/NewRpgBaseAction.cpp +++ b/src/strategy/rpg/NewRpgBaseAction.cpp @@ -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; } diff --git a/src/strategy/rpg/NewRpgBaseAction.h b/src/strategy/rpg/NewRpgBaseAction.h index 0d5a4ae8..62c415a2 100644 --- a/src/strategy/rpg/NewRpgBaseAction.h +++ b/src/strategy/rpg/NewRpgBaseAction.h @@ -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); diff --git a/src/strategy/rpg/NewRpgInfo.cpp b/src/strategy/rpg/NewRpgInfo.cpp index 70c7ef9f..a9c82646 100644 --- a/src/strategy/rpg/NewRpgInfo.cpp +++ b/src/strategy/rpg/NewRpgInfo.cpp @@ -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"; diff --git a/src/strategy/rpg/NewRpgInfo.h b/src/strategy/rpg/NewRpgInfo.h index 162b8465..d4b39b25 100644 --- a/src/strategy/rpg/NewRpgInfo.h +++ b/src/strategy/rpg/NewRpgInfo.h @@ -46,7 +46,7 @@ struct NewRpgInfo // RPG_NEAR_NPC struct NearNpc { NearNpc() = default; - ObjectGuid npc{}; + ObjectGuid npcOrGo{}; uint32 lastReach{0}; }; // RPG_NEAR_RANDOM