Advertisement
Callmephil

Ultimate Duel Script V1.2

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