Advertisement
Rochet2

Untitled

Oct 19th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "ScriptMgr.h"
  2. #include "ScriptedCreature.h"
  3. #include "ScriptedGossip.h"
  4. #include "GameEventMgr.h"
  5. #include "Player.h"
  6. #include "WorldSession.h"
  7. #include <stdlib.h>
  8.  
  9. // Colors
  10. #define TEXT_LIGHTBLUE  "|cFF00FFFC"
  11. #define TEXT_RED        "|cffA40000"
  12. #define TEXT_GREEN      "|cffABD473"
  13.  
  14. static const int32 bets_in_gold[] = {
  15.     100,
  16.     250,
  17.     500,
  18.     1000,
  19. };
  20.  
  21. class GoldGambling : public  CreatureScript
  22. {
  23. public:
  24.     GoldGambling() : CreatureScript("GoldGambling")
  25.     {
  26.     }
  27.  
  28.     bool OnGossipHello(Player* player, Creature* creature) override
  29.     {
  30.         for (auto gold : bets_in_gold)
  31.             player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_CHAT, TEXT_LIGHTBLUE "-> Gamble " TEXT_RED + std::to_string(gold) + " GOLD", GOSSIP_SENDER_MAIN, gold, "", gold*GOLD, false);
  32.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, TEXT_RED "Nevermind..", GOSSIP_SENDER_MAIN, 0);
  33.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  34.         return true;
  35.     }
  36.  
  37.  
  38.     bool OnGossipSelect(Player* player, Creature * creature, uint32 sender, uint32 bet) override
  39.     {
  40.         player->PlayerTalkClass->ClearMenus();
  41.         if (sender != GOSSIP_SENDER_MAIN)
  42.             return false;
  43.  
  44.         if (bet == 0)
  45.         {
  46.             player->PlayerTalkClass->SendCloseGossip();
  47.             return true;
  48.         }
  49.  
  50.         int32 copper = bet*GOLD;
  51.  
  52.         if (!player->HasEnoughMoney(copper))
  53.         {
  54.             player->GetSession()->SendNotification("Not enough money");
  55.             OnGossipHello(player, creature);
  56.             return true;
  57.         }
  58.  
  59.         uint32 number = urand(1, 10); // 1/10 = 10% chance
  60.         if (number == 2)
  61.         {
  62.             player->ModifyMoney(copper);
  63.             creature->Whisper(TEXT_LIGHTBLUE "CONGRATZ YOU WON!! " TEXT_GREEN + std::to_string(bet) + " GOLD", LANG_UNIVERSAL, player);
  64.         }
  65.         else
  66.         {
  67.             player->ModifyMoney(-copper);
  68.             creature->Whisper(TEXT_LIGHTBLUE "I'm sorry but you lost! :(" TEXT_RED + std::to_string(bet) + " GOLD", LANG_UNIVERSAL, player);
  69.         }
  70.  
  71.         OnGossipHello(player, creature);
  72.         return true;
  73.     }
  74. };
  75.  
  76. void addSC_GoldGambling()
  77. {
  78.     new GoldGambling();
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement