mod-playerbots/src/Ai/Base/Actions/TeleportAction.cpp
Keleborn 441f9f7552
Warnings PR 1: Event warnings and headers (#2106)
# Pull Request

This is the first in a series of PRs intended to eliminate warnings in
the module. The design intent is to eliminate the calling event when not
needed in the body of the function. Based off of SmashingQuasars work.

---

## How to Test the Changes

- Step-by-step instructions to test the change
- Any required setup (e.g. multiple players, bots, specific
configuration)
- Expected behavior and how to verify it

## Complexity & Impact

- Does this change add new decision branches?
    - [x] No
    - [ ] Yes (**explain below**)

- Does this change increase per-bot or per-tick processing?
    - [x] No
    - [ ] Yes (**describe and justify impact**)

- Could this logic scale poorly under load?
    - [x] No
    - [ ] Yes (**explain why**)

---

## Defaults & Configuration

- Does this change modify default bot behavior?
    - [x] No
    - [ ] Yes (**explain why**)

If this introduces more advanced or AI-heavy logic:

- [ ] Lightweight mode remains the default
- [ ] More complex behavior is optional and thereby configurable

---

## AI Assistance

- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
    - [x] No
    - [ ] Yes (**explain below**)

---

## Final Checklist

- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed

---

## Notes for Reviewers

Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.

---------

Co-authored-by: bashermens <31279994+hermensbas@users.noreply.github.com>
2026-02-14 20:55:10 +01:00

115 lines
4.0 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "TeleportAction.h"
#include "Event.h"
#include "LastMovementValue.h"
#include "AiObjectContext.h"
#include "PlayerbotAI.h"
#include "SpellMgr.h"
#include "Spell.h"
bool TeleportAction::Execute(Event /*event*/)
{
/*
// List of allowed portal entries (you can populate this dynamically)
std::vector<uint32> allowedPortals = {
187055, 195142, 195141, 201797, 202079, 194481, 195682, 191164, 176498, 182351,
178404, 176497, 181146, 184605, 176499, 195140, 193948, 193427, 193052, 193206,
192786, 184594, 183384, 182352, 184604, 189994, 193053, 193207, 193956, 195139,
176296, 194011, 194012, 189993, 176500, 176501, 193955, 193425, 193772, 193604,
191006, 191007, 191008, 191009, 191013, 191014, 191010, 190960, 191011, 191012,
183317, 183321, 183322, 187056, 183323, 183324, 183325, 183326, 183327, 190203,
190204, 190205, 190206, 193908, 181575, 181576, 181577, 181578, 202277, 202278
};
// Try teleporting using allowed portals
GuidVector closeObjects = *context->GetValue<GuidVector>("nearest game objects no los");
GameObject* closestPortal = nullptr;
float closestDistance = 100.0f;
for (ObjectGuid const& guid : closeObjects)
{
GameObject* go = botAI->GetGameObject(guid);
if (!go)
continue;
// Check if the game object entry is in the allowed portals list
if (std::find(allowedPortals.begin(), allowedPortals.end(), go->GetEntry()) != allowedPortals.end())
{
float tempDist = bot->GetDistance(go);
if (tempDist < closestDistance)
{
closestDistance = tempDist;
closestPortal = go;
}
}
}
// If a nearby portal is found, use it
if (closestPortal && bot->IsWithinDistInMap(closestPortal, INTERACTION_DISTANCE))
{
std::ostringstream out;
out << "Using portal: " << closestPortal->GetName();
botAI->TellMasterNoFacing(out.str());
WorldPacket data(CMSG_GAMEOBJ_USE);
data << closestPortal->GetGUID();
bot->GetSession()->HandleGameObjectUseOpcode(data);
return true;
}
*/
// If no portal was found, fallback to spellcaster-type game objects
GuidVector gos = *context->GetValue<GuidVector>("nearest game objects");
for (ObjectGuid const guid : gos)
{
GameObject* go = botAI->GetGameObject(guid);
if (!go)
continue;
GameObjectTemplate const* goInfo = go->GetGOInfo();
if (goInfo->type != GAMEOBJECT_TYPE_SPELLCASTER && goInfo->type != GAMEOBJECT_TYPE_GOOBER)
continue;
uint32 spellId = goInfo->spellcaster.spellId;
SpellInfo const* spellInfo = SpellMgr::instance()->GetSpellInfo(spellId);
if (!spellInfo || !spellInfo->HasEffect(SPELL_EFFECT_TELEPORT_UNITS))
continue;
std::ostringstream out;
out << "Teleporting using " << goInfo->name;
botAI->TellMasterNoFacing(out.str());
botAI->ChangeStrategy("-follow,+stay", BOT_STATE_NON_COMBAT);
Spell* spell = new Spell(bot, spellInfo, TRIGGERED_NONE);
SpellCastTargets targets;
targets.SetUnitTarget(bot);
spell->prepare(&targets, nullptr);
spell->cast(true);
return true;
}
// If no game objects were found, try using the last area trigger
LastMovement& movement = context->GetValue<LastMovement&>("last area trigger")->Get();
if (movement.lastAreaTrigger)
{
WorldPacket p(CMSG_AREATRIGGER);
p << movement.lastAreaTrigger;
p.rpos(0);
bot->GetSession()->HandleAreaTriggerOpcode(p);
movement.lastAreaTrigger = 0;
return true;
}
// If no teleport option is found
botAI->TellError("Cannot find any portal to teleport");
return false;
}