Advertisement
Guest User

instance_trial_of_the_champion.cpp

a guest
Apr 14th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.88 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify it
  5.  * under the terms of the GNU General Public License as published by the
  6.  * Free Software Foundation; either version 2 of the License, or (at your
  7.  * option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful, but WITHOUT
  10.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11.  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12.  * more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program. If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17.  
  18. /* ScriptData
  19. SDName: Instance Trial of the Champion
  20. SDComment:
  21. SDCategory: Trial Of the Champion
  22. EndScriptData */
  23.  
  24. #include "ScriptMgr.h"
  25. #include "ScriptedCreature.h"
  26. #include "InstanceScript.h"
  27. #include "ScriptPCH.h"
  28. #include "trial_of_the_champion.h"
  29. #include "Player.h"
  30.  
  31. #define MAX_ENCOUNTER  4
  32.  
  33. class instance_trial_of_the_champion : public InstanceMapScript
  34. {
  35. public:
  36.     instance_trial_of_the_champion() : InstanceMapScript("instance_trial_of_the_champion", 650) { }
  37.  
  38.     InstanceScript* GetInstanceScript(InstanceMap* pMap) const /*OVERRIDE*/
  39.     {
  40.         return new instance_trial_of_the_champion_InstanceMapScript(pMap);
  41.     }
  42.  
  43.     struct instance_trial_of_the_champion_InstanceMapScript : public InstanceScript
  44.     {
  45.         instance_trial_of_the_champion_InstanceMapScript(Map* pMap) : InstanceScript(pMap) {}
  46.  
  47.         uint32 m_auiEncounter[MAX_ENCOUNTER];
  48.         uint32 TeamInInstance;
  49.  
  50.         uint16 uiMovementDone;
  51.         uint16 uiGrandChampionsDeaths;
  52.         uint8 uiArgentSoldierDeaths;
  53.         uint8 uiAgroDone;
  54.         uint8 uiAggroDone;
  55.  
  56.         uint64 uiAnnouncerGUID;
  57.         uint64 uiHighlordGUID;
  58.         uint64 uiMainGateGUID;
  59.         uint64 uiMainGate1GUID;
  60.         uint64 uiGrandChampionVehicle1GUID;
  61.         uint64 uiGrandChampionVehicle2GUID;
  62.         uint64 uiGrandChampionVehicle3GUID;
  63.         uint64 uiGrandChampion1GUID;
  64.         uint64 uiGrandChampion2GUID;
  65.         uint64 uiGrandChampion3GUID;
  66.         uint64 uiChampionLootGUID;
  67.         uint64 uiArgentChampionGUID;
  68.  
  69.         std::list<uint64> VehicleList;
  70.  
  71.         std::string str_data;
  72.  
  73.         bool bDone;
  74.  
  75.         void Initialize() OVERRIDE
  76.         {
  77.             uiMovementDone         = 0;
  78.             uiGrandChampionsDeaths = 0;
  79.             uiArgentSoldierDeaths  = 0;
  80.             TeamInInstance         = 0;
  81.  
  82.             uiAnnouncerGUID        = 0;
  83.             uiHighlordGUID         = 0;
  84.             uiMainGateGUID         = 0;
  85.             uiMainGate1GUID        = 0;
  86.             uiGrandChampionVehicle1GUID   = 0;
  87.             uiGrandChampionVehicle2GUID   = 0;
  88.             uiGrandChampionVehicle3GUID   = 0;
  89.             uiGrandChampion1GUID          = 0;
  90.             uiGrandChampion2GUID          = 0;
  91.             uiGrandChampion3GUID          = 0;
  92.             uiChampionLootGUID            = 0;
  93.             uiArgentChampionGUID          = 0;
  94.  
  95.             bDone = false;
  96.  
  97.             VehicleList.clear();
  98.  
  99.             memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));
  100.         }
  101.  
  102.         bool IsEncounterInProgress() const OVERRIDE
  103.         {
  104.             for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
  105.             {
  106.                 if (m_auiEncounter[i] == IN_PROGRESS)
  107.                     return true;
  108.             }
  109.  
  110.             return false;
  111.         }
  112.  
  113.         void OnCreatureCreate(Creature* creature) OVERRIDE
  114.         {
  115.             Map::PlayerList const &players = instance->GetPlayers();
  116.  
  117.             if (!players.isEmpty())
  118.             {
  119.                 if (Player* player = players.begin()->GetSource())
  120.                     TeamInInstance = player->GetTeam();
  121.             }
  122.  
  123.             switch (creature->GetEntry())
  124.             {
  125.                 // Gran Champions
  126.                 case VEHICLE_MOKRA_SKILLCRUSHER_MOUNT:
  127.                     if (TeamInInstance == HORDE)
  128.                         creature->UpdateEntry(VEHICLE_MARSHAL_JACOB_ALERIUS_MOUNT, ALLIANCE);
  129.                     break;
  130.                 case NPC_MOKRA:
  131.                     if (TeamInInstance == HORDE)
  132.                         creature->UpdateEntry(NPC_JACOB, ALLIANCE);
  133.                     break;
  134.                 case VEHICLE_ERESSEA_DAWNSINGER_MOUNT:
  135.                     if (TeamInInstance == HORDE)
  136.                         creature->UpdateEntry(VEHICLE_AMBROSE_BOLTSPARK_MOUNT, ALLIANCE);
  137.                     break;
  138.                 case NPC_ERESSEA:
  139.                     if (TeamInInstance == HORDE)
  140.                         creature->UpdateEntry(NPC_AMBROSE, ALLIANCE);
  141.                     break;
  142.                 case VEHICLE_RUNOK_WILDMANE_MOUNT:
  143.                     if (TeamInInstance == HORDE)
  144.                         creature->UpdateEntry(VEHICLE_COLOSOS_MOUNT, ALLIANCE);
  145.                     break;
  146.                 case NPC_RUNOK:
  147.                     if (TeamInInstance == HORDE)
  148.                         creature->UpdateEntry(NPC_COLOSOS, ALLIANCE);
  149.                     break;
  150.                 case VEHICLE_ZUL_TORE_MOUNT:
  151.                     if (TeamInInstance == HORDE)
  152.                         creature->UpdateEntry(VEHICLE_EVENSONG_MOUNT, ALLIANCE);
  153.                     break;
  154.                 case NPC_ZULTORE:
  155.                     if (TeamInInstance == HORDE)
  156.                         creature->UpdateEntry(NPC_JAELYNE, ALLIANCE);
  157.                     break;
  158.                 case VEHICLE_DEATHSTALKER_VESCERI_MOUNT:
  159.                     if (TeamInInstance == HORDE)
  160.                         creature->UpdateEntry(VEHICLE_LANA_STOUTHAMMER_MOUNT, ALLIANCE);
  161.                     break;
  162.                 case NPC_VISCERI:
  163.                     if (TeamInInstance == HORDE)
  164.                         creature->UpdateEntry(NPC_LANA, ALLIANCE);
  165.                     break;
  166.                 // Faction Champions vehicles
  167.                 case VEHICLE_FORSAKE_WARHORSE:
  168.                     if (TeamInInstance == HORDE)
  169.                         creature->UpdateEntry(VEHICLE_IRONFORGE_RAM, ALLIANCE);
  170.                     break;
  171.                 case VEHICLE_THUNDER_BLUFF_KODO:
  172.                     if (TeamInInstance == HORDE)
  173.                         creature->UpdateEntry(VEHICLE_EXODAR_ELEKK, ALLIANCE);
  174.                     break;
  175.                 case VEHICLE_ORGRIMMAR_WOLF:
  176.                     if (TeamInInstance == HORDE)
  177.                         creature->UpdateEntry(VEHICLE_STORMWIND_STEED, ALLIANCE);
  178.                     break;
  179.                 case VEHICLE_SILVERMOON_HAWKSTRIDER:
  180.                     if (TeamInInstance == HORDE)
  181.                         creature->UpdateEntry(VEHICLE_GNOMEREGAN_MECHANOSTRIDER, ALLIANCE);
  182.                     break;
  183.                 case VEHICLE_DARKSPEAR_RAPTOR:
  184.                     if (TeamInInstance == HORDE)
  185.                         creature->UpdateEntry(VEHICLE_DARNASSIA_NIGHTSABER, ALLIANCE);
  186.                     break;
  187.                 // Faction champions
  188.                 case NPC_ORGRIMAR_CHAMPION:
  189.                     if (TeamInInstance == HORDE)
  190.                         creature->UpdateEntry(NPC_STORMWIND_CHAMPION, ALLIANCE);
  191.                     break;
  192.                 case NPC_SILVERMOON_CHAMPION:
  193.                     if (TeamInInstance == HORDE)
  194.                         creature->UpdateEntry(NPC_GNOMERAGN_CHAMPION, ALLIANCE);
  195.                     break;
  196.                 case NPC_THUNDER_CHAMPION:
  197.                     if (TeamInInstance == HORDE)
  198.                         creature->UpdateEntry(NPC_EXODAR_CHAMPION, ALLIANCE);
  199.                     break;
  200.                 case NPC_TROLL_CHAMPION:
  201.                     if (TeamInInstance == HORDE)
  202.                         creature->UpdateEntry(NPC_DRNASSUS_CHAMPION, ALLIANCE);
  203.                     break;
  204.                 case NPC_UNDERCITY_CHAMPION:
  205.                     if (TeamInInstance == HORDE)
  206.                         creature->UpdateEntry(NPC_IRONFORGE_CHAMPION, ALLIANCE);
  207.                     break;
  208.                 // Coliseum Announcer || Just NPC_JAEREN must be spawned.
  209.                 case NPC_HIGHLORD:
  210.                     uiHighlordGUID = creature->GetGUID();
  211.                     break;
  212.                 case NPC_JAEREN:
  213.                     if (TeamInInstance == ALLIANCE)
  214.                         creature->UpdateEntry(NPC_ARELAS, ALLIANCE);
  215.                     uiAnnouncerGUID = creature->GetGUID();
  216.                     break;
  217.                 case NPC_JAEREN_AN:
  218.                     if (TeamInInstance == ALLIANCE)
  219.                         creature->UpdateEntry(NPC_ARELAS_AN, ALLIANCE);
  220.                     break;
  221.                 case VEHICLE_ARGENT_WARHORSE:
  222.                 case VEHICLE_ARGENT_BATTLEWORG:
  223.                     VehicleList.push_back(creature->GetGUID());
  224.                     break;
  225.                 case NPC_EADRIC:
  226.                 case NPC_PALETRESS:
  227.                     uiArgentChampionGUID = creature->GetGUID();
  228.                     break;
  229.             }
  230.         }
  231.  
  232.         void OnGameObjectCreate(GameObject* go) OVERRIDE
  233.         {
  234.             switch (go->GetEntry())
  235.             {
  236.                 case GO_MAIN_GATE:
  237.                     uiMainGateGUID = go->GetGUID();
  238.                     break;
  239.                 case GO_MAIN_GATE1:
  240.                     uiMainGate1GUID = go->GetGUID();
  241.                     break;
  242.                 case GO_CHAMPIONS_LOOT:
  243.                 case GO_CHAMPIONS_LOOT_H:
  244.                     uiChampionLootGUID = go->GetGUID();
  245.                     break;
  246.             }
  247.         }
  248.  
  249.         void SetData(uint32 uiType, uint32 uiData) OVERRIDE
  250.         {
  251.             switch (uiType)
  252.             {
  253.                 case DATA_MOVEMENT_DONE:
  254.                     uiMovementDone = uiData;
  255.                     if (uiMovementDone == 3)
  256.                     {
  257.                         if (Creature* pAnnouncer =  instance->GetCreature(uiAnnouncerGUID))
  258.                             pAnnouncer->AI()->SetData(DATA_IN_POSITION, 0);
  259.                     }
  260.                     break;
  261.                 case BOSS_GRAND_CHAMPIONS:
  262.                     m_auiEncounter[0] = uiData;
  263.                     if (uiData == IN_PROGRESS)
  264.                     {
  265.                         for (std::list<uint64>::const_iterator itr = VehicleList.begin(); itr != VehicleList.end(); ++itr)
  266.                             if (Creature* summon = instance->GetCreature(*itr))
  267.                                 summon->RemoveFromWorld();
  268.                     } else if (uiData == DONE)
  269.                     {
  270.                         ++uiGrandChampionsDeaths;
  271.                         if (uiGrandChampionsDeaths >= 3)
  272.                         {
  273.                             if (Creature* pAnnouncer =  instance->GetCreature(uiAnnouncerGUID))
  274.                             {
  275.                                 pAnnouncer->AI()->SetData(DATA_RESET, 0);
  276.                                 m_auiEncounter[0] = uiData;
  277.                                 pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
  278.                                 pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
  279.                                 pAnnouncer->SummonGameObject(instance->IsHeroic()? GO_CHAMPIONS_LOOT_H : GO_CHAMPIONS_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, 0, 0, 0, 0, 90000000);
  280.                                                         if (GameObject* cache = instance->GetGameObject(GO_CHAMPIONS_LOOT))
  281.                                     cache->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE);
  282.                                                         else if (GameObject* cache = instance->GetGameObject(GO_CHAMPIONS_LOOT_H))
  283.                                     cache->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE);
  284.                             }
  285.                         }
  286.                     }
  287.                     break;
  288.                 case DATA_ARGENT_SOLDIER_DEFEATED:
  289.                     uiArgentSoldierDeaths = uiData;
  290.                     if (uiArgentSoldierDeaths == 9)
  291.                     {
  292.                         if (Creature* pBoss =  instance->GetCreature(uiArgentChampionGUID))
  293.                         {
  294.                             pBoss->GetMotionMaster()->MovePoint(0, 746.88f, 618.74f, 411.06f);
  295.                             pBoss->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
  296.                             pBoss->SetReactState(REACT_AGGRESSIVE);
  297.                             pBoss->setFaction(16);
  298.                         }
  299.                     }
  300.                     break;
  301.                 case BOSS_ARGENT_CHALLENGE_E:
  302.                     m_auiEncounter[1] = uiData;
  303.                     if (uiData == IN_PROGRESS)
  304.                     {
  305.                         for (std::list<uint64>::const_iterator itr = VehicleList.begin(); itr != VehicleList.end(); ++itr)
  306.                         if (Creature* pSummon = instance->GetCreature(*itr))
  307.                             pSummon->RemoveFromWorld();
  308.                     } else if (uiData == DONE)
  309.                     {
  310.                         if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
  311.                         {
  312.                             pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
  313.                             pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
  314.                             pAnnouncer->SummonGameObject(instance->IsHeroic() ? GO_EADRIC_LOOT_H : GO_EADRIC_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, 0, 0, 0, 0, 90000000);
  315.                         }
  316.                                                if (GameObject* cache = instance->GetGameObject(GO_EADRIC_LOOT))
  317.                                     cache->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE);
  318.                                                else if (GameObject* cache = instance->GetGameObject(GO_EADRIC_LOOT_H))
  319.                                     cache->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE);
  320.                     }
  321.                     break;
  322.                 case DATA_AGGRO_DONE:
  323.                     uiAgroDone = uiData;
  324.                     if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
  325.                     {
  326.                         pAnnouncer->SetVisible(false);
  327.                     }
  328.                     break;
  329.                 case DATA_AGRO_DONE:
  330.                     uiAggroDone = uiData;
  331.                     if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
  332.                     {
  333.                         pAnnouncer->SetVisible(false);
  334.                     }
  335.                     break;
  336.                 case BOSS_ARGENT_CHALLENGE_P:
  337.                     m_auiEncounter[2] = uiData;
  338.                     if (uiData == IN_PROGRESS)
  339.                     {
  340.                         for (std::list<uint64>::const_iterator itr = VehicleList.begin(); itr != VehicleList.end(); ++itr)
  341.                         if (Creature* pSummon = instance->GetCreature(*itr))
  342.                             pSummon->RemoveFromWorld();
  343.                     } else if (uiData == DONE)
  344.                     {
  345.                         if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
  346.                         {
  347.                             pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
  348.                             pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
  349.                             pAnnouncer->SummonGameObject(instance->IsHeroic() ? GO_PALETRESS_LOOT_H : GO_PALETRESS_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, 0, 0, 0, 0, 90000000);
  350.                         }
  351.                                                if (GameObject* cache = instance->GetGameObject(GO_PALETRESS_LOOT))
  352.                                     cache->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE);
  353.                                                else if (GameObject* cache = instance->GetGameObject(GO_PALETRESS_LOOT_H))
  354.                                     cache->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE);
  355.  
  356.                     }
  357.                     break;
  358.             }
  359.  
  360.             if (uiData == DONE)
  361.                 SaveToDB();
  362.         }
  363.  
  364.         uint32 GetData(uint32 uiData) const OVERRIDE
  365.         {
  366.             switch (uiData)
  367.             {
  368.                 case BOSS_GRAND_CHAMPIONS:  return m_auiEncounter[0];
  369.                 case BOSS_ARGENT_CHALLENGE_E: return m_auiEncounter[1];
  370.                 case BOSS_ARGENT_CHALLENGE_P: return m_auiEncounter[2];
  371.                 case BOSS_BLACK_KNIGHT: return m_auiEncounter[3];
  372.  
  373.                 case DATA_MOVEMENT_DONE: return uiMovementDone;
  374.                 case DATA_ARGENT_SOLDIER_DEFEATED: return uiArgentSoldierDeaths;
  375.                 case DATA_TEAM_IN_INSTANCE: return TeamInInstance;
  376.             }
  377.  
  378.             return 0;
  379.         }
  380.  
  381.         uint64 GetData64(uint32 uiData) const OVERRIDE
  382.         {
  383.             switch (uiData)
  384.             {
  385.                 case DATA_ANNOUNCER: return uiAnnouncerGUID;
  386.                 case DATA_HIGHLORD:  return uiHighlordGUID;
  387.                 case DATA_MAIN_GATE: return uiMainGateGUID;
  388.                 case DATA_MAIN_GATE1: return uiMainGate1GUID;
  389.  
  390.                 case DATA_GRAND_CHAMPION_1: return uiGrandChampion1GUID;
  391.                 case DATA_GRAND_CHAMPION_2: return uiGrandChampion2GUID;
  392.                 case DATA_GRAND_CHAMPION_3: return uiGrandChampion3GUID;
  393.             }
  394.  
  395.             return 0;
  396.         }
  397.  
  398.         void SetData64(uint32 uiType, uint64 uiData) OVERRIDE
  399.         {
  400.             switch (uiType)
  401.             {
  402.                 case DATA_GRAND_CHAMPION_1:
  403.                     uiGrandChampion1GUID = uiData;
  404.                     break;
  405.                 case DATA_GRAND_CHAMPION_2:
  406.                     uiGrandChampion2GUID = uiData;
  407.                     break;
  408.                 case DATA_GRAND_CHAMPION_3:
  409.                     uiGrandChampion3GUID = uiData;
  410.                     break;
  411.             }
  412.         }
  413.  
  414.         std::string GetSaveData() OVERRIDE
  415.         {
  416.             OUT_SAVE_INST_DATA;
  417.  
  418.             std::ostringstream saveStream;
  419.  
  420.             saveStream << "T C " << m_auiEncounter[0]
  421.                        << " " << m_auiEncounter[1]
  422.                        << " " << m_auiEncounter[2]
  423.                        << " " << m_auiEncounter[3]
  424.                        << " " << uiGrandChampionsDeaths
  425.                        << " " << uiMovementDone;
  426.  
  427.             str_data = saveStream.str();
  428.  
  429.             OUT_SAVE_INST_DATA_COMPLETE;
  430.             return str_data;
  431.         }
  432.  
  433.         void Load(const char* in) OVERRIDE
  434.         {
  435.             if (!in)
  436.             {
  437.                 OUT_LOAD_INST_DATA_FAIL;
  438.                 return;
  439.             }
  440.  
  441.             OUT_LOAD_INST_DATA(in);
  442.  
  443.             char dataHead1, dataHead2;
  444.             uint16 data0, data1, data2, data3, data4, data5;
  445.  
  446.             std::istringstream loadStream(in);
  447.             loadStream >> dataHead1 >> dataHead2 >> data0 >> data1 >> data2 >> data3 >> data4 >> data5;
  448.  
  449.             if (dataHead1 == 'T' && dataHead2 == 'C')
  450.             {
  451.                 m_auiEncounter[0] = data0;
  452.                 m_auiEncounter[1] = data1;
  453.                 m_auiEncounter[2] = data2;
  454.                 m_auiEncounter[3] = data3;
  455.  
  456.                 for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
  457.                     if (m_auiEncounter[i] == IN_PROGRESS)
  458.                         m_auiEncounter[i] = NOT_STARTED;
  459.  
  460.                 uiGrandChampionsDeaths = data4;
  461.                 uiMovementDone = data5;
  462.             }
  463.             else
  464.                 OUT_LOAD_INST_DATA_FAIL;
  465.  
  466.             OUT_LOAD_INST_DATA_COMPLETE;
  467.         }
  468.     };
  469.  
  470. };
  471.  
  472. void HandleSpellOnPlayersInInstanceToC5(Unit* caller, uint32 spellId)
  473. {
  474.     if (spellId <= 0 || !caller)
  475.         return;
  476.  
  477.     Map* map = caller->GetMap();
  478.     if (map && map->IsDungeon())
  479.     {
  480.         Map::PlayerList const &PlayerList = map->GetPlayers();
  481.  
  482.         if (PlayerList.isEmpty())
  483.             return;
  484.  
  485.         for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
  486.             if (i->GetSource() && i->GetSource()->IsAlive() && !i->GetSource()->IsGameMaster())
  487.                 caller->CastSpell(i->GetSource(), spellId);
  488.     }
  489. }
  490.  
  491. void AddSC_instance_trial_of_the_champion()
  492. {
  493.     new instance_trial_of_the_champion();
  494. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement