T端单机魔兽世界私服中的轮盘游戏(NPC脚本)

大概就是这个图的意思了~~~通过NPC来实现。。应该是非常有趣的一种设置了!增加单机中的趣味
然后我们来看看代码

 

 

#include "ScriptPCH.h"
 
class gamble_npc : public CreatureScript
{
public:
    gamble_npc() : CreatureScript("gamble_npc") { }
 
  std::string colorstring(uint16 type)
  {
        switch(type)
        {
        default:
            return false;
        case 2:
            return "black";
        case 3:
            return "red";
        case 4:
            return "green";
 
        }
    }
 
    int GenerateNumberMessage(uint32 numbervalue)
    {
        uint32 black[18] = {2, 28, 26, 11, 20, 17, 22, 15, 24, 13, 10, 29, 8, 31, 6, 33, 4, 35};
        uint32 red[18] = {9, 30, 7, 32, 5, 34, 3, 36, 1, 27, 25, 12, 19, 18, 21, 16, 23, 14};
        uint32 green[2] = {0, 00};
        
        for(uint16 i = 0; i < 18; i++)
        {
            if (numbervalue == black[i])
            return 2;
            else
                
            if (numbervalue == red[i])
            return 3;
            else
            if (numbervalue == 37 || 0)
            return 4;    
        }
    }
    
 
    bool OnGossipHello(Player * player, Creature * creature)
    {
 
        player->ADD_GOSSIP_ITEM(3, "I want to play Roulette!", GOSSIP_SENDER_MAIN, 1337);
        player->ADD_GOSSIP_ITEM(3, "How does this Game work?", GOSSIP_SENDER_MAIN, 999);
        player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
        return true;
    }
 
    bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 uiAction) 
    {
        player->PlayerTalkClass->ClearMenus();
        
        if (uiAction == 1337)
        {
        player->ADD_GOSSIP_ITEM(3, "I want to bet on a number.", GOSSIP_SENDER_MAIN,997);
        player->ADD_GOSSIP_ITEM(3, "I want to bet on a color.", GOSSIP_SENDER_MAIN, 996);
        player->ADD_GOSSIP_ITEM(3, "I want to bet on a number set.", GOSSIP_SENDER_MAIN, 995);
        player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
        }
        
        
        if(uiAction == 997)
        {
        player->ADD_GOSSIP_ITEM(3, "Stats for this table:\nOdds 35:1 (1-36, 0, and 00)\n Payout: x35", GOSSIP_SENDER_MAIN, 997);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 0.", GOSSIP_SENDER_MAIN, 0, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 1.", GOSSIP_SENDER_MAIN, 1, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 2.", GOSSIP_SENDER_MAIN, 2, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 3.", GOSSIP_SENDER_MAIN, 3, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 4.", GOSSIP_SENDER_MAIN, 4, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 5.", GOSSIP_SENDER_MAIN, 5, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 6.", GOSSIP_SENDER_MAIN, 6, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 7.", GOSSIP_SENDER_MAIN, 7, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 8.", GOSSIP_SENDER_MAIN, 8, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 9.", GOSSIP_SENDER_MAIN, 9, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM(3, "Next", GOSSIP_SENDER_MAIN, 1338);
        player->ADD_GOSSIP_ITEM(3, "Back", GOSSIP_SENDER_MAIN, 1337);
        }
        
                if(uiAction == 1338)
        {
        player->ADD_GOSSIP_ITEM(3, "Stats for this table:\nOdds 35:1 (1-36, 0, and 00)\n Payout: x35", GOSSIP_SENDER_MAIN, 997);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 10.", GOSSIP_SENDER_MAIN, 10, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 11.", GOSSIP_SENDER_MAIN, 11, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 12.", GOSSIP_SENDER_MAIN, 12, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 13.", GOSSIP_SENDER_MAIN, 13, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 14.", GOSSIP_SENDER_MAIN, 14, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 15.", GOSSIP_SENDER_MAIN, 15, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 16.", GOSSIP_SENDER_MAIN, 16, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 17.", GOSSIP_SENDER_MAIN, 17, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 18.", GOSSIP_SENDER_MAIN, 18, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM(3, "Next", GOSSIP_SENDER_MAIN, 1339);
        player->ADD_GOSSIP_ITEM(3, "Back", GOSSIP_SENDER_MAIN, 997);
        }
        
                if(uiAction == 1339)
        {
        player->ADD_GOSSIP_ITEM(3, "Stats for this table:\nOdds 35:1 (1-36, 0, and 00)\n Payout: x35", GOSSIP_SENDER_MAIN, 997);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 19.", GOSSIP_SENDER_MAIN, 19, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 20.", GOSSIP_SENDER_MAIN, 20, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 21.", GOSSIP_SENDER_MAIN, 21, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 22.", GOSSIP_SENDER_MAIN, 22, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 23.", GOSSIP_SENDER_MAIN, 23, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 24.", GOSSIP_SENDER_MAIN, 24, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 25.", GOSSIP_SENDER_MAIN, 25, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 26.", GOSSIP_SENDER_MAIN, 26, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 27.", GOSSIP_SENDER_MAIN, 27, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM(3, "Next", GOSSIP_SENDER_MAIN, 1340);
        player->ADD_GOSSIP_ITEM(3, "Back", GOSSIP_SENDER_MAIN, 1338);
        }
        
                if(uiAction == 1340)
        {
        player->ADD_GOSSIP_ITEM(3, "Stats for this table:\nOdds 35:1 (1-36, 0, and 00)\n Payout: x35", GOSSIP_SENDER_MAIN, 997);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 28.", GOSSIP_SENDER_MAIN, 28, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 29.", GOSSIP_SENDER_MAIN, 29, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 30.", GOSSIP_SENDER_MAIN, 30, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 31.", GOSSIP_SENDER_MAIN, 31, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 32.", GOSSIP_SENDER_MAIN, 32, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 33.", GOSSIP_SENDER_MAIN, 33, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 34.", GOSSIP_SENDER_MAIN, 34, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 35.", GOSSIP_SENDER_MAIN, 35, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 36.", GOSSIP_SENDER_MAIN, 36, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 00.", GOSSIP_SENDER_MAIN, 37, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM(3, "Back", GOSSIP_SENDER_MAIN, 1339);
        }
        
 
        if(uiAction == 996)
        {
        player->ADD_GOSSIP_ITEM(3, "Stats for this table:\nOdds 1:1 (green is 1:17, as it is 0 and 00)\n Payout: x1 (x17) ", GOSSIP_SENDER_MAIN, 996);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet red.", GOSSIP_SENDER_MAIN, 800, "How much gold do you want to bet?", 0, true));
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet black.", GOSSIP_SENDER_MAIN, 810, "How much gold do you want to bet?", 0, true));
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet green. (The leprechauns jackpot!)", GOSSIP_SENDER_MAIN, 818, "How much gold do you want to bet?", 0, true));        
        player->ADD_GOSSIP_ITEM(3, "Back", GOSSIP_SENDER_MAIN, 1337);
        }
 
        if(uiAction == 995)
        {
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 1-12. 2:1, Payout: 3x", GOSSIP_SENDER_MAIN, 700, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 13-24. 2:1, Payout: 3x", GOSSIP_SENDER_MAIN, 701, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 25-36. 2:1, Payout: 3x", GOSSIP_SENDER_MAIN, 702, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 1-5. 7:1 Payout: 7x", GOSSIP_SENDER_MAIN, 703, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 6-10. 7:1 Payout: 7x", GOSSIP_SENDER_MAIN, 704, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 11-15. 7:1 Payout: 7x", GOSSIP_SENDER_MAIN, 705, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 16-20. 7:1 Payout: 7x", GOSSIP_SENDER_MAIN, 706, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 21-25. 7:1 Payout: 7x", GOSSIP_SENDER_MAIN, 707, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 26-30. 7:1 Payout: 7x", GOSSIP_SENDER_MAIN, 708, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to bet on 31-35. 7:1 Payout: 7x", GOSSIP_SENDER_MAIN, 709, "How much gold do you want to bet?", 0, true);
        player->ADD_GOSSIP_ITEM(3, "Back", GOSSIP_SENDER_MAIN, 1337);
        }
 
        
        
        if(uiAction == 999)
        {
            player->ADD_GOSSIP_ITEM(7, "A ball is thrown onto the roulette table wheel, when the ball stops on a colored number, you either win or lose your bet. You may bet on specific numbers, even numbers, odd numbers, colors or ranges of 1-18 and 19-36. Your winnings will be  The colored numbers are the following:\n Black: 2, 28, 26, 11, 20, 17, 22, 15, 24, 13, 10, 29, 8, 31, 6, 33, 4, 35\n Red: 9, 30, 7, 32, 5, 34, 3, 36, 1, 27, 25, 12, 19, 18, 21, 16, 23, 14\n Green: 0, 00", GOSSIP_SENDER_MAIN, 666);
            player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
        }
        else if(uiAction == 666)
        {   
            OnGossipHello(player, creature);
        }
        return true;
    }
 
    bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 uiAction, const char* code) // happens when an extended gossip item is selected and the code is set to true for the gossip item.
    {
        player->PlayerTalkClass->ClearMenus();
 
        uint32 betnumber = 0;
        uint32 gold = uint32(atol(code)) * 1000; 
        std::ostringstream message;
        
 
        if(uiAction >= 0 && uiAction <= 37)
        {
        Gamblemode(player, creature, gold, 35, uiAction, uiAction, 0);
        }
        else
        {
        switch(uiAction)
        {
        case 700:
            Gamblemode(player, creature, gold, 3, 1, 12, 0);
        break;
        case 701:
            Gamblemode(player, creature, gold, 3, 13, 24, 0);
        break;
        case 702:
            Gamblemode(player, creature, gold, 3, 25, 36, 0);
        break;
        case 703:
            Gamblemode(player, creature, gold, 7, 1, 5, 0);
        break;
        case 704:
            Gamblemode(player, creature, gold, 7, 6, 10, 0);
        break;
        case 705:
            Gamblemode(player, creature, gold, 7, 11, 15, 0);
        break;
        case 706:
            Gamblemode(player, creature, gold, 7, 16, 20, 0);
        break;
        case 707:
            Gamblemode(player, creature, gold, 7, 21, 25, 0);
        break;
        case 708:
            Gamblemode(player, creature, gold, 7, 26, 30, 0);
        break;
 
        case 709:
            Gamblemode(player, creature, gold, 7, 31, 35, 0);
        break;
        
        case 800:
            Gamblemode(player, creature, gold, 2, 0, 37, 3);
            break;
 
        case 810:
            Gamblemode(player, creature, gold, 2, 0, 37, 2);
            break;
 
        case 818:
            Gamblemode(player, creature, gold, 17, 0, 37, 4);
            break;
        }
        }
        OnGossipHello(player, creature);
        return true;
    }
    
bool Gamblemode(Player* player, Creature * creature, uint32 moneybet, uint32 multiplier, uint32 minimum, uint32 maximum, bool color)
    {
        std::ostringstream message;
        uint32 winningnumber = 0;
        winningnumber = urand(0,37);
        uint32 winnings = moneybet * multiplier;
        
        if (winningnumber == 37)
        winningnumber == 00;
 
    if(color)
    {
        if(player->GetMoney() < moneybet)
        {
            player->GetSession()->SendNotification("You don't have enough gold!");
        }
        else
        { 
            if(GenerateNumberMessage(winningnumber) == color)
            {   
            
                player->ModifyMoney(player->GetMoney() + winnings);
                player->PlayDirectSound(3337);
                player->CastSpell(player, 47292);
                player->CastSpell(player, 44940);
                message << "AAAAAND the ball lands on" << colorstring(color) << winningnumber << "Congratulations" << player->GetName() << " You've won" << winnings << "gold!";
                player->MonsterWhisper(message.str().c_str(), player->GetGUID());
                return true;
                
            }
            else
            {
                player->ModifyMoney(player->GetMoney() - moneybet);
                message << "AAAAAND the ball lands on" << colorstring(color) << winningnumber << ". So sorry, " << player->GetName() << ", but you've lost. Better luck next time!";
                player->MonsterWhisper(message.str().c_str(), player->GetGUID());
                return false;
            }
        }
    }
    else
    {
        if(player->GetMoney() < moneybet)
        {
            player->GetSession()->SendNotification("You don't have enough gold!");
        }
        else
        { 
            if(winningnumber >= minimum && winningnumber <= maximum)
            {   
            
                player->ModifyMoney(player->GetMoney() + winnings);
                player->PlayDirectSound(3337);
                player->CastSpell(player, 47292);
                player->CastSpell(player, 44940);
                message << "AAAAAND the ball lands on" << GenerateNumberMessage(winningnumber) << winningnumber << "Congratulations" << player->GetName() << " You've won" << winnings << "gold!";
                player->MonsterWhisper(message.str().c_str(), player->GetGUID());
                return true;
                
            }
            else
            {
                player->ModifyMoney(player->GetMoney() - moneybet);
                message << "AAAAAND the ball lands on" << GenerateNumberMessage(winningnumber) << winningnumber << ". So sorry, " << player->GetName() << ", but you've lost. Better luck next time!";
                player->MonsterWhisper(message.str().c_str(), player->GetGUID());
                return false;
            }
        }
    }
    }
 
struct gambler_passivesAI : public ScriptedAI
{
                   gambler_passivesAI(Creature * c) : ScriptedAI(c){ }
 
                   uint32 uiAdATimer;
                   uint32 uiAdBTimer;
                   uint32 uiAdCTimer;
 
                   void Reset()
                   {
                           uiAdATimer = 1000;
                           uiAdBTimer = 23000;
                           uiAdCTimer = 11000;
                   }
 
 
                   void UpdateAI(const uint32 diff)
                   {
 
                           if(uiAdATimer <= diff)
                           {
                                  me->MonsterSay("Come one, come all! Step right up to Crow's Casino! place your bets, place your bets!", LANG_UNIVERSAL, NULL);
                                  me->HandleEmoteCommand(EMOTE_ONESHOT_EXCLAMATION);
                                  me->CastSpell(me, 44940);
                                  uiAdATimer = 61000;
                           }
                           else
                                   uiAdATimer -= diff;
 
                           if(uiAdBTimer <= diff)
                           {
                                   me->MonsterSay("Come on guys! Place your bets, Don't be a chicken, Go hard or go home!", LANG_UNIVERSAL, NULL);
                                   me->HandleEmoteCommand(EMOTE_ONESHOT_CHICKEN);
                                   uiAdBTimer = 61000;
                           }
                           else
                                   uiAdBTimer -= diff;
 
                           if(uiAdCTimer <= diff)
                           {
                                   me->MonsterSay("OH C'MON! YOU'RE MAKIN' ME CRY, Come and gamble! Step right up and win big today!", LANG_UNIVERSAL, NULL);
                                   me->HandleEmoteCommand(EMOTE_ONESHOT_CRY);
                                   uiAdCTimer = 61000;
                           }
                           else
                                   uiAdCTimer -= diff;
                   }
};
 
            CreatureAI * GetAI(Creature * pCreature) const
           {
                   return new gambler_passivesAI(pCreature);
           }
};
 
void AddSC_gamble_npc()
{
    new gamble_npc();
}

 

posted @ 2014-05-26 09:47  needly  阅读(1677)  评论(0编辑  收藏  举报