All pastes #995150 Raw Edit

BlehMcbleh

public cpp v1 · immutable
#995150 ·published 2008-04-23 22:07 UTC
rendered paste body
// Begin Hex Lord Malacrass#define MALACRASS		24239//summons#define GAZAKROTH		24244#define THURG			24241#define LORD_RAADAN		24243#define DARKHEART		24246#define ALYSON_ANTILLE	24240#define SLITHER			24242#define FENSTALKER		24245#define KORAGG			24247//spells#define DRAIN_POWER_S		44132	// Self#define DRAIN_POWER_V		44131	// Various#define SPIRIT_BOLTS		43383	// 43382class HexLordMalacrassAI : public CreatureAIScript{public:	ADD_CREATURE_FACTORY_FUNCTION(HexLordMalacrassAI);	SP_AI_Spell spells[4];	bool m_spellcheck[4];	HexLordMalacrassAI(Creature* pCreature) : CreatureAIScript(pCreature)	{		nrspells = 4;		for(int i=0;i<nrspells;i++)			m_spellcheck[i] = false;		spells[0].info = dbcSpell.LookupEntry( SPIRIT_BOLTS );		spells[0].targettype = TARGET_DESTINATION; 		spells[0].instant = true;		spells[0].perctrigger = 50.0f;		spells[0].attackstoptimer = 1000;		spells[0].cooldown = 30;		spells[0].soundid = 12345;		spells[0].speech = "Your soul gonna bleed!";		spells[1].info = dbcSpell.LookupEntry( DRAIN_POWER_S );		spells[1].targettype = TARGET_SELF;		spells[1].instant = true;		spells[1].perctrigger = 0.0f;		spells[1].attackstoptimer = 1000;		spells[1].cooldown = 0;		spells[1].minhp2cast = 80;		spells[1].soundid = 12345;		spells[1].speech = "Darkness comin' for you";		spells[2].info = dbcSpell.LookupEntry( DRAIN_POWER_V );		spells[2].targettype = TARGET_VARIOUS;		spells[2].instant = true;		spells[2].perctrigger = 0.0f;		spells[2].attackstoptimer = 1000;		spells[2].cooldown = 0;		spells[3].info = dbcSpell.LookupEntry( 0 );		spells[3].targettype = TARGET_SELF;		spells[3].instant = true;		spells[3].perctrigger = 0.0f;		spells[3].attackstoptimer = 1000;		spells[3].cooldown = 0;		spells[3].soundid = 12345;		spells[3].speech = "Your will beong ta me now!";		spells[3].mindist2cast = 0.0f;		spells[3].maxdist2cast = 100.0f;		SoulDrain = 0;		mobs = false;	}	void OnLoad()	{                char spawn[6];		if ( mobs == false )		{			for( int j = 0; j < 4; j++ )			{				summon = NULL;				switch (RandomUInt(7))				{				case 0:					summon = GAZAKROTH;					break;				case 1:					summon = DARKHEART;					break;				case 2:					summon = FENSTALKER;					break;				case 3:					summon = SLITHER;					break;				case 4:					summon = ALYSON_ANTILLE;					break;				case 5:					summon = THURG;					break;				case 6:					summon = KORAGG;					break;				case 7:					summon = LORD_RAADAN;					break;				}				Creature *summons = NULL;				summons = _unit->GetMapMgr()->GetInterface()->SpawnCreature(summon, (_unit->GetPositionX() + RandomFloat(10)-10), (_unit->GetPositionY() + RandomFloat(10)-10), _unit->GetPositionZ(), _unit->GetOrientation(), true, false, _unit->GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE), 0); 				summons->GetAIInterface()->setOutOfCombatRange(50000);				summons = NULL;			}			mobs = true;		}	}	void OnCombatStart(Unit * mTarget)	{		for( int i = 0; i < nrspells; i++ )			spells[i].casttime = 0;		spells[0].casttime = ( uint32 )time( NULL ) + spells[0].cooldown;		_unit->PlaySoundToSet(12041);		_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Da shadow gonna fall on you...");		RegisterAIUpdateEvent(1000);	}	void OnTargetDied(Unit * mTarget)	{		if (_unit->GetHealthPct() > 0)		{			uint32 sound = 0;			char * text = "";			switch (RandomUInt(1))			{			case 0:				sound = 12044;				text = "Azzaga choogo zinn!";				break;			case 1:				sound = 12043;				text = "Dis a nightmare ya don' wake up from!";				break;			}			_unit->PlaySoundToSet(sound);			_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, text);		}	}	void OnCombatStop(Unit * mTarget)	{		_unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);		_unit->GetAIInterface()->SetAIState(STATE_IDLE);		RemoveAIUpdateEvent();		mobs = false;	}	void OnDied(Unit * mKiller)	{		_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Dis not... da end of me..");		_unit->PlaySoundToSet(12051);		RemoveAIUpdateEvent();	}	void AIUpdate()	{		float val = (float)RandomFloat(100.0f);		SpellCast(val);		if( ( uint32 )time( NULL ) > SoulDrain )		{			if( _unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget() )			{				std::vector<Player*> TargetTable;				for( set<Player*>::iterator itr = _unit->GetInRangePlayerSetBegin(); itr != _unit->GetInRangePlayerSetEnd(); ++itr )				{					if( isHostile( _unit, (*itr) ) && (*itr)->GetInstanceID() == _unit->GetInstanceID() )					{						Player * RandomTarget = NULL;						RandomTarget = static_cast< Player* >( (*itr) );						if( RandomTarget->isAlive() && _unit->GetAIInterface()->getThreatByPtr( RandomTarget ) > 0 && isHostile( _unit, RandomTarget ) )							TargetTable.push_back( RandomTarget );					}				}				if( !TargetTable.size() )					return;				size_t RandTarget = rand() % TargetTable.size();				Unit * RTarget = TargetTable[RandTarget];				if( !RTarget )					return;				uint32 hexspell = 0;				uint32 hextarget = TARGET_SELF;				switch( RTarget->getClass() )				{				case WARRIOR:					switch( RandomUInt(2) )					{					case 0:						hexspell = 43443; // Spell Reflection						hextarget = TARGET_SELF;						break;					case 1:						hexspell = 43442; // Whirlwind						hextarget = TARGET_VARIOUS;						break;					case 2:						hexspell = 43441; // Mortal Strike						hextarget = TARGET_ATTACKING;						break;					}					break;				case PALADIN:					switch( RandomUInt(1) )					{					case 0:						hexspell = 43429; // Consecration						hextarget = TARGET_VARIOUS;						break;					case 1:						hexspell = 43430; // Avenging Wrath						hextarget = TARGET_SELF;						break;					/*					case 2:						hexspell = 43451; // Holy light						hextarget = TARGET_SELF;						break;					*/					}					break;				case HUNTER:					switch( RandomUInt(2) )					{					case 0:						hexspell = 43444; // Explosive Trap						hextarget = TARGET_SELF;						break;					case 1:						hexspell = 43447; // Freezing Trap						hextarget = TARGET_SELF;						break;					case 2:						hexspell = 43449; // Snake Trap						hextarget = TARGET_SELF;						break;					}					break;				case ROGUE:					switch( RandomUInt(2) )					{					case 0:						hexspell = 43433; // Blind						hextarget = TARGET_ATTACKING;						break;					case 1:						hexspell = 43547; // Slice and Dice						hextarget = TARGET_SELF;						break;					case 2:						hexspell = 39665; // Wound Poison						hextarget = TARGET_ATTACKING;						break;					}					break;				case PRIEST:					switch( RandomUInt(2) )					{					case 0:						hexspell = 41375; // Shadow Word: Death						hextarget = TARGET_RANDOM_SINGLE;						break;					case 1:						hexspell = 43432; // Physic Scream						hextarget = TARGET_VARIOUS;						break;					case 2:						hexspell = 44416; // Pain Suppression						hextarget = TARGET_SELF;						break;					/*					case 3:						hexspell = 41372; // Heal						hextarget = TARGET_SELF;						break;					case 4:						hexspell = 43550; // Mind Control						hextarget = TARGET_RANDOM_SINGLE;						break;					case 5:						hexspell = 41374; // Mind Blast						hextarget = TARGET_RANDOM_SINGLE						break;					*/					}					break;				case SHAMAN:					switch( RandomUInt(1) )					{					case 0:						hexspell = 43436; // Fire Nova Totem						hextarget = TARGET_SELF;						break;					/*					case 1:						hexspell = 43548 // Healing Wave						hextarget = TARGET_SELF;						break;					case 2:						hexspell = 43435; // Chain Lightning						hextarget = TARGET_RANDOM_SINGLE;						break;					*/					}					break;				case MAGE:					switch( RandomUInt(3) )					{					case 0:						hexspell = 41383; // Fireball						hextarget = TARGET_RANDOM_SINGLE;						break;					case 1:						hexspell = 43428; // Frostbolt						hextarget = TARGET_RANDOM_SINGLE;						break;					case 2:						hexspell = 43426; // Frost Nova						hextarget = TARGET_VARIOUS;						break;					case 3:						hexspell = 43427; // Ice Lance						hextarget = TARGET_RANDOM_SINGLE;						break;					}					break;				case WARLOCK:					switch( RandomUInt(2) )					{					case 0:						hexspell = 43439; // Curse of Doom						hextarget = TARGET_RANDOM_SINGLE;						break;					case 1:						hexspell = 43440; // Rain of Fire						hextarget = TARGET_RANDOM_DESTINATION;						break;					case 2:						hexspell = 35183; /// Unstable Affliction						hextarget = TARGET_RANDOM_SINGLE;						break;					}					break;				case DRUID:					switch( RandomUInt(2) )					{					case 0:						hexspell = 43421; // Lifebloom						hextarget = TARGET_SELF;						break;					case 1:						hexspell = 43420; // Thorns						hextarget = TARGET_SELF;						break;					case 2:						hexspell = 43545; // Moonfire						hextarget = TARGET_RANDOM_SINGLE;						break;					}					break;				}				spells[3].info = dbcSpell.LookupEntry( hexspell );				spells[3].targettype = hextarget;				spells[3].casttime = ( uint32 )time( NULL ) + 1;				SoulDrain = 0;			}		}	}	void SpellCast( float val )	{		if( _unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget() )		{			float comulativeperc = 0;			Unit * target = NULL;			for( int i = 0; i < nrspells; i++ )			{				if( !spells[i].perctrigger || !spells[i].minhp2cast || _unit->GetHealthPct() < spells[i].minhp2cast )					continue;				if( m_spellcheck[i] )				{					if( m_spellcheck[0] )						SoulDrain = 10;					if( m_spellcheck[1] )					{						_unit->CastSpell(_unit, spells[1].info, spells[1].instant);						_unit->CastSpell(_unit, spells[2].info, spells[2].instant);						m_spellcheck[1] = false;						return;					}					target = _unit->GetAIInterface()->GetNextTarget();					switch( spells[i].targettype )					{						case TARGET_SELF:						case TARGET_VARIOUS:							_unit->CastSpell( _unit, spells[i].info, spells[i].instant );							break;						case TARGET_ATTACKING:							_unit->CastSpell( target, spells[i].info, spells[i].instant );							break;						case TARGET_DESTINATION:							_unit->CastSpellAoF( target->GetPositionX(),target->GetPositionY(),target->GetPositionZ(), spells[i].info, spells[i].instant );							break;						case TARGET_RANDOM_FRIEND:						case TARGET_RANDOM_SINGLE:						case TARGET_RANDOM_DESTINATION:							CastSpellOnRandomTarget( i, spells[i].mindist2cast, spells[i].maxdist2cast, spells[i].minhp2cast, spells[i].maxhp2cast );							break;					}					m_spellcheck[i] = false;					return;				}				uint32 t = ( uint32 )time( NULL );				if( val > comulativeperc && val <= ( comulativeperc + spells[i].perctrigger ) && t > spells[i].casttime )				{					_unit->setAttackTimer( spells[i].attackstoptimer, false );					if( m_spellcheck[3] )						spells[i].casttime = 0;					else						spells[i].casttime = t + spells[i].cooldown;					m_spellcheck[i] = true;				}				comulativeperc += spells[i].perctrigger;			}		}	}	void CastSpellOnRandomTarget( uint32 i, float mindist2cast, float maxdist2cast, int minhp2cast, int maxhp2cast )	{		if( !maxdist2cast ) maxdist2cast = 100.0f;		if( !maxhp2cast ) maxhp2cast = 100;		if( _unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget() )		{			std::vector<Unit*> TargetTable;			for( set<Object*>::iterator itr = _unit->GetInRangeSetBegin(); itr != _unit->GetInRangeSetEnd(); ++itr )			{				if( ( ( spells[i].targettype == TARGET_RANDOM_FRIEND && isFriendly( _unit, ( *itr ) ) ) || ( spells[i].targettype != TARGET_RANDOM_FRIEND && isHostile( _unit, ( *itr ) ) && ( *itr ) != _unit ) ) && ( ( *itr )->GetTypeId()== TYPEID_UNIT || ( *itr )->GetTypeId() == TYPEID_PLAYER ) && ( *itr )->GetInstanceID() == _unit->GetInstanceID() )//isAttackable( _unit, ( *itr ) ) &&				{					Unit * RandomTarget = NULL;					RandomTarget = static_cast< Unit* >( ( *itr ) );					if( RandomTarget->isAlive() && _unit->GetDistance2dSq( RandomTarget ) >= mindist2cast * mindist2cast && _unit->GetDistance2dSq( RandomTarget ) <= maxdist2cast * maxdist2cast && ( ( RandomTarget->GetHealthPct() >= minhp2cast && RandomTarget->GetHealthPct() <= maxhp2cast && spells[i].targettype == TARGET_RANDOM_FRIEND ) || ( _unit->GetAIInterface()->getThreatByPtr( RandomTarget ) > 0 && isHostile( _unit, RandomTarget ) ) ) )						TargetTable.push_back( RandomTarget );				}			}			if( !TargetTable.size() )				return;			size_t RandTarget = rand() % TargetTable.size();			Unit * RTarget = TargetTable[RandTarget];			if( !RTarget )				return;			switch( spells[i].targettype )			{				case TARGET_RANDOM_FRIEND:				case TARGET_RANDOM_SINGLE:					_unit->CastSpell( RTarget, spells[i].info, spells[i].instant );					break;				case TARGET_RANDOM_DESTINATION:					_unit->CastSpellAoF( RTarget->GetPositionX(), RTarget->GetPositionY(), RTarget->GetPositionZ(), spells[i].info, spells[i].instant );					break;			}			TargetTable.clear();		}	}protected:	int nrspells;	uint32 SoulDrain;	uint32 summon;	bool mobs;};class HexSummonsAI : public CreatureAIScript{public:	ADD_CREATURE_FACTORY_FUNCTION(HexSummonsAI);	HexSummonsAI(Creature* pCreature) : CreatureAIScript(pCreature) {}	void OnDied(Unit * mKiller)	{		Creature *Malacrass = NULL;		Malacrass = _unit->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(_unit->GetPositionX(), _unit->GetPositionY(), _unit->GetPositionZ(), MALACRASS);		if( Malacrass != NULL )		{			uint32 sound = 0;			uint32 text = "";			switch( RandomUInt(2) )			{			case 0:				sound = 0;				text = "Dat no bodda me.";				break;			case 1:				sound = 0;				text = "It not gonna make a difference";				break;			case 2:				sound = 0;				text = "You gonna die worse dan him";				break;			}			_unit->PlaySoundToSet(sound);			Malacrass->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, text);		}};