Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*######
- ## npc_doctor (handles both Gustaf Vanhowzen and Gregory Victor)
- ######*/
- struct MANGOS_DLL_DECL npc_doctorAI : public ScriptedAI
- {
- npc_doctorAI(Creature* pCreature) : ScriptedAI(pCreature) {Reset();}
- uint64 Playerguid;
- uint32 SummonPatient_Timer;
- uint32 SummonPatientCount;
- uint32 PatientDiedCount;
- uint32 PatientSavedCount;
- bool Event;
- std::list<uint64> Patients;
- std::vector<Location*> Coordinates;
- void Reset()
- {
- Playerguid = 0;
- SummonPatient_Timer = 10000;
- SummonPatientCount = 0;
- PatientDiedCount = 0;
- PatientSavedCount = 0;
- Patients.clear();
- Coordinates.clear();
- Event = false;
- m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
- }
- void BeginEvent(Player* pPlayer);
- void PatientDied(Location* Point);
- void PatientSaved(Creature* soldier, Player* pPlayer, Location* Point);
- void UpdateAI(const uint32 diff);
- };
- /*#####
- ## npc_injured_patient (handles all the patients, no matter Horde or Alliance)
- #####*/
- struct MANGOS_DLL_DECL npc_injured_patientAI : public ScriptedAI
- {
- npc_injured_patientAI(Creature* pCreature) : ScriptedAI(pCreature) {Reset();}
- uint64 Doctorguid;
- Location* Coord;
- void Reset()
- {
- Doctorguid = 0;
- Coord = NULL;
- //no select
- m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
- //no regen health
- m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT);
- //to make them lay with face down
- m_creature->SetStandState(UNIT_STAND_STATE_DEAD);
- uint32 mobId = m_creature->GetEntry();
- switch (mobId)
- { //lower max health
- case 12923:
- case 12938: //Injured Soldier
- m_creature->SetHealth(uint32(m_creature->GetMaxHealth()*.75));
- break;
- case 12924:
- case 12936: //Badly injured Soldier
- m_creature->SetHealth(uint32(m_creature->GetMaxHealth()*.50));
- break;
- case 12925:
- case 12937: //Critically injured Soldier
- m_creature->SetHealth(uint32(m_creature->GetMaxHealth()*.25));
- break;
- }
- }
- void SpellHit(Unit *caster, const SpellEntry *spell)
- {
- if (caster->GetTypeId() == TYPEID_PLAYER && m_creature->isAlive() && spell->Id == 20804)
- {
- if ((((Player*)caster)->GetQuestStatus(6624) == QUEST_STATUS_INCOMPLETE) || (((Player*)caster)->GetQuestStatus(6622) == QUEST_STATUS_INCOMPLETE))
- {
- if (Doctorguid)
- {
- if (Creature* Doctor = ((Creature*)Unit::GetUnit((*m_creature), Doctorguid)))
- ((npc_doctorAI*)Doctor->AI())->PatientSaved(m_creature, ((Player*)caster), Coord);
- }
- }
- //make not selectable
- m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
- //regen health
- m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT);
- //stand up
- m_creature->SetStandState(UNIT_STAND_STATE_STAND);
- switch(urand(0, 2))
- {
- case 0: DoScriptText(SAY_DOC1,m_creature); break;
- case 1: DoScriptText(SAY_DOC2,m_creature); break;
- case 2: DoScriptText(SAY_DOC3,m_creature); break;
- }
- m_creature->RemoveSplineFlag(SPLINEFLAG_WALKMODE);
- uint32 mobId = m_creature->GetEntry();
- switch (mobId)
- {
- case 12923:
- case 12924:
- case 12925:
- m_creature->GetMotionMaster()->MovePoint(0, H_RUNTOX, H_RUNTOY, H_RUNTOZ);
- break;
- case 12936:
- case 12937:
- case 12938:
- m_creature->GetMotionMaster()->MovePoint(0, A_RUNTOX, A_RUNTOY, A_RUNTOZ);
- break;
- }
- }
- }
- void UpdateAI(const uint32 diff)
- {
- //lower HP on every world tick makes it a useful counter, not officlone though
- if (m_creature->isAlive() && m_creature->GetHealth() > 6)
- {
- m_creature->SetHealth(uint32(m_creature->GetHealth()-5));
- }
- if (m_creature->isAlive() && m_creature->GetHealth() <= 6)
- {
- m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT);
- m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
- m_creature->setDeathState(JUST_DIED);
- m_creature->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
- if (Doctorguid)
- {
- if (Creature* Doctor = ((Creature*)Unit::GetUnit((*m_creature), Doctorguid)))
- ((npc_doctorAI*)Doctor->AI())->PatientDied(Coord);
- }
- }
- }
- };
- CreatureAI* GetAI_npc_injured_patient(Creature* pCreature)
- {
- return new npc_injured_patientAI(pCreature);
- }
- /*
- npc_doctor (continue)
- */
- void npc_doctorAI::BeginEvent(Player* pPlayer)
- {
- Playerguid = pPlayer->GetGUID();
- SummonPatient_Timer = 10000;
- SummonPatientCount = 0;
- PatientDiedCount = 0;
- PatientSavedCount = 0;
- switch(m_creature->GetEntry())
- {
- case DOCTOR_ALLIANCE:
- for(uint8 i = 0; i < ALLIANCE_COORDS; ++i)
- Coordinates.push_back(&AllianceCoords[i]);
- break;
- case DOCTOR_HORDE:
- for(uint8 i = 0; i < HORDE_COORDS; ++i)
- Coordinates.push_back(&HordeCoords[i]);
- break;
- }
- Event = true;
- m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
- }
- void npc_doctorAI::PatientDied(Location* Point)
- {
- Player* pPlayer = ((Player*)Unit::GetUnit((*m_creature), Playerguid));
- if (pPlayer && ((pPlayer->GetQuestStatus(6624) == QUEST_STATUS_INCOMPLETE) || (pPlayer->GetQuestStatus(6622) == QUEST_STATUS_INCOMPLETE)))
- {
- ++PatientDiedCount;
- if (PatientDiedCount > 5 && Event)
- {
- if (pPlayer->GetQuestStatus(QUEST_TRIAGE_A) == QUEST_STATUS_INCOMPLETE)
- pPlayer->FailQuest(QUEST_TRIAGE_A);
- else if (pPlayer->GetQuestStatus(QUEST_TRIAGE_H) == QUEST_STATUS_INCOMPLETE)
- pPlayer->FailQuest(QUEST_TRIAGE_H);
- Reset();
- return;
- }
- Coordinates.push_back(Point);
- }
- else
- // If no player or player abandon quest in progress
- Reset();
- }
- void npc_doctorAI::PatientSaved(Creature* soldier, Player* pPlayer, Location* Point)
- {
- if (pPlayer && Playerguid == pPlayer->GetGUID())
- {
- if ((pPlayer->GetQuestStatus(QUEST_TRIAGE_A) == QUEST_STATUS_INCOMPLETE) || (pPlayer->GetQuestStatus(QUEST_TRIAGE_H) == QUEST_STATUS_INCOMPLETE))
- {
- ++PatientSavedCount;
- if (PatientSavedCount == 15)
- {
- if (!Patients.empty())
- {
- std::list<uint64>::iterator itr;
- for(itr = Patients.begin(); itr != Patients.end(); ++itr)
- {
- if (Creature* Patient = ((Creature*)Unit::GetUnit((*m_creature), *itr)))
- Patient->setDeathState(JUST_DIED);
- }
- }
- if (pPlayer->GetQuestStatus(QUEST_TRIAGE_A) == QUEST_STATUS_INCOMPLETE)
- pPlayer->GroupEventHappens(QUEST_TRIAGE_A, m_creature);
- else if (pPlayer->GetQuestStatus(QUEST_TRIAGE_H) == QUEST_STATUS_INCOMPLETE)
- pPlayer->GroupEventHappens(QUEST_TRIAGE_H, m_creature);
- Reset();
- return;
- }
- Coordinates.push_back(Point);
- }
- }
- }
- void npc_doctorAI::UpdateAI(const uint32 diff)
- {
- if (Event && SummonPatientCount >= 20)
- {
- Reset();
- return;
- }
- if (Event)
- {
- if (SummonPatient_Timer < diff)
- {
- Creature* Patient = NULL;
- Location* Point = NULL;
- if (Coordinates.empty())
- return;
- std::vector<Location*>::iterator itr = Coordinates.begin()+rand()%Coordinates.size();
- uint32 patientEntry = 0;
- switch(m_creature->GetEntry())
- {
- case DOCTOR_ALLIANCE: patientEntry = AllianceSoldierId[urand(0, 2)]; break;
- case DOCTOR_HORDE: patientEntry = HordeSoldierId[urand(0, 2)]; break;
- default:
- error_log("SD2: Invalid entry for Triage doctor. Please check your database");
- return;
- }
- Point = *itr;
- Patient = m_creature->SummonCreature(patientEntry, Point->x, Point->y, Point->z, Point->o, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 5000);
- if (Patient)
- {
- //303, this flag appear to be required for client side item->spell to work (TARGET_SINGLE_FRIEND)
- Patient->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
- Patients.push_back(Patient->GetGUID());
- ((npc_injured_patientAI*)Patient->AI())->Doctorguid = m_creature->GetGUID();
- if (Point)
- ((npc_injured_patientAI*)Patient->AI())->Coord = Point;
- Coordinates.erase(itr);
- }
- SummonPatient_Timer = 10000;
- ++SummonPatientCount;
- }else SummonPatient_Timer -= diff;
- }
- }
- bool QuestAccept_npc_doctor(Player* pPlayer, Creature* pCreature, const Quest* pQuest)
- {
- if ((pQuest->GetQuestId() == QUEST_TRIAGE_A) || (pQuest->GetQuestId() == QUEST_TRIAGE_H))
- {
- if (npc_doctorAI* pDocAI = dynamic_cast<npc_doctorAI*>(pCreature->AI()))
- pDocAI->BeginEvent(pPlayer);
- }
- return true;
- }
- CreatureAI* GetAI_npc_doctor(Creature* pCreature)
- {
- return new npc_doctorAI(pCreature);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement