예제 #1
0
void TowerDefenseInstanceScript::TowerDefenseMapInstanceScript::LoadPastEvents()
{
    if(QueryResult queryResult = CharacterDatabase.Query("SELECT * FROM custom_td_events"))
    {
        do
        {
            // If there is a result, then create new event data, and set it.
            if(queryResult)
            {
                Field* pFields = queryResult->Fetch();
                uint32 playerGUID = pFields[1].GetUInt32();
                uint32 currentResources = pFields[3].GetUInt32();
                bool finished = pFields[6].GetBool();

                if(!finished)
                {
                    if(QueryResult queryResult = CharacterDatabase.PQuery("SELECT * FROM custom_td_players WHERE playerGUID = '%u'", playerGUID)){
                        UpdatePlayerStats(playerGUID, TD_PLAYER_STAT_EVENTS_UNFINISHED, 1);
                        UpdatePlayerStats(playerGUID, TD_PLAYER_STAT_CURRENT_RESOURCES, currentResources);
                    }
                    else{
                        CharacterDatabase.PExecute("REPLACE INTO custom_td_players (playerGUID, eventsUnfinished, currentResources) values('%u','1','%u');",playerGUID,currentResources);
                        RecordLog("TowerDefense: Inserted stats for Player GUID: [%u], added [%u] resources and 1 unfinished events.", playerGUID,currentResources);
                    }
                    SendMailToPlayer(NULL, playerGUID, TD_SYSTEM_MSG_MAIL_BODY_EVENT_UNFINISHED, currentResources);
                    continue;
                }
            }
        }while(queryResult->NextRow());
        CharacterDatabase.PExecute("DELETE FROM custom_td_events WHERE eventFinished = '0'");
        RecordLog("TowerDefense: All past unfinished events were deleted, and their information was sent to the players.");
    }
    else if(!queryResult)
        RecordLog("TowerDefense: No past events exist!");
}
예제 #2
0
    void UpdateAI(uint32 const uiDiff) override
    {
        if (!m_eventTimer.IsSet() || !m_eventTimer.Expired(uiDiff))
            return;

        switch (m_eventStage)
        {
            case 0:
                if (Player* pPlayer = SelectPlayerInDalaran())
                {
                    self->SetVisibility(VISIBILITY_ON);
                    self->CastSpell(self, SPELL_TELEPORT_VISUAL, false);

                    float x, y, z;
                    pPlayer->GetClosePoint(x, y, z, 0.0f, 5.0f);
                    self->NearTeleportTo(x, y, z, -pPlayer->GetOrientation());

                    self->CastSpell(pPlayer, SPELL_MANABONKED, false);
                    SendMailToPlayer(pPlayer);
                }
                else
                {
                    m_eventTimer.Reset(0);
                    self->ForcedDespawn();
                    return;
                }

                m_eventTimer.Reset(3000);
                m_eventStage++;
                break;
            case 1:
                self->CastSpell(self, SPELL_IMPROVED_BLINK, false);

                float x, y, z;
                self->GetClosePoint(x, y, z, 0.0f, frand(15.0f, 40.0f));
                self->GetMotionMaster()->MovePoint(0, x, y, z);

                m_eventTimer.Reset(3000);
                m_eventStage++;
                break;
            case 2:
                self->CastSpell(self, SPELL_TELEPORT_VISUAL, false);

                m_eventTimer.Reset(500);
                m_eventStage++;
                break;
            case 3:
                m_eventTimer.Reset(0);

                self->SetVisibility(VISIBILITY_OFF);
                self->ForcedDespawn();
                break;
        }
    }
예제 #3
0
            void UpdateAI(uint32 diff)
            {

                if (!sWorld->getBoolConfig(CONFIG_MINIGOB_MANABONK))
                    return;

                events.Update(diff);

                while (uint32 eventId = events.ExecuteEvent())
                {
                    switch (eventId)
                    {
                        case EVENT_SELECT_TARGET:
                            me->SetVisible(true);
                            DoCast(me, SPELL_TELEPORT_VISUAL);
                            if (Player* player = SelectTargetInDalaran())
                            {
                                me->NearTeleportTo(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), 0.0f);
                                DoCast(player, SPELL_MANABONKED);
                                SendMailToPlayer(player);
                            }
                            events.ScheduleEvent(EVENT_BLINK, 3*IN_MILLISECONDS);
                            break;
                        case EVENT_BLINK:
                        {
                            DoCast(me, SPELL_IMPROVED_BLINK);
                            Position pos;
                            me->GetRandomNearPosition(pos, (urand(15, 40)));
                            me->GetMotionMaster()->MovePoint(0, pos.m_positionX, pos.m_positionY, pos.m_positionZ);
                            events.ScheduleEvent(EVENT_DESPAWN, 3 * IN_MILLISECONDS);
                            events.ScheduleEvent(EVENT_DESPAWN_VISUAL, 2.5*IN_MILLISECONDS);
                            break;
                        }
                        case EVENT_DESPAWN_VISUAL:
                            DoCast(me, SPELL_TELEPORT_VISUAL);
                            break;
                        case EVENT_DESPAWN:
                            me->DespawnOrUnsummon();
                            break;
                        default:
                            break;
                    }
                }
            }
예제 #4
0
            void UpdateAI(uint32 diff) override
            {
                events.Update(diff);

                while (uint32 eventId = events.ExecuteEvent())
                {
                    switch (eventId)
                    {
                        case EVENT_SELECT_TARGET:
                        {
                            std::vector<Player*> PlayerInDalaranList;
                            GetPlayersInDalaran(PlayerInDalaranList);

                            // Increases chance of event based on player count in Dalaran (100 players or more = 100% else player count%)
                            if (PlayerInDalaranList.empty() || urand(1, 100) > PlayerInDalaranList.size())
                                me->AddObjectToRemoveList();

                            me->SetVisible(true);
                            DoCastSelf(SPELL_TELEPORT_VISUAL);
                            if (Player* player = SelectTargetInDalaran(PlayerInDalaranList))
                            {
                                playerGuid = player->GetGUID();
                                Position pos = player->GetPosition();
                                float dist = frand(10.0f, 30.0f);
                                float angle = frand(0.0f, 1.0f) * M_PI * 2.0f;
                                player->MovePositionToFirstCollision(pos, dist, angle);
                                me->NearTeleportTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation());
                            }
                            events.ScheduleEvent(EVENT_LAUGH_1, Seconds(2));
                            break;
                        }
                        case EVENT_LAUGH_1:
                            me->HandleEmoteCommand(EMOTE_ONESHOT_LAUGH_NO_SHEATHE);
                            events.ScheduleEvent(EVENT_WANDER, 3s);
                            break;
                        case EVENT_WANDER:
                            me->GetMotionMaster()->MoveRandom(8);
                            events.ScheduleEvent(EVENT_PAUSE, 1min);
                            break;
                        case EVENT_PAUSE:
                            me->GetMotionMaster()->MoveIdle();
                            events.ScheduleEvent(EVENT_CAST, 2s);
                            break;
                        case EVENT_CAST:
                            if (Player* player = me->GetMap()->GetPlayer(playerGuid))
                            {
                                DoCast(player, SPELL_MANABONKED);
                                SendMailToPlayer(player);
                            }
                            else
                                me->AddObjectToRemoveList();

                            events.ScheduleEvent(EVENT_LAUGH_2, Seconds(8));
                            break;
                        case EVENT_LAUGH_2:
                            me->HandleEmoteCommand(EMOTE_ONESHOT_LAUGH_NO_SHEATHE);
                            events.ScheduleEvent(EVENT_BLINK, 3s);
                            break;
                        case EVENT_BLINK:
                            DoCastSelf(SPELL_IMPROVED_BLINK);
                            events.ScheduleEvent(EVENT_DESPAWN, 4s);
                            break;
                        case EVENT_DESPAWN:
                            me->AddObjectToRemoveList();
                            break;
                        default:
                            break;
                    }
                }
            }
예제 #5
0
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();
}