Casino Royale NPC (ScriptDev2)

Z WoWResource Wiki
Přejít na: navigace, hledání

Skript slouží k hádání náhodných čísel, hráč zvolí číslo v rozmezí od jedné do sta a poté se vygeneruje náhodné číslo. Porovnáním obou čísel se vyhodnotí výhra nebo prohra hráče, pokud hráč trefí číslo přesně získá 5x poplatek za jedno hádání. Základní poplatek je 20g (lze změnit ve skriptu) a ke správné funkci je potřeba vytvořit uvítací text do tabulky npc_text s id 55555.

Tabulka výher
Tolerance Výhra (násobek)
0 5x
+- 5 2,5x
+- 10 1,25x
+- 25 0,5x
#include "precompiled.h"

// /////////// do npc_text ///////////
#define CASINO_ROYALE_TEXT_ID_NPC 55555
// Vitej v casinu royale, jaky bude tvuj dnesni tip ?

// potrebne penize
#define CASINO_ROYALE_NEED_MONEY 200000

///////////////////////////////////////////////////

#define CR_WON_IT \
    int won = (int)(((float)CASINO_ROYALE_NEED_MONEY)*modifier); \
    pPlayer->ModifyMoney(won); \
    std::stringstream sr; \
    sr << "Tvuj tip byl " << tip << ", nas " << casino << " takze jsi vyhral " << modifier << "X vsazku"; \
    pCreature->MonsterSay(sr.str().c_str(), 0, pPlayer->GetGUID());


bool GossipSelect_casino_royale(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction)
{
    if (uiAction <= GOSSIP_ACTION_INFO_DEF + 10)
    {
        pPlayer->CLOSE_GOSSIP_MENU();
        int range = (uiAction - GOSSIP_ACTION_INFO_DEF) * 10;

        for (int i = 0; i < 10; i++)
        {
            std::stringstream str;
            int val = range + i;
            str << val;

            pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_1, str.str().c_str(), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 100 + val);
        }

        pPlayer->SEND_GOSSIP_MENU(CASINO_ROYALE_TEXT_ID_NPC, pCreature->GetGUID());
    } 
    else if (uiAction <= GOSSIP_ACTION_INFO_DEF + (100 * 2))
    { 
        pPlayer->CLOSE_GOSSIP_MENU();
        if (pPlayer->GetMoney() < CASINO_ROYALE_NEED_MONEY)
        {
            pCreature->MonsterSay("Nemas dost penez kamarade", 0, pPlayer->GetGUID());
            return true;
        }
        pPlayer->ModifyMoney(-CASINO_ROYALE_NEED_MONEY);

        int tip = uiAction - GOSSIP_ACTION_INFO_DEF - 100;
        int casino = rand()%100;
        
        int diff = abs(tip - casino);
        if (diff == 0)
        {
            float modifier = 5;
            CR_WON_IT
        } 
        else if (diff <= 5)
        {
            float modifier = 2.5f;
            CR_WON_IT
        }
        else if (diff <= 10)
        {
            float modifier = 1.25f;
            CR_WON_IT
        }
        else if (diff <= 25)
        {
            float modifier = 0.5f;
            CR_WON_IT
        } 
        else
        {
            std::stringstream str;
            str << "Smula tve cislo se vubec nepodoba nasi " << casino << ", zkus to priste.";
            pCreature->MonsterSay(str.str().c_str(), 0, pPlayer->GetGUID());
        }
    }

    return true;
}

bool GossipHello_casino_royale(Player* pPlayer, Creature* pCreature)
{
     for (int i = 0; i < 10; i++)
     {
        std::stringstream str;
        int lrange = i*10,
            urange = lrange + 9;

        str << lrange << " - " << urange;

        pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_1, str.str().c_str(), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + i);
    }
    pPlayer->SEND_GOSSIP_MENU(CASINO_ROYALE_TEXT_ID_NPC, pCreature->GetGUID());

    return true;
}

void AddSC_casino_royale()
{
    Script *newscript;

    newscript = new Script;
    newscript->Name = "casino_royale";
    newscript->pGossipHello = &GossipHello_casino_royale;
    newscript->pGossipSelect = &GossipSelect_casino_royale;
    newscript->RegisterSelf();
}