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

View File

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

View File

@@ -28,7 +28,7 @@ public:
protected: protected:
// MOVEMENT RELATED // MOVEMENT RELATED
bool MoveFarTo(WorldPosition dest); 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 MoveRandomNear(float moveStep = 50.0f, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
bool ForceToWait(uint32 duration, 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; break;
case RPG_NEAR_NPC: case RPG_NEAR_NPC:
out << "NEAR_NPC"; out << "NEAR_NPC";
out << "\nnpcEntry: " << near_npc.npc.GetCounter(); out << "\nnpcOrGoEntry: " << near_npc.npcOrGo.GetCounter();
out << "\nlastNearNpc: " << startT; out << "\nlastNearNpc: " << startT;
out << "\nlastReachNpc: " << near_npc.lastReach; out << "\nlastReachNpcOrGo: " << near_npc.lastReach;
break; break;
case RPG_NEAR_RANDOM: case RPG_NEAR_RANDOM:
out << "NEAR_RANDOM"; out << "NEAR_RANDOM";

View File

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