Advertisement
Easelm

[TrinityCore]: Outdoor PvP Borean Tundra Battle ~ By QQrofl

May 4th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.86 KB | None | 0 0
  1. /*
  2.         .__      .___.                
  3.         [__)  .    |   _ ._ _ ._ _   .
  4.         [__)\_|    |  (_)[ | )[ | )\_|
  5.             ._|                    ._|
  6.  
  7.             Was for Omni-WoW
  8.             Now: Released - 5/4/2012
  9. */
  10. #include "OutdoorPvPBT.h"
  11.  
  12. OutdoorPvPBT::OutdoorPvPBT()
  13. {
  14.     m_TypeId = OUTDOOR_PVP_BT;
  15.     m_ally_gathered = BT_RESOURCES_A;
  16.     m_horde_gathered = BT_RESOURCES_H;
  17.     IS_ABLE_TO_SHOW_MESSAGE = false;
  18.     IS_RESOURCE_MESSAGE_A = false;
  19.     IS_RESOURCE_MESSAGE_H = false;
  20.     m_FirstLoad = false;
  21.     limit_A = 0;
  22.     limit_H = 0;
  23.     m_LastWin = 0;
  24.     limit_resources_message_A = 0;
  25.     limit_resources_message_H = 0;
  26. }
  27.  
  28. bool OutdoorPvPBT::SetupOutdoorPvP()
  29. {
  30.     RegisterZone(3537);
  31.     return true;
  32. }
  33.  
  34. void OutdoorPvPBT::HandlePlayerEnterZone(Player * player, uint32 zone)
  35. {  
  36.     char message[250];
  37.     if(player->GetTeam() == ALLIANCE)
  38.         snprintf(message, 1024, "[Borean Tundra Defense]: Alliance has %u resources!", m_ally_gathered);
  39.     else
  40.         snprintf(message, 1024, "[Borean Tundra Defense]: Horde has %u resources!", m_horde_gathered);
  41.  
  42.     player->MonsterTextEmote(message, player->GetGUID());
  43.     OutdoorPvP::HandlePlayerEnterZone(player, zone);
  44. }
  45.  
  46. void OutdoorPvPBT::HandlePlayerLeaveZone(Player * player, uint32 zone)
  47. {
  48.     player->MonsterTextEmote("You're leaving while the zone PvP is active!", player->GetGUID());
  49.     OutdoorPvP::HandlePlayerLeaveZone(player, zone);
  50. }
  51.  
  52. void OutdoorPvPBT::HandleWinMessage(Player * player, uint8 type, const char * message)
  53. {
  54.     char str[250];
  55.     va_list ap;
  56.     va_start(ap, message);
  57.     vsnprintf(str, 1024, message, ap);
  58.     va_end(ap);
  59.     std::string msg(str);
  60.     WorldPacket data(SMSG_MESSAGECHAT, 200);
  61.     data << (uint8)type;
  62.     data << (uint32)LANG_UNIVERSAL;
  63.     data << (uint64)0;
  64.     data << (uint32)0;
  65.     data << (uint32)1;
  66.     data << (uint8)0;
  67.     data << (uint64)0;
  68.     data << (uint32)(msg.length() + 1);
  69.     data << msg.c_str();
  70.     data << (uint8)0;
  71.     player->SendMessageToSet(&data, true);
  72. }
  73.  
  74. void OutdoorPvPBT::PlaySounds(bool side)
  75. {
  76.     SessionMap m_sessions = sWorld->GetAllSessions();
  77.     for(SessionMap::iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
  78.     {
  79.         if(!itr->second || !itr->second->GetPlayer() || !itr->second->GetPlayer()->IsInWorld() ||
  80.             itr->second->GetPlayer()->GetZoneId() != 3537)
  81.             continue;
  82.  
  83.         if(itr->second->GetPlayer()->GetZoneId() == 3537)
  84.         {
  85.             if(itr->second->GetPlayer()->GetTeam() == ALLIANCE && side == true)
  86.                 itr->second->GetPlayer()->PlayDirectSound(BT_SOUND_ALLIANCE_GOOD, itr->second->GetPlayer());
  87.             else
  88.                 itr->second->GetPlayer()->PlayDirectSound(BT_SOUND_HORDE_GOOD, itr->second->GetPlayer());
  89.         }
  90.     }
  91. }
  92.  
  93. void OutdoorPvPBT::HandleReset()
  94. {
  95.     m_ally_gathered = BT_RESOURCES_A;
  96.     m_horde_gathered = BT_RESOURCES_H;
  97.     IS_ABLE_TO_SHOW_MESSAGE = false;
  98.     IS_RESOURCE_MESSAGE_A = false;
  99.     IS_RESOURCE_MESSAGE_H = false;
  100.     m_FirstLoad = false;
  101.     limit_A = 0;
  102.     limit_H = 0;
  103.     limit_resources_message_A = 0;
  104.     limit_resources_message_H = 0;
  105.     sLog->outString("[OutdoorPvPBT]: Borean Tundra : HandleReset()");
  106. }
  107.  
  108. void OutdoorPvPBT::HandleBuffs(Player * player, bool loser)
  109. {
  110.     if(loser)
  111.     {
  112.         for(int i = 0; i < LOSE_BUFFS; i++)
  113.             player->CastSpell(player, LoseBuffs[i], true);
  114.     }
  115.     else
  116.     {
  117.         for(int i = 0; i < WIN_BUFFS; i++)
  118.             player->CastSpell(player, WinBuffs[i], true);
  119.     }
  120. }
  121.  
  122. void OutdoorPvPBT::HandleRewards(Player * player, uint32 honorpointsorarena, bool honor, bool arena, bool both)
  123. {
  124.     char msg[250];
  125.     uint32 m_GetHonorPoints = player->GetHonorPoints();
  126.     uint32 m_GetArenaPoints = player->GetArenaPoints();
  127.     if(honor)
  128.     {
  129.         player->SetHonorPoints(m_GetHonorPoints + honorpointsorarena);
  130.         snprintf(msg, 250, "You received %u extra honor points!", honorpointsorarena);
  131.     }
  132.     else if(arena)
  133.     {
  134.         player->SetArenaPoints(m_GetArenaPoints + honorpointsorarena);
  135.         snprintf(msg, 250, "You received %u extra arena points!", honorpointsorarena);
  136.     }
  137.     else if(both)
  138.     {
  139.         player->SetHonorPoints(m_GetHonorPoints + honorpointsorarena);
  140.         player->SetArenaPoints(m_GetArenaPoints + honorpointsorarena);
  141.         snprintf(msg, 250, "You received %u extra honor and arena points!", honorpointsorarena);
  142.     }
  143.     HandleWinMessage(player, CHAT_MSG_MONSTER_EMOTE, msg);
  144. }
  145.  
  146. bool OutdoorPvPBT::Update(uint32 diff)
  147. {
  148.     OutdoorPvP::Update(diff);
  149.     if(m_FirstLoad == false)
  150.     {
  151.         if(m_LastWin == ALLIANCE)
  152.            sLog->outString("[OutdoorPvPBT]: Borean Tundra has started! Last Winner: Alliance(%u)", ALLIANCE);
  153.         else if(m_LastWin == HORDE)
  154.            sLog->outString("[OutdoorPvPBT]: Borean Tundra has started! Last Winner: Horde(%u)", HORDE);
  155.         else if(m_LastWin == 0)
  156.            sLog->outString("[OutdoorPvPBT]: Borean Tundra has started! Last Winner: Neutral(0)");
  157.         m_FirstLoad = true;
  158.     }
  159.  
  160.     if(m_ally_gathered <= 50 && limit_A == 0)
  161.     {
  162.        IS_ABLE_TO_SHOW_MESSAGE = true; // We allow the message to pass
  163.        IS_RESOURCE_MESSAGE_A = true; // We allow the message to be shown
  164.        limit_A = 1; // We set this to one to stop the spamming
  165.        PlaySounds(false);
  166.     }
  167.     else if(m_horde_gathered <= 50 && limit_H == 0)
  168.     {
  169.         IS_ABLE_TO_SHOW_MESSAGE = true; // We allow the message to pass
  170.         IS_RESOURCE_MESSAGE_H = true; // We allow the message to be shown
  171.         limit_H = 1; // Same as above
  172.         PlaySounds(true);
  173.     }
  174.     else if(m_ally_gathered <= 0 && limit_A == 1)
  175.     {
  176.         IS_ABLE_TO_SHOW_MESSAGE = true; // We allow the message to pass
  177.         IS_RESOURCE_MESSAGE_A = true; // We allow the message to be shown
  178.         limit_A = 2;
  179.         PlaySounds(false);
  180.     }
  181.     else if(m_horde_gathered <= 0 && limit_H == 1)
  182.     {
  183.         IS_ABLE_TO_SHOW_MESSAGE = true; // We allow the message to pass
  184.         IS_RESOURCE_MESSAGE_H = true; // We allow the message to be shown
  185.         limit_H = 2;
  186.         PlaySounds(true);
  187.     }
  188.     else if(m_ally_gathered <= 300 && limit_resources_message_A == 0)
  189.     {
  190.         IS_ABLE_TO_SHOW_MESSAGE = true;
  191.         limit_resources_message_A = 1;
  192.         PlaySounds(false);
  193.     }
  194.     else if(m_horde_gathered <= 300 && limit_resources_message_H == 0)
  195.     {
  196.         IS_ABLE_TO_SHOW_MESSAGE = true;
  197.         limit_resources_message_H = 1;
  198.         PlaySounds(true);
  199.     }
  200.     else if(m_ally_gathered <= 200 && limit_resources_message_A == 1)
  201.     {
  202.         IS_ABLE_TO_SHOW_MESSAGE = true;
  203.         limit_resources_message_A = 2;
  204.         PlaySounds(false);
  205.     }
  206.     else if(m_horde_gathered <= 200 && limit_resources_message_H == 1)
  207.     {
  208.         IS_ABLE_TO_SHOW_MESSAGE = true;
  209.         limit_resources_message_H = 2;
  210.         PlaySounds(true);
  211.     }
  212.     else if(m_ally_gathered <= 100 && limit_resources_message_A == 2)
  213.     {
  214.         IS_ABLE_TO_SHOW_MESSAGE = true;
  215.         limit_resources_message_A = 3;
  216.         PlaySounds(false);
  217.     }
  218.     else if(m_horde_gathered <= 100 && limit_resources_message_H == 2)
  219.     {
  220.         IS_ABLE_TO_SHOW_MESSAGE = true;
  221.         limit_resources_message_H = 3;
  222.         PlaySounds(true);
  223.     }
  224.  
  225.     if(IS_ABLE_TO_SHOW_MESSAGE == true) // This will limit the spam
  226.     {
  227.         SessionMap m_sessions = sWorld->GetAllSessions();
  228.         for(SessionMap::iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr) // We're searching for all the sessions(Players)
  229.         {
  230.             if(!itr->second || !itr->second->GetPlayer() || !itr->second->GetPlayer()->IsInWorld() ||
  231.                 itr->second->GetPlayer()->GetZoneId() != 3537)
  232.                 continue;
  233.  
  234.             if(itr->second->GetPlayer()->GetZoneId() == 3537)
  235.             {
  236.                 char msg[250];
  237.                 if(limit_resources_message_A == 1 || limit_resources_message_A == 2 || limit_resources_message_A == 3)
  238.                 {
  239.                     snprintf(msg, 1024, "[Borean Tundra Defense]: Alliance has %u resources remaining!", m_ally_gathered);
  240.                     itr->second->GetPlayer()->MonsterTextEmote(msg, itr->second->GetPlayer()->GetGUID());
  241.                 }
  242.                 else if(limit_resources_message_H == 1 || limit_resources_message_H == 2 || limit_resources_message_H == 3)
  243.                 {
  244.                     snprintf(msg, 1024, "[Borean Tundra Defense]: Horde has %u resources remaining!", m_horde_gathered);
  245.                     itr->second->GetPlayer()->MonsterTextEmote(msg, itr->second->GetPlayer()->GetGUID());
  246.                 }
  247.  
  248.                 if(IS_RESOURCE_MESSAGE_A == true)
  249.                 {
  250.                     if(limit_A == 1)
  251.                     {
  252.                         snprintf(msg, 1024, "[Borean Tundra Defense]: Alliance has %u resources remaining!", m_ally_gathered);
  253.                         itr->second->GetPlayer()->MonsterTextEmote(msg, itr->second->GetPlayer()->GetGUID());
  254.                         IS_RESOURCE_MESSAGE_A = false; // Reset
  255.                     }
  256.                     else if(limit_A == 2)
  257.                     {
  258.                         itr->second->GetPlayer()->MonsterTextEmote("[Borean Tundra Defense]: Alliance has 0 resources! Horde wins!",
  259.                         itr->second->GetPlayer()->GetGUID());
  260.                         HandleWinMessage(itr->second->GetPlayer(), CHAT_MSG_RAID_WARNING, "Horde Wins!");
  261.                         HandleRewards(itr->second->GetPlayer(), 1500, true, false, false);
  262.                         switch(itr->second->GetPlayer()->GetTeam())
  263.                         {
  264.                            case ALLIANCE:
  265.                                HandleBuffs(itr->second->GetPlayer(), true);
  266.                            break;
  267.  
  268.                            case HORDE:
  269.                                HandleBuffs(itr->second->GetPlayer(), false);
  270.                            break;
  271.                         }
  272.                         m_LastWin = HORDE;
  273.                         IS_RESOURCE_MESSAGE_A = false; // Reset
  274.                     }
  275.                 }
  276.                 else if(IS_RESOURCE_MESSAGE_H == true)
  277.                 {
  278.                     if(limit_H == 1)
  279.                     {
  280.                         snprintf(msg, 1024, "[Borean Tundra Defense]: Horde has %u resources remaining!", m_horde_gathered);
  281.                         itr->second->GetPlayer()->MonsterTextEmote(msg, itr->second->GetPlayer()->GetGUID());
  282.                         IS_RESOURCE_MESSAGE_H = false; // Reset
  283.                     }
  284.                     else if(limit_H == 2)
  285.                     {
  286.                         itr->second->GetPlayer()->MonsterTextEmote("[Borean Tundra Defense]: Horde has 0 resources! Alliance wins!",
  287.                         itr->second->GetPlayer()->GetGUID());
  288.                         HandleWinMessage(itr->second->GetPlayer(), CHAT_MSG_RAID_WARNING, "Alliance Wins!");
  289.                         HandleRewards(itr->second->GetPlayer(), 1500, true, false, false);
  290.                         switch(itr->second->GetPlayer()->GetTeam())
  291.                         {
  292.                            case ALLIANCE:
  293.                                HandleBuffs(itr->second->GetPlayer(), false);
  294.                            break;
  295.  
  296.                            case HORDE:
  297.                                HandleBuffs(itr->second->GetPlayer(), true);
  298.                            break;
  299.                         }
  300.                         m_LastWin = ALLIANCE;
  301.                         IS_RESOURCE_MESSAGE_H = false; // Reset
  302.                     }
  303.                 }
  304.             }
  305.             else
  306.             {
  307.                 // Don't send anything
  308.             }
  309.         }
  310.     }
  311.     IS_ABLE_TO_SHOW_MESSAGE = false; // Reset
  312.     return false;
  313. }
  314.  
  315. void OutdoorPvPBT::Randomizer(Player * player)
  316. {
  317.     switch(urand(0, 4))
  318.     {
  319.         case 0:
  320.             HandleRewards(player, 17, true, false, false);
  321.         break;
  322.  
  323.         case 1:
  324.             HandleRewards(player, 11, true, false, false);
  325.         break;
  326.  
  327.         case 2:
  328.             HandleRewards(player, 19, true, false, false);
  329.         break;
  330.  
  331.         case 3:
  332.             HandleRewards(player, 22, true, false, false);
  333.         break;
  334.     }
  335. }
  336.  
  337. void OutdoorPvPBT::HandleKill(Player * player, Unit * killed)
  338. {
  339.     uint32 take = POINTS_LOSE_ON_NPC_KILL;
  340.     if(killed->GetTypeId() == TYPEID_PLAYER) // Killing players will take their resources away. It also gives extra honor.
  341.     {
  342.         if(player->GetGUID() != killed->GetGUID())
  343.             return;
  344.  
  345.         switch(killed->ToPlayer()->GetTeam())
  346.         {
  347.            case ALLIANCE:
  348.                m_ally_gathered -= take;
  349.                Randomizer(player);
  350.            break;
  351.  
  352.            case HORDE:
  353.                m_horde_gathered -= take;
  354.                Randomizer(player);
  355.            break;
  356.         }
  357.     }
  358.     else // If is something besides a player
  359.     {
  360.         if(player->GetTeam() == ALLIANCE)
  361.         {
  362.             switch(killed->GetEntry()) // Alliance killing horde guards
  363.             {
  364.                 case WARSONG_BATTLEGUARD:
  365.                     m_horde_gathered -= take;
  366.                     Randomizer(player); // Randomizes the honor reward
  367.                 break;
  368.  
  369.                 case WARSONG_BATTLEGUARD_2: // 2?
  370.                     m_horde_gathered -= take;
  371.                     Randomizer(player); // Randomizes the honor reward
  372.                 break;
  373.  
  374.                 case WARSONG_CAPTAIN:
  375.                     m_horde_gathered -= take;
  376.                     Randomizer(player); // Randomizes the honor reward
  377.                 break;
  378.  
  379.                 case WARSONG_CARAVAN_GUARD:
  380.                     m_horde_gathered -= take;
  381.                     Randomizer(player); // Randomizes the honor reward
  382.                 break;
  383.  
  384.                 case WARSONG_HONOR_GUARD:
  385.                     m_horde_gathered -= take;
  386.                     Randomizer(player); // Randomizes the honor reward
  387.                 break;
  388.  
  389.                 case WARSONG_MARKSMAN:
  390.                     m_horde_gathered -= take;
  391.                     Randomizer(player); // Randomizes the honor reward
  392.                 break;
  393.  
  394.                 case WARSONG_RECRUITMENT_OFFICER:
  395.                     m_horde_gathered -= take;
  396.                     Randomizer(player); // Randomizes the honor reward
  397.                 break;
  398.  
  399.                 case WARSONG_SCOUT:
  400.                     m_horde_gathered -= take;
  401.                     Randomizer(player); // Randomizes the honor reward
  402.                 break;
  403.  
  404.                 case WARSONG_WIND_RIDER:
  405.                     m_horde_gathered -= take;
  406.                     Randomizer(player); // Randomizes the honor reward
  407.                 break;
  408.             }
  409.         }
  410.         else // Horde
  411.         {
  412.             switch(killed->GetEntry()) // Horde killing alliance guards
  413.             {
  414.                 case VALIANCE_KEEP_CANNONEER:
  415.                     m_ally_gathered -= take;
  416.                     Randomizer(player); // Randomizes the honor reward
  417.                 break;
  418.  
  419.                 case VALIANCE_KEEP_DEFENDER:
  420.                     m_ally_gathered -= take;
  421.                     Randomizer(player); // Randomizes the honor reward
  422.                 break;
  423.  
  424.                 case VALIANCE_KEEP_FISHERMAN:
  425.                     m_ally_gathered -= take;
  426.                     Randomizer(player); // Randomizes the honor reward
  427.                 break;
  428.  
  429.                 case VALIANCE_KEEP_FOOTMAN: // Wrong?
  430.                     m_ally_gathered -= take;
  431.                     Randomizer(player); // Randomizes the honor reward
  432.                 break;
  433.  
  434.                 case VALIANCE_KEEP_FOOTMAN_2: // 2?
  435.                     m_ally_gathered -= take;
  436.                     Randomizer(player); // Randomizes the honor reward
  437.                 break;
  438.  
  439.                 case VALIANCE_KEEP_OFFICER:
  440.                     m_ally_gathered -= take;
  441.                     Randomizer(player); // Randomizes the honor reward
  442.                 break;
  443.  
  444.                 case VALIANCE_KEEP_RIFLEMAN:
  445.                     m_ally_gathered -= take;
  446.                     Randomizer(player); // Randomizes the honor reward
  447.                 break;
  448.  
  449.                 case VALIANCE_KEEP_WORKER:
  450.                     m_ally_gathered -= take;
  451.                     Randomizer(player); // Randomizes the honor reward
  452.                 break;
  453.  
  454.                 case DURDAN_THUNDERBEAK:
  455.                     m_ally_gathered -= take;
  456.                     Randomizer(player); // Randomizes the honor reward
  457.                 break;
  458.             }
  459.         }
  460.     }
  461. }
  462.  
  463. class pvp_borean_tundra : public OutdoorPvPScript
  464. {
  465.     public:
  466.  
  467.         pvp_borean_tundra()
  468.             : OutdoorPvPScript("pvp_borean_tundra")
  469.         {
  470.         }
  471.  
  472.         OutdoorPvP* GetOutdoorPvP() const
  473.         {
  474.             return new OutdoorPvPBT();
  475.         }
  476. };
  477.  
  478. void AddSC_pvp_bt()
  479. {
  480.     new pvp_borean_tundra;
  481. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement