Advertisement
Easelm

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

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