[svn] * Proper SVN structure

--HG--
branch : trunk
This commit is contained in:
Neo2003
2008-10-02 16:23:55 -05:00
commit 9b1c0e006f
2564 changed files with 621124 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
/* Copyright (C) 2006 - 2008 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#include "precompiled.h"

View File

@@ -0,0 +1,25 @@
/* Copyright (C) 2006 - 2008 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#ifndef SC_PRECOMPILED_H
#define SC_PRECOMPILED_H
#include "../ScriptMgr.h"
#include "sc_creature.h"
#include "sc_gossip.h"
#include "sc_grid_searchers.h"
#include "sc_instance.h"
#ifdef WIN32
#include <windows.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return true;
}
#endif
#endif

View File

@@ -0,0 +1,612 @@
/* Copyright (C) 2006 - 2008 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#include "precompiled.h"
#include "Item.h"
#include "Spell.h"
#include "WorldPacket.h"
// Spell summary for ScriptedAI::SelectSpell
struct TSpellSummary {
uint8 Targets; // set of enum SelectTarget
uint8 Effects; // set of enum SelectEffect
} *SpellSummary;
bool ScriptedAI::IsVisible(Unit* who) const
{
if (!who)
return false;
return (m_creature->GetDistance(who) < VISIBLE_RANGE) && who->isVisibleForOrDetect(m_creature,true);
}
void ScriptedAI::MoveInLineOfSight(Unit *who)
{
if( !m_creature->getVictim() && who->isTargetableForAttack() && ( m_creature->IsHostileTo( who )) && who->isInAccessablePlaceFor(m_creature) )
{
if (m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
return;
float attackRadius = m_creature->GetAttackDistance(who);
if( m_creature->IsWithinDistInMap(who, attackRadius) && m_creature->IsWithinLOSInMap(who) )
{
DoStartAttackAndMovement(who);
who->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
if (!InCombat)
{
Aggro(who);
InCombat = true;
}
}
}
}
void ScriptedAI::AttackStart(Unit* who)
{
if (!who)
return;
if (who->isTargetableForAttack())
{
//Begin attack
DoStartAttackAndMovement(who);
if (!InCombat)
{
Aggro(who);
InCombat = true;
}
}
}
void ScriptedAI::UpdateAI(const uint32 diff)
{
//Check if we have a current target
if( m_creature->isAlive() && m_creature->SelectHostilTarget() && m_creature->getVictim())
{
if( m_creature->isAttackReady() )
{
//If we are within range melee the target
if( m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE))
{
m_creature->AttackerStateUpdate(m_creature->getVictim());
m_creature->resetAttackTimer();
}
}
}
}
void ScriptedAI::EnterEvadeMode()
{
m_creature->InterruptNonMeleeSpells(true);
m_creature->RemoveAllAuras();
m_creature->DeleteThreatList();
m_creature->CombatStop();
m_creature->LoadCreaturesAddon();
if( m_creature->isAlive() )
m_creature->GetMotionMaster()->MoveTargetedHome();
m_creature->SetLootRecipient(NULL);
InCombat = false;
Reset();
}
void ScriptedAI::JustRespawned()
{
InCombat = false;
Reset();
}
void ScriptedAI::DoStartAttackAndMovement(Unit* victim, float distance, float angle)
{
if (!victim)
return;
if ( m_creature->Attack(victim, true) )
{
m_creature->GetMotionMaster()->MoveChase(victim, distance, angle);
m_creature->AddThreat(victim, 0.0f);
}
}
void ScriptedAI::DoStartAttackNoMovement(Unit* victim)
{
if (!victim)
return;
if ( m_creature->Attack(victim, true) )
{
m_creature->AddThreat(victim, 0.0f);
}
}
void ScriptedAI::DoMeleeAttackIfReady()
{
//Make sure our attack is ready and we aren't currently casting before checking distance
if( m_creature->isAttackReady() && !m_creature->IsNonMeleeSpellCasted(false))
{
//If we are within range melee the target
if( m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE))
{
m_creature->AttackerStateUpdate(m_creature->getVictim());
m_creature->resetAttackTimer();
}
}
}
void ScriptedAI::DoStopAttack()
{
if( m_creature->getVictim() != NULL )
{
m_creature->AttackStop();
}
}
void ScriptedAI::DoCast(Unit* victim, uint32 spellId, bool triggered)
{
if (!victim || m_creature->IsNonMeleeSpellCasted(false))
return;
m_creature->StopMoving();
m_creature->CastSpell(victim, spellId, triggered);
}
void ScriptedAI::DoCastSpell(Unit* who,SpellEntry const *spellInfo, bool triggered)
{
if (!who || m_creature->IsNonMeleeSpellCasted(false))
return;
m_creature->StopMoving();
m_creature->CastSpell(who, spellInfo, triggered);
}
void ScriptedAI::DoSay(const char* text, uint32 language, Unit* target)
{
if (target)m_creature->Say(text, language, target->GetGUID());
else m_creature->Say(text, language, 0);
}
void ScriptedAI::DoYell(const char* text, uint32 language, Unit* target)
{
if (target)m_creature->Yell(text, language, target->GetGUID());
else m_creature->Yell(text, language, 0);
}
void ScriptedAI::DoTextEmote(const char* text, Unit* target, bool IsBossEmote)
{
if (target)m_creature->TextEmote(text, target->GetGUID(), IsBossEmote);
else m_creature->TextEmote(text, 0, IsBossEmote);
}
void ScriptedAI::DoWhisper(const char* text, Unit* reciever, bool IsBossWhisper)
{
if (!reciever || reciever->GetTypeId() != TYPEID_PLAYER)
return;
m_creature->Whisper(text, reciever->GetGUID(), IsBossWhisper);
}
void ScriptedAI::DoPlaySoundToSet(Unit* unit, uint32 sound)
{
if (!unit)
return;
if (!GetSoundEntriesStore()->LookupEntry(sound))
{
error_log("SD2: Invalid soundId %u used in DoPlaySoundToSet (by unit TypeId %u, guid %u)", sound, unit->GetTypeId(), unit->GetGUID());
return;
}
WorldPacket data(4);
data.SetOpcode(SMSG_PLAY_SOUND);
data << uint32(sound);
unit->SendMessageToSet(&data,false);
}
Creature* ScriptedAI::DoSpawnCreature(uint32 id, float x, float y, float z, float angle, uint32 type, uint32 despawntime)
{
return m_creature->SummonCreature(id,m_creature->GetPositionX() + x,m_creature->GetPositionY() + y,m_creature->GetPositionZ() + z, angle, (TempSummonType)type, despawntime);
}
Unit* ScriptedAI::SelectUnit(SelectAggroTarget target, uint32 position)
{
//ThreatList m_threatlist;
std::list<HostilReference*>& m_threatlist = m_creature->getThreatManager().getThreatList();
std::list<HostilReference*>::iterator i = m_threatlist.begin();
std::list<HostilReference*>::reverse_iterator r = m_threatlist.rbegin();
if (position >= m_threatlist.size() || !m_threatlist.size())
return NULL;
switch (target)
{
case SELECT_TARGET_RANDOM:
advance ( i , position + (rand() % (m_threatlist.size() - position ) ));
return Unit::GetUnit((*m_creature),(*i)->getUnitGuid());
break;
case SELECT_TARGET_TOPAGGRO:
advance ( i , position);
return Unit::GetUnit((*m_creature),(*i)->getUnitGuid());
break;
case SELECT_TARGET_BOTTOMAGGRO:
advance ( r , position);
return Unit::GetUnit((*m_creature),(*r)->getUnitGuid());
break;
}
return NULL;
}
SpellEntry const* ScriptedAI::SelectSpell(Unit* Target, int32 School, int32 Mechanic, SelectTarget Targets, uint32 PowerCostMin, uint32 PowerCostMax, float RangeMin, float RangeMax, SelectEffect Effects)
{
//No target so we can't cast
if (!Target)
return false;
//Silenced so we can't cast
if (m_creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED))
return false;
//Using the extended script system we first create a list of viable spells
SpellEntry const* Spell[4];
Spell[0] = 0;
Spell[1] = 0;
Spell[2] = 0;
Spell[3] = 0;
uint32 SpellCount = 0;
SpellEntry const* TempSpell;
SpellRangeEntry const* TempRange;
//Check if each spell is viable(set it to null if not)
for (uint32 i = 0; i < 4; i++)
{
TempSpell = GetSpellStore()->LookupEntry(m_creature->m_spells[i]);
//This spell doesn't exist
if (!TempSpell)
continue;
// Targets and Effects checked first as most used restrictions
//Check the spell targets if specified
if ( Targets && !(SpellSummary[m_creature->m_spells[i]].Targets & (1 << (Targets-1))) )
continue;
//Check the type of spell if we are looking for a specific spell type
if ( Effects && !(SpellSummary[m_creature->m_spells[i]].Effects & (1 << (Effects-1))) )
continue;
//Check for school if specified
if (School >= 0 && TempSpell->SchoolMask & School)
continue;
//Check for spell mechanic if specified
if (Mechanic >= 0 && TempSpell->Mechanic != Mechanic)
continue;
//Make sure that the spell uses the requested amount of power
if (PowerCostMin && TempSpell->manaCost < PowerCostMin)
continue;
if (PowerCostMax && TempSpell->manaCost > PowerCostMax)
continue;
//Continue if we don't have the mana to actually cast this spell
if (TempSpell->manaCost > m_creature->GetPower((Powers)TempSpell->powerType))
continue;
//Get the Range
TempRange = GetSpellRangeStore()->LookupEntry(TempSpell->rangeIndex);
//Spell has invalid range store so we can't use it
if (!TempRange)
continue;
//Check if the spell meets our range requirements
if (RangeMin && TempRange->maxRange < RangeMin)
continue;
if (RangeMax && TempRange->maxRange > RangeMax)
continue;
//Check if our target is in range
if (m_creature->IsWithinDistInMap(Target, TempRange->minRange) || !m_creature->IsWithinDistInMap(Target, TempRange->maxRange))
continue;
//All good so lets add it to the spell list
Spell[SpellCount] = TempSpell;
SpellCount++;
}
//We got our usable spells so now lets randomly pick one
if (!SpellCount)
return NULL;
return Spell[rand()%SpellCount];
}
bool ScriptedAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered)
{
//No target so we can't cast
if (!Target || !Spell)
return false;
//Silenced so we can't cast
if (!Triggered && m_creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED))
return false;
//Check for power
if (!Triggered && m_creature->GetPower((Powers)Spell->powerType) < Spell->manaCost)
return false;
SpellRangeEntry const *TempRange = NULL;
TempRange = GetSpellRangeStore()->LookupEntry(Spell->rangeIndex);
//Spell has invalid range store so we can't use it
if (!TempRange)
return false;
//Unit is out of range of this spell
if (m_creature->GetDistance(Target) > TempRange->maxRange || m_creature->GetDistance(Target) < TempRange->minRange)
return false;
return true;
}
void FillSpellSummary()
{
SpellSummary = new TSpellSummary[GetSpellStore()->GetNumRows()];
SpellEntry const* TempSpell;
for (int i=0; i < GetSpellStore()->GetNumRows(); i++ )
{
SpellSummary[i].Effects = 0;
SpellSummary[i].Targets = 0;
TempSpell = GetSpellStore()->LookupEntry(i);
//This spell doesn't exist
if (!TempSpell)
continue;
for (int j=0; j<3; j++)
{
//Spell targets self
if ( TempSpell->EffectImplicitTargetA[j] == TARGET_SELF )
SpellSummary[i].Targets |= 1 << (SELECT_TARGET_SELF-1);
//Spell targets a single enemy
if ( TempSpell->EffectImplicitTargetA[j] == TARGET_CHAIN_DAMAGE ||
TempSpell->EffectImplicitTargetA[j] == TARGET_CURRENT_ENEMY_COORDINATES )
SpellSummary[i].Targets |= 1 << (SELECT_TARGET_SINGLE_ENEMY-1);
//Spell targets AoE at enemy
if ( TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_ENEMY_IN_AREA ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_ENEMY_IN_AREA_INSTANT ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_AROUND_CASTER ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_ENEMY_IN_AREA_CHANNELED )
SpellSummary[i].Targets |= 1 << (SELECT_TARGET_AOE_ENEMY-1);
//Spell targets an enemy
if ( TempSpell->EffectImplicitTargetA[j] == TARGET_CHAIN_DAMAGE ||
TempSpell->EffectImplicitTargetA[j] == TARGET_CURRENT_ENEMY_COORDINATES ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_ENEMY_IN_AREA ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_ENEMY_IN_AREA_INSTANT ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_AROUND_CASTER ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_ENEMY_IN_AREA_CHANNELED )
SpellSummary[i].Targets |= 1 << (SELECT_TARGET_ANY_ENEMY-1);
//Spell targets a single friend(or self)
if ( TempSpell->EffectImplicitTargetA[j] == TARGET_SELF ||
TempSpell->EffectImplicitTargetA[j] == TARGET_SINGLE_FRIEND ||
TempSpell->EffectImplicitTargetA[j] == TARGET_SINGLE_PARTY )
SpellSummary[i].Targets |= 1 << (SELECT_TARGET_SINGLE_FRIEND-1);
//Spell targets aoe friends
if ( TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_PARTY_AROUND_CASTER ||
TempSpell->EffectImplicitTargetA[j] == TARGET_AREAEFFECT_PARTY ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_AROUND_CASTER)
SpellSummary[i].Targets |= 1 << (SELECT_TARGET_AOE_FRIEND-1);
//Spell targets any friend(or self)
if ( TempSpell->EffectImplicitTargetA[j] == TARGET_SELF ||
TempSpell->EffectImplicitTargetA[j] == TARGET_SINGLE_FRIEND ||
TempSpell->EffectImplicitTargetA[j] == TARGET_SINGLE_PARTY ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_PARTY_AROUND_CASTER ||
TempSpell->EffectImplicitTargetA[j] == TARGET_AREAEFFECT_PARTY ||
TempSpell->EffectImplicitTargetA[j] == TARGET_ALL_AROUND_CASTER)
SpellSummary[i].Targets |= 1 << (SELECT_TARGET_ANY_FRIEND-1);
//Make sure that this spell includes a damage effect
if ( TempSpell->Effect[j] == SPELL_EFFECT_SCHOOL_DAMAGE ||
TempSpell->Effect[j] == SPELL_EFFECT_INSTAKILL ||
TempSpell->Effect[j] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE ||
TempSpell->Effect[j] == SPELL_EFFECT_HEALTH_LEECH )
SpellSummary[i].Effects |= 1 << (SELECT_EFFECT_DAMAGE-1);
//Make sure that this spell includes a healing effect (or an apply aura with a periodic heal)
if ( TempSpell->Effect[j] == SPELL_EFFECT_HEAL ||
TempSpell->Effect[j] == SPELL_EFFECT_HEAL_MAX_HEALTH ||
TempSpell->Effect[j] == SPELL_EFFECT_HEAL_MECHANICAL ||
(TempSpell->Effect[j] == SPELL_EFFECT_APPLY_AURA && TempSpell->EffectApplyAuraName[j]== 8 ))
SpellSummary[i].Effects |= 1 << (SELECT_EFFECT_HEALING-1);
//Make sure that this spell applies an aura
if ( TempSpell->Effect[j] == SPELL_EFFECT_APPLY_AURA )
SpellSummary[i].Effects |= 1 << (SELECT_EFFECT_AURA-1);
}
}
}
void ScriptedAI::DoZoneInCombat(Unit* pUnit)
{
if (!pUnit)
pUnit = m_creature;
Map *map = pUnit->GetMap();
if (!map->IsDungeon()) //use IsDungeon instead of Instanceable, in case battlegrounds will be instantiated
{
error_log("SD2: DoZoneInCombat call for map that isn't an instance (pUnit entry = %d)", pUnit->GetTypeId() == TYPEID_UNIT ? ((Creature*)pUnit)->GetEntry() : 0);
return;
}
if (!pUnit->CanHaveThreatList() || pUnit->getThreatManager().isThreatListEmpty())
{
error_log("SD2: DoZoneInCombat called for creature that either cannot have threat list or has empty threat list (pUnit entry = %d)", pUnit->GetTypeId() == TYPEID_UNIT ? ((Creature*)pUnit)->GetEntry() : 0);
return;
}
InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers();
InstanceMap::PlayerList::const_iterator i;
for (i = PlayerList.begin(); i != PlayerList.end(); ++i)
{
if(!(*i)->isGameMaster())
pUnit->AddThreat(*i, 0.0f);
}
}
void ScriptedAI::DoResetThreat()
{
if (!m_creature->CanHaveThreatList() || m_creature->getThreatManager().isThreatListEmpty())
{
error_log("SD2: DoResetThreat called for creature that either cannot have threat list or has empty threat list (m_creature entry = %d)", m_creature->GetEntry());
return;
}
std::list<HostilReference*>& m_threatlist = m_creature->getThreatManager().getThreatList();
std::list<HostilReference*>::iterator itr;
for(itr = m_threatlist.begin(); itr != m_threatlist.end(); ++itr)
{
Unit* pUnit = NULL;
pUnit = Unit::GetUnit((*m_creature), (*itr)->getUnitGuid());
if(pUnit && m_creature->getThreatManager().getThreat(pUnit))
m_creature->getThreatManager().modifyThreatPercent(pUnit, -100);
}
}
void ScriptedAI::DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float o)
{
if(!pUnit || pUnit->GetTypeId() != TYPEID_PLAYER)
{
if(pUnit)
error_log("SD2: Creature %u (Entry: %u) Tried to teleport non-player unit (Type: %u GUID: %u) to x: %f y:%f z: %f o: %f. Aborted.", m_creature->GetGUID(), m_creature->GetEntry(), pUnit->GetTypeId(), pUnit->GetGUID(), x, y, z, o);
return;
}
((Player*)pUnit)->TeleportTo(pUnit->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT);
}
Unit* ScriptedAI::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff)
{
CellPair p(MaNGOS::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
Unit* pUnit = NULL;
MostHPMissingInRange u_check(m_creature, range, MinHPDiff);
MaNGOS::UnitLastSearcher<MostHPMissingInRange> searcher(pUnit, u_check);
/*
typedef TYPELIST_4(GameObject, Creature*except pets*, DynamicObject, Corpse*Bones*) AllGridObjectTypes;
This means that if we only search grid then we cannot possibly return pets or players so this is safe
*/
TypeContainerVisitor<MaNGOS::UnitLastSearcher<MostHPMissingInRange>, GridTypeMapContainer > grid_unit_searcher(searcher);
CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, grid_unit_searcher, *(m_creature->GetMap()));
return pUnit;
}
std::list<Creature*> ScriptedAI::DoFindFriendlyCC(float range)
{
CellPair p(MaNGOS::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
std::list<Creature*> pList;
FriendlyCCedInRange u_check(m_creature, range);
MaNGOS::CreatureListSearcher<FriendlyCCedInRange> searcher(pList, u_check);
TypeContainerVisitor<MaNGOS::CreatureListSearcher<FriendlyCCedInRange>, GridTypeMapContainer > grid_creature_searcher(searcher);
CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, grid_creature_searcher, *(m_creature->GetMap()));
return pList;
}
std::list<Creature*> ScriptedAI::DoFindFriendlyMissingBuff(float range, uint32 spellid)
{
CellPair p(MaNGOS::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY()));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
std::list<Creature*> pList;
FriendlyMissingBuffInRange u_check(m_creature, range, spellid);
MaNGOS::CreatureListSearcher<FriendlyMissingBuffInRange> searcher(pList, u_check);
TypeContainerVisitor<MaNGOS::CreatureListSearcher<FriendlyMissingBuffInRange>, GridTypeMapContainer > grid_creature_searcher(searcher);
CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, grid_creature_searcher, *(m_creature->GetMap()));
return pList;
}
void Scripted_NoMovementAI::MoveInLineOfSight(Unit *who)
{
if( !m_creature->getVictim() && who->isTargetableForAttack() && ( m_creature->IsHostileTo( who )) && who->isInAccessablePlaceFor(m_creature) )
{
if (m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
return;
float attackRadius = m_creature->GetAttackDistance(who);
if( m_creature->IsWithinDistInMap(who, attackRadius) && m_creature->IsWithinLOSInMap(who) )
{
DoStartAttackNoMovement(who);
who->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
if (!InCombat)
{
Aggro(who);
InCombat = true;
}
}
}
}
void Scripted_NoMovementAI::AttackStart(Unit* who)
{
if (!who)
return;
if (who->isTargetableForAttack())
{
//Begin attack
DoStartAttackNoMovement(who);
if (!InCombat)
{
Aggro(who);
InCombat = true;
}
}
}

View File

@@ -0,0 +1,196 @@
/* Copyright (C) 2006 - 2008 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#ifndef SC_CREATURE_H
#define SC_CREATURE_H
#include "CreatureAI.h"
#include "Creature.h"
//Spell targets used by SelectSpell
enum SelectTarget
{
SELECT_TARGET_DONTCARE = 0, //All target types allowed
SELECT_TARGET_SELF, //Only Self casting
SELECT_TARGET_SINGLE_ENEMY, //Only Single Enemy
SELECT_TARGET_AOE_ENEMY, //Only AoE Enemy
SELECT_TARGET_ANY_ENEMY, //AoE or Single Enemy
SELECT_TARGET_SINGLE_FRIEND, //Only Single Friend
SELECT_TARGET_AOE_FRIEND, //Only AoE Friend
SELECT_TARGET_ANY_FRIEND, //AoE or Single Friend
};
//Spell Effects used by SelectSpell
enum SelectEffect
{
SELECT_EFFECT_DONTCARE = 0, //All spell effects allowed
SELECT_EFFECT_DAMAGE, //Spell does damage
SELECT_EFFECT_HEALING, //Spell does healing
SELECT_EFFECT_AURA, //Spell applies an aura
};
//Selection method used by SelectTarget
enum SelectAggroTarget
{
SELECT_TARGET_RANDOM = 0, //Just selects a random target
SELECT_TARGET_TOPAGGRO, //Selects targes from top aggro to bottom
SELECT_TARGET_BOTTOMAGGRO, //Selects targets from bottom aggro to top
};
struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI
{
ScriptedAI(Creature* creature) : m_creature(creature), InCombat(false) {}
~ScriptedAI() {}
//*************
//CreatureAI Functions
//*************
//Called if IsVisible(Unit *who) is true at each *who move
void MoveInLineOfSight(Unit *);
//Called at each attack of m_creature by any victim
void AttackStart(Unit *);
//Called at stoping attack by any attacker
void EnterEvadeMode();
//Called at any heal cast/item used (call non implemented in mangos)
void HealBy(Unit *healer, uint32 amount_healed) {}
// Called at any Damage to any victim (before damage apply)
void DamageDeal(Unit *done_to, uint32 &damage) {}
// Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit *done_by, uint32 &damage) {}
//Is unit visible for MoveInLineOfSight
bool IsVisible(Unit *who) const;
//Called at World update tick
void UpdateAI(const uint32);
//Called at creature death
void JustDied(Unit*){}
//Called at creature killing another unit
void KilledUnit(Unit*){}
// Called when the creature summon successfully other creature
void JustSummoned(Creature* ) {}
// Called when a summoned creature is despawned
void SummonedCreatureDespawn(Creature* /*unit*/) {}
// Called when hit by a spell
void SpellHit(Unit*, 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){}
//*************
// Variables
//*************
//Pointer to creature we are manipulating
Creature* m_creature;
//Bool for if we are in combat or not
bool InCombat;
//*************
//Pure virtual functions
//*************
//Called at creature reset either by death or evade
virtual void Reset() = 0;
//Called at creature aggro either by MoveInLOS or Attack Start
virtual void Aggro(Unit*) = 0;
//*************
//AI Helper Functions
//*************
//Start attack of victim and go to him
void DoStartAttackAndMovement(Unit* victim, float distance = 0, float angle = 0);
//Start attack on victim but do not move
void DoStartAttackNoMovement(Unit* victim);
//Do melee swing of current victim if in rnage and ready and not casting
void DoMeleeAttackIfReady();
//Stop attack of current victim
void DoStopAttack();
//Cast spell by Id
void DoCast(Unit* victim, uint32 spellId, bool triggered = false);
//Cast spell by spell info
void DoCastSpell(Unit* who,SpellEntry const *spellInfo, bool triggered = false);
//Creature say
void DoSay(const char* text, uint32 language, Unit* target);
//Creature Yell
void DoYell(const char* text, uint32 language, Unit* target);
//Creature Text emote, optional bool for boss emote text
void DoTextEmote(const char* text, Unit* target, bool IsBossEmote = false);
//Creature whisper, optional bool for boss whisper
void DoWhisper(const char* text, Unit* reciever, bool IsBossWhisper = false);
//Plays a sound to all nearby players
void DoPlaySoundToSet(Unit* unit, uint32 sound);
//Places the entire map into combat with creature
void DoZoneInCombat(Unit* pUnit = 0);
//Drops all threat to 0%. Does not remove players from the threat list
void DoResetThreat();
//Teleports a player without dropping threat (only teleports to same map)
void DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float o);
//Returns friendly unit with the most amount of hp missing from max hp
Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1);
//Returns a list of friendly CC'd units within range
std::list<Creature*> DoFindFriendlyCC(float range);
//Returns a list of all friendly units missing a specific buff within range
std::list<Creature*> DoFindFriendlyMissingBuff(float range, uint32 spellid);
//Spawns a creature relative to m_creature
Creature* DoSpawnCreature(uint32 id, float x, float y, float z, float angle, uint32 type, uint32 despawntime);
//Selects a unit from the creature's current aggro list
Unit* SelectUnit(SelectAggroTarget target, uint32 position);
//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);
//Checks if you can cast the specified spell
bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered = false);
};
struct MANGOS_DLL_DECL Scripted_NoMovementAI : public ScriptedAI
{
Scripted_NoMovementAI(Creature* creature) : ScriptedAI(creature) {}
//Called if IsVisible(Unit *who) is true at each *who move
void MoveInLineOfSight(Unit *);
//Called at each attack of m_creature by any victim
void AttackStart(Unit *);
};
#endif

View File

@@ -0,0 +1,183 @@
/* Copyright (C) 2006 - 2008 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#ifndef SC_PLAYER_H
#define SC_PLAYER_H
#include "Player.h"
#include "GossipDef.h"
#include "QuestDef.h"
// Gossip Item Text
#define GOSSIP_TEXT_BROWSE_GOODS "I'd like to browse your goods."
#define GOSSIP_TEXT_TRAIN "Train me!"
#define GOSSIP_TEXT_BANK "The Bank"
#define GOSSIP_TEXT_WINDRIDER "Wind rider master"
#define GOSSIP_TEXT_GRYPHON "Gryphon Master"
#define GOSSIP_TEXT_BATHANDLER "Bat Handler"
#define GOSSIP_TEXT_HIPPOGRYPH "Hippogryph Master"
#define GOSSIP_TEXT_FLIGHTMASTER "Flight Master"
#define GOSSIP_TEXT_AUCTIONHOUSE "Auction House"
#define GOSSIP_TEXT_GUILDMASTER "Guild Master"
#define GOSSIP_TEXT_INN "The Inn"
#define GOSSIP_TEXT_MAILBOX "Mailbox"
#define GOSSIP_TEXT_STABLEMASTER "Stable Master"
#define GOSSIP_TEXT_WEAPONMASTER "Weapons Trainer"
#define GOSSIP_TEXT_BATTLEMASTER "Battlemaster"
#define GOSSIP_TEXT_CLASSTRAINER "Class Trainer"
#define GOSSIP_TEXT_PROFTRAINER "Profession Trainer"
#define GOSSIP_TEXT_OFFICERS "The officers` lounge"
#define GOSSIP_TEXT_ALTERACVALLEY "Alterac Valley"
#define GOSSIP_TEXT_ARATHIBASIN "Arathi Basin"
#define GOSSIP_TEXT_WARSONGULCH "Warsong Gulch"
#define GOSSIP_TEXT_ARENA "Arena"
#define GOSSIP_TEXT_EYEOFTHESTORM "Eye of The Storm"
#define GOSSIP_TEXT_DRUID "Druid"
#define GOSSIP_TEXT_HUNTER "Hunter"
#define GOSSIP_TEXT_PRIEST "Priest"
#define GOSSIP_TEXT_ROGUE "Rogue"
#define GOSSIP_TEXT_WARRIOR "Warrior"
#define GOSSIP_TEXT_PALADIN "Paladin"
#define GOSSIP_TEXT_SHAMAN "Shaman"
#define GOSSIP_TEXT_MAGE "Mage"
#define GOSSIP_TEXT_WARLOCK "Warlock"
#define GOSSIP_TEXT_ALCHEMY "Alchemy"
#define GOSSIP_TEXT_BLACKSMITHING "Blacksmithing"
#define GOSSIP_TEXT_COOKING "Cooking"
#define GOSSIP_TEXT_ENCHANTING "Enchanting"
#define GOSSIP_TEXT_ENGINEERING "Engineering"
#define GOSSIP_TEXT_FIRSTAID "First Aid"
#define GOSSIP_TEXT_HERBALISM "Herbalism"
#define GOSSIP_TEXT_LEATHERWORKING "Leatherworking"
#define GOSSIP_TEXT_POISONS "Poisons"
#define GOSSIP_TEXT_TAILORING "Tailoring"
#define GOSSIP_TEXT_MINING "Mining"
#define GOSSIP_TEXT_FISHING "Fishing"
#define GOSSIP_TEXT_SKINNING "Skinning"
#define GOSSIP_TEXT_JEWELCRAFTING "Jewelcrafting"
#define GOSSIP_TEXT_IRONFORGE_BANK "Bank of Ironforge"
#define GOSSIP_TEXT_STORMWIND_BANK "Bank of Stormwind"
#define GOSSIP_TEXT_DEEPRUNTRAM "Deeprun Tram"
#define GOSSIP_TEXT_ZEPPLINMASTER "Zeppelin master"
#define GOSSIP_TEXT_FERRY "Rut'theran Ferry"
// Skill defines
#define TRADESKILL_ALCHEMY 1
#define TRADESKILL_BLACKSMITHING 2
#define TRADESKILL_COOKING 3
#define TRADESKILL_ENCHANTING 4
#define TRADESKILL_ENGINEERING 5
#define TRADESKILL_FIRSTAID 6
#define TRADESKILL_HERBALISM 7
#define TRADESKILL_LEATHERWORKING 8
#define TRADESKILL_POISONS 9
#define TRADESKILL_TAILORING 10
#define TRADESKILL_MINING 11
#define TRADESKILL_FISHING 12
#define TRADESKILL_SKINNING 13
#define TRADESKILL_JEWLCRAFTING 14
#define TRADESKILL_LEVEL_NONE 0
#define TRADESKILL_LEVEL_APPRENTICE 1
#define TRADESKILL_LEVEL_JOURNEYMAN 2
#define TRADESKILL_LEVEL_EXPERT 3
#define TRADESKILL_LEVEL_ARTISAN 4
#define TRADESKILL_LEVEL_MASTER 5
// Gossip defines
#define GOSSIP_ACTION_TRADE 1
#define GOSSIP_ACTION_TRAIN 2
#define GOSSIP_ACTION_TAXI 3
#define GOSSIP_ACTION_GUILD 4
#define GOSSIP_ACTION_BATTLE 5
#define GOSSIP_ACTION_BANK 6
#define GOSSIP_ACTION_INN 7
#define GOSSIP_ACTION_HEAL 8
#define GOSSIP_ACTION_TABARD 9
#define GOSSIP_ACTION_AUCTION 10
#define GOSSIP_ACTION_INN_INFO 11
#define GOSSIP_ACTION_UNLEARN 12
#define GOSSIP_ACTION_INFO_DEF 1000
#define GOSSIP_SENDER_MAIN 1
#define GOSSIP_SENDER_INN_INFO 2
#define GOSSIP_SENDER_INFO 3
#define GOSSIP_SENDER_SEC_PROFTRAIN 4
#define GOSSIP_SENDER_SEC_CLASSTRAIN 5
#define GOSSIP_SENDER_SEC_BATTLEINFO 6
#define GOSSIP_SENDER_SEC_BANK 7
#define GOSSIP_SENDER_SEC_INN 8
#define GOSSIP_SENDER_SEC_MAILBOX 9
#define GOSSIP_SENDER_SEC_STABLEMASTER 10
#define DEFAULT_GOSSIP_MESSAGE 0xffffff
extern uint32 GetSkillLevel(Player *player,uint32 skill);
// Defined fuctions to use with player.
// This fuction add's a menu item,
// a - Icon Id
// b - Text
// c - Sender(this is to identify the current Menu with this item)
// d - Action (identifys this Menu Item)
// e - Text to be displayed in pop up box
// f - Money value in pop up box
#define ADD_GOSSIP_ITEM(a,b,c,d) PlayerTalkClass->GetGossipMenu()->AddMenuItem(a,b,c,d,"",0)
#define ADD_GOSSIP_ITEM_EXTENDED(a,b,c,d,e,f) PlayerTalkClass->GetGossipMenu()->AddMenuItem(a,b,c,d,e,f)
// This fuction Sends the current menu to show to client, a - NPCTEXTID(uint32) , b - npc guid(uint64)
#define SEND_GOSSIP_MENU(a,b) PlayerTalkClass->SendGossipMenu(a,b)
// This fuction shows POI(point of interest) to client.
// a - position X
// b - position Y
// c - Icon Id
// d - Flags
// e - Data
// f - Location Name
#define SEND_POI(a,b,c,d,e,f) PlayerTalkClass->SendPointOfInterest(a,b,c,d,e,f)
// Closes the Menu
#define CLOSE_GOSSIP_MENU() PlayerTalkClass->CloseGossip()
// Fuction to tell to client the details
// a - quest object
// b - npc guid(uint64)
// c - Activate accept(bool)
#define SEND_QUEST_DETAILS(a,b,c) PlayerTalkClass->SendQuestDetails(a,b,c)
// Fuction to tell to client the requested items to complete quest
// a - quest object
// b - npc guid(uint64)
// c - Iscompletable(bool)
// d - close at cancel(bool) - in case single incomplite ques
#define SEND_REQUESTEDITEMS(a,b,c,d) PlayerTalkClass->SendRequestedItems(a,b,c,d)
// Fuctions to send NPC lists, a - is always the npc guid(uint64)
#define SEND_VENDORLIST(a) GetSession()->SendListInventory(a)
#define SEND_TRAINERLIST(a) GetSession()->SendTrainerList(a)
#define SEND_BANKERLIST(a) GetSession()->SendShowBank(a)
#define SEND_TABARDLIST(a) GetSession()->SendTabardVendorActivate(a)
#define SEND_AUCTIONLIST(a) GetSession()->SendAuctionHello(a)
#define SEND_TAXILIST(a) GetSession()->SendTaxiStatus(a)
// Ressurect's the player if is dead.
#define SEND_SPRESURRECT() GetSession()->SendSpiritResurrect()
// Get the player's honor rank.
#define GET_HONORRANK() GetHonorRank()
// -----------------------------------
// defined fuctions to use with Creature
#define QUEST_DIALOG_STATUS(a,b,c) GetSession()->getDialogStatus(a,b,c)
#endif

View File

@@ -0,0 +1,131 @@
/* Copyright (C) 2006 - 2008 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#ifndef SC_GRIDSEARCH_H
#define SC_GRIDSEARCH_H
#include "Unit.h"
#include "GameObject.h"
#include "Cell.h"
#include "CellImpl.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
//Used in:
//sc_creature.cpp - DoSelectLowestHpFriendly()
class MostHPMissingInRange
{
public:
MostHPMissingInRange(Unit const* obj, float range, uint32 hp) : i_obj(obj), i_range(range), i_hp(hp) {}
bool operator()(Unit* u)
{
if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && u->GetMaxHealth() - u->GetHealth() > i_hp)
{
i_hp = u->GetMaxHealth() - u->GetHealth();
return true;
}
return false;
}
private:
Unit const* i_obj;
float i_range;
uint32 i_hp;
};
//Used in:
//sc_creature.cpp - DoFindFriendlyCC()
class FriendlyCCedInRange
{
public:
FriendlyCCedInRange(Unit const* obj, float range) : i_obj(obj), i_range(range) {}
bool operator()(Unit* u)
{
if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) &&
(u->isFeared() || u->isCharmed() || u->isFrozen() || u->hasUnitState(UNIT_STAT_STUNDED) || u->hasUnitState(UNIT_STAT_STUNDED) || u->hasUnitState(UNIT_STAT_CONFUSED)))
{
return true;
}
return false;
}
private:
Unit const* i_obj;
float i_range;
};
//Used in:
//sc_creature.cpp - DoFindFriendlyMissingBuff()
class FriendlyMissingBuffInRange
{
public:
FriendlyMissingBuffInRange(Unit const* obj, float range, uint32 spellid) : i_obj(obj), i_range(range), i_spell(spellid) {}
bool operator()(Unit* u)
{
if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) &&
!(u->HasAura(i_spell, 0) || u->HasAura(i_spell, 1) || u->HasAura(i_spell, 2)))
{
return true;
}
return false;
}
private:
Unit const* i_obj;
float i_range;
uint32 i_spell;
};
//Used in:
//hyjalAI.cpp
class AllFriendlyCreaturesInGrid
{
public:
AllFriendlyCreaturesInGrid(Unit const* obj) : pUnit(obj) {}
bool operator() (Unit* u)
{
if(u->isAlive() && u->GetVisibility() == VISIBILITY_ON && u->IsFriendlyTo(pUnit))
return true;
return false;
}
private:
Unit const* pUnit;
};
//Used in:
//hyjalAI.cpp
class AllGameObjectsWithEntryInGrid
{
public:
AllGameObjectsWithEntryInGrid(uint32 ent) : entry(ent) {}
bool operator() (GameObject* g)
{
if(g->GetEntry() == entry)
return true;
return false;
}
private:
uint32 entry;
};
class AllCreaturesOfEntryInRange
{
public:
AllCreaturesOfEntryInRange(Unit const* obj, uint32 ent, float ran) : pUnit(obj), entry(ent), range(ran) {}
bool operator() (Unit* u)
{
if(u->GetEntry() == entry && pUnit->IsWithinDistInMap(u, range))
return true;
return false;
}
private:
Unit const* pUnit;
uint32 entry;
float range;
};
#endif

View File

@@ -0,0 +1,48 @@
/* Copyright (C) 2006 - 2008 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#ifndef SC_INSTANCE_H
#define SC_INSTANCE_H
#include "InstanceData.h"
#include "Map.h"
enum EncounterState
{
NOT_STARTED = 0,
IN_PROGRESS = 1,
FAIL = 2,
DONE = 3
};
#define OUT_SAVE_INST_DATA debug_log("SD2: Saving Instance Data for Instance %s (Map %d, Instance Id %d)", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_SAVE_INST_DATA_COMPLETE debug_log("SD2: Saving Instance Data for Instance %s (Map %d, Instance Id %d) completed.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA(a) debug_log("SD2: Loading Instance Data for Instance %s (Map %d, Instance Id %d). Input is '%s'", instance->GetMapName(), instance->GetId(), instance->GetInstanceId(), a)
#define OUT_LOAD_INST_DATA_COMPLETE debug_log("SD2: Instance Data Load for Instance %s (Map %d, Instance Id: %d) is complete.",instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA_FAIL error_log("SD2: Unable to load Instance Data for Instance %s (Map %d, Instance Id: %d).",instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
class MANGOS_DLL_DECL ScriptedInstance : public InstanceData
{
public:
ScriptedInstance(Map *map) : InstanceData(map) {}
~ScriptedInstance() {}
//All-purpose data storage 64 bit
virtual uint64 GetData64(uint32) {return 0; }
virtual void SetData64(uint32, uint64) { }
//All-purpose data storage 32 bit
virtual uint32 GetData(uint32) { return 0; }
virtual void SetData(uint32, uint32 data) {}
// 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