void CMIDIMappingDialog::UpdateDialog(int selItem) //------------------------------------------------ { CheckDlgButton(IDC_CHECKACTIVE, m_Setting.IsActive() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(IDC_CHECKCAPTURE, m_Setting.GetCaptureMIDI() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(IDC_CHECK_PATRECORD, m_Setting.GetAllowPatternEdit() ? BST_CHECKED : BST_UNCHECKED); m_ChannelCBox.SetCurSel(m_Setting.GetChannel()); m_EventCBox.SetCurSel(-1); for(int i = 0; i < m_EventCBox.GetCount(); i++) { if(m_EventCBox.GetItemData(i) == m_Setting.GetEvent()) { m_EventCBox.SetCurSel(i); break; } } m_ControllerCBox.SetCurSel(m_Setting.GetController()); m_PluginCBox.SetCurSel(m_Setting.GetPlugIndex() - 1); m_PlugParamCBox.SetCurSel(m_Setting.GetParamIndex()); UpdateEvent(); UpdateParameters(); const bool enableMover = selItem >= 0 && ( (selItem > 0 && m_rMIDIMapper.AreOrderEqual(selItem - 1, selItem)) || (selItem + 1 < m_List.GetItemCount() && m_rMIDIMapper.AreOrderEqual(selItem, selItem + 1))); m_SpinMoveMapping.EnableWindow(enableMover); }
void CPhantom::UpdateCL() { inherited::UpdateCL(); if (!UpdateEvent.empty()) UpdateEvent(); if (m_TgtState!=m_CurState) SwitchToState_internal(m_TgtState); }
void CMIDIMappingDialog::OnCbnSelchangeComboEvent() //------------------------------------------------- { uint8 eventType = static_cast<uint8>(m_EventCBox.GetItemData(m_EventCBox.GetCurSel())); m_Setting.SetEvent(eventType); UpdateEvent(); }
void UpdateAI(const uint32 diff) { if (!CanDoSomething()) return; if(incinerate_Timer <= diff) { Yell(16149,"Que brûle la chair !"); DoCastRandom(SPELL_INCINERATE_FLESH); incinerate_Timer = 20000; } else incinerate_Timer -= diff; if(portal_Timer <= diff) { Speak(CHAT_TYPE_SAY,16150,"Viens, ma soeur, ton maître t'appelle."); CallCreature(34825,TEN_MINS,NEAR_15M,AGGRESSIVE_MAIN); portal_Timer = 120000; } else portal_Timer -= diff; UpdateEvent(diff); DoMeleeAttackIfReady(); }
void UpdateAI(const uint32 diff) { if (real_event_started) { if (initial_movement) { DoYell(SAY_BEGIN, LANG_UNIVERSAL, NULL); initial_movement = false; } Player* player = GetPlayerForEscort(); if (player) { if(player->isDead()) { player->FailQuest(QUEST_PROTECT_DAPHNE); SetVariables(); } if(m_creature->isDead() && player) player->FailQuest(QUEST_PROTECT_DAPHNE); } UpdateEvent(diff); } npc_escortAI::UpdateAI(diff); }
void UpdateAI(const uint32 diff) { if (!CanDoSomething()) return; UpdateEvent(diff); DoMeleeAttackIfReady(); }
bool CommandMap::ExecuteCommandWithStatus(std::string command) { int numArgs = 0; auto args = CommandLineToArgvA((PCHAR)command.c_str(), &numArgs); if (numArgs <= 0) return false; auto cmd = FindCommand(args[0]); if (!cmd) return false; std::vector<std::string> argsVect; if (numArgs > 1) for (int i = 1; i < numArgs; i++) argsVect.push_back(args[i]); if (cmd->Type == eCommandTypeCommand) { cmd->UpdateEvent(argsVect, std::string()); // if it's a command call it and return return true; } std::string previousValue; auto updateRet = SetVariable(cmd, (numArgs > 1 ? argsVect[0] : ""), previousValue); if (updateRet != eVariableSetReturnValueSuccess) return false; if (numArgs <= 1) return true; if (!cmd->UpdateEvent) return true; // no update event, so we'll just return with what we set the value to auto ret = cmd->UpdateEvent(argsVect, std::string()); if (ret) // error, revert the variable return true; // error, revert the variable this->SetVariable(cmd, previousValue, std::string()); return false; }
void UpdateAI(const uint32 diff) { //Return since we have no target if (!CanDoSomething()) return; UpdateEvent(diff); DoMeleeAttackIfReady(); }
/* called when event is initialized */ extern "C" __declspec(dllexport) void EventInit(void *_pData, int _iDataSize) { SPluginsKartEvent_t *psEventData; psEventData = (SPluginsKartEvent_t*)_pData; if (pBuf) { UpdateState(STATE_IN_GARAGE); UpdateEvent(psEventData); } }
void UpdateAI(const uint32 diff) { if (!CanDoSomething() || me->HasAura(66830)) { if(!me->HasAura(66830)) ModifyAuraStack(66830); EnterEvadeMode(); return; } UpdateEvent(diff); DoMeleeAttackIfReady(); }
static int Poll(int timeout) { Thread::Mutex::Scoped l(locker_poll); static int __init_dummy = Init(); UpdateEvent(); // ResumeTimer(); int maxevents = iomap.size(); fdset.resize(maxevents); int nevents = epoll_wait(ep, &fdset[0], maxevents, timeout); wakeup_flag = false; // SuspendTimer(); if (nevents > 0) std::for_each(fdset.begin(), fdset.begin() + nevents, std::ptr_fun(&TriggerEvent)); return __init_dummy; }
void UpdateAI(const uint32 diff) { //Return since we have no target if (!CanDoSomething()) return; //Summon Gizrul if (!Summoned && CheckPercentLife(25)) { CallAggressiveCreature(10268,300000,PREC_COORDS,AGGRESSIVE_RANDOM,ADD_1X,ADD_1Y,ADD_1Z); Summoned = true; } UpdateEvent(diff); DoMeleeAttackIfReady(); }
void CalendarMgr::AddEvent(CalendarEvent* calendarEvent, CalendarSendEventType sendType) { _events.insert(calendarEvent); UpdateEvent(calendarEvent); SendCalendarEvent(calendarEvent->GetCreatorGUID(), *calendarEvent, sendType); }
/** @brief ImageQueue の画像更新監視用のイベントハンドルを取得します。 画像が更新されたら、これがシグナル状態になります。 */ extern "C" HANDLE LIBPLAYER_API Sts_IQ_GetUpdateHandle(Sts_ImageQueueHandle_t hQueue) { auto pQueue = g_PlayerApp._imageQueue.GetItem(hQueue); if( !pQueue )return nullptr; return pQueue->UpdateEvent(); }
bool CommandMap::ExecuteCommandWithStatus(std::string command, bool isUserInput, std::string *output) { *output = ""; int numArgs = 0; auto args = CommandLineToArgvA((PCHAR)command.c_str(), &numArgs); if (numArgs <= 0) { *output = "Invalid input"; return false; } auto cmd = FindCommand(args[0]); if (!cmd || (isUserInput && cmd->Flags & eCommandFlagsInternal)) { *output = "Command/Variable not found"; return false; } if ((cmd->Flags & eCommandFlagsRunOnMainMenu) && !ElDorito::Instance().GameHasMenuShown) { queuedCommands.push_back(command); *output = "Command queued until mainmenu shows"; return true; } // Host-only commands if (cmd->Flags & eCommandFlagsCheat || cmd->Flags & eCommandFlagsHostOnly) { auto session = Blam::Network::GetActiveSession(); if (session && session->IsEstablished() && !session->IsHost()) { *output = "Only a player hosting a game can use this command"; return false; } } std::vector<std::string> argsVect; if (numArgs > 1) for (int i = 1; i < numArgs; i++) argsVect.push_back(args[i]); if (cmd->Type == eCommandTypeCommand && cmd->Flags == eCommandFlagsArgsNoParse) { argsVect.clear(); if (numArgs >= 2) argsVect.push_back(command.substr(std::strlen(args[0]) + 1)); //push unparsed arguments after the command return cmd->UpdateEvent(argsVect, *output); } if (cmd->Type == eCommandTypeCommand) return cmd->UpdateEvent(argsVect, *output); // if it's a command call it and return if (numArgs <= 1) { *output = cmd->ValueString; return true; } std::string previousValue; auto updateRet = SetVariable(cmd, argsVect[0], previousValue); switch (updateRet) { case eVariableSetReturnValueError: *output = "Command/variable not found"; return false; case eVariableSetReturnValueInvalidArgument: *output = "Invalid value"; return false; case eVariableSetReturnValueOutOfRange: if (cmd->Type == eCommandTypeVariableInt) *output = "Value " + argsVect[0] + " out of range [" + std::to_string(cmd->ValueIntMin) + ".." + std::to_string(cmd->ValueIntMax) + "]"; else if (cmd->Type == eCommandTypeVariableInt64) *output = "Value " + argsVect[0] + " out of range [" + std::to_string(cmd->ValueInt64Min) + ".." + std::to_string(cmd->ValueInt64Max) + "]"; else if (cmd->Type == eCommandTypeVariableFloat) *output = "Value " + argsVect[0] + " out of range [" + std::to_string(cmd->ValueFloatMin) + ".." + std::to_string(cmd->ValueFloatMax) + "]"; else *output = "Value " + argsVect[0] + " out of range [this shouldn't be happening!]"; return false; } if (!cmd->UpdateEvent) { *output = previousValue + " -> " + cmd->ValueString; // no update event, so we'll just return with what we set the value to return true; } auto ret = cmd->UpdateEvent(argsVect, *output); if (!ret) // error, revert the variable this->SetVariable(cmd, previousValue, std::string()); if (output->length() <= 0) *output = previousValue + " -> " + cmd->ValueString; return ret; }
// 窗口事件处理 Boolean TMessageCenterForm::EventHandler(TApplication * pApp, EventType * pEvent) { Boolean bHandled = FALSE; switch (pEvent->eType) { case EVENT_WinInit: { _OnWinInitEvent(pApp, pEvent); bHandled = TRUE; break; } case EVENT_WinClose: { _OnWinClose(pApp, pEvent); break; } case EVENT_WinEraseClient: { TDC dc(this); WinEraseClientEventType *pEraseEvent = reinterpret_cast< WinEraseClientEventType* >( pEvent ); TRectangle rc(pEraseEvent->rc); TRectangle rcBack(5, 142, 310, 314); this->GetBounds(&rcBack); dc.SetBackColor(RGB_COLOR_WHITE); dc.EraseRectangle(&rc, 0); dc.DrawBitmapsH(TResource::LoadConstBitmap(APP_KA_ID_BITMAP_title_bg), 0, 0, SCR_W, GUI_API_STYLE_ALIGNMENT_LEFT); pEraseEvent->result = 1; bHandled = TRUE; } break; case EVENT_CtrlSelect: { bHandled = _OnCtrlSelectEvent(pApp, pEvent); break; } case EVENT_KeyCommand: { // 抓取右软键事件 if (pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_UP || pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_LONG) { // 模拟退出按钮选中消息 HitControl(m_BackBtn); bHandled = TRUE; } } break; case MSG_FORM_UPDATE: { bHandled = TRUE; UpdateEvent(pApp); } break; default: break; } if (!bHandled) { bHandled = TWindow::EventHandler(pApp, pEvent); } return bHandled; }
void UpdateAI(const uint32 diff) { if (!CanDoSomething()) return; if(CheckHardMode_Timer <= diff) { for(uint8 i=0;i<3;i++) HardMode[i] = false; if(Creature* IronBranch = GetInstanceCreature(DATA_FREYA_ANCIENT_1)) if(IronBranch->isAlive()) HardMode[0] = true; if(Creature* BrightLeaf = GetInstanceCreature(DATA_FREYA_ANCIENT_2)) if(BrightLeaf->isAlive()) HardMode[1] = true; if(Creature* StoneBark = GetInstanceCreature(DATA_FREYA_ANCIENT_3)) if(StoneBark->isAlive()) HardMode[2] = true; CheckHardMode_Timer = 1500; } else CheckHardMode_Timer -= diff; if(phase == 1) { if(Check_InLife_Timer <= diff) { Check_InLife_Timer = 1500; if(!TriAdds.empty()) { uint8 AliveCount = 0; for(std::vector<uint64>::iterator itr = TriAdds.begin(); itr!= TriAdds.end(); ++itr) { if(Creature* cr = GetGuidCreature(*itr)) if(cr->isAlive()) AliveCount++; } if(!CheckInLife) { if(AliveCount > 0 && AliveCount < 3) CheckInLife = true; } else { CheckInLife = false; if(AliveCount > 0) { for(std::vector<uint64>::iterator itr = TriAdds.begin(); itr!= TriAdds.end(); ++itr) { if(Creature* cr = GetGuidCreature(*itr)) if(!cr->isAlive()) cr->Respawn(); } } } if(CheckInLife) Check_InLife_Timer = 10000; } } else Check_InLife_Timer -= diff; if(Vague_Timer <= diff) { Vague_Count++; switch(Vague_Count) { case 1: case 3: case 5: Yell(15533,"Mes enfants, venez m'aider !"); BossEmote(0,"Des allies de la Nature apparaissent !"); for(int i=0;i<(m_difficulty ? 10 : 8);i++) CallCreature(NPC_DETONATING_LASHER,TEN_MINS,NEAR_15M); break; case 2: Yell(15534,"La nuée des éléments va vous submerger !"); if(Creature* tmpCr = CallCreature(NPC_WATER_SPIRIT,TEN_MINS,NEAR_15M)) TriAdds.push_back(tmpCr->GetGUID()); if(Creature* tmpCr = CallCreature(NPC_STORM_LASHER,TEN_MINS,NEAR_15M)) TriAdds.push_back(tmpCr->GetGUID()); if(Creature* tmpCr = CallCreature(NPC_SNAPLASHER,TEN_MINS,NEAR_15M)) TriAdds.push_back(tmpCr->GetGUID()); break; case 4: case 6: Say(15528,"Eonar, ta servante a besoin d'aide"); for(uint8 i=0;i<(m_difficulty ? 12 : 5);i++) CallCreature(30391,60000,NEAR_7M,NOTHING); CallCreature(NPC_ANCIENT_CONSERVATOR,TEN_MINS,NEAR_15M); break; case 7: phase++; break; default: break; } Vague_Timer = 60000; } else Vague_Timer -= diff; } UpdateEvent(diff); UpdateEvent(diff,phase); if(HardMode[0]) UpdateEvent(diff,5); if(HardMode[1]) UpdateEvent(diff,6); if(HardMode[2]) UpdateEvent(diff,7); DoMeleeAttackIfReady(); }
void UpdateAI(const uint32 diff) { if (!CanDoSomething()) return; if(infection_Timer <= diff) { Yell(16991,"Ah c'est tout englué."); DoCastRandom(SPELL_MUTATED_INFECTION); infection_nb++; switch(m_difficulty) { case RAID_DIFFICULTY_10MAN_NORMAL: case RAID_DIFFICULTY_10MAN_HEROIC: { if(infection_nb > 12) infection_Timer = 8000; else if(infection_nb > 8) infection_Timer = 10000; else if(infection_nb > 5) infection_Timer = 11000; else if(infection_nb > 2) infection_Timer = 12500; else infection_Timer = 14000; break; } case RAID_DIFFICULTY_25MAN_NORMAL: case RAID_DIFFICULTY_25MAN_HEROIC: { if(infection_nb > 12) infection_Timer = 9000; else if(infection_nb > 8) infection_Timer = 11000; else if(infection_nb > 5) infection_Timer = 12500; else if(infection_nb > 2) infection_Timer = 15500; else infection_Timer = 17000; break; } } } else infection_Timer -= diff; if(check_Timer <= diff) { std::set<uint64> removableGuids; removableGuids.clear(); for(std::set<uint64>::iterator itr = PlayerSet.begin(); itr != PlayerSet.end(); ++itr) { if(Unit* u = GetGuidUnit(*itr)) { bool spawn = false; if(u->isAlive()) { if(!u->HasAura(SPELL_MUTATED_INFECTION)) spawn = true; } else spawn = true; if(spawn) { if(Creature* cr = CallAggressiveCreature(NPC_SMALL_OOZE,TEN_MINS,PREC_COORDS,u->GetPositionX(),u->GetPositionY(),u->GetPositionZ())) u->AddThreat(cr,100000.0f); removableGuids.insert(*itr); } } } for(std::set<uint64>::iterator itr = removableGuids.begin(); itr != removableGuids.end(); ++itr) PlayerSet.erase(*itr); check_Timer = 300; } else check_Timer = diff; if(pool_Timer <= diff) { if(Creature* cr = GetInstanceCreature(TYPE_PUTRICIDE)) Yell(17126,"Merveille nouvelle mes amis, la gelée coule à flots !"); if(Creature* cr1 = CallCreature(NPC_OOZE_STALKER,25000,PREC_COORDS,NOTHING,SpawnLoc[pool][0],SpawnLoc[pool][1],SpawnLoc[pool][2])) if(Creature* cr3 = CallCreature(NPC_OOZE_ROBINET,8000,PREC_COORDS,NOTHING,RobinetLoc[pool][0],RobinetLoc[pool][1],RobinetLoc[pool][2])) cr1->AddThreat(cr3,100000.0f); if(Creature* cr2 = CallCreature(NPC_OOZE_STALKER,25000,PREC_COORDS,NOTHING,SpawnLoc[pool+4][0],SpawnLoc[pool+4][1],SpawnLoc[pool+4][2])) if(Creature* cr4 = CallCreature(NPC_OOZE_ROBINET,8000,PREC_COORDS,NOTHING,RobinetLoc[pool+4][0],RobinetLoc[pool+4][1],RobinetLoc[pool+4][2])) cr2->AddThreat(cr4,100000.0f); pool++; if(pool >= 4) pool = 0; pool_Timer = 20000; } else pool_Timer -= diff; if(spray_Timer <= diff) { if(Unit* u = GetRandomUnit(0)) { if(Creature* cr = CallCreature(NPC_OOZE_SPRAY_STALKER,15000,PREC_COORDS,NOTHING,u->GetPositionX(),u->GetPositionY(),u->GetPositionZ())) { cr->SetDisplayId(16925); cr->SetFlag(UNIT_FIELD_FLAGS,UNIT_FLAG_NON_ATTACKABLE); cr->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); cr->setFaction(14); ModifyAuraStack(66830,1,cr,cr); } DoCast(u,SPELL_SLIME_SPRAY); } spray_Timer = 18000; } else spray_Timer -= diff; UpdateEvent(diff); DoMeleeAttackIfReady(); }
std::string CommandMap::ExecuteCommand(std::string command) { int numArgs = 0; auto args = CommandLineToArgvA((PCHAR)command.c_str(), &numArgs); if (numArgs <= 0) return "Invalid input"; auto cmd = FindCommand(args[0]); if (!cmd) return "Command/Variable not found"; if ((cmd->Flags & eCommandFlagsRunOnMainMenu) && !ElDorito::Instance().GameHasMenuShown) { queuedCommands.push_back(command); return "Command queued until mainmenu shows"; } if ((cmd->Flags & eCommandFlagsHostOnly) && !ElDorito::Instance().IsHostPlayer()) return "Only a player hosting a game can use this command"; std::vector<std::string> argsVect; if (numArgs > 1) for (int i = 1; i < numArgs; i++) argsVect.push_back(args[i]); if (cmd->Type == eCommandTypeCommand) { std::string retInfo; cmd->UpdateEvent(argsVect, retInfo); // if it's a command call it and return return retInfo; } std::string previousValue; auto updateRet = SetVariable(cmd, (numArgs > 1 ? argsVect[0] : ""), previousValue); switch (updateRet) { case eVariableSetReturnValueError: return "Command/Variable not found"; case eVariableSetReturnValueInvalidArgument: return "Invalid value"; case eVariableSetReturnValueOutOfRange: if (cmd->Type == eCommandTypeVariableInt) return "Value " + argsVect[0] + " out of range [" + std::to_string(cmd->ValueIntMin) + ".." + std::to_string(cmd->ValueIntMax) + "]"; if (cmd->Type == eCommandTypeVariableInt64) return "Value " + argsVect[0] + " out of range [" + std::to_string(cmd->ValueInt64Min) + ".." + std::to_string(cmd->ValueInt64Max) + "]"; if (cmd->Type == eCommandTypeVariableFloat) return "Value " + argsVect[0] + " out of range [" + std::to_string(cmd->ValueFloatMin) + ".." + std::to_string(cmd->ValueFloatMax) + "]"; return "Value " + argsVect[0] + " out of range [this shouldn't be happening!]"; } // special case for blanking strings if (cmd->Type == eCommandTypeVariableString && numArgs > 1 && argsVect[0].empty()) cmd->ValueString = ""; if (numArgs <= 1) return previousValue; if (!cmd->UpdateEvent) return previousValue + " -> " + cmd->ValueString; // no update event, so we'll just return with what we set the value to std::string retVal; auto ret = cmd->UpdateEvent(argsVect, retVal); if (!ret) // error, revert the variable this->SetVariable(cmd, previousValue, std::string()); if (retVal.length() <= 0) return previousValue + " -> " + cmd->ValueString; return retVal; }
void Engine::StartGame() { myGameIsRunning = true; // Close the game when we hit the close button myEventHost->RegisterEvent<CloseButtonPressedEvent>([=](CloseButtonPressedEvent &ev) { myGameIsRunning = false; }); // Show the window myRenderer->GetWindow()->SetVisible(true); Stopwatch stopwatch; std::vector<RenderCommand> *currentRenderCommands = new std::vector<RenderCommand>(); float time = 0.f; while (myGameIsRunning == true) { float deltaTime = stopwatch.GetElapsedSeconds(); time += deltaTime; stopwatch.Restart(); myRenderer->TriggerEvents(); std::swap(currentRenderCommands, myNewRenderCommands); float progressToNextFixedUpdate = (myTimeAccumulator / myTimeStep); myTimeAccumulator += deltaTime; Matrix33f worldToViewport; Transformation cameraTransformation = mySceneHost->GetCurrentScene()->GetCamera().GetTransformation(); auto gameLogicWork = myThreadPool->QueueWorkItem(std::function<void()>([=] { while (myTimeAccumulator >= myTimeStep) { myEventHost->TriggerEvent(UpdateEvent(myTimeStep)); myEventHost->TriggerEvent(EndUpdateEvent()); myTimeAccumulator -= myTimeStep; } myEventHost->TriggerEvent(DrawEvent()); })); Vector2f windowSize = Vector2f(myRenderer->GetWindow()->GetSize()); worldToViewport *= Matrix33f::CreateScale(2.f / windowSize.x, -2.f / windowSize.y, 1.f) * Matrix33f::CreateTranslation(-cameraTransformation.Position.x, -cameraTransformation.Position.y) * Matrix33f::CreateRotateAroundZ(cameraTransformation.Rotation); myRenderer->SetWorldToViewportMatrix(worldToViewport); myRenderer->Clear(); RenderTarget &renderTarget = *myRenderer->GetRenderTarget(); for (size_t i = 0; i < currentRenderCommands->size(); i++) { RenderCommand currentCommand = (*currentRenderCommands)[i]; Vector2f position = currentCommand.previousPosition + (currentCommand.currentPosition - currentCommand.previousPosition) * progressToNextFixedUpdate; renderTarget.Render(currentCommand.texture, position); } currentRenderCommands->clear(); myRenderer->PresentBackBuffer(); float beginSleep = stopwatch.GetElapsedSeconds(); std::this_thread::sleep_for(std::chrono::microseconds(1)); // Wait for the game logic update to finish gameLogicWork->Wait(); if (mySceneHost->GetCurrentScene() == nullptr) { myGameIsRunning = false; } } delete currentRenderCommands; myEventHost->TriggerEvent(ExitingEvent()); }
LRESULT ProgressDialog::dialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { const auto updateDialogTimerID = 1U; const auto progressDialogShowDetailedOutputSetting = String("ProgressDialogShowDetailedOutput"); switch (message) { case WM_INITDIALOG: { detailedOutput_.clear(); isTaskComplete_ = false; currentTaskString_.clear(); // Set the exporter version label SetWindowTextA(GetDlgItem(hDlg, IDC_VERSION), ("Version " + BuildInfo::getVersion()).cStr()); // Hide the Close button ShowWindow(GetDlgItem(hDlg, IDC_CLOSE), SW_HIDE); // Start a timer to update the progress bar at 25Hz SetTimer(hDlg, updateDialogTimerID, 40, nullptr); // Set range of progress bar to 0-1000 SendMessage(GetDlgItem(hDlg, IDC_PROGRESS), PBM_SETRANGE32, 0, 1000); // Move the Close button on top of the Cancel button, only one is available at any given time auto cancelRect = RECT(); GetWindowRect(GetDlgItem(hDlg, IDC_CANCEL), &cancelRect); auto p = POINT{cancelRect.left, cancelRect.top}; ScreenToClient(hDlg, &p); SetWindowPos(GetDlgItem(hDlg, IDC_CLOSE), nullptr, p.x, p.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); // Initialize the show detailed output checkbox and state if (settings().getBoolean(progressDialogShowDetailedOutputSetting)) CheckDlgButton(hDlg, IDC_SHOW_DETAILED_OUTPUT, BST_CHECKED); else { CheckDlgButton(hDlg, IDC_SHOW_DETAILED_OUTPUT, BST_UNCHECKED); dialogProc(hDlg, WM_COMMAND, MAKEWPARAM(IDC_SHOW_DETAILED_OUTPUT, 0), 0); } // Create events used for inter-thread communication hUpdateOutputEvent_ = CreateEvent(nullptr, FALSE, FALSE, nullptr); hWorkerCompleteEvent_ = CreateEvent(nullptr, FALSE, FALSE, nullptr); hWorkerSucceededEvent_ = CreateEvent(nullptr, FALSE, FALSE, nullptr); // Start worker thread workerThread_ = HANDLE(_beginthreadex(nullptr, 0, staticWorkerThreadMain, this, 0, nullptr)); if (workerThread_) SetThreadPriority(workerThread_, THREAD_PRIORITY_BELOW_NORMAL); return TRUE; } case WM_DESTROY: { // The worker thread should be finished by now assuming everything worked correctly. However, it is // important to check it is finished, as odd behavior or crashes could result from lurking worker threads. auto workerThreadExitCode = DWORD(); GetExitCodeThread(workerThread_, &workerThreadExitCode); if (workerThreadExitCode == STILL_ACTIVE) { // Give the worker thread more time to close Sleep(10000); // Check the thread state again GetExitCodeThread(workerThread_, &workerThreadExitCode); if (workerThreadExitCode == STILL_ACTIVE) { LOG_WARNING << "Worker thread is still active after progress dialog closed"; MessageBoxA(GetParent(hDlg), "Warning: Worker thread still active after progress dialog closed", Globals::getClientName().cStr(), MB_ICONERROR); } } // Cleanup CloseHandle(workerThread_); CloseHandle(hUpdateOutputEvent_); CloseHandle(hWorkerCompleteEvent_); CloseHandle(hWorkerSucceededEvent_); break; } case WM_TIMER: { if (wParam == updateDialogTimerID) { events().dispatchEvent(UpdateEvent()); // Update log output display if required if (WaitForSingleObject(hUpdateOutputEvent_, 0) == WAIT_OBJECT_0) { auto lock = ScopedMutexLock(detailedOutputMutex_); // Update text in the output editbox from the 'output' variable SetWindowTextW(GetDlgItem(hDlg, IDC_OUTPUT), detailedOutput_.toUTF16().as<wchar_t>()); } if (WaitForSingleObject(hWorkerCompleteEvent_, 0) == WAIT_OBJECT_0) { isTaskComplete_ = true; // Hide the Cancel button and show the Close button ShowWindow(GetDlgItem(hDlg, IDC_CANCEL), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLOSE), SW_SHOW); SetFocus(GetDlgItem(hDlg, IDC_CLOSE)); // Check if job completed successfully if (WaitForSingleObject(hWorkerSucceededEvent_, 0) == WAIT_OBJECT_0) { // Set task label to 'Done' and progress bar to full SetWindowTextA(GetDlgItem(hDlg, IDC_TASK), "Done"); PostMessage(GetDlgItem(hDlg, IDC_PROGRESS), PBM_SETPOS, 1000, 0); } else { // The job did not complete successfully if (runnable_->isCancelled()) { // Close the dialog following cancellation EndDialog(hDlg, IDC_CLOSE); } else SetWindowTextA(GetDlgItem(hDlg, IDC_TASK), "Failed"); } } if (!isTaskComplete_) { // Update current task display if (runnable_->isTaskStringDirty()) { auto newTaskString = String(); if (IsDlgButtonChecked(hDlg, IDC_SHOW_DETAILED_OUTPUT)) newTaskString = runnable_->getTaskString(); else newTaskString = runnable_->getSimpleTaskString(); newTaskString += " ..."; // Check the new task string is different if (currentTaskString_ != newTaskString) { SetWindowTextA(GetDlgItem(hDlg, IDC_TASK), newTaskString.cStr()); currentTaskString_ = newTaskString; } } // Update progress bar position if (runnable_->isPercentageDirty()) { auto position = runnable_->getPercentage() * 10.0f; PostMessage(GetDlgItem(hDlg, IDC_PROGRESS), PBM_SETPOS, int(position), 0); } } } return TRUE; } case WM_CLOSE: { // Close the dialog if the task is complete, otherwise cancel it if (isTaskComplete_) EndDialog(hDlg, IDC_CLOSE); else dialogProc(hDlg, WM_COMMAND, MAKEWPARAM(IDC_CANCEL, 0), 0); return TRUE; } case WM_COMMAND: { if (LOWORD(wParam) == IDC_CANCEL) { runnable_->cancel(); EnableWindow(GetDlgItem(hDlg, IDC_CANCEL), FALSE); SetWindowTextA(GetDlgItem(hDlg, IDC_TASK), "Cancelling ..."); } else if (LOWORD(wParam) == IDC_CLOSE) { // Close the dialog EndDialog(hDlg, IDC_CLOSE); } else if (LOWORD(wParam) == IDC_SHOW_DETAILED_OUTPUT) { // Show/hide the detailed output auto showDetailedOutput = (IsDlgButtonChecked(hDlg, IDC_SHOW_DETAILED_OUTPUT) == BST_CHECKED); // Update output window visibility ShowWindow(GetDlgItem(hDlg, IDC_OUTPUT), showDetailedOutput); // Get sizes of the dialog items needed to do resize the dialog window correctly auto cancelRect = RECT(); auto outputRect = RECT(); auto dialogRect = RECT(); GetWindowRect(GetDlgItem(hDlg, IDC_CANCEL), &cancelRect); GetWindowRect(GetDlgItem(hDlg, IDC_OUTPUT), &outputRect); GetWindowRect(hDlg, &dialogRect); auto heightDelta = (outputRect.bottom - cancelRect.bottom); if (!showDetailedOutput) heightDelta = -heightDelta; // Update dialog size SetWindowPos(hDlg, nullptr, 0, 0, dialogRect.right - dialogRect.left, dialogRect.bottom - dialogRect.top + heightDelta, SWP_NOZORDER | SWP_NOMOVE); // Force the task string to update runnable_->setTaskStringDirty(); // Update the persistent show detailed output setting settings().set(progressDialogShowDetailedOutputSetting, showDetailedOutput); } break; } } return FALSE; }
void UpdateAI(const uint32 diff) { //Speach if (DoingSpeach) { if (SpeachTimer < diff) { switch (SpeachNum) { case 0: //16 seconds till next line DoScriptText(SAY_LINE2, me); SpeachTimer = 16000; ++SpeachNum; break; case 1: //This one is actually 16 seconds but we only go to 10 seconds because he starts attacking after he says "I must fight this!" DoScriptText(SAY_LINE3, me); SpeachTimer = 10000; ++SpeachNum; break; case 2: me->setFaction(103); me->SetHealth(int(me->GetMaxHealth()*.3)); if (PlayerGUID && Unit::GetUnit((*me),PlayerGUID)) { AttackStart(Unit::GetUnit((*me),PlayerGUID)); DoCastMe(SPELL_ESSENCEOFTHERED); } SpeachTimer = 0; DoingSpeach = false; break; } }else SpeachTimer -= diff; } //Return since we have no target if (!CanDoSomething()) return; // Yell if hp lower than 15% if (CheckPercentLife(15) && !HasYelled) { DoScriptText(SAY_HALFLIFE, me); HasYelled = true; } //BurningAdrenalineTank_Timer if (BurningAdrenalineTank_Timer < diff) { // have the victim cast the spell on himself otherwise the third effect aura will be applied // to Vael instead of the player me->getVictim()->CastSpell(me->getVictim(),SPELL_BURNINGADRENALINE,1); BurningAdrenalineTank_Timer = 45000; }else BurningAdrenalineTank_Timer -= diff; //TailSwipe_Timer if (TailSwipe_Timer < diff) { //Only cast if we are behind if (!me->HasInArc(M_PI, me->getVictim())) { DoCastVictim(SPELL_TAILSWIPE); } TailSwipe_Timer = 20000; }else TailSwipe_Timer -= diff; UpdateEvent(diff); DoMeleeAttackIfReady(); }