Beispiel #1
0
    bool OnGossipHello(Player* player, Creature* creature)
    {
        if (IsEventActive(HALLOWEEN_EVENTID) && !player->HasAura(SPELL_TRICK_OR_TREATED))
        {
            const char* localizedEntry;
            switch (player->GetSession()->GetSessionDbcLocale())
            {
                case LOCALE_ruRU: localizedEntry = LOCALE_TRICK_OR_TREAT_1; break;
                case LOCALE_enUS: default: localizedEntry = LOCALE_TRICK_OR_TREAT_0;
            }
            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, localizedEntry, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+HALLOWEEN_EVENTID);
        }

        if (creature->IsQuestGiver())
            player->PrepareQuestMenu(creature->GetGUID());

        if (creature->IsVendor())
            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_VENDOR, GOSSIP_TEXT_BROWSE_GOODS, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_TRADE);

        if (creature->IsInnkeeper())
        {
            const char* localizedEntry;
            switch (player->GetSession()->GetSessionDbcLocale())
            {
                case LOCALE_ruRU: localizedEntry = LOCALE_INNKEEPER_1; break;
                case LOCALE_enUS: default: localizedEntry = LOCALE_INNKEEPER_0;
            }
            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_1, localizedEntry, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INN);
        }

        player->TalkedToCreature(creature->GetEntry(), creature->GetGUID());
        player->SEND_GOSSIP_MENU(player->GetGossipTextId(creature), creature->GetGUID());
        return true;
    }
Beispiel #2
0
BOOL CALLBACK StatusDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
	static StatusData sd = {0};

	switch (msg){
		case WM_INITDIALOG:{
			sd.io = (InterfaceOpts *) lParam;
			sd.hwndStatusDlg = hwnd;
			
			sd.hWorkerThread = (HANDLE)_beginthreadex(NULL,0,parseFiles,
															(void*)&sd,0,NULL);

			SetTimer(hwnd, 1, TIMERUNIT, NULL);
			SendMessage(hwnd, WM_TIMER, 1, 0);
			
			//Sets focus on abort button (use in place of SetFocus). Must be PostMessage due to _beginthreadex
			PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, ID_S_ABORT), TRUE);
		} break;

		case WM_TIMER:{
			wchar_t buf[BUFSIZ];
			int timeInSeconds = sd.timeLapsed / TIMERUNITSPERSEC;
			
			//Determine if the worker thread is finished
			if (IsEventActive(sd.hWorkerThread)){
				EndDialog(sd.hwndStatusDlg, IDOK);
				break;
			}

			if (tsgGetPositionStr(sd.p, buf, BUFSIZ))
				SetDlgItemText(hwnd, IDE_S_FILEPOS, buf);
			
			_snwprintf_s(buf, BUFSIZ, _TRUNCATE, L"%.2d:%.2d:%.2d", 
				timeInSeconds / 3600,(timeInSeconds % 3600) / 60, timeInSeconds);
			SetDlgItemText(hwnd, IDE_S_TIMELAPSED, buf);
			InterlockedIncrement(&sd.timeLapsed);

			SendDlgItemMessage(hwnd, IDP_S_PROGRESS, PBM_SETPOS, 
								tsgGetProgress(sd.p), 0);
		} break;

		case WM_COMMAND:{
			switch (LOWORD(wParam)){
		case ID_S_ABORT: case IDOK: case IDCANCEL:{
					tsgSignalAbort(sd.p);
					//EndDialog(hwnd, LOWORD(wParam));
				} break;
			}
		} break;

		default:{
			return FALSE;
		} break;
	}
	return TRUE;
}
Beispiel #3
0
    bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)
    {
        player->PlayerTalkClass->ClearMenus();
        if (action == GOSSIP_ACTION_INFO_DEF+HALLOWEEN_EVENTID && IsEventActive(HALLOWEEN_EVENTID) && !player->HasAura(SPELL_TRICK_OR_TREATED))
        {
            player->CastSpell(player, SPELL_TRICK_OR_TREATED, true);

            if (urand(0, 1))
                player->CastSpell(player, SPELL_TREAT, true);
            else
            {
                uint32 trickspell = 0;
                switch (urand(0, 13))
                {
					// TER-Server на Эвент Хэлуин костюмы от хояев таверны

                    case 0: trickspell = 24753; break; // cannot cast, random 30sec
                    case 1: trickspell = 24713; break; // lepper gnome costume
                    case 2: trickspell = 24735; break; // male ghost costume
                    case 3: trickspell = 24736; break; // female ghostcostume
                    case 4: trickspell = 24710; break; // male ninja costume
                    case 5: trickspell = 24711; break; // female ninja costume
                    case 6: trickspell = 24708; break; // male pirate costume
                    case 7: trickspell = 24709; break; // female pirate costume
                    case 8: trickspell = 24723; break; // skeleton costume
                    case 9: trickspell = 24753; break; // Trick
                    case 10: trickspell = 24924; break; // Hallow's End Candy
                    case 11: trickspell = 24925; break; // Hallow's End Candy
                    case 12: trickspell = 24926; break; // Hallow's End Candy
                    case 13: trickspell = 24927; break; // Hallow's End Candy
                }
                player->CastSpell(player, trickspell, true);
            }
            player->CLOSE_GOSSIP_MENU();
            return true;
        }

        player->CLOSE_GOSSIP_MENU();

        switch (action)
        {
            case GOSSIP_ACTION_TRADE: player->GetSession()->SendListInventory(creature->GetGUID()); break;
            case GOSSIP_ACTION_INN: player->SetBindPoint(creature->GetGUID()); break;
        }
        return true;
    }
    bool OnGossipHello(Player* player, Creature* creature)
    {
        if (IsEventActive(HALLOWEEN_EVENTID) && !player->HasAura(SPELL_TRICKED_OR_TREATED))
            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "不给糖就捣蛋!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+HALLOWEEN_EVENTID);

        if (creature->IsQuestGiver())
            player->PrepareQuestMenu(creature->GetGUID());

        if (creature->IsVendor())
            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_VENDOR, GOSSIP_TEXT_BROWSE_GOODS, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_TRADE);

        if (creature->IsInnkeeper())
            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_1, "把这里设为我的家.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INN);

        player->TalkedToCreature(creature->GetEntry(), creature->GetGUID());
        player->SEND_GOSSIP_MENU(player->GetGossipTextId(creature), creature->GetGUID());
        return true;
    }
Beispiel #5
0
bool GossipSelect_npc_innkeeper(Player* pPlayer, Creature* pCreature, uint32 /*uiSender*/, uint32 uiAction)
{
    if (uiAction == GOSSIP_ACTION_INFO_DEF+HALLOWEEN_EVENTID && IsEventActive(HALLOWEEN_EVENTID) && !pPlayer->HasAura(SPELL_TRICK_OR_TREATED))
    {
        pPlayer->CastSpell(pPlayer, SPELL_TRICK_OR_TREATED, true);

        if (urand(0, 1))
            pPlayer->CastSpell(pPlayer, SPELL_TREAT, true);
        else
        {
            uint32 trickspell = 0;
            switch (urand(0, 13))
            {
                case 0: trickspell = 24753; break; // cannot cast, random 30sec
                case 1: trickspell = 24713; break; // lepper gnome costume
                case 2: trickspell = 24735; break; // male ghost costume
                case 3: trickspell = 24736; break; // female ghostcostume
                case 4: trickspell = 24710; break; // male ninja costume
                case 5: trickspell = 24711; break; // female ninja costume
                case 6: trickspell = 24708; break; // male pirate costume
                case 7: trickspell = 24709; break; // female pirate costume
                case 8: trickspell = 24723; break; // skeleton costume
                case 9: trickspell = 24753; break; // Trick
                case 10: trickspell = 24924; break; // Hallow's End Candy
                case 11: trickspell = 24925; break; // Hallow's End Candy
                case 12: trickspell = 24926; break; // Hallow's End Candy
                case 13: trickspell = 24927; break; // Hallow's End Candy
            }
            pPlayer->CastSpell(pPlayer, trickspell, true);
        }
        pPlayer->CLOSE_GOSSIP_MENU();
        return true;
    }

    pPlayer->CLOSE_GOSSIP_MENU();

    switch (uiAction)
    {
        case GOSSIP_ACTION_TRADE: pPlayer->SEND_VENDORLIST(pCreature->GetGUID()); break;
        case GOSSIP_ACTION_INN: pPlayer->SetBindPoint(pCreature->GetGUID()); break;
    }
    return true;
}
    bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)
    {
        player->PlayerTalkClass->ClearMenus();
        if (action == GOSSIP_ACTION_INFO_DEF+HALLOWEEN_EVENTID && IsEventActive(HALLOWEEN_EVENTID) && !player->HasAura(SPELL_TRICKED_OR_TREATED))
        {
            player->CastSpell(player, SPELL_TRICKED_OR_TREATED, true);
			creature->CastSpell(player, roll_chance_i(50) ? SPELL_TRICK : SPELL_TREAT, true);

            player->CLOSE_GOSSIP_MENU();
            return true;
        }

        player->CLOSE_GOSSIP_MENU();

        switch (action)
        {
            case GOSSIP_ACTION_TRADE: player->GetSession()->SendListInventory(creature->GetGUID()); break;
            case GOSSIP_ACTION_INN: player->SetBindPoint(creature->GetGUID()); break;
        }
        return true;
    }
Beispiel #7
0
bool GossipHello_npc_innkeeper(Player *pPlayer, Creature *pCreature)
{
    if (IsEventActive(HALLOWEEN_EVENTID) && !pPlayer->HasAura(SPELL_TRICK_OR_TREATED))
    {
        char* localizedEntry;
        switch (pPlayer->GetSession()->GetSessionDbcLocale())
        {
            case LOCALE_frFR: localizedEntry = LOCALE_TRICK_OR_TREAT_2; break;
            case LOCALE_deDE: localizedEntry = LOCALE_TRICK_OR_TREAT_3; break;
            case LOCALE_esES: localizedEntry = LOCALE_TRICK_OR_TREAT_6; break;
            case LOCALE_enUS: default: localizedEntry = LOCALE_TRICK_OR_TREAT_0;
        }
        pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, localizedEntry, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+HALLOWEEN_EVENTID);
    }

    if (pCreature->isQuestGiver())
        pPlayer->PrepareQuestMenu(pCreature->GetGUID());

    if (pCreature->isVendor())
        pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_VENDOR, GOSSIP_TEXT_BROWSE_GOODS, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_TRADE);

    if (pCreature->isInnkeeper())
    {
        char* localizedEntry;
        switch (pPlayer->GetSession()->GetSessionDbcLocale())
        {
            case LOCALE_deDE: localizedEntry = LOCALE_INNKEEPER_3; break;
            case LOCALE_enUS: default: localizedEntry = LOCALE_INNKEEPER_0;
        }
        pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_1, localizedEntry, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INN);
    }

    pPlayer->TalkedToCreature(pCreature->GetEntry(), pCreature->GetGUID());
    pPlayer->SEND_GOSSIP_MENU(pPlayer->GetGossipTextId(pCreature), pCreature->GetGUID());
    return true;
}
Beispiel #8
0
        void UpdateAI(const uint32 diff)
        {
            if (IsEventActive(EVENT_BLOODYLOTTO))
            {
                if (me->IsVisible())
                {
                    me->SetVisible(false);
                    QueryResult result = CharacterDatabase.Query("SELECT MAX(id) FROM lotto_tickets");
                    uint32 maxTickets = result->Fetch()->GetUInt32();
                    if (!maxTickets)
                        return;

                    result = CharacterDatabase.Query("SELECT name, guid FROM `lotto_tickets` ORDER BY RAND() LIMIT 3;");
                    uint32 position = 0;

                    do
                    {
                        ++position;

                        Field *fields = result->Fetch();

                        const char* name = fields[0].GetCString();
                        uint32 guid = fields[1].GetUInt32();
                        uint32 reward = TICKET_COST / (1 << position) * maxTickets;

                        CharacterDatabase.PExecute("INSERT INTO `lotto_extractions` (winner,guid,position,reward) VALUES ('%s',%u,%u,%u);",name,guid,position,reward);

                        // Send reward by mail
                        Player *pPlayer = sObjectMgr->GetPlayerByLowGUID(guid);
                        SQLTransaction trans = CharacterDatabase.BeginTransaction();
                        MailDraft("Herzlichen Glückwunsch", "Du hast in unserer Lotterie gewonnen!")
                            .AddMoney(reward)
                            .SendMailTo(trans, MailReceiver(pPlayer, GUID_LOPART(guid)), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM));
                        CharacterDatabase.CommitTransaction(trans);

                        // Event Message
                        char msg[500];
                        switch (position)
                        {
                            case 1:
                                sWorld->SendWorldText(LANG_EVENTMESSAGE, "| Die Lotteriegewinner wurden gezogen |");
                                sprintf(msg, "| 1 - %s gewinnt %i gold!",name,reward/10000);
                                break;
                            case 2:
                                sprintf(msg, "| 2 - %s gewinnt %i gold!",name,reward/10000);
                                break;
                            case 3:
                                sprintf(msg, "| 3 - %s gewinnt %i gold!",name,reward/10000);
                                break;
                        }
                        sWorld->SendWorldText(LANG_EVENTMESSAGE, msg);
                    }
                    while (result->NextRow());

                    // Delete tickets after extraction
                    CharacterDatabase.PExecute("DELETE FROM lotto_tickets;");
                }
            }
            else
            {
                if (!me->IsVisible())
                    me->SetVisible(true);
                    
                if (SayTimer <= diff)
                {
                    me->MonsterSay("Kauft Lottoscheine! Werdet mit nur 50 Gold Einsatz reich!", 0, NULL);
                    SayTimer = 1800*IN_MILLISECONDS;
                }
                else SayTimer -= diff;
            }
        }
Beispiel #9
0
        void UpdateAI(const uint32 diff)
        {
            if (IsEventActive(EVENT_LOTTO))
            {
                if (me->IsVisible())
                {
                    me->SetVisible(false);
                    QueryResult result = ExtraDatabase.Query("SELECT MAX(id) FROM lotto_tickets");
                    uint32 maxTickets = result->Fetch()->GetUInt32();
                    if (!maxTickets)
                        return;

                    result = ExtraDatabase.Query("SELECT name, guid FROM `lotto_tickets` ORDER BY RAND() LIMIT 3;");
                    uint32 position = 0;

                    do
                    {
                        ++position;

                        Field *fields = result->Fetch();

                        const char* name = fields[0].GetCString();
                        uint32 guid = fields[1].GetUInt32();
                        uint32 reward = TICKET_COST / (1 << position) * maxTickets;

                        ExtraDatabase.PExecute("INSERT INTO `lotto_extractions` (winner,guid,position,reward) VALUES ('%s',%u,%u,%u);",name,guid,position,reward);

                        // Send reward by mail
                        Player *pPlayer = sObjectMgr->GetPlayerByLowGUID(guid);
                        SQLTransaction trans = CharacterDatabase.BeginTransaction();
                        MailDraft("Лотерея", "Поздравляем! Вы выйграли!")
                            .AddMoney(reward)
                            .SendMailTo(trans, MailReceiver(pPlayer, GUID_LOPART(guid)), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM));
                        CharacterDatabase.CommitTransaction(trans);

                        // Event Message
                        char msg[500];
                        switch (position)
                        {
                            case 1:
                                sWorld->SendWorldText(LANG_EVENTMESSAGE, "| Призы |");
                                sprintf(msg, "| 1 - %s выиграл %i золота!",name,reward/10000);
                                break;
                            case 2:
                                sprintf(msg, "| 2 - %s выиграл %i золота!",name,reward/10000);
                                break;
                            case 3:
                                sprintf(msg, "| 3 - %s выиграл %i золота!",name,reward/10000);
                                break;
                        }
                        sWorld->SendWorldText(LANG_EVENTMESSAGE, msg);
                    }
                    while (result->NextRow());

                    // Delete tickets after extraction
                    ExtraDatabase.PExecute("DELETE FROM lotto_tickets;");
                }
            }
            else
            {
                if (!me->IsVisible())
                    me->SetVisible(true);
                    
                if (SayTimer <= diff)
                {
                    me->MonsterSay("Билеты лотереи! Всего лишь 100 золотых, чтобы стать миллионером!", 0, NULL);
                    SayTimer = 1800*IN_MILLISECONDS;
                }
                else SayTimer -= diff;
            }
        }
Beispiel #10
0
        void UpdateAI(uint32 diff) override
        {
            static uint64 playerguid;
            events.Update(diff);

            DoWork(diff);

             //Always decrease our global cooldown first
            if (globalCooldown1 > diff)
                globalCooldown1 -= diff;
            else
                globalCooldown1 = 0;

            if (globalCooldown2 > diff)
                globalCooldown2 -= diff;
            else
                globalCooldown2 = 0;

            //Buff for Love is in the Air
            if (me->IsAlive() && IsEventActive(8) && !me->IsInCombat() && !me->HasAura(71507) &&
                (me->GetEntry() == NPC_STORMWIND_CITY_GUARD || me->GetEntry() == NPC_STORMWIND_CITY_PATROLLER || me->GetEntry() == NPC_ORGRIMMAR_GRUNT))
                me->AddAura(71507, me);
            else if (!IsEventActive(8) && me->HasAura(71507))
                me->RemoveAura(71507);

            Player * pplayer = me->SelectNearestPlayer(20);

            //Fun emotes they do to players
            if (pplayer && pplayer->GetGUIDLow() != playerguid)
            {
                playerguid = pplayer->GetGUIDLow();
                if (me->GetDistance(pplayer->GetPositionX(), pplayer->GetPositionY(), pplayer->GetPositionZ()) <= 7 && me->IsAlive() && !me->IsInCombat() && (me->GetEntry() == NPC_STORMWIND_CITY_GUARD
                    || me->GetEntry() == NPC_STORMWIND_CITY_PATROLLER || me->GetEntry() == NPC_ORGRIMMAR_GRUNT) && globalCooldown2 == 0)
                {
                    if ((pplayer->GetQuestStatus(13188) != QUEST_STATUS_NONE && pplayer->GetQuestStatus(13188) != QUEST_STATUS_REWARDED) || (pplayer->GetQuestStatus(13189) != QUEST_STATUS_NONE && pplayer->GetQuestStatus(13189) != QUEST_STATUS_REWARDED))
                        events.ScheduleEvent(3, 100);
                    else
                        events.ScheduleEvent(urand(1, 2), 100);
                }
            }
            else if (!pplayer)
                playerguid = 0;
            while (uint32 eventId = events.ExecuteEvent())
            {
                switch (eventId)
                {
                case 1:
                    me->HandleEmoteCommand(EMOTE_ONESHOT_WAVE);
                    events.Reset();
                    events.ScheduleEvent(4, 100);
                    break;
                case 2:
                    me->HandleEmoteCommand(EMOTE_ONESHOT_SALUTE);
                    events.Reset();
                    events.ScheduleEvent(4, 100);
                    break;
                case 4:

                    globalCooldown2 = urand(9000, 10000);
                    events.Reset();
                    break;
                case 3:
                    me->HandleEmoteCommand(EMOTE_ONESHOT_RUDE);
                    int ur = urand(1, 3);
                    if (ur == 1)
                        me->CastSpell(pplayer, 58511, true);
                    else if (ur == 2)
                        me->CastSpell(pplayer, 58514, true);
                    else
                        me->CastSpell(pplayer, 58519, true);
                    int ura = urand(1, 5);
                    if (ura == 1)
                        me->MonsterYell("How dare you set foot in our city!", 0, 0);
                    else if (ura == 2)
                        me->MonsterYell("My family was wiped out by the scourge! MONSTER!", 0, 0);
                    else if (ura == 3)
                        me->MonsterYell("GET A ROPE!", 0, 0);
                    else if (ura == 4)
                        me->MonsterYell("Traitorous dog!", 0, 0);
                    else if (ura == 5)
                        me->MonsterYell("Monster!", 0, 0);
                    events.Reset();
                    events.ScheduleEvent(4, 100);
                    break;

                }
            }

            //Buff timer (only buff when we are alive and not in combat
            if (me->IsAlive() && !me->IsInCombat())
            {
                if (buffTimer <= diff)
                {
                    //Find a spell that targets friendly and applies an aura (these are generally buffs)
                    SpellInfo const* info = SelectSpell(me, 0, 0, SELECT_TARGET_ANY_FRIEND, 0, 0, 0, 0, SELECT_EFFECT_AURA);

                    if (info && !globalCooldown1)
                    {
                        //Cast the buff spell
                        DoCast(me, info->Id);

                        //Set our global cooldown
                        globalCooldown1 = GENERIC_CREATURE_COOLDOWN;

                        //Set our timer to 10 minutes before rebuff
                        buffTimer = 600000;
                    }                                                   //Try again in 30 seconds
                    else buffTimer = 30000;
                } else buffTimer -= diff;
            }

            //Return since we have no target
            if (!UpdateVictim())
                return;

            // Make sure our attack is ready and we arn't currently casting
            if (me->isAttackReady() && !me->IsNonMeleeSpellCast(false))
            {
                //If we are within range melee the target
                if (me->IsWithinMeleeRange(me->GetVictim()))
                {
                    bool healing = false;
                    SpellInfo const* info = NULL;

                    //Select a healing spell if less than 30% hp
                    if (me->HealthBelowPct(30))
                        info = SelectSpell(me, 0, 0, SELECT_TARGET_ANY_FRIEND, 0, 0, 0, 0, SELECT_EFFECT_HEALING);

                    //No healing spell available, select a hostile spell
                    if (info)
                        healing = true;
                    else
                        info = SelectSpell(me->GetVictim(), 0, 0, SELECT_TARGET_ANY_ENEMY, 0, 0, 0, 0, SELECT_EFFECT_DONTCARE);

                    //20% chance to replace our white hit with a spell
                    if (info && urand(0, 99) < 20 && !globalCooldown1)
                    {
                        //Cast the spell
                        if (healing)
                            DoCast(me, info->Id);
                        else
                            DoCastVictim(info->Id);

                        //Set our global cooldown
                        globalCooldown1 = GENERIC_CREATURE_COOLDOWN;
                    }
                    else
                        me->AttackerStateUpdate(me->GetVictim());

                    me->resetAttackTimer();
                }
            }
            else
            {
                //Only run this code if we arn't already casting
                if (!me->IsNonMeleeSpellCast(false))
                {
                    bool healing = false;
                    SpellInfo const* info = NULL;

                    //Select a healing spell if less than 30% hp ONLY 33% of the time
                    if (me->HealthBelowPct(30) && 33 > urand(0, 99))
                        info = SelectSpell(me, 0, 0, SELECT_TARGET_ANY_FRIEND, 0, 0, 0, 0, SELECT_EFFECT_HEALING);

                    //No healing spell available, See if we can cast a ranged spell (Range must be greater than ATTACK_DISTANCE)
                    if (info)
                        healing = true;
                    else
                        info = SelectSpell(me->GetVictim(), 0, 0, SELECT_TARGET_ANY_ENEMY, 0, 0, NOMINAL_MELEE_RANGE, 0, SELECT_EFFECT_DONTCARE);

                    //Found a spell, check if we arn't on cooldown
                    if (info && !globalCooldown1)
                    {
                        //If we are currently moving stop us and set the movement generator
                        if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() != IDLE_MOTION_TYPE)
                        {
                            me->GetMotionMaster()->Clear(false);
                            me->GetMotionMaster()->MoveIdle();
                        }

                        //Cast spell
                        if (healing)
                            DoCast(me, info->Id);
                        else
                            DoCastVictim(info->Id);

                        //Set our global cooldown
                        globalCooldown1 = GENERIC_CREATURE_COOLDOWN;
                    }                                               //If no spells available and we arn't moving run to target
                    else if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE)
                    {
                        //Cancel our current spell and then mutate new movement generator
                        me->InterruptNonMeleeSpells(false);
                        me->GetMotionMaster()->Clear(false);
                        me->GetMotionMaster()->MoveChase(me->GetVictim());
                    }
                }
            }

            DoMeleeAttackIfReady();
        }
