aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-10 16:26:00 -0700
committermaximius <none@none>2009-10-10 16:26:00 -0700
commit8ea2639b627a382ee3db4fc5701d95eb7907f7ce (patch)
tree9d4aa178eb5dd03dc21a2b02651b9be655f19d55
parent566472918bd658aa0a5352ca5cc462a3ca222d54 (diff)
*Creature::_IsTargetAcceptable rewrite, should hopefully fix the bugs ogeraisi reported.
*Creature health regen patch, written and tested by Gyullo. --HG-- branch : trunk
-rw-r--r--src/game/Creature.cpp80
-rw-r--r--src/game/CreatureAIImpl.h14
2 files changed, 54 insertions, 40 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index cc2bc64ae39..8e246cba4cc 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -533,30 +533,41 @@ void Creature::Update(uint32 diff)
if(!isAlive())
break;
+ if(m_regenTimer > 0)
+ {
+ if(diff >= m_regenTimer)
+ m_regenTimer = 0;
+ else
+ m_regenTimer -= diff;
+ }
+
+ if (m_regenTimer != 0)
+ break;
+
bool bIsPolymorphed = IsPolymorphed();
bool bInCombat = isInCombat() && (!getVictim() || // if isInCombat() is true and this has no victim
!getVictim()->GetCharmerOrOwnerPlayerOrPlayerItself() || // or the victim/owner/charmer is not a player
!getVictim()->GetCharmerOrOwnerPlayerOrPlayerItself()->isGameMaster()); // or the victim/owner/charmer is not a GameMaster
- if(m_regenTimer > diff && !bIsPolymorphed) // if polymorphed, skip the timer
- m_regenTimer -= diff;
- else
- {
- if(!bInCombat || bIsPolymorphed) // regenerate health if not in combat or if polymorphed
- RegenerateHealth();
-
- if(getPowerType() == POWER_ENERGY)
- {
- if(!IsVehicle() || GetVehicleKit()->GetVehicleInfo()->m_powerType != POWER_PYRITE)
- Regenerate(POWER_ENERGY);
- }
- else
- RegenerateMana();
+ /*if(m_regenTimer <= diff)
+ {*/
+ if(!bInCombat || bIsPolymorphed) // regenerate health if not in combat or if polymorphed
+ RegenerateHealth();
- if(!bIsPolymorphed) // only increase the timer if not polymorphed
- m_regenTimer += 2000 - diff;
+ if(getPowerType() == POWER_ENERGY)
+ {
+ if(!IsVehicle() || GetVehicleKit()->GetVehicleInfo()->m_powerType != POWER_PYRITE)
+ Regenerate(POWER_ENERGY);
}
+ else
+ RegenerateMana();
+ /*if(!bIsPolymorphed) // only increase the timer if not polymorphed
+ m_regenTimer += 2000 - diff;
+ }
+ else
+ if(!bIsPolymorphed) // if polymorphed, skip the timer
+ m_regenTimer -= diff;*/
break;
}
case DEAD_FALLING:
@@ -2173,31 +2184,38 @@ bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /
// use this function to avoid having hostile creatures attack
// friendlies and other mobs they shouldn't attack
-bool Creature::_IsTargetAcceptable(const Unit* target) const
+bool Creature::_IsTargetAcceptable(const Unit *target) const
{
- if(IsFriendlyTo(target)) // friends shouldn't fight friends
- return false;
-
- const Unit* targetVictim = target->getAttackerForHelper();
+ const Unit *myVictim = getAttackerForHelper();
- if(!targetVictim) // if target does not have a victim, the target is acceptable
+ // if I'm already fighting target, the target is acceptable
+ if (myVictim == target)
return true;
- const Player* targetVictimPlayer = targetVictim->GetCharmerOrOwnerPlayerOrPlayerItself();
+ // if I'm not aggressive, the target is not acceptable
+ if (GetReactState() != REACT_AGGRESSIVE)
+ return false;
- if(!targetVictimPlayer) // if the victim is not a player, the target is acceptable
+ // if I'm hostile towards the target, the target is acceptable
+ if (IsHostileTo(target))
return true;
- // if the victim is a non-friendly player, the target is not acceptable
- if(!IsFriendlyTo(targetVictim))
+ // if the target is passive, the target is not acceptable
+ if (((Creature*)target)->GetReactState() == REACT_PASSIVE)
return false;
- // if the target is passive, the target is not acceptable
- if(((Creature*)target)->GetReactState() == REACT_PASSIVE)
+ const Unit *targetVictim = target->getAttackerForHelper();
+
+ // if the target does not have a victim, the target is not acceptable
+ if (!targetVictim)
return false;
-
- // otherwise, the target is acceptable
- return true;
+
+ // if the target's victim is friendly, and the target is neutral, the target is acceptable
+ if (IsFriendlyTo(targetVictim) && !IsFriendlyTo(target))
+ return true;
+
+ // if the target's victim is not friendly, or the target is friendly, the target is not acceptable
+ return false;
}
void Creature::SaveRespawnTime()
diff --git a/src/game/CreatureAIImpl.h b/src/game/CreatureAIImpl.h
index be11a35095b..89d5bbc2a9e 100644
--- a/src/game/CreatureAIImpl.h
+++ b/src/game/CreatureAIImpl.h
@@ -488,7 +488,7 @@ inline void CreatureAI::SetGazeOn(Unit *target)
if(me->canAttack(target))
{
AttackStart(target);
- me->SetReactState(REACT_AGGRESSIVE);
+ me->SetReactState(REACT_PASSIVE);
}
}
@@ -524,7 +524,6 @@ inline bool CreatureAI::UpdateCombatState()
else if(me->getThreatManager().isThreatListEmpty())
{
EnterEvadeMode();
- me->SetReactState(REACT_PASSIVE);
return false;
}
@@ -545,7 +544,6 @@ inline bool CreatureAI::UpdateVictim()
else if(me->getThreatManager().isThreatListEmpty())
{
EnterEvadeMode();
- me->SetReactState(REACT_PASSIVE);
return false;
}
@@ -569,18 +567,16 @@ inline bool CreatureAI::_EnterEvadeMode()
return false;
// sometimes bosses stuck in combat?
+ me->RemoveAllAuras();
me->DeleteThreatList();
me->CombatStop(true);
+ me->LoadCreaturesAddon();
+ me->SetLootRecipient(NULL);
me->ResetPlayerDamageReq();
-
+
if(me->IsInEvadeMode())
return false;
- me->RemoveAllAuras();
- me->LoadCreaturesAddon();
- me->SetLootRecipient(NULL);
- me->SetReactState(REACT_AGGRESSIVE);
-
return true;
}