From 6b11f9a511ac5893b93f693b5320e3a89bb5f349 Mon Sep 17 00:00:00 2001 From: megamage Date: Mon, 13 Apr 2009 17:53:09 -0500 Subject: *Call new function InitializeAI() instead of Reset() to do one-time work. --HG-- branch : trunk --- src/bindings/scripts/include/sc_creature.h | 2 +- src/game/Creature.cpp | 2 +- src/game/CreatureAI.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index a545d47332b..40a331b7d6b 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -98,7 +98,7 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI //************* //Called at creature reset either by death or evade - virtual void Reset() = 0; + void Reset() {} //Called at creature aggro either by MoveInLOS or Attack Start virtual void Aggro(Unit*) = 0; diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 8e1be5145c4..0681dcddd04 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -620,7 +620,7 @@ bool Creature::AIM_Initialize(CreatureAI* ai) i_motionMaster.Initialize(); i_AI = ai ? ai : FactorySelector::selectAI(this); IsAIEnabled = true; - i_AI->Reset(); + i_AI->InitializeAI(); return true; } diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h index 275ecbeb3b4..b7a584fd36e 100644 --- a/src/game/CreatureAI.h +++ b/src/game/CreatureAI.h @@ -79,7 +79,8 @@ class TRINITY_DLL_SPEC UnitAI virtual void AttackStart(Unit *); virtual void UpdateAI(const uint32 diff) = 0; - // Initialize + virtual void InitializeAI() { Reset(); } + virtual void Reset() {}; // Called when unit is charmed -- cgit v1.2.3 From 25f71813c5666ad5105418601b5ea89e55f4516a Mon Sep 17 00:00:00 2001 From: megamage Date: Mon, 13 Apr 2009 18:03:28 -0500 Subject: *Update moveinLOS assistance code. --HG-- branch : trunk --- src/game/CreatureAI.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index 9d9a3fc3a63..d21fe43fcaa 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -23,6 +23,7 @@ #include "Player.h" #include "Pet.h" #include "SpellAuras.h" +#include "World.h" void UnitAI::AttackStart(Unit *victim) { @@ -72,22 +73,15 @@ void CreatureAI::OnCharmed(bool apply) void CreatureAI::MoveInLineOfSight(Unit *who) { - if(!me->getVictim() && me->canStartAttack(who)) - AttackStart(who); + if(me->getVictim()) + return; - if (who->isInCombat() && who->getVictim() && me->GetCreatureType()==CREATURE_TYPE_HUMANOID && me->IsFriendlyTo(who)) - { - if (me->GetDistanceZ(who) <= 2 && me->IsWithinLOSInMap(who)) - { - float attackRadius = (me->GetAttackDistance(who) *0.5); - if (me->IsWithinDistInMap(who, attackRadius)) - { - Unit* target = NULL; - target = who->getVictim(); - AttackStart(target); - } - } - } + if(me->canStartAttack(who)) + AttackStart(who); + else if(who->getVictim() && me->IsFriendlyTo(who) + && me->IsWithinDistInMap(who, sWorld.getConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_RADIUS)) + && me->canAttack(who->getVictim())) + AttackStart(who->getVictim()); } bool CreatureAI::UpdateVictim() -- cgit v1.2.3 From c5c6b4ff1b7bac973e3be9a5e6b91f473d596558 Mon Sep 17 00:00:00 2001 From: megamage Date: Mon, 13 Apr 2009 18:03:58 -0500 Subject: *Use function RandomResizeList to resize spell target list. --HG-- branch : trunk --- src/game/Spell.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src') diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 4396c2f94f1..ee9855dea09 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -2016,14 +2016,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,std::list &TagUnitMap) if(m_spellInfo->Id == 5246) //Intimidating Shout TagUnitMap.remove(m_targets.getUnitTarget()); - // remove random units from the map - std::list::iterator itr; - while(TagUnitMap.size() > unMaxTargets) - { - itr = TagUnitMap.begin(); - advance(itr, urand(0, TagUnitMap.size() - 1)); - TagUnitMap.erase(itr); - } + Trinity::RandomResizeList(TagUnitMap, unMaxTargets); } } -- cgit v1.2.3 From 57b33b244f281119e41f83f8b8655bb0042ec24d Mon Sep 17 00:00:00 2001 From: megamage Date: Mon, 13 Apr 2009 18:15:26 -0500 Subject: *Add Aura::m_tickNumber to handle some script spells. --HG-- branch : trunk --- src/game/SpellAuras.cpp | 10 +++++++--- src/game/SpellAuras.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index c3af4d70a43..1a837de8775 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -324,6 +324,7 @@ m_timeCla(1000), m_castItemGuid(castItem?castItem->GetGUID():0), m_auraSlot(MAX_ m_positive(false), m_permanent(false), m_isPeriodic(false), m_isTrigger(false), m_isAreaAura(false), m_isPersistent(false), m_updated(false), m_removeMode(AURA_REMOVE_BY_DEFAULT), m_isRemovedOnShapeLost(true), m_in_use(false), m_periodicTimer(0), m_PeriodicEventId(0), m_AuraDRGroup(DIMINISHING_NONE) +,m_tickNumber(0) { assert(target); @@ -578,6 +579,8 @@ void Aura::Update(uint32 diff) m_periodicTimer -= diff; if(m_periodicTimer <= 0) // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N { + ++m_tickNumber; + if( m_modifier.m_auraname == SPELL_AURA_MOD_REGEN || m_modifier.m_auraname == SPELL_AURA_MOD_POWER_REGEN || // Cannibalize, eating items and other spells @@ -5306,7 +5309,7 @@ void Aura::PeriodicTick() break; } } - m_modifier.m_amount += 100; + m_modifier.m_amount = 100 * m_tickNumber; }break; default: break; @@ -5341,11 +5344,12 @@ void Aura::PeriodicTick() // Curse of Agony damage-per-tick calculation if (GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (GetSpellProto()->SpellFamilyFlags & 0x0000000000000400LL) && GetSpellProto()->SpellIconID==544) { + uint32 totalTick = m_maxduration / m_modifier.periodictime; // 1..4 ticks, 1/2 from normal tick damage - if (m_duration>=((m_maxduration-m_modifier.periodictime)*2/3)) + if(m_tickNumber <= totalTick / 3) pdamage = pdamage/2; // 9..12 ticks, 3/2 from normal tick damage - else if(m_duration<((m_maxduration-m_modifier.periodictime)/3)) + else if(m_tickNumber > totalTick * 2 / 3) pdamage += (pdamage+1)/2; // +1 prevent 0.5 damage possible lost at 1..4 ticks // 5..8 ticks have normal tick damage } diff --git a/src/game/SpellAuras.h b/src/game/SpellAuras.h index 9d26d1b76dd..40552a3cb40 100644 --- a/src/game/SpellAuras.h +++ b/src/game/SpellAuras.h @@ -240,6 +240,7 @@ class TRINITY_DLL_SPEC Aura void UpdateAuraDuration(); void SendAuraDurationForCaster(Player* caster); void UpdateSlotCounterAndDuration(); + uint32 GetTickNumber() const { return m_tickNumber; } uint64 const& GetCasterGUID() const { return m_caster_guid; } Unit* GetCaster() const; @@ -321,6 +322,7 @@ class TRINITY_DLL_SPEC Aura Unit* m_target; int32 m_maxduration; int32 m_duration; + uint32 m_tickNumber; int32 m_timeCla; uint64 m_castItemGuid; // it is NOT safe to keep a pointer to the item because it may get deleted time_t m_applyTime; -- cgit v1.2.3