Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::bitset<31> phases;
- struct MatchStruct {
- MatchStruct(Player* _player1, Player* _player2) : phaseID(0) // cant phase, use 1 (2^0 = 1)
- {
- player1 = _player1->GetGUID();
- player2 = _player2->GetGUID();
- }
- uint64 player1;
- uint64 player2;
- uint8 phaseID;
- };
- typedef std::list<MatchStruct> MatchList;
- MatchList MatchData;
- class DuelPhasing : public PlayerScript
- {
- public:
- DuelPhasing() : PlayerScript("DuelPhasing") { }
- void OnDuelStart(Player* player1, Player* player2)
- {
- MatchStruct info(player1, player2);
- if(phases.all()) // if all phases full, check if players offline:
- ErasePlayers();
- if(phases.all()) // 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 (int i = 0; i < phases.size(); ++i)
- {
- if (!phases.test(i))
- {
- phases.set(i, true); // phase in use
- info.phaseID = i;
- break;
- }
- }
- ChatHandler(player1->GetSession()).SendSysMessage("You have been phased.");
- ChatHandler(player2->GetSession()).SendSysMessage("You have been phased.");
- }
- MatchData.push_back(info);
- player1->SetPhaseMask(pow(2.0f, info.phaseID), true);
- player2->SetPhaseMask(pow(2.0f, info.phaseID), true);
- // teleport etc
- };
- void ErasePlayers()
- {
- for(MatchList::iterator it = MatchData.begin(); it != MatchData.end();) // loop records
- {
- Player* player1 = sObjectAccessor->FindPlayer(it->player1);
- Player* player2 = sObjectAccessor->FindPlayer(it->player2);
- if(!player1 || !player2) // neither or both offline
- {
- // Teleport players out or something
- phases.set(it->phaseID, false); // set phase unused
- MatchData.erase(it++);
- continue;
- }
- ++it;
- }
- }
- };
- void AddSC_DuelPhasing()
- {
- new DuelPhasing();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement