Advertisement
Guest User

Untitled

a guest
May 1st, 2013
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.62 KB | None | 0 0
  1. /************************************************************************/
  2. /* Copyright (C) 2006 DotA-WoW Team, assistance by Woof.                */
  3. /************************************************************************/
  4. #include "game/StdAfx.h"
  5.  
  6. /* Script Export Declarations */
  7. extern "C" WOWD_SCRIPT_DECL CreatureAIScript* CreateCreatureAIClass(uint32 uEntryId, Creature* creature);
  8. extern "C" WOWD_SCRIPT_DECL InstanceScript* CreateInstanceClass(uint32 uMapId, MapMgr* instance);
  9. extern "C" WOWD_SCRIPT_DECL void ScriptInitialize(ScriptModule *mod);
  10.  
  11. // Build version info function
  12. BUILD_VERSIONINFO_DATA(SCRIPTLIB_VERSION_MAJOR, SCRIPTLIB_VERSION_MINOR);
  13.  
  14. /* This is needed because windows is a piece of shit. ;) */
  15. #ifdef WIN32
  16.  
  17. BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved )
  18. {
  19.     return TRUE;
  20. }
  21.  
  22. #endif
  23.  
  24.  
  25. /************************************************************************/
  26. /* INSTANCE / MAP SCRIPTING SECTION                                     */
  27. /************************************************************************/
  28.  
  29. class DotABattleground : public InstanceScript
  30. {
  31. public:
  32.     DotABattleground(MapMgr* mapmgr) : InstanceScript(mapmgr)
  33.     {
  34.         script_debuglog("dotabattleground instance script CREATED!");
  35.  
  36.         // Register our update event.
  37.         // Called every 1 second.
  38.         mapmgr->RegisterScriptUpdater(1000);
  39.  
  40.         // reset all variables
  41.         tPushPlayersToJail = 0;
  42.         tRemovePlayersFromJail = 0;
  43.         tJailMsg1 = 0;
  44.         tJailMsg2 = 0;
  45.        
  46.         // set our battleground var
  47.         me = ((WarsongGulch*)sBattlegroundMgr.GetBattlegroundByInstanceID(_instance->GetInstanceID(), 2));
  48.         ASSERT(me);
  49.     }
  50.  
  51.     void TransportPlayers(float* AllianceVector, float* HordeVector)
  52.     {
  53.         script_debuglog("player transport:\n    alliance: %f %f %f\n    horde: %f %f %f", AllianceVector[0],
  54.             AllianceVector[1], AllianceVector[2], HordeVector[0], HordeVector[1], HordeVector[2]);
  55.  
  56.         std::list<Player*>::iterator iter = me->GetPlayersBegin();
  57.         Player *plyr;
  58.         for(; iter != me->GetPlayersEnd(); ++iter)
  59.         {
  60.             plyr = *iter;
  61.             if(plyr->GetTeam() == 0)    // Alliance
  62.             {
  63.                 plyr->Relocate(_instance->GetMapId(), AllianceVector[0],
  64.                     AllianceVector[1], AllianceVector[2], plyr->GetOrientation(), false, false);
  65.             }
  66.             else
  67.             {
  68.                 plyr->Relocate(_instance->GetMapId(), HordeVector[0],
  69.                     HordeVector[1], HordeVector[2], plyr->GetOrientation(), false, false);
  70.             }
  71.         }
  72.     }
  73.  
  74.     void UpdateEvent()
  75.     {
  76.         // Update our timers
  77.  
  78.         if(tPushPlayersToJail)
  79.         {
  80.             if(getMSTime() > tPushPlayersToJail)
  81.             {
  82.                 script_debuglog("pushing all players into jail.");
  83.  
  84.                 // Time to push all the battlegrounds players into our temporary jail cell.
  85.                 float AllianceJailVector[3] = {1512.233154f, 1457.687866f, 362.712616f};
  86.                 float HordeJailVector[3] = {942.312927f, 1458.473389f, 356.188507f};
  87.  
  88.                 // Send them all to jail.
  89.                 TransportPlayers(AllianceJailVector, HordeJailVector);
  90.  
  91.                 // Disable the timer so we don't get double transports.
  92.                 tPushPlayersToJail = 0;
  93.  
  94.                 // Set timer for first message at 10 seconds.
  95.                 tJailMsg1 = getMSTime() + 10000;
  96.             }
  97.         }
  98.  
  99.         if(tRemovePlayersFromJail)
  100.         {
  101.             if(getMSTime() > tRemovePlayersFromJail)
  102.             {
  103.                 script_debuglog("removing all players from jail.");
  104.  
  105.                 // Time to push all the battlegrounds players back to the start.
  106.                 float AllianceStartVector[3] = {1519.423096f, 1476.264648f, 352.043610f};
  107.                 float HordeStartVector[3] = {934.636108f, 1434.188843f, 345.535767f};
  108.  
  109.                 // Send them all to jail.
  110.                 TransportPlayers(AllianceStartVector, HordeStartVector);
  111.  
  112.                 // Disable the timer so we don't get double transports.
  113.                 tRemovePlayersFromJail= 0;
  114.  
  115.                 // Remove the jail walls.
  116.                 DespawnJailWalls();
  117.             }
  118.         }
  119.  
  120.         if(tJailMsg1)
  121.         {
  122.             if(getMSTime() > tJailMsg1)
  123.             {
  124.                 script_debuglog("jail message 1");
  125.  
  126.                 string msg = MSG_COLOR_YELLOW;
  127.                 msg += "Discuss your tactics for the next round! It will start in 1 minute.";
  128.  
  129.                 me->SendCMessageToAll(msg.c_str(), false);
  130.                 tJailMsg1 = 0;
  131.  
  132.                 // Set next timer.
  133.                 tJailMsg2 = getMSTime() + 30000;
  134.             }
  135.         }
  136.  
  137.         if(tJailMsg2)
  138.         {
  139.             if(getMSTime() > tJailMsg2)
  140.             {
  141.                 script_debuglog("jail message 2");
  142.  
  143.                 string msg = MSG_COLOR_LIGHTRED;
  144.                 msg += "The battleground is respawning. All objects will be deleted/recreated, some players may experience lag for a few seconds.";
  145.                 me->SendCMessageToAll(msg.c_str(), false);
  146.  
  147.                 script_debuglog("respawning battleground");
  148.                 me->GetMapMgr()->Respawn(true, true);
  149.  
  150.                 msg = MSG_COLOR_YELLOW;
  151.                 msg += "The next round will begin in 30 seconds.";
  152.  
  153.                 me->SendCMessageToAll(msg.c_str(), false);
  154.                 tJailMsg2 = 0;
  155.  
  156.                 // Set next timer.
  157.                 tRemovePlayersFromJail = getMSTime() + 30000;
  158.             }
  159.         }
  160.     }
  161.  
  162.     struct govector
  163.     {
  164.         uint32 entry;
  165.         float x;
  166.         float y;
  167.         float z;
  168.     };
  169.  
  170.     void SpawnJailWalls()
  171.     {
  172.         script_debuglog("spawning jail walls");
  173.  
  174.         // Spawn gameobjects in specific locations to hold players in :P
  175.         static govector AllianceObjects[] =
  176.         {
  177.             { 175352, 1503.853882f, 1458.184082f, 362.711946f },
  178.             { 175352, 1520.908081f, 1457.287231f, 362.701782f },
  179.             { 0, 0.0f, 0.0f, 0.0f },
  180.         };
  181.  
  182.         static govector HordeObjects[] =
  183.         {
  184.             { 175352, 932.693542f, 1458.518188f, 356.453979f },
  185.             { 175352, 951.369995f, 1458.481201f, 356.188507f },
  186.             { 0, 0.0f, 0.0f, 0.0f },
  187.         };
  188.  
  189.         for(uint32 i = 0; AllianceObjects[i].entry != 0; ++i)
  190.         {
  191.             GameObject *pGo = _instance->GetInterface()->SpawnGameObject(AllianceObjects[i].entry,
  192.                                     AllianceObjects[i].x, AllianceObjects[i].y, AllianceObjects[i].z, 0, false, 0, 0);
  193.             ASSERT(pGo);
  194.             pGo->SetUInt32Value(GAMEOBJECT_FLAGS, 33);
  195.             pGo->Spawn();
  196.  
  197.             jailgameobjects.push(pGo);
  198.         }
  199.  
  200.         for(uint32 i = 0; HordeObjects[i].entry != 0; ++i)
  201.         {
  202.             GameObject *pGo = _instance->GetInterface()->SpawnGameObject(HordeObjects[i].entry,
  203.                 HordeObjects[i].x, HordeObjects[i].y, HordeObjects[i].z, 0, false, 0, 0);
  204.             ASSERT(pGo);
  205.             pGo->SetUInt32Value(GAMEOBJECT_FLAGS, 33);
  206.             pGo->Spawn();
  207.  
  208.             jailgameobjects.push(pGo);
  209.         }
  210.     }
  211.  
  212.     void DespawnJailWalls()
  213.     {
  214.         script_debuglog("removing jail walls");
  215.  
  216.         // Remove jail walls.
  217.         GameObject *pGameObject;
  218.         while(!jailgameobjects.empty())
  219.         {
  220.             pGameObject = jailgameobjects.front();
  221.             jailgameobjects.pop();
  222.  
  223.             // Despawn him (fade animation !)
  224.             pGameObject->Despawn(60000);
  225.  
  226.             // Delete him from memory.
  227.             _instance->GetInterface()->DeleteGameObject(pGameObject);
  228.         }
  229.     }
  230.  
  231.     void PlayerScores(Unit* victim, Player* killer, uint32 team)
  232.     {
  233.         // We've already sent the message saying that we've scored and the sound.
  234.         // Let's increase the score by one.
  235.         if(team == 0)
  236.             me->SetHordeScore(me->GetHordeScore() + 1);
  237.         else
  238.             me->SetAllianceScore(me->GetAllianceScore() + 1);
  239.  
  240.         if(me->GetAllianceScore() == 3 || me->GetHordeScore() == 3)
  241.         {
  242.             // maybe do smth?
  243.         }
  244.         else
  245.         {
  246.             // we need to reset players, put them in jail, etc.
  247.             string msg = MSG_COLOR_LIGHTBLUE;
  248.             msg += "A round was won. Players will be teleported to their jail cells shortly.";
  249.             me->SendCMessageToAll(msg.c_str(), false);
  250.  
  251.             // spawn jail walls
  252.             script_debuglog("round won");
  253.             SpawnJailWalls();
  254.  
  255.             // move players to jail cells in 5 seconds
  256.             tPushPlayersToJail = getMSTime() + 5000;    // 5 second timer.
  257.  
  258.             // root all players
  259.             std::list<Player*>::iterator iter = me->GetPlayersBegin();
  260.             Player *plyr;
  261.             for(; iter != me->GetPlayersEnd(); ++iter)
  262.             {
  263.                  (*iter)->SetMovement(MOVE_ROOT, 1);
  264.             }
  265.         }
  266.     }
  267.  
  268.     inline WarsongGulch * GetMe() { return me; }
  269. protected:
  270.    
  271.     // temporary jail gameobject set.
  272.     std::queue<GameObject*> jailgameobjects;
  273.  
  274.     // our timers
  275.     uint32 tPushPlayersToJail;
  276.     uint32 tRemovePlayersFromJail;
  277.     uint32 tEndGame;
  278.  
  279.     uint32 tJailMsg1;
  280.     uint32 tJailMsg2;
  281.  
  282.     WarsongGulch *me;
  283. };
  284.  
  285. /************************************************************************/
  286. /* GENERAL DOTA CREATURE SECTION                                        */
  287. /************************************************************************/
  288.  
  289. class DotACreature : public CreatureAIScript
  290. {
  291. public:
  292.     DotACreature(Creature *creature) : CreatureAIScript(creature)
  293.     {
  294.         mDeathCausesScore = false;
  295.         onDeathText = "";
  296.         onCombatText = "";
  297.         onKilledText = "";
  298.         combatsound = 0;
  299.         deathsound = 0;
  300.         team = 0;
  301.     }
  302.     virtual void OnLoad()
  303.     {
  304.         myscript = static_cast<DotABattleground*>(_unit->GetMapMgr()->GetScript());
  305.         wsg = myscript->GetMe();
  306.     }
  307.  
  308.     virtual void OnDied(Unit *mKiller)
  309.     {
  310.         if(onDeathText.size())
  311.         {
  312.             string cmsg = MSG_COLOR_RED;
  313.             cmsg += onDeathText;
  314.  
  315.             wsg->SendCMessageToAll(cmsg.c_str(), true);
  316.         }
  317.  
  318.         if(deathsound)
  319.             wsg->SendSoundToBattleground(deathsound);
  320.  
  321.         if(mDeathCausesScore && mKiller->GetTypeId() == TYPEID_PLAYER)
  322.             myscript->PlayerScores(_unit, static_cast<Player*>(mKiller), team);
  323.     }
  324.  
  325.     virtual void OnCombatStart()
  326.     {
  327.         if(onCombatText.size())
  328.         {
  329.             string cmsg = MSG_COLOR_RED;
  330.             cmsg += onCombatText;
  331.  
  332.             wsg->SendCMessageToAll(cmsg.c_str(), true);
  333.         }
  334.  
  335.         if(combatsound)
  336.             wsg->SendSoundToBattleground(combatsound);
  337.     }
  338.  
  339.     virtual void OnTargetDied(Unit* mTarget)
  340.     {
  341.         if(onKilledText.size())
  342.         {
  343.             string cmsg = MSG_COLOR_RED;
  344.             cmsg += onKilledText;
  345.  
  346.             wsg->SendCMessageToAll(cmsg.c_str(), true);
  347.         }
  348.     }
  349.  
  350. protected:
  351.     DotABattleground * myscript;
  352.     bool mDeathCausesScore;
  353.     uint32 team;
  354.     string onDeathText;
  355.     string onKilledText;
  356.     string onCombatText;
  357.     uint32 combatsound;
  358.     uint32 deathsound;
  359.  
  360.     WarsongGulch * wsg;
  361. };
  362.  
  363. /************************************************************************/
  364. /* DOTA BOSS SCRIPTING SECTION                                          */
  365. /************************************************************************/
  366.  
  367. // Tyrande Whisperwind - Silverwing/Alliance boss
  368.  
  369. class Tyrande_Whisperwind : public DotACreature
  370. {
  371. public:
  372.     Tyrande_Whisperwind(Creature* pCreature) : DotACreature(pCreature)
  373.     {
  374.         // Set me up.
  375.         mDeathCausesScore = true;
  376.         onDeathText = "The Horde Score! Tyrande Whisperwind was killed!";
  377.         onCombatText = "The Horde Is Advancing! Tyrande Whisperwind is under attack!";
  378.         onKilledText = "That was a warning. Leave us in piece.";
  379.         combatsound = SOUND_HORDE_CAPTURE;
  380.         deathsound = SOUND_HORDE_SCORES;
  381.         team = 0;
  382.     }
  383.  
  384.     void OnDied(Unit* mKiller)
  385.     {
  386.         if(mKiller->GetTypeId() != TYPEID_PLAYER)
  387.             return;
  388.  
  389.         // Unit Chat Message
  390.         _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Elune give me strength...");
  391.         DotACreature::OnDied(mKiller);
  392.     }
  393.  
  394.     void OnCombatStart(Unit* mTarget)
  395.     {
  396.         if(mTarget->GetTypeId() != TYPEID_PLAYER)
  397.             return;
  398.  
  399.         _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "You dare to engage the Silverwing Elite!?");
  400.         DotACreature::OnCombatStart();
  401.  
  402.         string msg = MSG_COLOR_BLUE;
  403.         msg += "Tutorial: You have attacked the boss. Kill him to score a point for your team.";
  404.         wsg->SendCMessageToPlayer(static_cast<Player*>(mTarget), msg.c_str(), false);
  405.     }
  406.  
  407.     void Destroy()
  408.     {
  409.         delete (Tyrande_Whisperwind*)this;
  410.     }
  411. };
  412.  
  413. // Varimathras AI Script - horde boss
  414.  
  415. class Varimathras : public DotACreature
  416. {
  417. public:
  418.     Varimathras(Creature* pCreature) : DotACreature(pCreature)
  419.     {
  420.         // Set me up.
  421.         mDeathCausesScore = true;
  422.         onDeathText = "The Alliance Score! Varimathras was killed!";
  423.         onCombatText = "The Alliance Is Advancing! Varimathras is under attack!";
  424.         onKilledText = "Pathetic scum, when will you learn that you are no match for the mighty horde.";
  425.         combatsound = SOUND_ALLIANCE_CAPTURE;
  426.         deathsound = SOUND_ALLIANCE_SCORES;
  427.         team = 1;
  428.     }
  429.  
  430.     void OnDied(Unit* mKiller)
  431.     {
  432.         if(mKiller->GetTypeId() != TYPEID_PLAYER)
  433.             return;
  434.  
  435.         // Unit Chat Message
  436.         _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "This is not possible! The powerful Varimathras defeated by a bunch of worms!");
  437.  
  438.         DotACreature::OnDied(mKiller);
  439.     }
  440.  
  441.     void OnCombatStart(Unit* mTarget)
  442.     {
  443.         if(mTarget->GetTypeId() != TYPEID_PLAYER)
  444.             return;
  445.  
  446.         _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "You think you can match the might of a Dreadlord!");
  447.         DotACreature::OnCombatStart();
  448.  
  449.         string msg = MSG_COLOR_BLUE;
  450.         msg += "Tutorial: You have attacked the boss. Kill him to score a point for your team.";
  451.         wsg->SendCMessageToPlayer(static_cast<Player*>(mTarget), msg.c_str(), false);
  452.     }
  453.  
  454.     void Destroy()
  455.     {
  456.         delete (Varimathras*)this;
  457.     }
  458. };
  459.  
  460. CreatureAIScript* CreateCreatureAIClass(uint32 uEntryId, Creature* creature)
  461. {
  462.     switch(uEntryId)
  463.     {
  464.     case 7999:  // Tyrande Whisperwind
  465.         return new Tyrande_Whisperwind(creature);
  466.         break;
  467.     case 2425:  // Varimthras
  468.         return new Varimathras(creature);
  469.         break;
  470.     }
  471.     return 0;
  472. }
  473.  
  474. /************************************************************************/
  475. /* Instance Class Factory                                               */
  476. /************************************************************************/
  477.  
  478. InstanceScript* CreateInstanceClass(uint32 uMapId, MapMgr* instance)
  479. {
  480.     switch(uMapId)
  481.     {
  482.     case 489:    // WSG
  483.         return new DotABattleground(instance);
  484.         break;
  485.     }
  486.  
  487.     return 0;
  488. }
  489.  
  490. /************************************************************************/
  491. /* Script Initialize - Bind entries to this module.                     */
  492. /************************************************************************/
  493.  
  494. void ScriptInitialize(ScriptModule *mod)
  495. {
  496.     sScriptMgr.ScriptAddCreatureModule(7999, mod);   // Tyrande Whisperwind
  497.     sScriptMgr.ScriptAddCreatureModule(2425, mod);   // Varimathras
  498.  
  499.     sScriptMgr.ScriptAddInstanceModule(489, mod);   // Warsong Gulch
  500. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement