void StrandOfTheAncient::TimeTick(){ SetTime( RoundTime - 5 ); if( RoundTime == 0){ sEventMgr.RemoveEvents(this, EVENT_SOTA_TIMER); FinishRound(); } };
bool StrandOfTheAncient::HookQuickLockOpen( GameObject *go, Player *player, Spell *spell ){ uint32 entry = go->GetEntry(); if( entry == GO_RELIC ) FinishRound(); return true; }
void CTrivia::Game(void) { Sleep(50); DWORD dwQuestion; int nFile = 0; UINT nStartTic = 0; int nQuestion = 0; int nDefPoints = m_Ini.GetValue("Trivia", "Points", 1); if(nDefPoints <= 0) nDefPoints = 1; int nDefTime = m_Ini.GetValue("Trivia", "Time", 45); if(nDefTime <= 0) nDefTime = 45; CString strTmp; FloodSafeInput(m_dwTriviaID, m_strStart); FloodSafeInput(m_dwTriviaID, m_strStartAdmin); while(m_bTrivia){ if(m_strQuestion.IsEmpty() && !m_bPause){ // Get the next question nFile = rand() % (int)m_aTrivia.GetSize(); dwQuestion = rand() % m_aTrivia[nFile].dwNum; TiXmlDocument doc(m_aTrivia[nFile].strFile); if(doc.LoadFile() == false){ CString strError; strError.Format("Error in file %s.", m_aTrivia[nFile].strFile); WriteEchoText(m_dwTriviaID, strError, RGB(0, 0, 255), RGB(255,50, 50)); continue; } TiXmlNode* mainNode = 0; mainNode = doc.FirstChild("config"); TiXmlNode* triviaNode = 0, *childNode = 0; DWORD n = 0; while((triviaNode = mainNode->IterateChildren("Trivia", triviaNode)) != NULL){ if(n++ >= dwQuestion){ triviaNode->ToElement()->Attribute("score", (int*)&m_nPoints); if(m_nPoints <= 0) m_nPoints = nDefPoints; triviaNode->ToElement()->Attribute("time", (int*)&m_nTime); if(m_nTime <= 0) m_nTime = nDefTime; childNode = triviaNode->FirstChild("q"); if(childNode != NULL){ if(childNode->FirstChild() != NULL){ m_strQuestion = childNode->FirstChild()->ToText()->Value(); } } else continue; childNode = 0; while((childNode = triviaNode->IterateChildren("a", childNode)) != NULL){ if(childNode->FirstChild() != NULL){ m_aAnswers.Add(childNode->FirstChild()->ToText()->Value()); } } if(m_aAnswers.IsEmpty()){ m_strQuestion.Empty(); continue; } else break; } // end if(n++ >= dwQuestion) }// end while(trivia) strTmp = m_strQuestionText; m_nCurrentQuestion = nQuestion; nQuestion++; strTmp.Replace("%QUES%", m_strQuestion); strTmp.Replace("%NUM%", itocstr(nQuestion)); strTmp.Replace("%POINTS%", itocstr(m_nPoints)); strTmp.Replace("%TIME%", itocstr(m_nTime)); if(m_bHints){ m_strCurrentHint = m_aAnswers.GetAt(0); int nLen = m_strCurrentHint.GetLength(); int nBlankStart = nLen / 3; if(nBlankStart > 3) nBlankStart = 3; for(int i = nBlankStart; i < nLen; i++){ if(m_strCurrentHint[i] != ' ') m_strCurrentHint.SetAt(i, '_'); } TRACE("Hint: %s\n", m_strCurrentHint); } else{ m_strCurrentHint.Empty(); } Sleep(3000); FloodSafeInput(m_dwTriviaID, strTmp); #ifdef _DEBUG WriteEchoText(m_dwTriviaID, m_aAnswers[0] + "\n", RGB(255,255,255), m_crBg); #endif nStartTic = GetTickCount(); } // end if(strQuestion.IsEmpty()) else if(m_bHints && m_strCurrentHint.GetLength() && ((GetTickCount() - nStartTic) >= (UINT)m_nTime*500)){ strTmp = m_strHintText; strTmp.Replace("%HINT%", m_strCurrentHint); FloodSafeInput(m_dwTriviaID, strTmp); m_strCurrentHint.Empty(); } else if((GetTickCount() - nStartTic) >= (UINT)m_nTime*1000){ // time is up; strTmp = m_strNoAnswer; strTmp.Replace("%QUES%", m_strQuestion); strTmp.Replace("%ANS%", m_aAnswers[0]); strTmp.Replace("%POINTS%", itocstr(m_nPoints)); strTmp.Replace("%TIME%", itocstr(m_nTime)); m_strQuestion.Empty(); m_aAnswers.RemoveAll(); FloodSafeInput(m_dwTriviaID, strTmp); if((m_nRoundEnd != -1) && (m_nCurrentQuestion >= m_nRoundEnd+1)){ FinishRound(m_dwTriviaID); //, strNickname); break; } } Sleep(10); } m_bTrivia = FALSE; //m_dwTriviaID = 0; }
void CTrivia::OnMessage(DWORD dwID, CString* pUser, CString* pMsg, BOOL bIsAction) { if(m_dwTriviaID != dwID){ return; } CString strNickname = *pUser; CString strMessage = *pMsg; // Nickname is emtpy, ignore input :-P if(strNickname.IsEmpty()){ return; } // Message is emtpy, ignore input :-P if(strMessage.IsEmpty()){ return; } if(m_strQuestion.GetLength() && (strMessage.Find(m_strQuestion) >= 0)){ return; } CString strTmp; if((strMessage == "!hints") && IsAdmin(strNickname)){ m_bHints = !m_bHints; if(m_bHints) FloodSafeInput(dwID, "Enabled Hints."); else FloodSafeInput(dwID, "Disabled Hints."); } if(!m_bTrivia){ if((strMessage.Find("!trivia") == 0) && IsAdmin(strNickname)){ strTmp = strMessage.Mid(7); strTmp.TrimLeft(); strTmp.TrimRight(); if(strTmp.IsEmpty()){ m_nRoundEnd = -1; } else{ m_nRoundEnd = atoi(strTmp); } m_bTrivia = TRUE; m_eTrivia.ResetEvent(); AfxBeginThread(TriviaThread, (LPVOID)this, THREAD_PRIORITY_NORMAL); } else{ return; } } if(m_bTrivia){ if((strMessage == "!strivia") && IsAdmin(strNickname)){ m_bTrivia = FALSE; WaitForSingleObject(m_eTrivia.m_hObject, INFINITE); CString strMsg; strMsg.Format("Game has been stopped by '%s'.", strNickname); FloodSafeInput(m_dwTriviaID, strMsg); } } if(strMessage == "!score"){ strTmp = m_strScore; strTmp.Replace("%NAME%", strNickname); strTmp.Replace("%POINTS%", itocstr(GetScore(strNickname))); FloodSafeInput(m_dwTriviaID, strTmp); return; } if(strMessage == "!ranking"){ if(!m_aPlayers.GetSize()) return; PLAYER uTemp, u1, u2, u3; //CString strTmp; u1.nTriviaScore = -1; u1.strName = ""; POSITION pos = m_aPlayers.GetStartPosition(); //for(int i = 0; i < m_aPlayers.GetSize(); i++){ while(pos){ m_aPlayers.GetNextAssoc(pos, strTmp, uTemp); if(uTemp.nTriviaScore > u1.nTriviaScore){ TRACE("1> %s %d\n", uTemp.strName, uTemp.nTriviaScore); u1 = uTemp; } } pos = NULL; if(m_aPlayers.GetSize() > 1){ u2.nTriviaScore = -1; u2.strName = ""; pos = m_aPlayers.GetStartPosition(); //for(i = 0; i < m_aPlayers.GetSize(); i++){ while(pos){ m_aPlayers.GetNextAssoc(pos, strTmp, uTemp); if((uTemp.nTriviaScore > u2.nTriviaScore) && (uTemp.nTriviaScore <= u1.nTriviaScore) && (uTemp.strName != u1.strName)){ TRACE("2> %s %d\n", uTemp.strName, uTemp.nTriviaScore); u2 = uTemp; } } } pos = NULL; if(m_aPlayers.GetSize() > 2){ u3.nTriviaScore = -1; u3.strName = ""; pos = m_aPlayers.GetStartPosition(); //for(i = 0; i < m_aPlayers.GetSize(); i++){ while(pos){ m_aPlayers.GetNextAssoc(pos, strTmp, uTemp); if((uTemp.nTriviaScore > u3.nTriviaScore) && (uTemp.nTriviaScore <= u2.nTriviaScore) && (uTemp.strName != u2.strName) && (uTemp.strName != u1.strName)){ TRACE("3> %s %d\n", uTemp.strName, uTemp.nTriviaScore); u3 = uTemp; } } } FloodSafeInput(m_dwTriviaID, "Trivia UserRanking:"); Sleep(100); strTmp.Format(" Place 1: %s (%02d points)", u1.strName, u1.nTriviaScore); FloodSafeInput(m_dwTriviaID, strTmp); Sleep(100); if(m_aPlayers.GetSize() > 1){ strTmp.Format(" Place 2: %s (%02d points)", u2.strName, u2.nTriviaScore); FloodSafeInput(m_dwTriviaID, strTmp); Sleep(100); } if(m_aPlayers.GetSize() > 2){ strTmp.Format(" Place 3: %s (%02d points)", u3.strName, u3.nTriviaScore); FloodSafeInput(m_dwTriviaID, strTmp); Sleep(100); } return; } if((strMessage == "!pause") && IsAdmin(strNickname)){ m_bPause = !m_bPause; if(m_bPause){ FloodSafeInput(m_dwTriviaID, "Game has been paused."); } else{ FloodSafeInput(m_dwTriviaID, "Game has been unpaused."); } } if((strMessage == "!skip") && IsAdmin(strNickname)){ strTmp = m_strSkipText; strTmp.Replace("%QUES%", m_strQuestion); strTmp.Replace("%ANS%", m_aAnswers[0]); strTmp.Replace("%TIME%", itocstr(m_nTime)); strTmp.Replace("%POINTS%", itocstr(m_nPoints)); strTmp.Replace("%NAME%", strNickname); FloodSafeInput(m_dwTriviaID, strTmp); m_strQuestion.Empty(); m_aAnswers.RemoveAll(); return; } if((strMessage.Find("!reset") == 0) && IsAdmin(strNickname)){ POSITION pos = m_aPlayers.GetStartPosition(); while(pos){ PLAYER uTemp; m_aPlayers.GetNextAssoc(pos, strTmp, uTemp); uTemp.nTriviaScore = 0; m_aPlayers.SetAt(uTemp.strName, uTemp); } strTmp = strMessage.Mid(6); strTmp.TrimLeft(); strTmp.TrimRight(); if(strTmp.IsEmpty()){ m_nRoundEnd = -1; } else{ m_nRoundEnd = atoi(strTmp); } if(m_nRoundEnd != -1){ strTmp.Format("Trivia score reset. Starting new round: %d questions", m_nRoundEnd); } else{ strTmp = "Trivia score reset."; } FloodSafeInput(m_dwTriviaID, strTmp); m_aAnswers.RemoveAll(); m_strQuestion.Empty(); m_nCurrentRow = 0; m_strLastName.Empty(); m_strLastWinner.Empty(); m_nCurrentWin = 0; return; } if(m_strQuestion.IsEmpty()){ return; } for(int i = 0; i < m_aAnswers.GetSize(); i++){ if(m_strQuestion.IsEmpty()) break; if(ContainsStringExact(strMessage, m_aAnswers[i], FALSE) >= 0){ //int nDone = 0; strTmp = m_strCorrect; strTmp.Replace("%SCORE%", itocstr(IncreaseScore(strNickname, m_nPoints))); //, &nDone))); strTmp.Replace("%ANS%", m_aAnswers[i]); strTmp.Replace("%QUES%", m_strQuestion); strTmp.Replace("%TIME%", itocstr(m_nTime)); strTmp.Replace("%POINTS%", itocstr(m_nPoints)); strTmp.Replace("%NAME%", strNickname); FloodSafeInput(m_dwTriviaID, strTmp); if(m_strLastName == GetBaseName(strNickname)){ m_nCurrentRow++; if((m_nCurrentRow % m_nRowWin) == 0){ strTmp = m_strStreakMsg; strTmp.Replace("%NAME%", strNickname); strTmp.Replace("%STREAK%", itocstr(m_nCurrentRow)); FloodSafeInput(m_dwTriviaID, strTmp); } } else{ m_strLastName = GetBaseName(strNickname); m_nCurrentRow = 0; } if((m_nRoundEnd != -1) && (m_nCurrentQuestion >= m_nRoundEnd+1)){ FinishRound(dwID); //, strNickname); } m_strQuestion.Empty(); m_aAnswers.RemoveAll(); break; } } }