Beispiel #11
0
        void UpdateAI(const uint32 diff)
        {
            if (IsEventActive(EVENT_LOTTERY))
            {
                if (me->IsVisible())
                {
                    QueryResult qMaxID = WorldDatabase.Query("SELECT MAX(id) FROM lottery_bets");
                    if (!qMaxID)
                        return;

                    uint32 betMaxID = qMaxID->Fetch()->GetUInt32();
                    uint32 luckyNumber[5];
                    uint32 lotteryID;
                    uint32 jackpotWinners = 0;

                    QueryResult qlotteryID = WorldDatabase.Query("SELECT MAX(id) FROM lottery");
                    if (!qlotteryID)
                        lotteryID = 0;
                    else
                        lotteryID = qlotteryID->Fetch()->GetUInt32();

                    QueryResult qBets  = WorldDatabase.Query("SELECT guid, bet, name FROM lottery_bets");
                    if (qBets)
                    {
                        for (int8 n = 0; n < 5; ++n)
                        {
                            luckyNumber[n] = urand(1, sConfig->GetIntDefault("Lottery.MaxNumber", 30));
                        }

                        do
                        {
                            Field *fBets = qBets->Fetch();
                            uint32 guid = fBets[0].GetUInt32();
                            std::string bet = fBets[1].GetString();
                            std::string rBet = bet; 
                            std::string name = fBets[2].GetString();
                            uint32 points = 0;
                            uint32 cash;

                            int32 number[5];
                            char * tmp;

                            tmp = strtok ((char*)bet.c_str()," ");

                            for (int8 n = 0; n < 5; ++n)
                            {
                                if (tmp != NULL)
                                {
                                    number[n] = atoi(tmp);
                                    tmp = strtok (NULL, " ");
                                }
                            }

                            for (int8 n = 0; n < 5; ++n)
                            {
                                for (int8 i = 0; i < 5; ++i)
                                {
                                    if (number[n] == luckyNumber[i])
                                        ++points;
                                }
                            }

                            switch (points)
                            {
                                case 1:
                                {
                                    cash = uint32(betMaxID * sConfig->GetIntDefault("Lottery.BetCost", 500000) * 0.005f);
                                    break;
                                }
                                case 2:
                                {
                                    cash = uint32(betMaxID * sConfig->GetIntDefault("Lottery.BetCost", 500000) * 0.01f);
                                    break;
                                }
                                case 3:
                                {
                                    cash = uint32(betMaxID * sConfig->GetIntDefault("Lottery.BetCost", 500000) * 0.05f);
                                    break;
                                }
                                case 4:
                                {
                                    cash = uint32(betMaxID * sConfig->GetIntDefault("Lottery.BetCost", 500000) * 0.2f);
                                    break;
                                }
                                case 5:
                                {
                                    WorldDatabase.PExecute("INSERT INTO lottery_winners (id, name, guid, bet, betPoints) VALUES ('%u', '%s', '%u', '%s', '%u')", lotteryID+1, name.c_str(), guid, rBet.c_str(), points);
                                    ++jackpotWinners;
                                    continue;
                                }
                                default:
                                    continue;
                            }

                            Player *pWinner = sObjectMgr->GetPlayerByLowGUID(guid);
                            SQLTransaction trans = CharacterDatabase.BeginTransaction();
                            MailDraft("Выигрыш", "Поздравляем! Ваша комбинация чисел оказалась счастливой!")
                                .AddMoney(cash)
                                .SendMailTo(trans, MailReceiver(pWinner, GUID_LOPART(guid)), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM));
                            CharacterDatabase.CommitTransaction(trans);

                            WorldDatabase.PExecute("INSERT INTO lottery_winners (id, name, guid, bet, betPoints) VALUES ('%u', '%s', '%u', '%s', '%u')", lotteryID+1, name.c_str(), guid, rBet.c_str(), points);
                        } while (qBets->NextRow());
                        uint64 jackpot;
                        uint64 rJackpot;
                        uint64 defJackpot = uint64(betMaxID * sConfig->GetIntDefault("Lottery.BetCost", 500000) * 0.7f);
                        QueryResult qJackpot  = WorldDatabase.PQuery("SELECT jackpot FROM lottery WHERE id = '%u'", lotteryID);
                        if (qJackpot)
                            jackpot = qJackpot->Fetch()->GetUInt32();
                        else
                            jackpot = 0;

                        rJackpot = jackpot;

                        if (jackpotWinners > 0)
                        {
                            QueryResult qJackpotWinners = WorldDatabase.PQuery("SELECT guid FROM lottery_winners WHERE betPoints = '5' and id = '%u'", lotteryID+1);
                            QueryResult qJackpotWinnersName;
                            if (jackpotWinners == 1)
                                qJackpotWinnersName = WorldDatabase.PQuery("SELECT name FROM lottery_winners WHERE betPoints = '5' and id = '%u'", lotteryID+1);

                            if (qJackpotWinners)
                            {
                                jackpot = uint64(jackpot / jackpotWinners);
                                do
                                {
                                    Field *fJackpotWinners = qJackpotWinners->Fetch();
                                    uint32 JPguid = fJackpotWinners[0].GetUInt32();

                                    Player *pJPWinner = sObjectMgr->GetPlayerByLowGUID(JPguid);
                                    SQLTransaction trans = CharacterDatabase.BeginTransaction();
                                    MailDraft("Джекпот!", "Вау! Да Вы просто везунчик! Вам удалось сорвать джекпот! Примите поздравление от организаторов лотареи")
                                        .AddMoney(jackpot = 0 ? uint64(betMaxID * sConfig->GetIntDefault("Lottery.BetCost", 500000) * 0.7f) : jackpot)
                                        .SendMailTo(trans, MailReceiver(pJPWinner, GUID_LOPART(JPguid)), MailSender(MAIL_NORMAL, 0, MAIL_STATIONERY_GM));
                                    CharacterDatabase.CommitTransaction(trans);
                                } while (qJackpotWinners->NextRow());
                            }

                            if (jackpotWinners == 1 && qJackpotWinnersName)
                            {
                                std::string wName = qJackpotWinnersName->Fetch()->GetString();
                                sWorld->SendWorldText(LANG_LOTTERY_ANNOUNCE_JACKPOT, betMaxID, luckyNumber[0], luckyNumber[1], luckyNumber[2], luckyNumber[3], luckyNumber[4], ((jackpot = 0 ? uint64(betMaxID * sConfig->GetIntDefault("Lottery.BetCost", 500000) * 0.7f) : rJackpot) * 0.0001f), wName.c_str());
                            }
                            else
                                sWorld->SendWorldText(LANG_LOTTERY_ANNOUNCE_JACKPOT_M_PLAYERS, betMaxID, luckyNumber[0], luckyNumber[1], luckyNumber[2], luckyNumber[3], luckyNumber[4], ((jackpot = 0 ? uint64(betMaxID * sConfig->GetIntDefault("Lottery.BetCost", 500000) * 0.7f) : rJackpot) * 0.0001f), jackpotWinners);

                            WorldDatabase.PExecute("INSERT INTO lottery (number_1, number_2, number_3, number_4, number_5, jackpot) VALUES ('%u', '%u', '%u', '%u', '%u', '%u')", luckyNumber[0], luckyNumber[1], luckyNumber[2], luckyNumber[3], luckyNumber[4], defJackpot);
                        }
                        else
                        {
                            sWorld->SendWorldText(LANG_LOTTERY_ANNOUNCE, betMaxID, luckyNumber[0], luckyNumber[1], luckyNumber[2], luckyNumber[3], luckyNumber[4], ((jackpot + defJackpot) * 0.0001f));
                            WorldDatabase.PExecute("INSERT INTO lottery (number_1, number_2, number_3, number_4, number_5, jackpot) VALUES ('%u', '%u', '%u', '%u', '%u', '%u')", luckyNumber[0], luckyNumber[1], luckyNumber[2], luckyNumber[3], luckyNumber[4], (jackpot + defJackpot));
                        }
                        WorldDatabase.PExecute("DELETE FROM lottery_bets");

                        me->SetVisible(false);
                    }
                }
            }
            else
            {
                if (!me->IsVisible())
                    me->SetVisible(true);
            }
        }