Advertisement
Callmephil

Ultimate Duel Script V1.3

Jan 17th, 2014
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.20 KB | None | 0 0
  1. #include "scriptPCH.h"
  2. #include "MapManager.h"
  3. #include "Chat.h"
  4. #include "Pet.h"
  5. #include "Config.h"
  6. #include "WorldSession.h"
  7. #include "World.h"
  8.      
  9. /* SQL (Only if you use Rating System) (Characters database)
  10.     ALTER TABLE `characters`
  11.     ADD COLUMN `duelW` int(10) UNSIGNED NOT NULL DEFAULT '0',
  12.     ADD COLUMN `duelL` int(10) UNSIGNED NOT NULL DEFAULT '0',
  13.     ADD COLUMN `duelR` int(10) UNSIGNED NOT NULL DEFAULT '1000';
  14. */
  15.      
  16.     /* WorldConf (At the end of the file)
  17.     # Duel_Reward.Cata_User
  18.     #        Default:     0 - (Disabled)
  19.     #                     1 - (Enabled)
  20.      
  21.     Duel_Reward.Cata_User = 0
  22.      
  23.     # Duel_Reward.Wotlk_User
  24.     #        Default:     0 - (Disabled)
  25.     #                     1 - (Enabled)
  26.      
  27.     Duel_Reward.Wotlk_User = 0
  28.      
  29.     # Duel_Reward.Rating
  30.     #        Default:     0 - (Disabled)
  31.     #                     1 - (Enabled)
  32.      
  33.     Duel_Reward.Rating = 0
  34.      
  35.     # Duel_Reward.Security
  36.     #        Default:     1 - (Enabled)
  37.     #                     0 - (Disabled)
  38.      
  39.     Duel_Reward.Security = 1
  40.      
  41.     # Duel_Phasing.Activation
  42.     #        Default:     0 - (Disabled)
  43.     #                     1 - (Enabled)
  44.      
  45.     Duel_Phasing.Activation = 0
  46.     */
  47.      
  48.     /*
  49.     Ultimate Duel Script (Reward/Rating/Phasing/Security/Zoned & Reset)
  50.     Author : Philippe
  51.     Version : V1.3
  52.     Release Date : 14/01/14
  53.     Script Complete : 100 %
  54.     Version : 3.3.5 & 4.3.4
  55.     TrinityCore based.
  56.     Tested on 4.3.4 Works Well
  57.      
  58.     Note :
  59.     -Reward Part is explain you need to read.
  60.     -For the Rating system please use SQL given. You can add a Top for you're website or create a rating npc.
  61.      
  62.     -Phasing system isn't done by me, Credits go to Deathmane1337 (Ac-Web) & Rewrite by Rochet & Tommy (EmuDevs)
  63.     Rochet & Tommy (EmuDevs) :
  64.     http://emudevs.com/showthread.php/2316-new-phaseing-out-duel-dont-work-100?highlight=duel
  65.     http://emudevs.com/showthread.php/2282-phase-out-dueling-error/page2
  66.     */
  67.      
  68.     // Need both to work.
  69.     enum Zone_ID
  70.     {
  71.             Zone_ID_1 = 12 // Change Zone ID
  72.     };
  73.      
  74.     enum Area_ID
  75.     {
  76.             Area_ID_1 = 12 // Change Area ID
  77.     };
  78.      
  79.     #define Item_Reward_ID 241 // Currency ID For Cata User Or Item ID For Wotlk
  80.      
  81.     #define Token_Winner 3 // Reward Count (Winner)
  82.     #define Token_loser 1 // Reward Count (Loser)
  83.      
  84.      
  85.     // Rating Info Setup Config
  86.     void RatingInfo(Player* player)
  87.     {
  88.             if(sConfigMgr->GetBoolDefault("Duel_Reward.Rating", 1))
  89.             {
  90.                     QueryResult result = CharacterDatabase.PQuery("SELECT duelW,duelL,duelR FROM characters WHERE guid = '%u'", player->GetGUID());
  91.                     if(!result)
  92.                             return;
  93.      
  94.                     Field * fields = NULL;
  95.                     do
  96.                     {
  97.                             fields = result->Fetch();
  98.                             uint32 duelW = fields[0].GetUInt32();
  99.                             uint32 duelL = fields[1].GetUInt32();
  100.                             uint32 duelR = fields[2].GetUInt32();
  101.                             char msg[250];
  102.                             snprintf(msg, 250, "[System Information] - [Duel Stats] : |cffFFFF00%u |cFF90EE90Duel win & |cffFFFF00%u |cFF90EE90Duel lose  |cffff6060[Rating] : |cffFFFF00%u \n", duelW,duelL,duelR);                                      
  103.                             ChatHandler(player->GetSession()).PSendSysMessage(msg);
  104.                     }
  105.                     while(result->NextRow());
  106.             }
  107.     }
  108.      
  109.     class Duel_Reset : public PlayerScript
  110.     {
  111.     public:
  112.             Duel_Reset() : PlayerScript("Duel_Reset") {}
  113.      
  114.             void RevivePlayer(Player* player)
  115.             {
  116.                     player->SetHealth(player->GetMaxHealth());
  117.                     if(player->getPowerType() == POWER_MANA)
  118.                             player->SetPower(POWER_MANA, player->GetMaxPower(POWER_MANA));
  119.                     if(player->getPowerType() == POWER_ENERGY)
  120.                             player->SetPower(POWER_ENERGY, player->GetMaxPower(POWER_ENERGY));
  121.             }
  122.      
  123.             void OnDuelStart(Player *player, Player *plTarget)
  124.             {
  125.                     // Duel Start Reset (Hp/Mana etc)      
  126.                     RevivePlayer(player);
  127.                     RevivePlayer(plTarget);
  128.                     player->SetPower(POWER_RAGE, 0);
  129.                     plTarget->SetPower(POWER_RAGE, 0);
  130.                     player->SetPower(POWER_RUNIC_POWER, 0);
  131.                     plTarget->SetPower(POWER_RUNIC_POWER, 0);
  132.      
  133.                     if(sConfigMgr->GetBoolDefault("Duel_Reward.Rating", 1))
  134.                     {
  135.                             // Rating checkup
  136.                             RatingInfo(player);
  137.                             RatingInfo(plTarget);
  138.                     }
  139.             }      
  140.      
  141.             void OnDuelEnd(Player *player, Player * plTarget, DuelCompleteType type)
  142.             {
  143.                     //Removing all Cooldown
  144.                     player->RemoveAllSpellCooldown();
  145.                     plTarget->RemoveAllSpellCooldown();
  146.                     // Duel Reset (Hp/Mana etc)    
  147.                     RevivePlayer(player);
  148.                     RevivePlayer(plTarget);
  149.                     // Stopping Combat (Auto Hit/Cast/Range Auto Hit) Break (Useful)              
  150.                     player->CombatStop();
  151.                     plTarget->CombatStop();
  152.      
  153.                     player->InterruptSpell(CURRENT_AUTOREPEAT_SPELL); // break Auto Shot and auto hit
  154.                     plTarget->InterruptSpell(CURRENT_CHANNELED_SPELL);  // break channelled spells
  155.      
  156.                     player->AttackStop();
  157.                     plTarget->AttackStop();
  158.             }
  159.      
  160.     };
  161.      
  162.     class Duel_Token_Reward : public PlayerScript
  163.     {
  164.     public:
  165.             Duel_Token_Reward() : PlayerScript("Duel_Token_Reward") { }
  166.      
  167.             void OnDuelEnd(Player *winner, Player *looser, DuelCompleteType type)
  168.             {
  169.                     //Zone & Area Check Please change value in enum.
  170.                     if ((winner->GetZoneId() == Zone_ID_1 && looser->GetZoneId() == Zone_ID_1 || winner->GetAreaId() == Area_ID_1 &&  looser->GetAreaId() == Area_ID_1) && type == DUEL_WON)
  171.                     {
  172.                             if(sConfigMgr->GetBoolDefault("Duel_Reward.Security", 1))
  173.                             {
  174.                                     // Level Check if player is not MaxLevel (80+)
  175.                                     if (winner->getLevel() >= 1 && looser->getLevel() <= 79 && (type == DUEL_WON || type == DUEL_INTERRUPTED || type == DUEL_FLED))
  176.                                     {
  177.                                             return;
  178.                                     }
  179.                                     // Check Latency of both (Not Really needed)
  180.                                     if (looser->GetSession()->GetLatency() > 350 && (type == DUEL_WON || type == DUEL_INTERRUPTED || type == DUEL_FLED))
  181.                                     {
  182.                                             ChatHandler(winner->GetSession()).PSendSysMessage("|cFFFFFC00[System]|cFF00FFFF  !! ALERT !! One of you has a latency superior to 350");
  183.                                             ChatHandler(looser->GetSession()).PSendSysMessage("|cFFFFFC00[System]|cFF00FFFF  !! ALERT !! One of you has a latency superior to 350");
  184.                                             return;
  185.                                     }
  186.                                     // Used if player didn't reach less than 10 life.
  187.                                     if (looser->GetHealth() > 10)
  188.                                     {
  189.                                             ChatHandler(looser->GetSession()).PSendSysMessage("|cFFFFFC00[System]|cFF00FFFF No one killed the other !");
  190.                                             ChatHandler(winner->GetSession()).PSendSysMessage("|cFFFFFC00[System]|cFF00FFFF No one killed the other !");
  191.                                     }
  192.                                     // Used For Test Versus GM
  193.                                     if (looser->GetSession()->GetSecurity() >= 2 && (type == DUEL_WON || type == DUEL_INTERRUPTED || type == DUEL_FLED))
  194.                                     {
  195.                                             ChatHandler(winner->GetSession()).PSendSysMessage("|cFFFFFC00[System]|cFF00FFFF You Can't Claim Reward When you're versus a GameMaster !");
  196.                                             ChatHandler(looser->GetSession()).PSendSysMessage("|cFFFFFC00[System]|cFF00FFFF You Can't Claim Reward When you're versus a GameMaster !" );
  197.                                             return;
  198.                                     }
  199.                                     if (winner->GetSession()->GetSecurity() >= 2 && (type == DUEL_WON || type == DUEL_INTERRUPTED || type == DUEL_FLED))
  200.                                     {
  201.                                             ChatHandler(winner->GetSession()).PSendSysMessage("|cFFFFFC00[System]|cFF00FFFF You Can't Claim Reward When you're versus a GameMaster !");
  202.                                             ChatHandler(looser->GetSession()).PSendSysMessage("|cFFFFFC00[System]|cFF00FFFF You Can't Claim Reward When you're versus a GameMaster !");
  203.                                             return;
  204.                                     }
  205.                                     // Used for Cata user if player doesn't have enough gear equipped based on (Stamina/life)
  206.                                     // *Could be adapted for Wotlk Users.
  207.                                     if (looser->GetStat(STAT_STAMINA) < 4000 && type == DUEL_WON)
  208.                                     {
  209.                                             ChatHandler(winner->GetSession()).PSendSysMessage("|cFFFFFC00[Cheating System]|cFF00FFFF The player you are fighting doesn't have enough gear equipped !");
  210.                                             ChatHandler(looser->GetSession()).PSendSysMessage("|cFFFFFC00[Cheating System]|cFF00FFFF you don't have enough gear equipped  !");
  211.                                             return;
  212.                                     }
  213.                                     // Used for Local Connections, same IP
  214.                                     if (winner->GetSession()->GetRemoteAddress() == looser->GetSession()->GetRemoteAddress())
  215.                                     {
  216.                                             ChatHandler(winner->GetSession()).SendGlobalGMSysMessage("|cFFFFFC00[Cheating System]|cFF00FFFF A player is trying to cheat in duel Area !");
  217.                                             ChatHandler(winner->GetSession()).PSendSysMessage("|cFFFFFC00[Cheating System]|cFF00FFFF you can't claim reward versus a same ip address !");
  218.                                             ChatHandler(looser->GetSession()).PSendSysMessage("|cFFFFFC00[Cheating System]|cFF00FFFF you can't claim reward versus a same ip address !");
  219.                                     }
  220.                             }
  221.                             //If everything is passed then reward will be.
  222.                             else
  223.                             {
  224.                             //To make it work please make sure the worldserver.conf is correctly configurate
  225.                             // Start : If you are a WOTLK User delete between Start & Stop or comment it with /**/
  226.                                     /*--------------Cataclysm Users------------*/
  227.                                     if(sConfigMgr->GetBoolDefault("Duel_Reward.Cata_User", 1))
  228.                                     {
  229.                                             winner->ModifyCurrency(Item_Reward_ID, Token_Winner, true,true);
  230.                                             looser->ModifyCurrency(Item_Reward_ID, Token_loser, true,true);
  231.                                     }
  232.                                     // STOP
  233.                                     /*----------------Wotlk Users---------------*/
  234.                                     if(sConfigMgr->GetBoolDefault("Duel_Reward.Wotlk_User", 1))
  235.                                     {
  236.                                             winner->AddItem(Item_Reward_ID, Token_Winner);
  237.                                             looser->AddItem(Item_Reward_ID, Token_loser);
  238.                                     }
  239.      
  240.                                     /*Duel Rating*/
  241.                                     //Duel Ratio, Win/lose
  242.                                     if(sConfigMgr->GetBoolDefault("Duel_Reward.Rating", 1))
  243.                                     {
  244.                                             //Duel Rating, Win/lose (Change Points Manually)
  245.                                             CharacterDatabase.PExecute("UPDATE characters SET duelW = (duelW+1), duelR = (duelR+14) WHERE guid = '%u'", winner->GetGUID());
  246.                                             CharacterDatabase.PExecute("UPDATE characters SET duelL = (duelL+1), duelR = (duelR-7) WHERE guid = '%u'", looser->GetGUID());
  247.                                             //Duel Announcement, Win/lose (Change Points Manually.
  248.                                             ChatHandler(winner->GetSession()).PSendSysMessage("|cFFFFFC00[System Information]|cFF00FFFF Well done you won 14 Points !");
  249.                                             ChatHandler(looser->GetSession()).PSendSysMessage("|cFFFFFC00[System Information]|cFF00FFFF Ow you lose 7 Points !");
  250.                                     }
  251.                                     winner->SaveToDB();
  252.                                     looser->SaveToDB();
  253.                             }
  254.                     }
  255.             }
  256.     };
  257.      
  258.     class PhasedDueling : public PlayerScript
  259.     {
  260.     public:
  261.             PhasedDueling() : PlayerScript("PhasedDueling") { }
  262.      
  263.             void OnDuelStart(Player* firstplayer, Player* secondplayer)
  264.             {
  265.                     if(sConfigMgr->GetBoolDefault("Duel_Phasing.Activation", 1))
  266.                     {
  267.                              Map* map = firstplayer->GetMap();
  268.                     uint32 usedPhases = 0; // used phases
  269.                     Map::PlayerList const& players = map->GetPlayers();
  270.                     for (Map::PlayerList::const_iterator iter = players.begin(); iter != players.end(); ++iter)
  271.                     {
  272.                             Player* check = iter->GetSource();
  273.                             if (!check || !check->GetSession())
  274.                                     continue;
  275.                             usedPhases |= check->GetPhaseMask(); // insert player's phases to used phases
  276.                     }
  277.      
  278.                     for (uint32 phase = 2; phase <= ULONG_MAX/2; phase *= 2) // loop all unique phases
  279.                     {
  280.                             if (usedPhases & phase) // If phase in use
  281.                                     continue;
  282.      
  283.                             firstplayer->SetPhaseMask(phase, true);
  284.                             secondplayer->SetPhaseMask(phase, true);
  285.                             if (GameObject* go = map->GetGameObject(firstplayer->GetUInt64Value(PLAYER_DUEL_ARBITER)))
  286.                                     go->SetPhaseMask(phase, true);
  287.      
  288.                             return;
  289.                     }
  290.                     // Could not phase pet :(
  291.                     }
  292.             }
  293.      
  294.             // Restore phases
  295.             void OnDuelEnd(Player* firstplayer, Player* secondplayer, DuelCompleteType type)
  296.             {
  297.                     if(sConfigMgr->GetBoolDefault("Duel_Phasing.Activation", 1))
  298.                     {
  299.                             {
  300.                                     firstplayer->SetPhaseMask(GetPhase(firstplayer), true);
  301.                     if (Pet* pet = firstplayer->GetPet())
  302.                             pet->SetPhaseMask(GetPhase(firstplayer), true);
  303.                     secondplayer->SetPhaseMask(GetPhase(secondplayer), true);
  304.                     if (Pet* pet = secondplayer->GetPet())
  305.                             pet->SetPhaseMask(GetPhase(secondplayer), true);
  306.                             }
  307.                     }
  308.             }
  309.      
  310.             // Attempt in storing the player phase with spell phases included.
  311.             uint32 GetPhase(Player* player) const
  312.             {
  313.                     if(sConfigMgr->GetBoolDefault("Duel_Phasing.Activation", 1))
  314.                     {
  315.                             if (player->IsGameMaster())
  316.                             return uint32(PHASEMASK_ANYWHERE);
  317.      
  318.                     // GetPhaseMaskForSpawn copy-paste
  319.                     uint32 phase = PHASEMASK_NORMAL;
  320.                     Player::AuraEffectList const& phases = player->GetAuraEffectsByType(SPELL_AURA_PHASE);
  321.                     if (!phases.empty())
  322.                             phase = phases.front()->GetMiscValue();
  323.                     if (uint32 n_phase = phase & ~PHASEMASK_NORMAL)
  324.                             return n_phase;
  325.      
  326.                     }
  327.                     return PHASEMASK_NORMAL;
  328.             }
  329.     };
  330.      
  331.     void AddSC_Reset()
  332.     {
  333.             new Duel_Token_Reward();
  334.             new Duel_Reset();
  335.             new PhasedDueling();
  336.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement