More castcheck improvements

This commit is contained in:
nytmyr
2024-12-12 08:01:15 -06:00
parent 90fe8a31d7
commit 4019e7da65
3 changed files with 50 additions and 74 deletions
+15 -10
View File
@@ -9663,6 +9663,21 @@ bool Bot::CastChecks(uint16 spell_id, Mob* tar, uint16 spellType, bool doPrechec
return false; return false;
} }
if (tar->GetSpecialAbility(SpecialAbility::MagicImmunity)) {
LogBotPreChecksDetail("{} says, 'Cancelling cast of {} on {} due to MagicImmunity.'", GetCleanName(), GetSpellName(spell_id), tar->GetCleanName()); //deleteme
return false;
}
if (tar->GetSpecialAbility(SpecialAbility::CastingFromRangeImmunity) && !CombatRange(tar)) {
LogBotPreChecksDetail("{} says, 'Cancelling cast of {} on {} due to CastingFromRangeImmunity.'", GetCleanName(), GetSpellName(spell_id), tar->GetCleanName()); //deleteme
return false;
}
if (tar->IsImmuneToBotSpell(spell_id, this)) {
LogBotPreChecksDetail("{} says, 'Cancelling cast of {} on {} due to IsImmuneToBotSpell.'", GetCleanName(), GetSpellName(spell_id), tar->GetCleanName()); //deleteme
return false;
}
if (!AECheck && !IsValidSpellRange(spell_id, tar)) { if (!AECheck && !IsValidSpellRange(spell_id, tar)) {
LogBotPreChecksDetail("{} says, 'Cancelling cast of {} on {} due to IsValidSpellRange.'", GetCleanName(), GetSpellName(spell_id), tar->GetCleanName()); //deleteme LogBotPreChecksDetail("{} says, 'Cancelling cast of {} on {} due to IsValidSpellRange.'", GetCleanName(), GetSpellName(spell_id), tar->GetCleanName()); //deleteme
return false; return false;
@@ -9687,16 +9702,6 @@ bool Bot::CastChecks(uint16 spell_id, Mob* tar, uint16 spellType, bool doPrechec
return false; return false;
} }
if (tar->GetSpecialAbility(SpecialAbility::CastingFromRangeImmunity) && !CombatRange(tar)) {
LogBotPreChecksDetail("{} says, 'Cancelling cast of {} on {} due to IMMUNE_CASTING_FROM_RANGE.'", GetCleanName(), GetSpellName(spell_id), tar->GetCleanName()); //deleteme
return false;
}
if (tar->IsImmuneToBotSpell(spell_id, this)) {
LogBotPreChecksDetail("{} says, 'Cancelling cast of {} on {} due to IsImmuneToBotSpell.'", GetCleanName(), GetSpellName(spell_id), tar->GetCleanName()); //deleteme
return false;
}
if ( if (
(RequiresStackCheck(spellType) || (!RequiresStackCheck(spellType) && CalcBuffDuration(this, tar, spell_id) != 0)) (RequiresStackCheck(spellType) || (!RequiresStackCheck(spellType) && CalcBuffDuration(this, tar, spell_id) != 0))
&& &&
+1 -22
View File
@@ -207,7 +207,7 @@ bool Bot::AICastSpell(Mob* tar, uint8 iChance, uint16 spellType, uint16 subTarge
break; break;
case BotSpellTypes::Charm: case BotSpellTypes::Charm:
if (tar->IsCharmed() || !tar->IsNPC() || tar->GetSpecialAbility(SpecialAbility::CharmImmunity)) { if (HasPet() || tar->IsCharmed() || !tar->IsNPC() || tar->GetSpecialAbility(SpecialAbility::CharmImmunity)) {
return false; return false;
} }
@@ -596,27 +596,6 @@ bool Bot::AIDoSpellCast(int32 i, Mob* tar, int32 mana_cost, uint32* oDontDoAgain
} else } else
dist2 = DistanceSquared(m_Position, tar->GetPosition()); dist2 = DistanceSquared(m_Position, tar->GetPosition());
//if (
// (
// (
// (
// (spells[AIBot_spells[i].spellid].target_type==ST_GroupTeleport && AIBot_spells[i].type == BotSpellTypes::RegularHeal) ||
// spells[AIBot_spells[i].spellid].target_type ==ST_AECaster ||
// spells[AIBot_spells[i].spellid].target_type ==ST_Group ||
// spells[AIBot_spells[i].spellid].target_type ==ST_AEBard ||
// (
// tar == this && spells[AIBot_spells[i].spellid].target_type != ST_TargetsTarget
// )
// ) &&
// dist2 <= spells[AIBot_spells[i].spellid].aoe_range*spells[AIBot_spells[i].spellid].aoe_range
// ) ||
// dist2 <= GetActSpellRange(AIBot_spells[i].spellid, spells[AIBot_spells[i].spellid].range)*GetActSpellRange(AIBot_spells[i].spellid, spells[AIBot_spells[i].spellid].range)
// ) &&
// (
// mana_cost <= GetMana() ||
// IsBotNonSpellFighter()
// )
//) {
if (IsValidSpellRange(AIBot_spells[i].spellid, tar) && (mana_cost <= GetMana() || IsBotNonSpellFighter())) { if (IsValidSpellRange(AIBot_spells[i].spellid, tar) && (mana_cost <= GetMana() || IsBotNonSpellFighter())) {
casting_spell_AIindex = i; casting_spell_AIindex = i;
LogAI("spellid [{}] tar [{}] mana [{}] Name [{}]", AIBot_spells[i].spellid, tar->GetName(), mana_cost, spells[AIBot_spells[i].spellid].name); LogAI("spellid [{}] tar [{}] mana [{}] Name [{}]", AIBot_spells[i].spellid, tar->GetName(), mana_cost, spells[AIBot_spells[i].spellid].name);
+34 -42
View File
@@ -7579,8 +7579,9 @@ bool Mob::IsImmuneToBotSpell(uint16 spell_id, Mob* caster)
{ {
int effect_index; int effect_index;
if (caster == nullptr) if (caster == nullptr) {
return(false); return(false);
}
//TODO: this function loops through the effect list for //TODO: this function loops through the effect list for
//this spell like 10 times, this could easily be consolidated //this spell like 10 times, this could easily be consolidated
@@ -7588,14 +7589,19 @@ bool Mob::IsImmuneToBotSpell(uint16 spell_id, Mob* caster)
LogSpells("Checking to see if we are immune to spell [{}] cast by [{}]", spell_id, caster->GetName()); LogSpells("Checking to see if we are immune to spell [{}] cast by [{}]", spell_id, caster->GetName());
if (!IsValidSpell(spell_id)) if (!IsValidSpell(spell_id)) {
return true; return true;
}
if (IsBeneficialSpell(spell_id) && (caster->GetNPCTypeID())) //then skip the rest, stop NPCs aggroing each other with buff spells. 2013-03-05 if (IsDispelSpell(spell_id) && GetSpecialAbility(SpecialAbility::DispellImmunity)) {
return false; return false;
}
if (IsMesmerizeSpell(spell_id)) if (IsHarmonySpell(spell_id) && GetSpecialAbility(SpecialAbility::PacifyImmunity)) {
{ return false;
}
if (IsMesmerizeSpell(spell_id)) {
if (GetSpecialAbility(SpecialAbility::MesmerizeImmunity)) { if (GetSpecialAbility(SpecialAbility::MesmerizeImmunity)) {
return true; return true;
} }
@@ -7604,90 +7610,76 @@ bool Mob::IsImmuneToBotSpell(uint16 spell_id, Mob* caster)
effect_index = GetSpellEffectIndex(spell_id, SE_Mez); effect_index = GetSpellEffectIndex(spell_id, SE_Mez);
assert(effect_index >= 0); assert(effect_index >= 0);
// NPCs get to ignore the max level // NPCs get to ignore the max level
if ((GetLevel() > spells[spell_id].max_value[effect_index]) && if (
(!caster->IsNPC() || (caster->IsNPC() && !RuleB(Spells, NPCIgnoreBaseImmunity)))) (GetLevel() > spells[spell_id].max_value[effect_index]) &&
{ (!caster->IsNPC() || (caster->IsNPC() && !RuleB(Spells, NPCIgnoreBaseImmunity)))
) {
return true; return true;
} }
} }
// slow and haste spells // slow and haste spells
if (GetSpecialAbility(SpecialAbility::SlowImmunity) && IsEffectInSpell(spell_id, SE_AttackSpeed)) if (GetSpecialAbility(SpecialAbility::SlowImmunity) && IsEffectInSpell(spell_id, SE_AttackSpeed)) {
{
return true; return true;
} }
// client vs client fear // client vs client fear
if (IsEffectInSpell(spell_id, SE_Fear)) if (IsEffectInSpell(spell_id, SE_Fear)) {
{
effect_index = GetSpellEffectIndex(spell_id, SE_Fear); effect_index = GetSpellEffectIndex(spell_id, SE_Fear);
if (GetSpecialAbility(SpecialAbility::FearImmunity)) { if (GetSpecialAbility(SpecialAbility::FearImmunity)) {
return true; return true;
} }
else if (IsClient() && caster->IsClient() && (caster->CastToClient()->GetGM() == false)) else if (IsClient() && caster->IsClient() && (caster->CastToClient()->GetGM() == false)) {
{
LogSpells("Clients cannot fear eachother!"); LogSpells("Clients cannot fear eachother!");
caster->MessageString(Chat::Red, IMMUNE_FEAR); // need to verify message type, not in MQ2Cast for easy look up caster->MessageString(Chat::Red, IMMUNE_FEAR); // need to verify message type, not in MQ2Cast for easy look up
return true; return true;
} }
else if (GetLevel() > spells[spell_id].max_value[effect_index] && spells[spell_id].max_value[effect_index] != 0) else if (GetLevel() > spells[spell_id].max_value[effect_index] && spells[spell_id].max_value[effect_index] != 0) {
{
return true; return true;
} }
else if (CheckAATimer(aaTimerWarcry)) else if (CheckAATimer(aaTimerWarcry)) {
{
return true; return true;
} }
} }
if (IsCharmSpell(spell_id)) if (IsCharmSpell(spell_id)) {
{ if (GetSpecialAbility(SpecialAbility::CharmImmunity)) {
if (GetSpecialAbility(SpecialAbility::CharmImmunity))
{
return true; return true;
} }
if (this == caster) if (this == caster) {
{
return true; return true;
} }
//let npcs cast whatever charm on anyone //let npcs cast whatever charm on anyone
if (!caster->IsNPC()) if (!caster->IsNPC()) {
{
// check level limit of charm spell // check level limit of charm spell
effect_index = GetSpellEffectIndex(spell_id, SE_Charm); effect_index = GetSpellEffectIndex(spell_id, SE_Charm);
assert(effect_index >= 0); assert(effect_index >= 0);
if (GetLevel() > spells[spell_id].max_value[effect_index] && spells[spell_id].max_value[effect_index] != 0) if (GetLevel() > spells[spell_id].max_value[effect_index] && spells[spell_id].max_value[effect_index] != 0) {
{
return true; return true;
} }
} }
} }
if if (
( IsEffectInSpell(spell_id, SE_Root) ||
IsEffectInSpell(spell_id, SE_Root) || IsEffectInSpell(spell_id, SE_MovementSpeed)
IsEffectInSpell(spell_id, SE_MovementSpeed) ) {
)
{
if (GetSpecialAbility(SpecialAbility::SnareImmunity)) { if (GetSpecialAbility(SpecialAbility::SnareImmunity)) {
return true; return true;
} }
} }
if (IsLifetapSpell(spell_id)) if (IsLifetapSpell(spell_id)) {
{ if (this == caster) {
if (this == caster)
{
return true; return true;
} }
} }
if (IsSacrificeSpell(spell_id)) if (IsSacrificeSpell(spell_id)) {
{ if (this == caster) {
if (this == caster)
{
return true; return true;
} }
} }