Advertisement
Rochet2

Untitled

Jun 6th, 2013
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const uint8 MAX_PHASES = 31;
  2.  
  3. struct MatchStruct {
  4.     MatchStruct(Player* _player1, Player* _player2)
  5.     {
  6.         player1 = _player1->GetGUID();
  7.         player2 = _player2->GetGUID();
  8.     }
  9.  
  10.     uint64 player1;
  11.     uint64 player2;
  12. };
  13. // typedef std::list<MatchStruct> MatchList;
  14. typedef std::map<uint8, MatchStruct> MatchList;
  15. MatchList MatchData;
  16.  
  17. class DuelPhasing : public PlayerScript
  18. {
  19. public:
  20.     DuelPhasing() : PlayerScript("DuelPhasing") { }
  21.  
  22.     void OnDuelStart(Player* player1, Player* player2)
  23.     {
  24.         MatchStruct info(player1, player2);
  25.         uint8 phaseID = 0;
  26.  
  27.         if(MatchData.size() >= MAX_PHASES) // if all phases full, check if players offline:
  28.             ErasePlayers();
  29.  
  30.         if(MatchData.size() >= MAX_PHASES) // full
  31.         {
  32.             ChatHandler(player1->GetSession()).SendSysMessage("You cannot be phased at the moment");// this won't happen often
  33.             ChatHandler(player2->GetSession()).SendSysMessage("You cannot be phased at the moment");// this won't happen often
  34.         }
  35.         else // has phases left
  36.         {
  37.             for (uint8 i = phaseID+1; i < MAX_PHASES; ++i)
  38.             {
  39.                 if (MatchData.find(i) == MatchData.end())
  40.                 {
  41.                     phaseID = i;
  42.                     break;
  43.                 }
  44.             }
  45.             ChatHandler(player1->GetSession()).SendSysMessage("You have been phased.");
  46.             ChatHandler(player2->GetSession()).SendSysMessage("You have been phased.");
  47.         }
  48.  
  49.         // MatchData.push_back(info);
  50.         if(phaseID)
  51.             MatchData[phaseID] = info;
  52.         player1->SetPhaseMask(pow(2.0f, phaseID), true);
  53.         player2->SetPhaseMask(pow(2.0f, phaseID), true);
  54.         // teleport etc
  55.     };
  56.  
  57.     void ErasePlayers()
  58.     {
  59.         for(MatchList::iterator it = MatchData.begin(); it != MatchData.end(); ++it) // loop records
  60.         {
  61.             Player* player1 = sObjectAccessor->FindPlayer(it->second.player1);
  62.             Player* player2 = sObjectAccessor->FindPlayer(it->second.player2);
  63.             uint32 phase = pow(2.0f, it->first);
  64.             if(player1 && player2 && player1->GetPhaseMask() == phase && player2->GetPhaseMask() == phase)
  65.                 continue;
  66.  
  67.             // teleport players out or something
  68.             MatchData.erase(it);
  69.         }
  70.     }
  71.  
  72.     void OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType /*type*/)
  73.     {
  74.         double phase = sqrt(double(pWinner->GetPhaseMask()));
  75.         if(phase - uint8(phase))
  76.             return; // was not unique
  77.         uint8 phaseID = uint8(phase);
  78.         if(phaseID >= MAX_PHASES)
  79.             return; // wrong ID
  80.         MatchData.erase(phaseID); // if not cleared right, still cleared if ErasePlayers is called
  81.  
  82.         pWinner->RemoveAllSpellCooldown();
  83.         pLoser->RemoveAllSpellCooldown();
  84.         pWinner->SetHealth(pWinner->GetMaxHealth());
  85.         if ( pWinner->getPowerType() == POWER_MANA )
  86.             pWinner->SetPower(POWER_MANA, pWinner->GetMaxPower(POWER_MANA));
  87.         pLoser->SetHealth(pLoser->GetMaxHealth());
  88.         if ( pLoser->getPowerType() == POWER_MANA )
  89.             pLoser->SetPower(POWER_MANA,  pLoser->GetMaxPower(POWER_MANA));
  90.     }
  91. };
  92.  
  93. void AddSC_DuelPhasing()
  94. {
  95.     new DuelPhasing();
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement