diff options
| author | QAston <none@none> | 2009-05-15 18:00:50 +0200 |
|---|---|---|
| committer | QAston <none@none> | 2009-05-15 18:00:50 +0200 |
| commit | a796012723dd2410a150264a4f32f00bc570ef76 (patch) | |
| tree | d55cada7db3c9c752815c79d9d164069acd99edc /src/bindings/scripts/include | |
| parent | ae461a4158d6376e28e7bc53d3f7ad5690a5064e (diff) | |
| parent | ad92f5e210b7a2c0584cdabd30560fe723d160be (diff) | |
*Merge some fixes from tc1
--HG--
branch : trunk
Diffstat (limited to 'src/bindings/scripts/include')
| -rw-r--r-- | src/bindings/scripts/include/precompiled.h | 3 | ||||
| -rw-r--r-- | src/bindings/scripts/include/sc_creature.cpp | 285 | ||||
| -rw-r--r-- | src/bindings/scripts/include/sc_creature.h | 122 | ||||
| -rw-r--r-- | src/bindings/scripts/include/sc_instance.h | 13 |
4 files changed, 153 insertions, 270 deletions
diff --git a/src/bindings/scripts/include/precompiled.h b/src/bindings/scripts/include/precompiled.h index 2c36cc924e0..fa676f460ef 100644 --- a/src/bindings/scripts/include/precompiled.h +++ b/src/bindings/scripts/include/precompiled.h @@ -12,10 +12,11 @@ #include "GridNotifiersImpl.h" #include "Unit.h" #include "GameObject.h" -#include "TemporarySummon.h" #include "sc_creature.h" #include "sc_gossip.h" #include "sc_instance.h" +#include "AggressorAI.h" +#include "NullCreatureAI.h" #ifdef WIN32 #include <windows.h> diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index 258c7627dce..e575e40fac1 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -9,6 +9,7 @@ #include "Item.h" #include "Spell.h" #include "ObjectMgr.h" +#include "TemporarySummon.h" // Spell summary for ScriptedAI::SelectSpell struct TSpellSummary { @@ -16,13 +17,26 @@ struct TSpellSummary { uint8 Effects; // set of enum SelectEffect } *SpellSummary; +void SummonList::DoZoneInCombat(uint32 entry) +{ + for(iterator i = begin(); i != end();) + { + Creature *summon = Unit::GetCreature(*m_creature, *i); + ++i; + if(summon && summon->IsAIEnabled + && (!entry || summon->GetEntry() == entry)) + summon->AI()->DoZoneInCombat(); + } +} + void SummonList::DoAction(uint32 entry, uint32 info) { for(iterator i = begin(); i != end();) { Creature *summon = Unit::GetCreature(*m_creature, *i); ++i; - if(summon && summon->IsAIEnabled) + if(summon && summon->IsAIEnabled + && (!entry || summon->GetEntry() == entry)) summon->AI()->DoAction(info); } } @@ -55,7 +69,11 @@ void SummonList::DespawnAll() else { erase(begin()); - summon->setDeathState(JUST_DIED); + summon->SetVisibility(VISIBILITY_OFF); + if(summon->HasSummonMask(SUMMON_MASK_SUMMON) && !summon->isPet()) + ((TempSummon*)summon)->UnSummon(); + else + summon->setDeathState(JUST_DIED); summon->RemoveCorpse(); } } @@ -108,26 +126,6 @@ void ScriptedAI::UpdateAI(const uint32 diff) } } -void ScriptedAI::EnterEvadeMode() -{ - //m_creature->InterruptNonMeleeSpells(true); - m_creature->RemoveAllAuras(); - m_creature->DeleteThreatList(); - m_creature->CombatStop(); - m_creature->LoadCreaturesAddon(); - m_creature->SetLootRecipient(NULL); - - if(m_creature->isAlive()) - m_creature->GetMotionMaster()->MoveTargetedHome(); - - Reset(); -} - -void ScriptedAI::JustRespawned() -{ - Reset(); -} - void ScriptedAI::DoStartMovement(Unit* victim, float distance, float angle) { if (!victim) @@ -228,6 +226,19 @@ Creature* ScriptedAI::DoSpawnCreature(uint32 id, float x, float y, float z, floa return m_creature->SummonCreature(id,m_creature->GetPositionX() + x,m_creature->GetPositionY() + y,m_creature->GetPositionZ() + z, angle, (TempSummonType)type, despawntime); } +Creature *ScriptedAI::DoSummon(uint32 entry, const float pos[4], uint32 despawntime, TempSummonType type) +{ + return me->SummonCreature(entry, pos[0], pos[1], pos[2], pos[3], type, despawntime); +} + +Creature *ScriptedAI::DoSummon(uint32 entry, WorldObject *obj, float radius, uint32 despawntime, TempSummonType type) +{ + float x, y, z; + obj->GetGroundPointAroundUnit(x, y, z, radius * rand_norm(), rand_norm()*2*M_PI); + return me->SummonCreature(entry, x, y, z, me->GetOrientation(), type, despawntime); +} + + Unit* ScriptedAI::SelectUnit(SelectAggroTarget target, uint32 position) { //ThreatList m_threatlist; @@ -259,147 +270,7 @@ Unit* ScriptedAI::SelectUnit(SelectAggroTarget target, uint32 position) return NULL; } -struct TargetDistanceOrder : public std::binary_function<const Unit, const Unit, bool> -{ - const Unit* me; - TargetDistanceOrder(const Unit* Target) : me(Target) {}; - // functor for operator ">" - bool operator()(const Unit* _Left, const Unit* _Right) const - { - return (me->GetDistance(_Left) < me->GetDistance(_Right)); - } -}; - -Unit* ScriptedAI::SelectUnit(SelectAggroTarget targetType, uint32 position, float dist, bool playerOnly) -{ - if(targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) - { - std::list<HostilReference*> &m_threatlist = m_creature->getThreatManager().getThreatList(); - if(m_threatlist.empty()) return NULL; - std::list<Unit*> targetList; - std::list<HostilReference*>::iterator itr = m_threatlist.begin(); - for(; itr!= m_threatlist.end(); ++itr) - { - Unit *target = (*itr)->getTarget(); - if(!target - || playerOnly && target->GetTypeId() != TYPEID_PLAYER - || dist && !m_creature->IsWithinCombatRange(target, dist)) - { - continue; - } - targetList.push_back(target); - } - if(position >= targetList.size()) - return NULL; - targetList.sort(TargetDistanceOrder(m_creature)); - if(targetType == SELECT_TARGET_NEAREST) - { - std::list<Unit*>::iterator i = targetList.begin(); - advance(i, position); - return *i; - } - else - { - std::list<Unit*>::reverse_iterator i = targetList.rbegin(); - advance(i, position); - return *i; - } - } - else - { - std::list<HostilReference*> m_threatlist = m_creature->getThreatManager().getThreatList(); - std::list<HostilReference*>::iterator i; - Unit *target; - while(position < m_threatlist.size()) - { - if(targetType == SELECT_TARGET_BOTTOMAGGRO) - { - i = m_threatlist.end(); - advance(i, - (int32)position - 1); - } - else - { - i = m_threatlist.begin(); - if(targetType == SELECT_TARGET_TOPAGGRO) - advance(i, position); - else // random - advance(i, position + rand()%(m_threatlist.size() - position)); - } - - target = (*i)->getTarget(); - if(!target - || playerOnly && target->GetTypeId() != TYPEID_PLAYER - || dist && !m_creature->IsWithinCombatRange(target, dist)) - { - m_threatlist.erase(i); - } - else - { - return target; - } - } - } - - return NULL; -} - -void ScriptedAI::SelectUnitList(std::list<Unit*> &targetList, uint32 num, SelectAggroTarget targetType, float dist, bool playerOnly) -{ - if(targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) - { - std::list<HostilReference*> &m_threatlist = m_creature->getThreatManager().getThreatList(); - if(m_threatlist.empty()) return; - std::list<HostilReference*>::iterator itr = m_threatlist.begin(); - for(; itr!= m_threatlist.end(); ++itr) - { - Unit *target = (*itr)->getTarget(); - if(!target - || playerOnly && target->GetTypeId() != TYPEID_PLAYER - || dist && !m_creature->IsWithinCombatRange(target, dist)) - { - continue; - } - targetList.push_back(target); - } - targetList.sort(TargetDistanceOrder(m_creature)); - targetList.resize(num); - if(targetType == SELECT_TARGET_FARTHEST) - targetList.reverse(); - } - else - { - std::list<HostilReference*> m_threatlist = m_creature->getThreatManager().getThreatList(); - std::list<HostilReference*>::iterator i; - Unit *target; - while(m_threatlist.size() && num) - { - if(targetType == SELECT_TARGET_BOTTOMAGGRO) - { - i = m_threatlist.end(); - --i; - } - else - { - i = m_threatlist.begin(); - if(targetType == SELECT_TARGET_RANDOM) - advance(i, rand()%m_threatlist.size()); - } - - target = (*i)->getTarget(); - m_threatlist.erase(i); - if(!target - || playerOnly && target->GetTypeId() != TYPEID_PLAYER - || dist && !m_creature->IsWithinCombatRange(target, dist)) - { - continue; - } - targetList.push_back(target); - --num; - } - } -} - -SpellEntry const* ScriptedAI::SelectSpell(Unit* Target, int32 School, int32 Mechanic, SelectTarget Targets, uint32 PowerCostMin, uint32 PowerCostMax, float RangeMin, float RangeMax, SelectEffect Effects) +SpellEntry const* ScriptedAI::SelectSpell(Unit* Target, int32 School, int32 Mechanic, SelectTargetType Targets, uint32 PowerCostMin, uint32 PowerCostMax, float RangeMin, float RangeMax, SelectEffect Effects) { //No target so we can't cast if (!Target) @@ -515,7 +386,6 @@ bool ScriptedAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered) return true; } - float GetSpellMaxRangeForHostile(uint32 id) { SpellEntry const *spellInfo = GetSpellStore()->LookupEntry(id); @@ -531,7 +401,7 @@ void FillSpellSummary() SpellEntry const* TempSpell; - for (int i=0; i < GetSpellStore()->GetNumRows(); i++ ) + for(uint32 i = 0; i < GetSpellStore()->GetNumRows(); ++i) { SpellSummary[i].Effects = 0; SpellSummary[i].Targets = 0; @@ -541,7 +411,7 @@ void FillSpellSummary() if (!TempSpell) continue; - for (int j=0; j<3; j++) + for(uint32 j = 0; j < 3; ++j) { //Spell targets self if ( TempSpell->EffectImplicitTargetA[j] == TARGET_UNIT_CASTER ) @@ -649,6 +519,11 @@ void ScriptedAI::DoTeleportTo(float x, float y, float z, uint32 time) m_creature->SendMonsterMove(x, y, z, time); } +void ScriptedAI::DoTeleportTo(const float pos[4]) +{ + me->NearTeleportTo(pos[0], pos[1], pos[2], pos[3]); +} + void ScriptedAI::DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float o) { if(!pUnit || pUnit->GetTypeId() != TYPEID_PLAYER) @@ -775,23 +650,85 @@ void Scripted_NoMovementAI::AttackStart(Unit* who) } } +void BossAI::_Reset() +{ + events.Reset(); + summons.DespawnAll(); + instance->SetBossState(bossId, NOT_STARTED); +} + +void BossAI::_JustDied() +{ + events.Reset(); + summons.DespawnAll(); + instance->SetBossState(bossId, DONE); +} + +void BossAI::_EnterCombat() +{ + DoZoneInCombat(); + instance->SetBossState(bossId, IN_PROGRESS); +} + +void BossAI::JustSummoned(Creature *summon) +{ + summons.Summon(summon); + if(me->isInCombat()) + DoZoneInCombat(summon); +} + +void BossAI::SummonedCreatureDespawn(Creature *summon) +{ + summons.Despawn(summon); +} + +#define GOBJECT(x) (const_cast<GameObjectInfo*>(GetGameObjectInfo(x))) + void LoadOverridenSQLData() { GameObjectInfo *goInfo; // Sunwell Plateau : Kalecgos : Spectral Rift - goInfo = const_cast<GameObjectInfo*>(GetGameObjectInfo(187055)); - if(goInfo && goInfo->type == GAMEOBJECT_TYPE_GOOBER) - goInfo->goober.lockId = 57; // need LOCKTYPE_QUICK_OPEN + if(goInfo = GOBJECT(187055)) + if(goInfo->type == GAMEOBJECT_TYPE_GOOBER) + goInfo->goober.lockId = 57; // need LOCKTYPE_QUICK_OPEN + + // Naxxramas : Sapphiron Birth + if(goInfo = GOBJECT(181356)) + if(goInfo->type == GAMEOBJECT_TYPE_TRAP) + goInfo->trap.radius = 50; } void LoadOverridenDBCData() { SpellEntry *spellInfo; + for(uint32 i = 0; i < GetSpellStore()->GetNumRows(); ++i) + { + spellInfo = (SpellEntry*)GetSpellStore()->LookupEntry(i); + if(!spellInfo) + continue; - // Black Temple : Illidan : Parasitic Shadowfiend Passive - spellInfo = const_cast<SpellEntry*>(GetSpellStore()->LookupEntry(41913)); - if(spellInfo) - spellInfo->EffectApplyAuraName[0] = 4; // proc debuff, and summon infinite fiends + switch(i) + { + // Black Temple : Illidan : Parasitic Shadowfiend Passive + case 41013: + spellInfo->EffectApplyAuraName[0] = 4; // proc debuff, and summon infinite fiends + break; + //temp, not needed in 310 + case 28531: + case 55799: + spellInfo->DurationIndex = 21; + spellInfo->Effect[0] = SPELL_EFFECT_APPLY_AREA_AURA_ENEMY; + break; + // Naxxramas: Gothik : Inform Inf range + case 27892: + case 27928: + case 27935: + case 27915: + case 27931: + case 27937: + spellInfo->rangeIndex = 13; + break; + } + } } - diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index 638b6926a27..80016619e8b 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -8,75 +8,28 @@ #ifndef SC_CREATURE_H #define SC_CREATURE_H -#include "CreatureAI.h" #include "Creature.h" +#include "CreatureAI.h" +#include "CreatureAIImpl.h" -#define HEROIC(n,h) (HeroicMode ? h : n) - -template<class T> -inline -const T& RAND(const T& v1, const T& v2) -{ - return rand()%2 ? v1 : v2; -} - -template<class T> -inline -const T& RAND(const T& v1, const T& v2, const T& v3) -{ - switch(rand()%3) - { - default: - case 0: return v1; - case 1: return v2; - case 2: return v3; - } -} - -template<class T> -inline -const T& RAND(const T& v1, const T& v2, const T& v3, const T& v4) -{ - switch(rand()%4) - { - default: - case 0: return v1; - case 1: return v2; - case 2: return v3; - case 3: return v4; - } -} - -template<class T> -inline -const T& RAND(const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) -{ - switch(rand()%4) - { - default: - case 0: return v1; - case 1: return v2; - case 2: return v3; - case 3: return v4; - case 4: return v5; - } -} - -float GetSpellMaxRangeForHostile(uint32 id); +class ScriptedInstance; class SummonList : private std::list<uint64> { -public: - explicit SummonList(Creature* creature) : m_creature(creature) {} - void Summon(Creature *summon) { push_back(summon->GetGUID()); } - void Despawn(Creature *summon) { remove(summon->GetGUID()); } - void DespawnEntry(uint32 entry); - void DespawnAll(); - void DoAction(uint32 entry, uint32 info); -private: - Creature *m_creature; + public: + explicit SummonList(Creature* creature) : m_creature(creature) {} + void Summon(Creature *summon) { push_back(summon->GetGUID()); } + void Despawn(Creature *summon) { remove(summon->GetGUID()); } + void DespawnEntry(uint32 entry); + void DespawnAll(); + void DoAction(uint32 entry, uint32 info); + void DoZoneInCombat(uint32 entry = 0); + private: + Creature *m_creature; }; +float GetSpellMaxRangeForHostile(uint32 id); + //Get a single creature of given entry Unit* FindCreature(uint32 entry, float range, Unit* Finder); @@ -106,9 +59,6 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI void AttackStart(Unit *); void AttackStart(Unit *, bool melee); - //Called at stoping attack by any attacker - void EnterEvadeMode(); - // Called at any Damage from any attacker (before damage apply) void DamageTaken(Unit *done_by, uint32 &damage) {} @@ -133,11 +83,8 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI // Called when spell hits a target void SpellHitTarget(Unit* target, const SpellEntry*) {} - // Called when creature is spawned or respawned (for reseting variables) - void JustRespawned(); - //Called at waypoint reached or PointMovement end - void MovementInform(uint32, uint32){} + void MovementInform(uint32 type, uint32 id){} // Called when AI is temporarily replaced or put back when possess is applied or removed void OnPossess(bool apply) {} @@ -206,6 +153,7 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI void DoModifyThreatPercent(Unit *pUnit, int32 pct); void DoTeleportTo(float x, float y, float z, uint32 time = 0); + void DoTeleportTo(const float pos[4]); void DoAction(const int32 param) {} @@ -224,16 +172,16 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI //Spawns a creature relative to m_creature Creature* DoSpawnCreature(uint32 id, float x, float y, float z, float angle, uint32 type, uint32 despawntime); + Creature *DoSummon(uint32 entry, const float pos[4], uint32 despawntime = 30000, TempSummonType type = TEMPSUMMON_CORPSE_TIMED_DESPAWN); + Creature *DoSummon(uint32 entry, WorldObject *obj, float radius = 5.0f, uint32 despawntime = 30000, TempSummonType type = TEMPSUMMON_CORPSE_TIMED_DESPAWN); //Selects a unit from the creature's current aggro list Unit* SelectUnit(SelectAggroTarget target, uint32 position); - Unit* SelectUnit(SelectAggroTarget target, uint32 position, float dist, bool playerOnly); - void SelectUnitList(std::list<Unit*> &targetList, uint32 num, SelectAggroTarget target, float dist, bool playerOnly); bool HealthBelowPct(uint32 pct) const { return me->GetHealth() * 100 < m_creature->GetMaxHealth() * pct; } //Returns spells that meet the specified criteria from the creatures spell list - SpellEntry const* SelectSpell(Unit* Target, int32 School, int32 Mechanic, SelectTarget Targets, uint32 PowerCostMin, uint32 PowerCostMax, float RangeMin, float RangeMax, SelectEffect Effect); + SpellEntry const* SelectSpell(Unit* Target, int32 School, int32 Mechanic, SelectTargetType Targets, uint32 PowerCostMin, uint32 PowerCostMax, float RangeMin, float RangeMax, SelectEffect Effect); //Checks if you can cast the specified spell bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered = false); @@ -254,19 +202,29 @@ struct TRINITY_DLL_DECL Scripted_NoMovementAI : public ScriptedAI void AttackStart(Unit *); }; -struct TRINITY_DLL_DECL NullCreatureAI : public ScriptedAI +struct TRINITY_DLL_DECL BossAI : public ScriptedAI { - NullCreatureAI(Creature* c) : ScriptedAI(c) {} - ~NullCreatureAI() {} + BossAI(Creature *c, uint32 id) : ScriptedAI(c), bossId(id) + , summons(me), instance(c->GetInstanceData()) + {} - void Reset() {} - void EnterCombat(Unit*) {} - void MoveInLineOfSight(Unit *) {} - void AttackStart(Unit *) {} - void EnterEvadeMode() {} - bool IsVisible(Unit *) const { return false; } + uint32 bossId; + EventMap events; + SummonList summons; + InstanceData *instance; + + void JustSummoned(Creature *summon); + void SummonedCreatureDespawn(Creature *summon); + + void UpdateAI(const uint32 diff) = 0; + + void _Reset(); + void _EnterCombat(); + void _JustDied(); - void UpdateAI(const uint32) {} + void Reset() { _Reset(); } + void EnterCombat(Unit *who) { _EnterCombat(); } + void JustDied(Unit *killer) { _JustDied(); } }; #endif diff --git a/src/bindings/scripts/include/sc_instance.h b/src/bindings/scripts/include/sc_instance.h index cdf0e03aa37..0620e89af07 100644 --- a/src/bindings/scripts/include/sc_instance.h +++ b/src/bindings/scripts/include/sc_instance.h @@ -17,20 +17,7 @@ class TRINITY_DLL_DECL ScriptedInstance : public InstanceData { public: - ScriptedInstance(Map *map) : InstanceData(map) {} - ~ScriptedInstance() {} - - //All-purpose data storage 64 bit - virtual uint64 GetData64(uint32 Data) { return 0; } - virtual void SetData64(uint32 Data, uint64 Value) { } - - // Called every instance update - virtual void Update(uint32) {} - - // Save and Load instance data to the database - const char* Save() { return NULL; } - void Load(const char* in) { } }; #endif |
