void TowerDefenseInstanceScript::TowerDefenseMapInstanceScript::SaveEventData() { if(QueryResult queryResult = CharacterDatabase.PQuery("SELECT * FROM custom_td_events WHERE Id = '%u'", GetEventId())){ CharacterDatabase.PExecute("UPDATE custom_td_events SET eventFinished = '%u'", GetFinished()); RecordLog("TowerDefense: Updated Event Id: [%u], it is now set to finished!",GetEventId()); } else{ CharacterDatabase.PExecute("INSERT INTO custom_td_events VALUES ('%u', '%u', '%u', '%u', '%u', NOW(), '%u')", GetEventId(), GetPlayerGUID(), GetCurrentWaveId(), GetResources(),GetBaseHealth(), GetFinished()); RecordLog("TowerDefense: Inserted Event Id: [%u] to the database.", GetEventId()); } }
void t4p::FinderActionClass::BackgroundWork() { if (!Finder.Prepare()) { return; } Code = t4p::CharToIcu(Utf8Buf); int32_t nextIndex(0); bool found = Finder.FindNext(Code, nextIndex); int32_t matchStart(0); int32_t matchLength(0); while (found) { if (Finder.GetLastMatch(matchStart, matchLength)) { // convert match back to UTF-8 ugh int utf8Start = t4p::CharToUtf8Pos(Utf8Buf, BufferLength, matchStart); int utf8End = t4p::CharToUtf8Pos(Utf8Buf, BufferLength, matchStart + matchLength); t4p::FinderHitEventClass hit(GetEventId(), utf8Start, utf8End - utf8Start); PostEvent(hit); nextIndex = matchStart + matchLength + 1; // prevent infinite find next's } else { break; } found = Finder.FindNext(Code, nextIndex); } delete[] Utf8Buf; }
bool NX::TimerEvent::Tick(const int iDeltaTime){ bool bTicked = NX::NXTick::Tick(iDeltaTime); if(bTicked){ NX::SendEvent(GetEventId()); } return bTicked; }
void t4p::ExplorerModifyActionClass::BackgroundWork() { wxFileName parentDir; wxString name; bool totalSuccess = true; std::vector<wxFileName> dirsDeleted; std::vector<wxFileName> dirsNotDeleted; std::vector<wxFileName> filesDeleted; std::vector<wxFileName> filesNotDeleted; if (t4p::ExplorerModifyActionClass::DELETE_FILES_DIRS == Action) { std::vector<wxFileName>::iterator d; for (d = Dirs.begin(); d != Dirs.end(); ++d) { bool success = t4p::RecursiveRmDir(d->GetPath()); if (success) { wxFileName wxFileName; wxFileName.AssignDir(d->GetPath()); dirsDeleted.push_back(wxFileName); } else { wxFileName wxFileName; wxFileName.AssignDir(d->GetPath()); dirsNotDeleted.push_back(wxFileName); } totalSuccess &= success; } std::vector<wxFileName>::iterator f; for (f = Files.begin(); f != Files.end(); ++f) { bool success = wxRemoveFile(f->GetFullPath()); if (success) { wxFileName deletedFile(f->GetFullPath()); filesDeleted.push_back(deletedFile); } else { wxFileName deletedFile(f->GetFullPath()); filesNotDeleted.push_back(deletedFile); } totalSuccess &= success; } t4p::ExplorerModifyEventClass modEvent(GetEventId(), dirsDeleted, filesDeleted, dirsNotDeleted, filesNotDeleted, totalSuccess); PostEvent(modEvent); } else if (t4p::ExplorerModifyActionClass::RENAME_FILE == Action) { wxFileName destFile(OldFile.GetPath(), NewName); bool success = wxRenameFile(OldFile.GetFullPath(), destFile.GetFullPath(), false); t4p::ExplorerModifyEventClass modEvent(GetEventId(), OldFile, NewName, success); PostEvent(modEvent); } }
void TowerDefenseInstanceScript::TowerDefenseMapInstanceScript::UpdateHealth(uint32 remove) { if(!remove) return; Player *player = GetPlayer(); if(!player) return; uint32 currentHealth = GetBaseHealth(); if(remove > currentHealth){ SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_DEST); // the removal from the base health is larger than the base health. the player's event ends. player->PlayDirectSound(TD_ENDEVENT_MUSIC,player); // play ending music player->GetSession()->SendNotification("The Tower defense game has finished. You lost!"); HandleEventComplete(TD_EVENT_COMPLETE_LOST); // Complete the event data using the lost type RecordLog("TowerDefense: Player Name: [%s] has lost the tower defense event. With Event Id: [%u]",player->GetName(), GetEventId()); // record a log to the server log if enabled. return; }else { currentHealth -= remove; // decrement current health SetBaseHealth(currentHealth); RecordLog("TowerDefense: Updated health for Event Id: [%u] to [%u].", GetEventId(), currentHealth); } switch(currentHealth) { case 90: SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_REACHED, 90); break; case 80: SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_LOWERING, 80); break; case 70: SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_REACHED, 70); break; case 60: SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_LOWERING, 60); break; case 50: SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_REACHED, 50); break; case 40: SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_LOW); player->CastSpell(player,GetSpellIdByUniqueId(3),true); player->PlayDirectSound(TD_ENDEVENT_MUSIC,player); SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_REACHED, 40); break; case 25: SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_VERYLOW); player->CastSpell(player,GetSpellIdByUniqueId(2),true); player->PlayDirectSound(TD_BASE_LOSING_HEALTH,_player); SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_LOWERING, 25); break; case 10: SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_REACHED, 10); SendMessageToPlayer(TD_SYSTEM_MSG_HEALTH_ALMOSTDEST); break; } return; }
int NX::TimerEvent::Release(){ int iRefCount = GetRefCount(); /** * will be deleted */ if(iRefCount == 1){ NX::TimerManager::Instance().RemoveTimer(GetEventId()); } return NX::Event::Release(); }
bool DragAndDropSprite::OnMouseOver(int x, int y, bool button, StringId& eventId, void*& userData) { if (!IsEnabled()) { dragging_=false; return false; } if (dragging_) { SetPosition((float)x-dragOffsetX_,(float)y-dragOffsetY_); } const BitmapStrip& bitmapStrip=GetBitmap(); if (bitmapStrip.GetCelCount()!=0) { int currentCel=(int)GetCel(); const Bitmap& bitmap=bitmapStrip.GetCel(currentCel); if (bitmap.GetPixelAlpha(x-(int)(GetX()+GetOriginX()),y-(int)(GetY()+GetOriginY()))>128) { if (IsEnabled()) { // highlighted_=true; if (button) { SetState(State_Pressed); if (!dragging_) { dragOffsetX_=x-GetX()+GetOriginX(); dragOffsetY_=y-GetY()+GetOriginY(); } dragging_=true; } else { SetState(State_Highlighted); dragging_=false; } } eventId=GetEventId(); userData=GetEventUserData(); return true; } } return false; }
void t4p::VolumeListActionClass::BackgroundWork() { #ifdef __WXMSW__ wxArrayString localVolArray = wxFSVolume::GetVolumes(wxFS_VOL_MOUNTED, wxFS_VOL_REMOTE | wxFS_VOL_REMOVABLE | wxFS_VOL_READONLY); std::vector<wxString> localVols; for (size_t i = 0; i < localVolArray.GetCount(); ++i) { localVols.push_back(localVolArray[i]); } t4p::VolumeListEventClass evt(GetEventId(), localVols); PostEvent(evt); #endif }
void TowerDefenseInstanceScript::TowerDefenseMapInstanceScript::HandleEventComplete(TDEventCompleteType completeType) { Player *player = GetPlayer(); if(!player) return; if(!completeType) return; switch(completeType) { case TD_EVENT_COMPLETE_UNFINISHED: { if(IsAwardingFledPlayers()){ UpdatePlayerStats(GetPlayerGUID(), TD_PLAYER_STAT_CURRENT_RESOURCES, GetResources()); SendMailToPlayer(NULL, GetPlayerGUID(), TD_SYSTEM_MSG_MAIL_BODY_EVENT_UNFINISHED, GetResources()); RecordLog("TowerDefense: Player: [%s] has received: [%u] resources due to an unfinished Event Id: [%u].", player->GetName(), GetResources(), GetEventId()); }else{ SendMailToPlayer(NULL, GetPlayerGUID(), TD_SYSTEM_MSG_MAIL_BODY_EVENT_UNFINISHED_FLED, GetResources(), GetCurrentWaveId()); RecordLog("TowerDefense: Player: [%s] was informed that he lost all his unfinished Event Id: [%u] rewards.", player->GetName(), GetResources(), GetEventId()); } UpdatePlayerStats(player->GetGUIDLow(), TD_PLAYER_STAT_EVENTS_UNFINISHED, 1); }break; case TD_EVENT_COMPLETE_QUIT: { if(player->GetSession()->isLogingOut()){ SendMessageToPlayer(TD_SYSTEM_MSG_LOGGING_OUT); return; } if(GetCurrentWaveId() < GetQuitAfterWave()){ uint32 remaining = GetQuitAfterWave() - GetCurrentWaveId(); SendMessageToPlayer(TD_SYSTEM_MSG_MORE_WAVES, remaining); return; } SendMessageToPlayer(TD_SYSTEM_MSG_QUIT_EVENT, GetResources(), GetCurrentWaveId()); UpdatePlayerStats(GetPlayerGUID(), TD_PLAYER_STAT_CURRENT_RESOURCES, GetResources()); UpdatePlayerStats(player->GetGUIDLow(), TD_PLAYER_STAT_EVENTS_LOST, 1); RecordLog("TowerDefense: Player: [%s] has received: [%u] resources after leaving Event Id: [%u].", player->GetName(), GetResources(), GetEventId()); }break; case TD_EVENT_COMPLETE_LOST: { player->PlayDirectSound(TD_ENDEVENT_MUSIC,_player); SendMessageToPlayer(TD_SYSTEM_MSG_LOST_EVENT, GetResources(), GetCurrentWaveId()); UpdatePlayerStats(player->GetGUIDLow(), TD_PLAYER_STAT_EVENTS_LOST, 1); RecordLog("TowerDefense: Player: [%s] was informed that he lost all his Event Id: [%u] rewards.", player->GetName(), GetResources(), GetEventId()); }break; case TD_EVENT_COMPLETE_WON: { SendMessageToPlayer(TD_SYSTEM_MSG_WON_EVENT, GetResources()); UpdatePlayerStats(GetPlayerGUID(), TD_PLAYER_STAT_CURRENT_RESOURCES, GetResources()); UpdatePlayerStats(player->GetGUIDLow(), TD_PLAYER_STAT_EVENTS_WON, 1); RecordLog("TowerDefense: Player: [%s] has won [%u] resources after completing Event Id: [%u].", player->GetName(), GetResources(), GetEventId()); }break; } player->DestroyItemCount(GetItemEntry(),1,true); // destroy the item from the player player->TeleportTo(1, -3673.392090, -4384.723145, 10.026433, 3.879712); // Teleport to a Neutral Mall player->RemoveAllAuras(); // remove all auras set by event player->RemoveAllAttackers(); // remove all attackers SetFinished(true); // finish the event SaveEventData(); // save event information RecordLog("TowerDefense: Player: [%s] has completed Event Id: [%u] and his event data was saved and he was teleported.", player->GetName(), GetEventId()); DeleteEventData(); }
void TowerDefenseInstanceScript::TowerDefenseMapInstanceScript::SpawnGuard(uint32 entry) { if (!entry) return; Player *player = GetPlayer(); if(!player) return; GuardInfo* guard = new GuardInfo(); bool found = false; float objectX, objectY, objectZ, objectO; uint32 objectLowGUID, objectId; uint16 objectMap, objectPhase; uint32 objectPool; GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr->GetActiveEventList(); std::ostringstream eventFilter; eventFilter << " AND (eventEntry IS NULL "; bool initString = true; for (GameEventMgr::ActiveEvents::const_iterator itr = activeEventsList.begin(); itr != activeEventsList.end(); ++itr) { if (initString) { eventFilter << "OR eventEntry IN (" << *itr; initString = false; } else eventFilter << ',' << *itr; } if (!initString) eventFilter << "))"; else eventFilter << ')'; QueryResult queryResult = WorldDatabase.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, phaseMask, " "(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject " "LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10", player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(), eventFilter.str().c_str()); if (!queryResult) { SendMessageToPlayer(TD_SYSTEM_MSG_NO_NEARBY_PLATFORM); // if there were no nearby platforms to place guards. return; } do { Field* fields = queryResult->Fetch(); objectLowGUID = fields[0].GetUInt32(); objectId = fields[1].GetUInt32(); objectX = fields[2].GetFloat(); objectY = fields[3].GetFloat(); objectZ = fields[4].GetFloat(); objectO = fields[5].GetFloat(); objectMap = fields[6].GetUInt16(); objectPhase = fields[7].GetUInt16(); objectPool = sPoolMgr->IsPartOfAPool<GameObject>(objectLowGUID); if (!objectPool || sPoolMgr->IsSpawnedObject<GameObject>(objectLowGUID)) found = true; } while (queryResult->NextRow() && !found); if (!found) { SendMessageToPlayer(TD_SYSTEM_MSG_NEARBY_PLATFORM_NOT_EXIST); // no nearby platform found return; } GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId); if (!objectInfo) { SendMessageToPlayer(TD_SYSTEM_MSG_NEARBY_PLATFORM_NOT_EXIST); // nearby platform is not an actual object return; } guard->Entry = entry; guard->X = objectX; guard->Y = objectY; guard->Z = objectZ + 0.5; // depends on size of platform object guard->O = objectO; if(player->GetDistance(objectX,objectY,objectZ) > 3) { SendMessageToPlayer(TD_SYSTEM_MSG_NEARBY_PLATFORM_TOO_FAR); return; }else { if(QueryResult queryResult = CharacterDatabase.PQuery("SELECT creatureEntry FROM custom_td_base_stats WHERE creatureType = 'Guard' ORDER BY Id ASC LIMIT 1")) { do { Field *Fields = queryResult->Fetch(); uint32 creatureEntry = Fields[0].GetUInt32(); Creature* creature = player->FindNearestCreature(creatureEntry,2,true); if(creature){ SendMessageToPlayer(TD_SYSTEM_MSG_NEARBY_GUARD_TOO_CLOSE); return; } }while(queryResult->NextRow()); } if(QueryResult queryResult = CharacterDatabase.PQuery("SELECT creatureName, creatureEntry, creatureCost FROM custom_td_base_stats WHERE creatureEntry = '%u'", entry)) { Field *Fields = queryResult->Fetch(); std::string creatureName = Fields[0].GetString(); uint32 creatureEntry = Fields[1].GetUInt32(); uint32 creatureCost = Fields[2].GetUInt32(); if(GetResources() < creatureCost) { SendMessageToPlayer(TD_SYSTEM_MSG_MORE_RESOURCES, creatureCost - GetResources()); return; }else { guard->Spawn(player); Guards[guard->Guid] = guard; guard->SetDefSpell(guard->GetSpellIdByCastType(TD_CAST_DEFAULT_CAST_TARGET)); // set default spell UpdateResources(TD_EVENT_DEC,creatureCost); SendMessageToPlayer(TD_SYSTEM_MSG_BOUGHT_GUARD, creatureName.c_str(), creatureCost); RecordLog("TowerDefense: Event ID: [%u] has spawned Guard Entry: [%u] for [%u] resources.", GetEventId(), guard->Entry,creatureCost); } } } }
void TowerDefenseInstanceScript::TowerDefenseMapInstanceScript::StartEvent(Player* player, uint32 Action) { if (!player || player->isInCombat() || player->GetSession()->isLogingOut() || player->GetGroup()){ ChatHandler(player).SendSysMessage(TD_SYSTEM_MSG_CANNOT_START_DUE); return; } if(GetPlayer() && player->GetGUIDLow() != GetPlayer()->GetGUIDLow()){ ChatHandler(player).SendSysMessage(TD_SYSTEM_MSG_CANNOT_START_ALREADY); return; }else{ SetPlayer(player); } if(!player) return; player->PlayDirectSound(TD_STARTEVENT_MUSIC,player); SetupEventData(); player->AddItem(34131, 1); // add the spawning item to the player player->SaveToDB(); // save the player to the db in case of crash player->TeleportTo(GetMapId(), GetPSpawnX(), GetPSpawnY(), GetPSpawnZ(), GetPSpawnO()); // teleport to starting location SetEventStatus(TD_EVENT_STATUS_TELEPORT); switch(Action) { case 1051: // Easy SetEventMode(TD_EVENT_MODE_EASY); SendMessageToPlayer(TD_SYSTEM_MSG_STARTED_EVENT_EASY); // wait for user input to start wave break; case 1052: // Hard SetEventMode(TD_EVENT_MODE_HARD); SendMessageToPlayer(TD_SYSTEM_MSG_STARTED_EVENT_HARD); StartNextWave(30000); // start wave from the start within 30 seconds break; case 1053: // Extreme SetEventMode(TD_EVENT_MODE_EXTREME); SendMessageToPlayer(TD_SYSTEM_MSG_STARTED_EVENT_EXTREME); StartNextWave(1000); // start waves right away break; } RecordLog("TowerDefense: Player Name: [%s] has started the tower defense event. With Event Id: [%u]",player->GetName(), GetEventId()); }