Core: hooks the bot module uses

This commit is contained in:
Karrz1
2026-10-27 23:06:42 +00:00
parent 9df935eed5
commit aefce1bcdc
16 changed files with 360 additions and 26 deletions
@@ -366,6 +366,21 @@ class TC_GAME_API Battleground
{
return thisTeamPlayers < maxPlayersPerTeam ? maxPlayersPerTeam - thisTeamPlayers : 0u;
}
// A waiting real player's team is full of bots but none can leave this moment (all in combat or carrying a flag): the player waits
// for one to become free instead of a second instance being opened. False when the places can be made now, or when the team is
// mostly real players and there is nobody to swap.
static constexpr bool WaitForBotToFree(uint32 placesToMake, uint32 evictableNow, uint32 botsOnTeam)
{
return placesToMake > evictableNow && botsOnTeam >= placesToMake;
}
// The shortfall minus the bots an earlier top-up already created or reused for this side that have not queued yet (their setup is
// still running). WSG 2026-10-21: one player's queue opened ten instances, because every 20 s prep tick asked again for places
// the bots in setup were about to take, and the surplus formed new battlegrounds.
static constexpr uint32 TopUpAfterInFlight(uint32 thisTeamPlayers, uint32 maxPlayersPerTeam, uint32 inFlight)
{
uint32 const request = TopUpRequest(thisTeamPlayers, maxPlayersPerTeam);
return request > inFlight ? request - inFlight : 0u;
}
bool isArena() const;
bool isBattleground() const;
@@ -35,6 +35,7 @@
#include "SharedDefines.h"
#include "World.h"
#include "WorldSession.h"
#include <algorithm>
bool BattlegroundTemplate::IsArena() const
{
@@ -47,7 +48,8 @@ uint16 BattlegroundTemplate::GetMinPlayersPerTeam() const
// topping the match up to 40 a side while it runs. Playerbot.Bg.Av.MinPlayersPerTeam (bot module config), 0 or unset = the table's value.
if (BattlemasterEntry->ID == BATTLEGROUND_AV)
{
uint32 const configured = uint32(sConfigMgr->GetIntDefault("Playerbot.Bg.Av.MinPlayersPerTeam", 0));
// Read once: this runs on every queue check. Changing it needs a restart.
static uint32 const configured = uint32(std::max(0, sConfigMgr->GetIntDefault("Playerbot.Bg.Av.MinPlayersPerTeam", 0)));
if (configured > 0 && configured < BattlemasterEntry->MinPlayers)
return uint16(configured);
}
+5
View File
@@ -182,6 +182,10 @@ class TC_GAME_API ThreatManager
// threat reductions. Written on the world thread, read from map threads in AddThreat: atomic, relaxed.
void SetGeneratedThreatMultiplier(float mult) { _generatedThreatMultiplier.store(mult, std::memory_order_relaxed); }
float GetGeneratedThreatMultiplier() const { return _generatedThreatMultiplier.load(std::memory_order_relaxed); }
// Taunts (Taunt, Growl, Mocking Blow, Challenging Shout/Roar) this unit casts never miss, resists and immunity aside
// (playerbot raid tanks, Playerbot.Raid.SureTaunt; WorldObject::SpellHitResult). Same threading as the multiplier.
void SetTauntNeverMisses(bool on) { _tauntNeverMisses.store(on, std::memory_order_relaxed); }
bool GetTauntNeverMisses() const { return _tauntNeverMisses.load(std::memory_order_relaxed); }
///== REDIRECT SYSTEM ==
// Register a redirection effect that redirects pct% of threat generated by owner to victim
@@ -233,6 +237,7 @@ class TC_GAME_API ThreatManager
std::array<float, MAX_SPELL_SCHOOL> _singleSchoolModifiers; // most spells are single school - we pre-calculate these and store them
mutable std::unordered_map<std::underlying_type<SpellSchoolMask>::type, float> _multiSchoolModifiers; // these are calculated on demand
std::atomic<float> _generatedThreatMultiplier{ 1.0f }; // see SetGeneratedThreatMultiplier
std::atomic<bool> _tauntNeverMisses{ false }; // see SetTauntNeverMisses
// redirect system (is kind of dumb, but that's because none of the redirection spells actually have any aura effect associated with them, so spellscript needs to deal with it)
void UpdateRedirectInfo();
+39 -2
View File
@@ -25,6 +25,7 @@
#include "Player.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
#include "StringFormat.h"
#include "WorldSession.h"
namespace Trainer
@@ -182,8 +183,17 @@ namespace Trainer
++tally->spells;
if (trainerSpell.ReqSkillLine)
{
if (tally) ++tally->skill_line;
continue;
// A class skill line (a rogue's Poisons) is the class's own, not a profession: the bot holds it at the value its level gives
// (five per level, as a rogue's Poisons skill rises), and the poison ranks behind it open as at the trainer.
SkillLineEntry const* line = sSkillLineStore.LookupEntry(trainerSpell.ReqSkillLine);
if (!line || line->CategoryID != SKILL_CATEGORY_CLASS || !player->IsSpellFitByClassAndRace(trainerSpell.SpellId))
{
if (tally) ++tally->skill_line;
continue;
}
uint16 const wanted = uint16(std::min<uint32>(player->GetLevel() * 5, 300));
if (player->GetBaseSkillValue(trainerSpell.ReqSkillLine) < wanted)
player->SetSkill(trainerSpell.ReqSkillLine, 0, wanted, 300);
}
if (BattlePets::BattlePetMgr::GetBattlePetSpeciesBySpell(trainerSpell.SpellId))
{
@@ -226,6 +236,33 @@ namespace Trainer
return learned;
}
std::string Trainer::DescribeFreeTeachRefusal(Player const* player, uint32 spellId) const
{
Spell const* trainerSpell = GetSpell(spellId);
if (!trainerSpell)
return "not on this trainer";
if (!(GetClassMask() & player->GetClassMask()))
return Trinity::StringFormat("trainer {} class mask {:#x} leaves the class out", _id, GetClassMask());
if (player->HasSpell(spellId))
return "known";
if (!player->IsSpellFitByClassAndRace(spellId))
return "IsSpellFitByClassAndRace refuses the spell";
if (trainerSpell->ReqSkillLine && player->GetBaseSkillValue(trainerSpell->ReqSkillLine) < trainerSpell->ReqSkillRank)
{
SkillLineEntry const* line = sSkillLineStore.LookupEntry(trainerSpell->ReqSkillLine);
return Trinity::StringFormat("skill line {} rank {} needed, player has {} ({})", trainerSpell->ReqSkillLine, trainerSpell->ReqSkillRank,
player->GetBaseSkillValue(trainerSpell->ReqSkillLine), line && line->CategoryID == SKILL_CATEGORY_CLASS ? "class line" : "other line");
}
for (int32 req : trainerSpell->ReqAbility)
if (req && !player->HasSpell(req))
return Trinity::StringFormat("needs spell {} first", req);
if (player->GetLevel() < trainerSpell->ReqLevel)
return Trinity::StringFormat("needs level {}", trainerSpell->ReqLevel);
if (BattlePets::BattlePetMgr::GetBattlePetSpeciesBySpell(spellId))
return "battle pet";
return "would be taught";
}
Spell const* Trainer::GetSpell(uint32 spellId) const
{
auto itr = std::find_if(_spells.begin(), _spells.end(), [spellId](Spell const& trainerSpell)
@@ -95,6 +95,8 @@ namespace Trainer
// class skill lines name; all classes when the data does not say. Some Forever class spells (Paladin Judgement, Seal of Righteousness) carry no
// class restriction of their own, so IsSpellFitByClassAndRace lets them through for any class: the trainer decides.
uint32 GetClassMask() const;
// Why TeachAvailableSpellsFree would not teach `spellId` to this player, in the order it checks ("would be taught" when it would).
std::string DescribeFreeTeachRefusal(Player const* player, uint32 spellId) const;
private:
Spell const* GetSpell(uint32 spellId) const;
@@ -2026,6 +2026,12 @@ SpellMissInfo WorldObject::SpellHitResult(Unit* victim, SpellInfo const* spellIn
if (spellInfo->HasAttribute(SPELL_ATTR3_ALWAYS_HIT))
return SPELL_MISS_NONE;
// A playerbot raid tank's taunt lands (ThreatManager::SetTauntNeverMisses): immunity and reflect above still apply.
if (Unit const* caster = ToUnit())
if (caster->GetThreatManager().GetTauntNeverMisses() &&
(spellInfo->HasAura(SPELL_AURA_MOD_TAUNT) || spellInfo->HasEffect(SPELL_EFFECT_ATTACK_ME)))
return SPELL_MISS_NONE;
switch (spellInfo->DmgClass)
{
case SPELL_DAMAGE_CLASS_RANGED:
+25
View File
@@ -844,6 +844,11 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit const* excludeCasterChannel
return effects;
}
// Running totals of the rage a melee hit rewarded (the damage it was computed from and the power gained, in tenths of rage), read by the damage
// parity run to log rage per hit against the formula.
TC_GAME_API std::atomic<uint64> g_classicRageHitDamage(0);
TC_GAME_API std::atomic<uint64> g_classicRageHitGained(0);
/*static*/ uint32 Unit::DealDamage(Unit* attacker, Unit* victim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellInfo const* spellProto, bool durabilityLoss)
{
uint32 damageDone = damage;
@@ -2349,6 +2354,23 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extr
// Send log damage message to client
Unit::DealDamageMods(damageInfo.Attacker, victim, damageInfo.Damage, &damageInfo.Absorb);
{
uint8 outcome = HIT_OUTCOME_OTHER;
switch (damageInfo.HitOutCome)
{
case MELEE_HIT_MISS: outcome = HIT_OUTCOME_MISS; break;
case MELEE_HIT_DODGE: outcome = HIT_OUTCOME_DODGE; break;
case MELEE_HIT_PARRY: outcome = HIT_OUTCOME_PARRY; break;
case MELEE_HIT_BLOCK: outcome = HIT_OUTCOME_BLOCK; break;
case MELEE_HIT_GLANCING: outcome = HIT_OUTCOME_GLANCING; break;
case MELEE_HIT_CRIT: outcome = HIT_OUTCOME_CRIT; break;
case MELEE_HIT_CRUSHING: outcome = HIT_OUTCOME_CRUSHING; break;
case MELEE_HIT_NORMAL: outcome = HIT_OUTCOME_HIT; break;
default: break;
}
sScriptMgr->OnHitOutcome(this, victim, 0, outcome, damageInfo.Damage);
}
// sparring
if (Creature* victimCreature = victim->ToCreature())
{
@@ -2371,6 +2393,8 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extr
{
damageInfo.HitInfo |= HITINFO_RAGE_GAIN;
damageInfo.RageGained = RewardClassicRage(rageDamage, true);
g_classicRageHitDamage.fetch_add(rageDamage, std::memory_order_relaxed);
g_classicRageHitGained.fetch_add(uint64(std::max<int64>(int64(damageInfo.RageGained), 0)), std::memory_order_relaxed);
}
}
@@ -6691,6 +6715,7 @@ void Unit::SetCharm(Unit* charm, bool apply)
// Hook for OnHeal Event
sScriptMgr->OnHeal(healer, victim, (uint32&)gain);
sScriptMgr->OnHealOutcome(healer, victim, healInfo.GetSpellInfo() ? healInfo.GetSpellInfo()->Id : 0, addhealth, uint32(gain));
Unit* unit = healer;
if (healer && healer->GetTypeId() == TYPEID_UNIT && healer->IsTotem())
@@ -20,6 +20,9 @@
#include "Define.h"
#include <string>
#include <vector>
class Group;
class Player;
@@ -29,6 +32,14 @@ namespace GroupFinderListings
{
TC_GAME_API void OnGroupChanged(Group const* group);
TC_GAME_API void OnLogout(Player const* player);
// The module lists a group a bot leads (the same list a player's own listing goes in; no packet of its own). The play style is the
// Group Finder dropdown value: 1 Learning, 2 Relaxed, 3 Competitive, 4 Carry Offered.
TC_GAME_API void PostBotListing(Player const* leader, uint32 categoryId, std::vector<uint32> const& activities,
std::string const& name, std::string const& comment, uint8 playStyle);
TC_GAME_API void RemoveBotListing(Player const* leader);
// The category a player's own listing was posted in (0 = none): the module learns the dungeon category from it.
TC_GAME_API uint32 CategoryOf(Player const* leader);
}
#endif
@@ -132,6 +132,10 @@ void WorldSession::HandlePartyInviteOpcode(WorldPackets::Party::PartyInviteClien
group = invitingPlayer->GetGroupInvite();
Group* group2 = invitedPlayer->GetGroup(packet.PartyIndex);
// a bot group listed in the Group Finder takes a player who invites its member as a sign-up
if (group2 && !invitingPlayer->GetGroup(packet.PartyIndex) && sScriptMgr->OnPlayerGroupFinderJoinRequest(invitedPlayer, invitingPlayer))
return;
// player already in another group or invited
if (group2 || invitedPlayer->GetGroupInvite())
{
+115 -5
View File
@@ -35,6 +35,7 @@
#include "ObjectMgr.h"
#include "ObjectAccessor.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "World.h"
void WorldSession::HandleGuildQueryOpcode(WorldPackets::Guild::QueryGuildInfo& query)
@@ -1004,6 +1005,7 @@ namespace
time_t Created = 0;
std::string Name, Comment; // as the leader typed them (for the Discord bot's LFG channel)
uint8 PlayStyle = 0; // the play style dropdown: 1 Learning, 2 Relaxed, 3 Competitive, 4 Carry Offered
bool Silent = false; // a group the bots made: not written to the "groupfinder" log (Discord)
};
std::unordered_map<ObjectGuid, LfgListing> LfgListings;
@@ -1044,8 +1046,10 @@ namespace
if (bits[7])
listing.PlayStyle = data.read<uint8>(); // play style (retail LFGEntryGeneralPlaystyle)
listing.Request.assign(data.data() + start, data.data() + data.rpos());
return data.rpos() == data.size();
// The client's request ends with one more byte after the optional values (it is 0 in the captured request); the request is
// echoed whole.
listing.Request.assign(data.data() + start, data.data() + data.size());
return data.rpos() == data.size() || data.rpos() + 1 == data.size();
}
WorldPackets::LFG::RideTicket LfgListTicket(ObjectGuid const& leader, LfgListing const& listing)
@@ -1074,6 +1078,34 @@ namespace
session->SendPacket(&data);
}
// The request bytes of a listing the server makes itself, laid out as a request of the real client (captured 2026-10-20: all nine
// flag bits off, no name or comment, the int8 after the three floats 2 = Relaxed, the activity id, one closing zero byte).
std::vector<uint8> BuildLfgListRequest(uint32 categoryId, std::vector<uint32> const& activities, std::string_view name,
std::string_view comment, uint8 playStyle)
{
ByteBuffer data;
data.WriteBits(uint32(std::min<size_t>(activities.size(), 31)), 5);
data.WriteBits(uint32(std::min<size_t>(name.size(), 1023)), 10);
data.WriteBits(uint32(std::min<size_t>(comment.size(), 2047)), 11);
data.WriteBits(0, 8);
for (uint8 i = 0; i < 9; ++i)
data.WriteBit(false);
data.FlushBits();
data << uint32(categoryId);
data << float(0.0f) << float(0.0f) << float(0.0f);
data << uint32(0);
data << int8(playStyle);
for (size_t i = 0; i < std::min<size_t>(activities.size(), 31); ++i)
data << uint32(activities[i]);
// ByteBuffer::append asserts on a zero-sized value: an empty name or comment writes nothing
if (size_t const nameSize = std::min<size_t>(name.size(), 1023))
data.append(name.data(), nameSize);
if (size_t const commentSize = std::min<size_t>(comment.size(), 2047))
data.append(comment.data(), commentSize);
data << uint8(0);
return std::vector<uint8>(data.data(), data.data() + data.size());
}
// one LFGListSearchResult (Classic reader rva 0xA4EC70)
void WriteLfgListSearchResult(WorldPacket& data, ObjectGuid const& leader, LfgListing const& listing)
{
@@ -1128,7 +1160,11 @@ namespace
data << guid;
data << int8(member ? member->GetLevel() : info ? info->Level : 0);
data << int8(member ? member->GetClass() : info ? info->Class : 0);
data << int8(spec ? spec->Role : 2);
// the role the group gave the member (a bot has no talent specialization of its own), else the specialization's
uint8 const groupRole = leaderPlayer && leaderPlayer->GetGroup() ? leaderPlayer->GetGroup()->GetLfgRoles(guid) : 0;
int8 const role = (groupRole & lfg::PLAYER_ROLE_TANK) ? 0 : (groupRole & lfg::PLAYER_ROLE_HEALER) ? 1
: (groupRole & lfg::PLAYER_ROLE_DAMAGE) ? 2 : int8(spec ? spec->Role : 2);
data << role;
data << int32(member ? member->GetZoneId() : 0);
data << uint8(member ? member->GetLevel() : 0);
data << ObjectGuid::Empty;
@@ -1174,6 +1210,8 @@ namespace
// {"event": "listed" | "updated" | "delisted", "id", "faction", "activities", "title", "comment", "members": [...]}
void LogLfgListing(char const* event, ObjectGuid const& leader, LfgListing const& listing)
{
if (listing.Silent)
return;
if (!sLog->ShouldLog("groupfinder", LOG_LEVEL_INFO))
return;
@@ -1251,6 +1289,33 @@ void GroupFinderListings::OnLogout(Player const* player)
LfgListings.erase(itr);
}
void GroupFinderListings::PostBotListing(Player const* leader, uint32 categoryId, std::vector<uint32> const& activities,
std::string const& name, std::string const& comment, uint8 playStyle)
{
LfgListing listing;
listing.Id = NextLfgListingId++;
listing.CategoryId = categoryId;
listing.Activities = activities;
listing.Created = GameTime::GetGameTime();
listing.Name = name;
listing.Comment = comment;
listing.PlayStyle = playStyle;
listing.Silent = true;
listing.Request = BuildLfgListRequest(categoryId, activities, name, comment, playStyle);
LfgListings[leader->GetGUID()] = std::move(listing);
}
void GroupFinderListings::RemoveBotListing(Player const* leader)
{
OnLogout(leader);
}
uint32 GroupFinderListings::CategoryOf(Player const* leader)
{
auto itr = LfgListings.find(leader->GetGUID());
return itr != LfgListings.end() ? itr->second.CategoryId : 0;
}
void WorldSession::HandleLfgListProbe(WorldPackets::Null& packet)
{
WorldPacket const* raw = packet.GetRawPacket();
@@ -1283,6 +1348,25 @@ void WorldSession::HandleLfgListProbe(WorldPackets::Null& packet)
SendPacket(&result);
SendLfgListStatus(this, stored, true);
LogLfgListing("listed", _player->GetGUID(), stored);
sScriptMgr->OnPlayerGroupFinderListing(_player, stored.CategoryId, stored.Activities, true);
break;
}
case CMSG_LFG_LIST_APPLY_TO_GROUP: // the reply layouts are not captured: the ticket is read as the one of the search result
{
// A bot group listed by the module takes the applicant at once (the same as inviting a member). The packet is in
// the log above; a ticket that does not read or names no listed bot group is only logged.
WorldPackets::LFG::RideTicket ticket;
data >> ticket;
auto itr = LfgListings.find(ticket.RequesterGuid);
Player* leader = ObjectAccessor::FindConnectedPlayer(ticket.RequesterGuid);
if (itr == LfgListings.end() || !itr->second.Silent || !leader || !leader->GetGroup())
{
TC_LOG_INFO("network.opcode", "GroupFinder: apply by {} names ticket leader {} id {}: no listed bot group", GetPlayerInfo(),
ticket.RequesterGuid.ToString(), ticket.Id);
break;
}
bool const taken = !_player->GetGroup() && sScriptMgr->OnPlayerGroupFinderJoinRequest(leader, _player);
TC_LOG_INFO("network.opcode", "GroupFinder: apply by {} to {}: {}", GetPlayerInfo(), leader->GetName(), taken ? "joined" : "not taken");
break;
}
case CMSG_LFG_LIST_UPDATE_REQUEST: // edit (serializer rva 0x944C00): ticket, request
@@ -1311,6 +1395,7 @@ void WorldSession::HandleLfgListProbe(WorldPackets::Null& packet)
LfgListings.erase(itr);
SendLfgListStatus(this, listing, false);
LogLfgListing("delisted", _player->GetGUID(), listing);
sScriptMgr->OnPlayerGroupFinderListing(_player, listing.CategoryId, listing.Activities, false);
break;
}
case CMSG_PERKS_PROGRAM_REQUEST_REFUND: // Classic 0x3E02B3: the roles ticked in the Group Finder (uint8 mask)
@@ -1350,6 +1435,7 @@ void WorldSession::HandleLfgListProbe(WorldPackets::Null& packet)
activities.insert(data.read<uint32>());
}
sScriptMgr->OnPlayerGroupFinderSearch(_player); // the bots list a group for this player's faction when there is none
WorldPacket results(SMSG_LFG_LIST_SEARCH_RESULTS, 256);
std::vector<std::pair<ObjectGuid, LfgListing const*>> found;
bool const crossFaction = sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP);
@@ -1368,11 +1454,35 @@ void WorldSession::HandleLfgListProbe(WorldPackets::Null& packet)
++itr;
continue;
}
if (itr->second.CategoryId == categoryId && (activities.empty() || std::ranges::any_of(itr->second.Activities,
[&](uint32 activityId) { return activities.contains(activityId); })))
// A bot group does not know the client's category id: it is shown in the category the search asks for when one of its
// activities is among the searched ones, or when no activity is searched (an activity id belongs to one dungeon).
// A listing carries its activity id shifted left by 8 bits (Upper Blackrock Spire 214272 = 837 << 8) while the search
// filter carries the plain id (837): either form matches.
bool const activityMatch = std::ranges::any_of(itr->second.Activities,
[&](uint32 activityId) { return activities.contains(activityId) || activities.contains(activityId >> 8); });
bool const match = itr->second.Silent ? (activities.empty() || activityMatch)
: (itr->second.CategoryId == categoryId && (activities.empty() || activityMatch));
if (itr->second.Silent)
{
TC_LOG_INFO("network.opcode", "GroupFinder: bot listing of {} category {} activity {}: {}", leaderPlayer->GetName(),
itr->second.CategoryId, itr->second.Activities.empty() ? 0 : itr->second.Activities.front(), match ? "shown" : "no match");
if (match && itr->second.CategoryId != categoryId)
{
itr->second.CategoryId = categoryId;
itr->second.Request = BuildLfgListRequest(categoryId, itr->second.Activities, itr->second.Name, itr->second.Comment,
itr->second.PlayStyle);
}
}
if (match)
found.emplace_back(itr->first, &itr->second);
++itr;
}
// the searched activity ids are how the id of a dungeon or raid is read: pick it in the filter and search
std::string searched;
for (uint32 activityId : activities)
searched += (searched.empty() ? "" : ",") + std::to_string(activityId);
TC_LOG_INFO("network.opcode", "GroupFinder: search category {} activities [{}] by {}: {} of {} listing(s) found", categoryId,
searched, GetPlayerInfo(), found.size(), LfgListings.size());
results << uint16(found.size());
results << uint32(found.size());
for (auto const& [leader, listing] : found)
+17 -2
View File
@@ -119,10 +119,11 @@ bool PathGenerator::CalculatePath(float srcX, float srcY, float srcZ, float dest
{
_wetRoute = false;
bool ok = CalculatePathImpl(srcX, srcY, srcZ, destX, destY, destZ, forceDest);
if (!ok || (_type & PATHFIND_NOPATH) || !_liquidRouteCheck || !_liquidRouteCheck(_source, _pathPoints))
if (!ok || (_type & PATHFIND_NOPATH) || !_liquidRouteCheck || !_liquidRouteCheck(_source, _pathPoints, CrossesWaterPolys()))
return ok;
_avoidWater = true;
bool const dry = CalculatePathImpl(srcX, srcY, srcZ, destX, destY, destZ, forceDest) && !(_type & PATHFIND_NOPATH) && !_liquidRouteCheck(_source, _pathPoints);
bool const dry = CalculatePathImpl(srcX, srcY, srcZ, destX, destY, destZ, forceDest) && !(_type & PATHFIND_NOPATH)
&& !_liquidRouteCheck(_source, _pathPoints, CrossesWaterPolys());
_avoidWater = false;
if (dry)
return true;
@@ -131,6 +132,20 @@ bool PathGenerator::CalculatePath(float srcX, float srcY, float srcZ, float dest
return ok;
}
// The start polygon is where the source stands: a source leaving the water must be able to start.
bool PathGenerator::CrossesWaterPolys() const
{
if (!_navMesh)
return false;
for (uint32 i = 1; i < _polyLength; ++i)
{
unsigned short flags = 0;
if (dtStatusSucceed(_navMesh->getPolyFlags(_pathPolyRefs[i], &flags)) && (flags & NAV_WATER))
return true;
}
return false;
}
bool PathGenerator::CalculatePathImpl(float srcX, float srcY, float srcZ, float destX, float destY, float destZ, bool forceDest)
{
if (!Trinity::IsValidMapCoord(destX, destY, destZ) || !Trinity::IsValidMapCoord(srcX, srcY, srcZ))
+3 -1
View File
@@ -76,7 +76,8 @@ class TC_GAME_API PathGenerator
// Optional check (set by a module): returns true when `source` should keep out of liquid and `path` touches liquid.
// CalculatePath then searches a land-only route and keeps it when it is dry, else keeps the first route (IsWetRoute).
using LiquidRouteCheck = bool(*)(WorldObject const* source, Movement::PointsArray const& path);
// `waterPolys`: the corridor runs over navmesh water polygons past its first one (the liquid probes miss some of them).
using LiquidRouteCheck = bool(*)(WorldObject const* source, Movement::PointsArray const& path, bool waterPolys);
static void SetLiquidRouteCheck(LiquidRouteCheck check) { _liquidRouteCheck = check; }
bool CalculatePath(float destX, float destY, float destZ, bool forceDest = false);
bool IsInvalidDestinationZ(WorldObject const* target) const;
@@ -113,6 +114,7 @@ class TC_GAME_API PathGenerator
private:
dtPolyRef _pathPolyRefs[MAX_PATH_LENGTH]; // array of detour polygon references
bool CrossesWaterPolys() const;
uint32 _polyLength; // number of polygons in the path
Movement::PointsArray _pathPoints; // our actual (x,y,z) path to the target
+49
View File
@@ -2237,6 +2237,24 @@ void ScriptMgr::OnPlayerLfgJoin(Player* player, uint32 dungeonId, uint8 roles)
FOREACH_SCRIPT(PlayerScript)->OnLfgJoin(player, dungeonId, roles);
}
void ScriptMgr::OnPlayerGroupFinderListing(Player* player, uint32 categoryId, std::vector<uint32> const& activities, bool listed)
{
FOREACH_SCRIPT(PlayerScript)->OnGroupFinderListing(player, categoryId, activities, listed);
}
void ScriptMgr::OnPlayerGroupFinderSearch(Player* searcher)
{
FOREACH_SCRIPT(PlayerScript)->OnGroupFinderSearch(searcher);
}
bool ScriptMgr::OnPlayerGroupFinderJoinRequest(Player* member, Player* applicant)
{
FOR_SCRIPTS_RET(PlayerScript, itr, end, false)
if (itr->second->OnGroupFinderJoinRequest(member, applicant))
return true;
return false;
}
void ScriptMgr::OnPlayerLfgProposal(Player* player, uint32 proposalId)
{
FOREACH_SCRIPT(PlayerScript)->OnLfgProposal(player, proposalId);
@@ -2382,11 +2400,21 @@ void ScriptMgr::OnHeal(Unit* healer, Unit* reciever, uint32& gain)
FOREACH_SCRIPT(UnitScript)->OnHeal(healer, reciever, gain);
}
void ScriptMgr::OnHealOutcome(Unit* healer, Unit* target, uint32 spellId, uint32 raw, uint32 effective)
{
FOREACH_SCRIPT(UnitScript)->OnHealOutcome(healer, target, spellId, raw, effective);
}
void ScriptMgr::OnDamageSpell(Unit* attacker, Unit* victim, uint32 damage, SpellInfo const* spellInfo)
{
FOREACH_SCRIPT(UnitScript)->OnDamageSpell(attacker, victim, damage, spellInfo);
}
void ScriptMgr::OnHitOutcome(Unit* attacker, Unit* victim, uint32 spellId, uint8 outcome, uint32 damage)
{
FOREACH_SCRIPT(UnitScript)->OnHitOutcome(attacker, victim, spellId, outcome, damage);
}
void ScriptMgr::OnDamage(Unit* attacker, Unit* victim, uint32& damage)
{
FOREACH_SCRIPT(UnitScript)->OnDamage(attacker, victim, damage);
@@ -2769,10 +2797,18 @@ void UnitScript::OnHeal(Unit* /*healer*/, Unit* /*reciever*/, uint32& /*gain*/)
{
}
void UnitScript::OnHealOutcome(Unit* /*healer*/, Unit* /*target*/, uint32 /*spellId*/, uint32 /*raw*/, uint32 /*effective*/)
{
}
void UnitScript::OnDamageSpell(Unit* /*attacker*/, Unit* /*victim*/, uint32 /*damage*/, SpellInfo const* /*spellInfo*/)
{
}
void UnitScript::OnHitOutcome(Unit* /*attacker*/, Unit* /*victim*/, uint32 /*spellId*/, uint8 /*outcome*/, uint32 /*damage*/)
{
}
void UnitScript::OnDamage(Unit* /*attacker*/, Unit* /*victim*/, uint32& /*damage*/)
{
}
@@ -3205,6 +3241,19 @@ void PlayerScript::OnLfgJoin(Player* /*player*/, uint32 /*dungeonId*/, uint8 /*r
{
}
void PlayerScript::OnGroupFinderListing(Player* /*player*/, uint32 /*categoryId*/, std::vector<uint32> const& /*activities*/, bool /*listed*/)
{
}
bool PlayerScript::OnGroupFinderJoinRequest(Player* /*member*/, Player* /*applicant*/)
{
return false;
}
void PlayerScript::OnGroupFinderSearch(Player* /*searcher*/)
{
}
void PlayerScript::OnLfgProposal(Player* /*player*/, uint32 /*proposalId*/)
{
}
+38
View File
@@ -420,6 +420,21 @@ class TC_GAME_API ItemScript : public ScriptObject
virtual bool OnCastItemCombatSpell(Player* player, Unit* victim, SpellInfo const* spellInfo, Item* item);
};
// The roll behind a swing or a spell hit, for UnitScript::OnHitOutcome
enum HitOutcomeKind : uint8
{
HIT_OUTCOME_HIT = 0,
HIT_OUTCOME_CRIT,
HIT_OUTCOME_MISS,
HIT_OUTCOME_DODGE,
HIT_OUTCOME_PARRY,
HIT_OUTCOME_BLOCK,
HIT_OUTCOME_GLANCING,
HIT_OUTCOME_CRUSHING,
HIT_OUTCOME_RESIST,
HIT_OUTCOME_OTHER
};
class TC_GAME_API UnitScript : public ScriptObject
{
protected:
@@ -433,12 +448,20 @@ class TC_GAME_API UnitScript : public ScriptObject
// Called when a unit deals healing to another unit
virtual void OnHeal(Unit* healer, Unit* reciever, uint32& gain);
// Called after a heal landed: what the heal was worth before the target's missing health capped it (`raw`) and what it restored (`effective`);
// the difference is overheal. `spellId` is 0 for a heal without a spell.
virtual void OnHealOutcome(Unit* healer, Unit* target, uint32 spellId, uint32 raw, uint32 effective);
// Called when a unit deals damage to another unit
virtual void OnDamage(Unit* attacker, Unit* victim, uint32& damage);
// Called just before OnDamage with the spell that dealt the damage (null for a melee swing)
virtual void OnDamageSpell(Unit* attacker, Unit* victim, uint32 damage, SpellInfo const* spellInfo);
// Called before the damage of a swing or a direct spell hit is dealt, and for a spell that missed, with what the roll gave. spellId is 0
// for a melee swing; outcome is a HitOutcomeKind
virtual void OnHitOutcome(Unit* attacker, Unit* victim, uint32 spellId, uint8 outcome, uint32 damage);
// Called when DoT's Tick Damage is being Dealt
virtual void ModifyPeriodicDamageAurasTick(Unit* target, Unit* attacker, uint32& damage);
@@ -842,6 +865,16 @@ class TC_GAME_API PlayerScript : public ScriptObject
// Called after a player joined the dungeon finder
virtual void OnLfgJoin(Player* player, uint32 dungeonId, uint8 roles);
// Called when a player posts (listed) or removes (!listed) a Classic Group Finder listing
virtual void OnGroupFinderListing(Player* player, uint32 categoryId, std::vector<uint32> const& activities, bool listed);
// Called when `applicant` invites a player who is already in a group (the sign-up of the Group Finder list until its Apply
// button is answered). Return true when the script took the request: the usual "already in a group" answer is then not sent.
virtual bool OnGroupFinderJoinRequest(Player* member, Player* applicant);
// Called when a player searches the Classic Group Finder list, before the listings are read
virtual void OnGroupFinderSearch(Player* searcher);
// Called when a dungeon finder proposal is sent to a player
virtual void OnLfgProposal(Player* player, uint32 proposalId);
};
@@ -1317,6 +1350,9 @@ class TC_GAME_API ScriptMgr
void OnPlayerBattlegroundInvite(Player* player, uint32 instanceId, uint32 bgTypeId);
void OnPlayerBattlegroundPortFailed(Player* player, uint8 reason, uint32 instanceId);
void OnPlayerLfgJoin(Player* player, uint32 dungeonId, uint8 roles);
void OnPlayerGroupFinderListing(Player* player, uint32 categoryId, std::vector<uint32> const& activities, bool listed);
bool OnPlayerGroupFinderJoinRequest(Player* member, Player* applicant);
void OnPlayerGroupFinderSearch(Player* searcher);
void OnPlayerLfgProposal(Player* player, uint32 proposalId);
void OnPlayerChoiceResponse(WorldObject* object, Player* player, PlayerChoice const* choice, PlayerChoiceResponse const* response, uint16 clientIdentifier);
@@ -1356,8 +1392,10 @@ class TC_GAME_API ScriptMgr
public: /* UnitScript */
void OnHeal(Unit* healer, Unit* reciever, uint32& gain);
void OnHealOutcome(Unit* healer, Unit* target, uint32 spellId, uint32 raw, uint32 effective);
void OnDamage(Unit* attacker, Unit* victim, uint32& damage);
void OnDamageSpell(Unit* attacker, Unit* victim, uint32 damage, SpellInfo const* spellInfo);
void OnHitOutcome(Unit* attacker, Unit* victim, uint32 spellId, uint8 outcome, uint32 damage);
void ModifyPeriodicDamageAurasTick(Unit* target, Unit* attacker, uint32& damage);
void ModifyMeleeDamage(Unit* target, Unit* attacker, uint32& damage);
void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage, SpellInfo const* spellInfo);
+27 -15
View File
@@ -2965,6 +2965,8 @@ void Spell::TargetInfo::DoDamageAndTriggers(Spell* spell)
}
spell->m_damage = damageInfo.damage;
sScriptMgr->OnHitOutcome(caster, spell->unitTarget, spell->m_spellInfo->Id,
IsCrit ? HIT_OUTCOME_CRIT : MissCondition == SPELL_MISS_BLOCK ? HIT_OUTCOME_BLOCK : HIT_OUTCOME_HIT, damageInfo.damage);
caster->DealSpellDamage(&damageInfo, true);
// Send log damage message to client
@@ -2985,6 +2987,11 @@ void Spell::TargetInfo::DoDamageAndTriggers(Spell* spell)
// Fill base damage struct (unitTarget - is real spell target)
SpellNonMeleeDamage damageInfo(caster, spell->unitTarget, spell->m_spellInfo, spell->m_SpellVisual, spell->m_spellSchoolMask);
ProcHitMask |= createProcHitMask(&damageInfo, MissCondition);
// A hostile spell that missed, was dodged, parried or resisted
if (MissCondition == SPELL_MISS_MISS || MissCondition == SPELL_MISS_DODGE || MissCondition == SPELL_MISS_PARRY || MissCondition == SPELL_MISS_RESIST)
sScriptMgr->OnHitOutcome(caster, spell->unitTarget, spell->m_spellInfo->Id,
MissCondition == SPELL_MISS_MISS ? HIT_OUTCOME_MISS : MissCondition == SPELL_MISS_DODGE ? HIT_OUTCOME_DODGE
: MissCondition == SPELL_MISS_PARRY ? HIT_OUTCOME_PARRY : HIT_OUTCOME_RESIST, 0);
// Do triggers for unit
if (canEffectTrigger)
{
@@ -7514,21 +7521,26 @@ bool Spell::CanIncreaseRangeByMovement(Unit const* unit)
}
SpellRange Spell::GetMinMaxRange(bool strict) const
{
return CalcMinMaxRange(m_caster, m_targets.GetUnitTarget(), m_targets.GetCorpseTarget() != nullptr, m_spellInfo, strict, const_cast<Spell*>(this));
}
// The numbers CheckRange tests, available before any Spell exists (a bot picks its standing spot from the same minimum the cast will be held to)
SpellRange Spell::CalcMinMaxRange(WorldObject const* caster, Unit const* target, bool corpseTarget, SpellInfo const* spellInfo, bool strict, Spell* spell /*= nullptr*/)
{
float rangeMod = 0.0f;
SpellRange range;
if (strict && m_spellInfo->IsNextMeleeSwingSpell())
if (strict && spellInfo->IsNextMeleeSwingSpell())
{
range = { .Min = 0.0f, .Max = 100.0f };
return range;
}
Unit* unitCaster = m_caster->ToUnit();
if (m_spellInfo->RangeEntry)
Unit const* unitCaster = caster->ToUnit();
if (spellInfo->RangeEntry)
{
Unit* target = m_targets.GetUnitTarget();
if (m_spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE)
if (spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE)
{
// when the target is not a unit, take the caster's combat reach as the target's combat reach.
if (unitCaster)
@@ -7537,36 +7549,36 @@ SpellRange Spell::GetMinMaxRange(bool strict) const
else
{
float meleeRange = 0.0f;
if (m_spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED)
if (spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED)
{
// when the target is not a unit, take the caster's combat reach as the target's combat reach.
if (unitCaster)
meleeRange = unitCaster->GetMeleeRange(target ? target : unitCaster);
}
range = m_caster->GetSpellMinMaxRangeForTarget(target, m_spellInfo);
range = caster->GetSpellMinMaxRangeForTarget(target, spellInfo);
range.Min += meleeRange;
if (target || m_targets.GetCorpseTarget())
if (target || corpseTarget)
{
rangeMod = m_caster->GetCombatReach() + (target ? target->GetCombatReach() : m_caster->GetCombatReach());
rangeMod = caster->GetCombatReach() + (target ? target->GetCombatReach() : caster->GetCombatReach());
if (range.Min > 0.0f && !(m_spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED))
if (range.Min > 0.0f && !(spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED))
range.Min += rangeMod;
}
}
if (target && unitCaster && CanIncreaseRangeByMovement(target) && CanIncreaseRangeByMovement(unitCaster) &&
((m_spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE) || target->GetTypeId() == TYPEID_PLAYER))
((spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE) || target->GetTypeId() == TYPEID_PLAYER))
rangeMod += 8.0f / 3.0f;
}
if (m_spellInfo->HasAttribute(SPELL_ATTR0_USES_RANGED_SLOT) && m_caster->GetTypeId() == TYPEID_PLAYER)
if (Item* ranged = m_caster->ToPlayer()->GetWeaponForAttack(RANGED_ATTACK, true))
if (spellInfo->HasAttribute(SPELL_ATTR0_USES_RANGED_SLOT) && caster->GetTypeId() == TYPEID_PLAYER)
if (Item* ranged = caster->ToPlayer()->GetWeaponForAttack(RANGED_ATTACK, true))
range.Max *= ranged->GetTemplate()->GetRangedModRange() * 0.01f;
if (Player* modOwner = m_caster->GetSpellModOwner())
modOwner->ApplySpellMod(m_spellInfo, SpellModOp::Range, range.Max, const_cast<Spell*>(this));
if (Player* modOwner = caster->GetSpellModOwner())
modOwner->ApplySpellMod(spellInfo, SpellModOp::Range, range.Max, spell);
range.Max += rangeMod;
+1
View File
@@ -740,6 +740,7 @@ class TC_GAME_API Spell
static bool CanIncreaseRangeByMovement(Unit const* unit);
SpellRange GetMinMaxRange(bool strict) const;
static SpellRange CalcMinMaxRange(WorldObject const* caster, Unit const* target, bool corpseTarget, SpellInfo const* spellInfo, bool strict, Spell* spell = nullptr);
protected:
bool HasGlobalCooldown() const;