Guest User

Untitled

a guest
Mar 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. //updated
  2. // added check for negative bets
  3.  
  4. #include "ScriptedCreature.h"
  5. #include "ScriptedGossip.h"
  6. #include "WorldSession.h"
  7. #include "Player.h"
  8. #include "ScriptMgr.h"
  9. #include "Random.h"
  10. #include "Chat.h"
  11.  
  12. /* config */
  13. #define AMOUNT_IN_GOLD true
  14. #define WIN_PERCENTAGE 50
  15. /* config end */
  16.  
  17. #define GOLD(b,f) f ? b/10000 : b*10000
  18.  
  19. class Gamble_npc : public CreatureScript
  20. {
  21. public:
  22. Gamble_npc() : CreatureScript("Gambler") {}
  23.  
  24. struct Gamble_npc_AI : public ScriptedAI
  25. {
  26. Gamble_npc_AI(Creature* creature) : ScriptedAI(creature) { }
  27.  
  28. bool GossipHello(Player* player)
  29. {
  30. ClearGossipMenuFor(player);
  31. std::string text = "Enter money amount " + std::string(AMOUNT_IN_GOLD ? "in gold" : "in copper");
  32. AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface\\Icons\\INV_Misc_Coin_02:30|t Let's Gamble!", GOSSIP_SENDER_MAIN, 1, text, 0, true);
  33. AddGossipItemFor(player, GOSSIP_ICON_CHAT, "|TInterface\\Icons\\Spell_Shadow_SacrificialShield:30|t Goodbye", GOSSIP_SENDER_MAIN, 500);
  34. SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, me->GetGUID());
  35. return true;
  36. }
  37.  
  38. bool GossipSelect(Player* player, uint32 /*menuId*/, uint32 gossipListId)
  39. {
  40. uint32 const sender = player->PlayerTalkClass->GetGossipOptionSender(gossipListId);
  41. uint32 const action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
  42.  
  43. ClearGossipMenuFor(player);
  44.  
  45. if (sender == GOSSIP_SENDER_MAIN)
  46. {
  47. if (action == 500)
  48. {
  49. CloseGossipMenuFor(player);
  50. }
  51. }
  52. return true;
  53. }
  54.  
  55. bool GossipSelectCode(Player* player, uint32 menuId, uint32 gossipListId, char const* code)
  56. {
  57. uint32 const sender = player->PlayerTalkClass->GetGossipOptionSender(gossipListId);
  58. uint32 const action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
  59.  
  60. int32 betAmount = atoi(code);
  61.  
  62. bool isNegative = betAmount < 0;
  63. if (!betAmount || isNegative)
  64. {
  65. player->GetSession()->SendNotification("Invalid bet amount");
  66. GossipHello(player);
  67. return false;
  68. }
  69.  
  70. int32 money = AMOUNT_IN_GOLD ? GOLD(player->GetMoney(), true) : player->GetMoney();
  71. if (money < betAmount)
  72. {
  73. player->GetSession()->SendNotification("You don't have enough money");
  74. GossipHello(player);
  75. return false;
  76. }
  77.  
  78. int32 doubledBetAmount = betAmount * 2;
  79.  
  80. std::stringstream ss;
  81. ss << "|cffE68318[Gamble System]:|r |cff00ff00You won and doubled your bet! +" << doubledBetAmount << " gold";
  82. std::string winTextStr = ss.str();
  83.  
  84. std::stringstream ss1;
  85. ss1 << "|cffE68318[Gamble System]:|r |cffFF0000You lost.. better luck next time! -" << betAmount << " gold";
  86. std::string lossTextStr = ss1.str();
  87.  
  88. int32 randVal = 100 / WIN_PERCENTAGE - 1;
  89. if (!urand(0, randVal)) // player won
  90. {
  91. player->ModifyMoney(AMOUNT_IN_GOLD ? GOLD(doubledBetAmount, false) : doubledBetAmount);
  92. player->GetSession()->SendAreaTriggerMessage(winTextStr.c_str());
  93. ChatHandler(player->GetSession()).PSendSysMessage(winTextStr.c_str());
  94.  
  95. }
  96. else
  97. {
  98. player->ModifyMoney(AMOUNT_IN_GOLD ? GOLD(-betAmount, false) : ~betAmount + 1u);
  99. player->GetSession()->SendAreaTriggerMessage(lossTextStr.c_str());
  100. ChatHandler(player->GetSession()).PSendSysMessage(lossTextStr.c_str());
  101. }
  102. GossipHello(player);
  103. return true;
  104. }
  105. };
  106.  
  107. CreatureAI* GetAI(Creature* creature) const override
  108. {
  109. return new Gamble_npc_AI(creature);
  110. }
  111. };
  112.  
  113. void AddSC_Gamble_npc()
  114. {
  115. new Gamble_npc();
  116. }
Add Comment
Please, Sign In to add comment