Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const uint8 MAX_PHASES = 31;
- struct MatchStruct {
- MatchStruct(Player* _player1, Player* _player2)
- {
- player1 = _player1->GetGUID();
- player2 = _player2->GetGUID();
- }
- uint64 player1;
- uint64 player2;
- };
- // typedef std::list<MatchStruct> MatchList;
- typedef std::map<uint8, MatchStruct> MatchList;
- MatchList MatchData;
- class DuelPhasing : public PlayerScript
- {
- public:
- DuelPhasing() : PlayerScript("DuelPhasing") { }
- void OnDuelStart(Player* player1, Player* player2)
- {
- MatchStruct info(player1, player2);
- uint8 phaseID = 0;
- if(MatchData.size() >= MAX_PHASES) // if all phases full, check if players offline:
- ErasePlayers();
- if(MatchData.size() >= MAX_PHASES) // full
- {
- ChatHandler(player1->GetSession()).SendSysMessage("You cannot be phased at the moment");// this won't happen often
- ChatHandler(player2->GetSession()).SendSysMessage("You cannot be phased at the moment");// this won't happen often
- }
- else // has phases left
- {
- for (uint8 i = phaseID+1; i < MAX_PHASES; ++i)
- {
- if (MatchData.find(i) == MatchData.end())
- {
- phaseID = i;
- break;
- }
- }
- ChatHandler(player1->GetSession()).SendSysMessage("You have been phased.");
- ChatHandler(player2->GetSession()).SendSysMessage("You have been phased.");
- }
- // MatchData.push_back(info);
- if(phaseID)
- MatchData[phaseID] = info;
- player1->SetPhaseMask(pow(2.0f, phaseID), true);
- player2->SetPhaseMask(pow(2.0f, phaseID), true);
- // teleport etc
- };
- void ErasePlayers()
- {
- for(MatchList::iterator it = MatchData.begin(); it != MatchData.end(); ++it) // loop records
- {
- Player* player1 = sObjectAccessor->FindPlayer(it->second.player1);
- Player* player2 = sObjectAccessor->FindPlayer(it->second.player2);
- uint32 phase = pow(2.0f, it->first);
- if(player1 && player2 && player1->GetPhaseMask() == phase && player2->GetPhaseMask() == phase)
- continue;
- // teleport players out or something
- MatchData.erase(it);
- }
- }
- void OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType /*type*/)
- {
- double phase = sqrt(double(pWinner->GetPhaseMask()));
- if(phase - uint8(phase))
- return; // was not unique
- uint8 phaseID = uint8(phase);
- if(phaseID >= MAX_PHASES)
- return; // wrong ID
- MatchData.erase(phaseID); // if not cleared right, still cleared if ErasePlayers is called
- pWinner->RemoveAllSpellCooldown();
- pLoser->RemoveAllSpellCooldown();
- pWinner->SetHealth(pWinner->GetMaxHealth());
- if ( pWinner->getPowerType() == POWER_MANA )
- pWinner->SetPower(POWER_MANA, pWinner->GetMaxPower(POWER_MANA));
- pLoser->SetHealth(pLoser->GetMaxHealth());
- if ( pLoser->getPowerType() == POWER_MANA )
- pLoser->SetPower(POWER_MANA, pLoser->GetMaxPower(POWER_MANA));
- }
- };
- void AddSC_DuelPhasing()
- {
- new DuelPhasing();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement