Index: scripts/npc/sc_bartleby.cpp =================================================================== --- scripts/npc/sc_bartleby.cpp (revision 0) +++ scripts/npc/sc_bartleby.cpp (revision 0) @@ -0,0 +1,159 @@ +/* Copyright (C) 2006,2007 ScriptDev2 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "../sc_defines.h" + +// **** This script is still under Developement **** + +struct MANGOS_DLL_DECL bartlebyAI : public ScriptedAI +{ + + bartlebyAI(Creature *c) : ScriptedAI(c) {EnterEvadeMode();} + + int16 justDieTimer; + + void EnterEvadeMode() + { + justDieTimer = -1; + m_creature->setFaction(84); + m_creature->RemoveAllAuras(); + m_creature->DeleteThreatList(); + DoGoHome(); + } + + void AttackStart(Unit *who) + { + if (!who) + return; + + m_creature->setEmoteState(0); + + if (who->isTargetableForAttack() && who!= m_creature) + { + if(who->GetTypeId() == TYPEID_PLAYER && ((Player*)who)->GetQuestStatus(1640) == QUEST_STATUS_INCOMPLETE ) + DoStartMeleeAttack(who); + else + EnterEvadeMode(); + } + } + + void MoveInLineOfSight(Unit *who) + { + if (!who || m_creature->getVictim()) + return; + + if (who->isTargetableForAttack() && who->isInAccessablePlaceFor(m_creature) && m_creature->IsHostileTo(who)) + { + float attackRadius = m_creature->GetAttackDistance(who); + if (m_creature->IsWithinDistInMap(who, attackRadius) && m_creature->GetDistanceZ(who) <= CREATURE_Z_ATTACK_RANGE) + { + if(who->HasStealthAura()) + who->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); + + DoStartMeleeAttack(who); + } + } + + if( who->GetTypeId() == TYPEID_PLAYER && m_creature->IsWithinDistInMap(who, 15.0f) && ((Player*)who)->GetQuestStatus(1640) == QUEST_STATUS_INCOMPLETE && m_creature->getFaction() != 16 ) + m_creature->setFaction(16); + } + + void UpdateAI(const uint32 diff) + { + if (!m_creature->SelectHostilTarget() || + !m_creature->getVictim() || + !m_creature->isAlive() || + !m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE) ) return; + + if( m_creature->isAttackReady()) + { + m_creature->AttackerStateUpdate(m_creature->getVictim()); + m_creature->resetAttackTimer(); + } + if( justDieTimer > 2000 ) + { + m_creature->setEmoteState(0); //Unstunt //Will do nothing good until Dealdamage() work fine. + DoGoHome(); //Will do nothing good until Dealdamage() work fine. + if( justDieTimer > 10000 ) + EnterEvadeMode(); + } + else if( justDieTimer == 0) + justDieTimer += diff; + } + + // Here should be DealDamage(), but it trigger after the damage is done, so it not usefull. + void JustDied(Unit* Killer) + { + //Best choices, is creature never die in fact, so she noe respawning, but simply DoGoHome() + // Need core patch to make it very story like. + // 2 Way i see, stop creature dying with a better Dealdamage() Trigger + // Or Create a function to be able to change respawn COORD, who are proctected value, and put back original value after. + m_creature->setFaction(84); + //m_creature->setEmoteState(64); //Will do nothing good until Dealdamage() work fine. + m_creature->setDeathState(DEAD); //Not used when Dealdamage() will work fine. + m_creature->SetRespawnTime(0); //Not used when Dealdamage() will work fine. + //justDieTimer = 0; //Will do nothing good until Dealdamage() will work fine. + m_creature->Update(0);//Not used when Dealdamage() will work fine. + DoCast(m_creature,32343); + } +}; + +CreatureAI* GetAI_bartleby(Creature *_Creature) +{ + return new bartlebyAI (_Creature); +} + +bool QuestAccept_bartleby(Player *player, Creature *_Creature, Quest *_Quest ) +{ + if( _Quest->GetQuestId() == 1640 ) + { + if(player->HasStealthAura()) + player->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); + + _Creature->setFaction(16); + _Creature->AddThreat(player,2000.0f); // Be sure we will stay on him for the last of the fight + } + + return true; +} +bool QuestComplete_bartleby(Player *player, Creature *_Creature, Quest *_Quest ) +{ + _Creature->Say( "Anyone read me! Moon to earth?",LANG_UNIVERSAL,player->GetGUID() ); + if( _Quest->GetQuestId() == 1640 ) + ((bartlebyAI*)_Creature->AI())->EnterEvadeMode(); + + return true; +} + +bool GossipHello_bartleby(Player *player, Creature *_Creature) +{ + if( player->GetQuestStatus(1640) == QUEST_STATUS_INCOMPLETE) + return true; + + return false; +} + +void AddSC_bartleby() +{ + Script *newscript; + newscript = new Script; + newscript->Name="bartleby"; + newscript->pQuestAccept = &QuestAccept_bartleby; + newscript->pQuestComplete = &QuestComplete_bartleby; + newscript->pGossipHello = &GossipHello_bartleby; + newscript->GetAI = GetAI_bartleby; + m_scripts[nrscripts++] = newscript; +}