mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Casting tweaks
This commit is contained in:
@@ -1473,7 +1473,7 @@ bool PlayerbotAI::IsTellAllowed(PlayerbotSecurityLevel securityLevel)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (sPlayerbotAIConfig->whisperDistance && !bot->GetGroup() && sRandomPlayerbotMgr->IsRandomBot(bot) && master->GetSession()->GetSecurity() < SEC_GAMEMASTER &&
|
if (sPlayerbotAIConfig->whisperDistance && !bot->GetGroup() && sRandomPlayerbotMgr->IsRandomBot(bot) && master->GetSession()->GetSecurity() < SEC_GAMEMASTER &&
|
||||||
(bot->GetMapId() != master->GetMapId() || bot->GetDistance(master) > sPlayerbotAIConfig->whisperDistance))
|
(bot->GetMapId() != master->GetMapId() || sServerFacade->GetDistance2d(bot, master) > sPlayerbotAIConfig->whisperDistance))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1687,7 +1687,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bot != target && bot->GetDistance(target) > sPlayerbotAIConfig->sightDistance)
|
if (bot != target && sServerFacade->GetDistance2d(bot, target) > sPlayerbotAIConfig->sightDistance)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1756,7 +1756,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, GameObject* goTarget, uint8 effec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bot->GetDistance(goTarget) > sPlayerbotAIConfig->sightDistance)
|
if (sServerFacade->GetDistance2d(bot, goTarget) > sPlayerbotAIConfig->sightDistance)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ObjectGuid oldSel = bot->GetTarget();
|
ObjectGuid oldSel = bot->GetTarget();
|
||||||
@@ -1899,10 +1899,8 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
|
|||||||
WorldObject* faceTo = target;
|
WorldObject* faceTo = target;
|
||||||
if (!bot->HasInArc(CAST_ANGLE_IN_FRONT, faceTo))
|
if (!bot->HasInArc(CAST_ANGLE_IN_FRONT, faceTo))
|
||||||
{
|
{
|
||||||
if (!bot->isMoving())
|
sServerFacade->SetFacingTo(bot, faceTo);
|
||||||
bot->SetFacingToObject(faceTo);
|
//failWithDelay = true;
|
||||||
|
|
||||||
failWithDelay = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failWithDelay)
|
if (failWithDelay)
|
||||||
@@ -1962,17 +1960,18 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spell->prepare(&targets);
|
|
||||||
|
|
||||||
if (bot->isMoving() && spell->GetCastTime())
|
if (bot->isMoving() && spell->GetCastTime())
|
||||||
{
|
{
|
||||||
bot->StopMoving();
|
bot->StopMoving();
|
||||||
SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown);
|
// SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown);
|
||||||
spell->cancel();
|
// spell->cancel();
|
||||||
//delete spell;
|
//delete spell;
|
||||||
return false;
|
// return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spell->prepare(&targets);
|
||||||
|
SpellCastResult spellSuccess = spell->CheckCast(true);
|
||||||
|
|
||||||
if (spellInfo->Effects[0].Effect == SPELL_EFFECT_OPEN_LOCK || spellInfo->Effects[0].Effect == SPELL_EFFECT_SKINNING)
|
if (spellInfo->Effects[0].Effect == SPELL_EFFECT_OPEN_LOCK || spellInfo->Effects[0].Effect == SPELL_EFFECT_SKINNING)
|
||||||
{
|
{
|
||||||
LootObject loot = *aiObjectContext->GetValue<LootObject>("loot target");
|
LootObject loot = *aiObjectContext->GetValue<LootObject>("loot target");
|
||||||
@@ -1984,8 +1983,13 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (spellSuccess != SPELL_CAST_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
WaitForSpellCast(spell);
|
WaitForSpellCast(spell);
|
||||||
aiObjectContext->GetValue<LastSpellCast&>("last spell cast")->Get().Set(spellId, target->GetGUID(), time(nullptr));
|
if (spell->GetCastTime())
|
||||||
|
aiObjectContext->GetValue<LastSpellCast&>("last spell cast")->Get().Set(spellId, target->GetGUID(), time(nullptr));
|
||||||
|
|
||||||
aiObjectContext->GetValue<PositionMap&>("position")->Get()["random"].Reset();
|
aiObjectContext->GetValue<PositionMap&>("position")->Get()["random"].Reset();
|
||||||
|
|
||||||
if (oldSel)
|
if (oldSel)
|
||||||
@@ -2367,6 +2371,9 @@ bool PlayerbotAI::IsInVehicle(bool canControl, bool canCast, bool canAttack, boo
|
|||||||
if (!vehicleBase || !vehicleBase->IsAlive())
|
if (!vehicleBase || !vehicleBase->IsAlive())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!vehicle->GetVehicleInfo())
|
||||||
|
return false;
|
||||||
|
|
||||||
// get seat
|
// get seat
|
||||||
VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(bot);
|
VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(bot);
|
||||||
if (!seat)
|
if (!seat)
|
||||||
@@ -2480,7 +2487,6 @@ bool PlayerbotAI::IsInterruptableSpellCasting(Unit* target, std::string const sp
|
|||||||
bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
|
bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
|
||||||
{
|
{
|
||||||
bool isFriend = bot->IsFriendlyTo(target);
|
bool isFriend = bot->IsFriendlyTo(target);
|
||||||
bool isHostile = bot->IsHostileTo(target);
|
|
||||||
for (uint32 type = SPELL_AURA_NONE; type < TOTAL_AURAS; ++type)
|
for (uint32 type = SPELL_AURA_NONE; type < TOTAL_AURAS; ++type)
|
||||||
{
|
{
|
||||||
Unit::AuraEffectList const& auras = target->GetAuraEffectsByType((AuraType)type);
|
Unit::AuraEffectList const& auras = target->GetAuraEffectsByType((AuraType)type);
|
||||||
@@ -2493,7 +2499,7 @@ bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
|
|||||||
if (isPositiveSpell && isFriend)
|
if (isPositiveSpell && isFriend)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!isPositiveSpell && isHostile)
|
if (!isPositiveSpell && !isFriend)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() && aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration)
|
if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() && aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration)
|
||||||
@@ -2673,7 +2679,7 @@ bool PlayerbotAI::HasManyPlayersNearby(uint32 trigerrValue, float range)
|
|||||||
|
|
||||||
for (auto& player : sRandomPlayerbotMgr->GetPlayers())
|
for (auto& player : sRandomPlayerbotMgr->GetPlayers())
|
||||||
{
|
{
|
||||||
if ((!player->IsGameMaster() || player->isGMVisible()) && player->GetDistance(bot) < sqRange)
|
if ((!player->IsGameMaster() || player->isGMVisible()) && sServerFacade->GetDistance2d(player, bot) < sqRange)
|
||||||
{
|
{
|
||||||
found++;
|
found++;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SpellIdValue.h"
|
#include "SpellIdValue.h"
|
||||||
|
|
||||||
|
#include <ranges>
|
||||||
#include "ChatHelper.h"
|
#include "ChatHelper.h"
|
||||||
#include "Playerbots.h"
|
#include "Playerbots.h"
|
||||||
#include "Vehicle.h"
|
#include "Vehicle.h"
|
||||||
@@ -95,22 +97,65 @@ uint32 SpellIdValue::Calculate()
|
|||||||
if (spellIds.empty()) return 0;
|
if (spellIds.empty()) return 0;
|
||||||
|
|
||||||
int32 saveMana = (int32)round(AI_VALUE(double, "mana save level"));
|
int32 saveMana = (int32)round(AI_VALUE(double, "mana save level"));
|
||||||
int32 rank = 1;
|
uint32 rank = 1;
|
||||||
int32 highest = 0;
|
uint32 highestRank = 0;
|
||||||
int32 lowest = 0;
|
uint32 highestSpellId = 0;
|
||||||
for (std::set<uint32>::reverse_iterator i = spellIds.rbegin(); i != spellIds.rend(); ++i)
|
uint32 lowestRank = 0;
|
||||||
|
uint32 lowestSpellId = 0;
|
||||||
|
if (saveMana <= 1)
|
||||||
{
|
{
|
||||||
if (!highest)
|
for (uint32 spellId : std::ranges::reverse_view(spellIds))
|
||||||
highest = *i;
|
{
|
||||||
|
const SpellInfo *pSpellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||||
|
if (!pSpellInfo)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (saveMana == rank)
|
std::string spellName = pSpellInfo->Rank[0];
|
||||||
return *i;
|
|
||||||
|
|
||||||
lowest = *i;
|
// For atoi, the input string has to start with a digit, so lets search for the first digit
|
||||||
++rank;
|
size_t i = 0;
|
||||||
|
for (; i < spellName.length(); i++)
|
||||||
|
{ if (isdigit(spellName[i])) break; }
|
||||||
|
|
||||||
|
// remove the first chars, which aren't digits
|
||||||
|
spellName = spellName.substr(i, spellName.length() - i);
|
||||||
|
|
||||||
|
// convert the remaining text to an integer
|
||||||
|
int id = atoi(spellName.c_str());
|
||||||
|
|
||||||
|
if (!id)
|
||||||
|
{
|
||||||
|
highestSpellId = spellId;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!highestRank || id > highestRank)
|
||||||
|
{
|
||||||
|
highestRank = id;
|
||||||
|
highestSpellId = spellId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lowestRank || (lowestRank && id < lowestRank))
|
||||||
|
{
|
||||||
|
lowestRank = id;
|
||||||
|
lowestSpellId = spellId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (uint32 spellId : std::ranges::reverse_view(spellIds))
|
||||||
|
{
|
||||||
|
if (!highestSpellId)
|
||||||
|
highestSpellId = spellId;
|
||||||
|
if (saveMana == rank)
|
||||||
|
return spellId;
|
||||||
|
lowestSpellId = spellId;
|
||||||
|
rank++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveMana > 1 ? lowest : highest;
|
return saveMana > 1 ? lowestSpellId : highestSpellId;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 VehicleSpellIdValue::Calculate()
|
uint32 VehicleSpellIdValue::Calculate()
|
||||||
|
|||||||
Reference in New Issue
Block a user