Advertisement
skillz79

Untitled

May 11th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.31 KB | None | 0 0
  1. /*######################-> [[GOLD BANKER ]] <-#########################
  2. **************************! DEV: ak47sigh !****************************
  3. #######################################################################*/
  4. #include "ScriptPCH.h"
  5. #include <cstring>
  6. #include "Chat.h"
  7.  
  8. // -- [[ Configs:
  9. uint32 maxPlayerDeposits = 3;\
  10. uint32 minDepositNameLenght = 5;
  11. uint32 createDepositCost = 100000; // default 10 gold per deposit
  12. uint32 createDepositPlus = 50000; // increase the cost by X gold for each new repository
  13. uint32 maxDepositAmount = 2000000000; // recommended not to pass this value 2 000 000 000
  14.  
  15. // -- [[ DO NOT EDIT BELLOW // --
  16. #define MENIU(a, b, c, d) PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, a, b, c, d, "", 0)
  17. #define MENIU_EXTENDED(a, b, c, d, e, f, g) PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, a, b, c, d, e, f, g)
  18. #define TRIMITE_MENIU(a, b) PlayerTalkClass->SendGossipMenu(a, b)
  19.  
  20. struct DepositInfo
  21. {
  22. uint64 editselectedid;
  23. uint64 depid;
  24. std::string depname;
  25. };
  26. static std::map<uint32, DepositInfo> editselectedid;
  27.  
  28. class gold_banker : public CreatureScript
  29. {
  30. public:
  31. gold_banker() : CreatureScript("Gold_Banker") { }
  32. // Deposit gold in the last selected deposit
  33. bool DepositGold(Player* player, Creature* creature, uint32 amount, uint32 deposit_id)
  34. {
  35. QueryResult depInfo = WorldDatabase.PQuery("SELECT * FROM `gold_bank_data` WHERE `depositGUID`='%u'", deposit_id);
  36.  
  37. if(!depInfo)
  38. {
  39. ChatHandler(player->GetSession()).PSendSysMessage("ERR: You are trying to deposit into a non existing one!");
  40. ListPlayerDeposits(player, creature);
  41. return false;
  42. }
  43.  
  44. Field * pField = depInfo->Fetch();
  45.  
  46. if(amount + pField[2].GetUInt32() > maxDepositAmount)
  47. {
  48. ChatHandler(player->GetSession()).PSendSysMessage("ERR: Amount is to higher enough to pass '%u' of gold.", maxDepositAmount);
  49. ListPlayerDeposits(player, creature);
  50. return false;
  51. }
  52.  
  53. if(amount > player->GetMoney()/10000)
  54. {
  55. ChatHandler(player->GetSession()).PSendSysMessage("ERR: You dont have the amount inserted.");
  56. ListPlayerDeposits(player, creature);
  57. return false;
  58. }
  59.  
  60. if(amount <= 0)
  61. {
  62. ChatHandler(player->GetSession()).PSendSysMessage("ERR: Invalid amount to deposit.");
  63. ListPlayerDeposits(player, creature);
  64. return false;
  65. }
  66.  
  67. WorldDatabase.PExecute("UPDATE `gold_bank_data` SET `depGold`=`depGold`+'%u' WHERE `depositGUID`='%u'", amount, deposit_id);
  68. player->ModifyMoney(-amount*10000, false);
  69. ChatHandler(player->GetSession()).PSendSysMessage("Deposit [\'%u\'][%s] loaded with a plus of \'%u\' gold.", deposit_id, editselectedid[player->GetGUID()].depname.c_str(), amount);
  70. player->PlayerTalkClass->SendCloseGossip();
  71.  
  72. return true;
  73. }
  74. // Withdraw gold from the last deposit selected
  75. bool WithdrawGold(Player* player, Creature* creature, uint32 amount, uint32 deposit_id)
  76. {
  77. QueryResult depInfo = WorldDatabase.PQuery("SELECT * FROM `gold_bank_data` WHERE `depositGUID`='%u'", deposit_id);
  78.  
  79. if(!depInfo)
  80. {
  81. ChatHandler(player->GetSession()).PSendSysMessage("ERR: You are trying to withdraw from a non existing deposit!");
  82. ListPlayerDeposits(player, creature);
  83. return false;
  84. }
  85.  
  86. Field * pField = depInfo->Fetch();
  87.  
  88. if(amount > pField[2].GetUInt32())
  89. {
  90. ChatHandler(player->GetSession()).PSendSysMessage("ERR: You can't withdraw more than you don't have!", maxDepositAmount);
  91. ListPlayerDeposits(player, creature);
  92. return false;
  93. }
  94.  
  95. if(amount <= 0)
  96. {
  97. ChatHandler(player->GetSession()).PSendSysMessage("ERR: Invalid amount to withdraw.");
  98. ListPlayerDeposits(player, creature);
  99. return false;
  100. }
  101.  
  102. WorldDatabase.PExecute("UPDATE `gold_bank_data` SET `depGold`=`depGold`-'%u' WHERE `depositGUID`='%u'", amount, deposit_id);
  103. player->ModifyMoney(amount*10000, false);
  104.  
  105. if(amount == pField[2].GetUInt32())
  106. ChatHandler(player->GetSession()).PSendSysMessage("Deposit [\'%u\'][%s] drawn all \'%u\' gold.", deposit_id, editselectedid[player->GetGUID()].depname.c_str(), amount);
  107. else
  108. ChatHandler(player->GetSession()).PSendSysMessage("Deposit [\'%u\'][%s] drawn an amount of \'%u\' gold.", deposit_id, editselectedid[player->GetGUID()].depname.c_str(), amount);
  109.  
  110. player->PlayerTalkClass->SendCloseGossip();
  111.  
  112. return true;
  113. }
  114. // Rename the last selected deposit
  115. bool RenameDeposit(Player* player, Creature* creature, const char* deposit_name)
  116. {
  117. QueryResult depInfo = WorldDatabase.PQuery("SELECT * FROM `gold_bank_data` WHERE `depositGUID`='%u'", editselectedid[player->GetGUID()].depid);
  118.  
  119. if(!depInfo)
  120. {
  121. ChatHandler(player->GetSession()).PSendSysMessage("ERR: You are trying to rename a non existing deposit!");
  122. ListPlayerDeposits(player, creature);
  123. return false;
  124. }
  125.  
  126. std::string depnamepreview = deposit_name;
  127.  
  128. if(depnamepreview.length() < minDepositNameLenght)
  129. {
  130. ChatHandler(player->GetSession()).PSendSysMessage("ERR: Invalid string length, minimum %u characters required.", minDepositNameLenght);
  131. ListPlayerDeposits(player, creature);
  132. return false;
  133. }
  134.  
  135. WorldDatabase.PExecute("UPDATE `gold_bank_data` SET `depName`='%s' WHERE `depositGUID`='%u'", deposit_name, editselectedid[player->GetGUID()].depid);
  136. ChatHandler(player->GetSession()).PSendSysMessage("Deposit renamed to \'%s\'.", deposit_name);
  137. player->PlayerTalkClass->SendCloseGossip();
  138.  
  139. return true;
  140. }
  141. //Disband deposit
  142. bool DisbandDeposit(Player* player, Creature* creature, uint32 deposit_id)
  143. {
  144. QueryResult depInfo = WorldDatabase.PQuery("SELECT * FROM `gold_bank_data` WHERE `depositGUID`='%u'", deposit_id);
  145.  
  146. if(!depInfo)
  147. {
  148. ChatHandler(player->GetSession()).PSendSysMessage("ERR: You are trying to disband a non existing deposit!");
  149. ListPlayerDeposits(player, creature);
  150. return false;
  151. }
  152.  
  153. Field * pField = depInfo->Fetch();
  154. WorldDatabase.PExecute("DELETE FROM `gold_bank_data` WHERE `depositGUID`='%u'", deposit_id);
  155. ChatHandler(player->GetSession()).PSendSysMessage("Deposit disbanded.");
  156. player->PlayerTalkClass->SendCloseGossip();
  157.  
  158. return true;
  159. }
  160. // Creates a deposit
  161. bool CreateDeposit(Player* player, Creature* creature)
  162. {
  163. QueryResult depResult = WorldDatabase.PQuery("SELECT * FROM `gold_bank_data` WHERE plrGUID = %u", player->GetGUID());
  164.  
  165. uint32 deposits = 0;
  166. uint32 cost = createDepositCost;
  167.  
  168. if(depResult)
  169. {
  170. deposits = depResult->GetRowCount();
  171.  
  172. if(deposits > maxPlayerDeposits)
  173. {
  174. ChatHandler(player->GetSession()).PSendSysMessage("You already have the max deposits allowed.");
  175. return false;
  176. }
  177. Field * pField = depResult->Fetch();
  178. }
  179.  
  180. if(deposits == 0)
  181. {
  182. cost = createDepositCost;
  183. }
  184. else
  185. {
  186. cost = createDepositCost + (deposits * createDepositPlus);
  187. }
  188.  
  189. player->ModifyMoney(-cost, false);
  190. WorldDatabase.PExecute("INSERT INTO `gold_bank_data` (`plrGUID`, `depName`) VALUES (%u, 'Change my name')", player->GetGUID());
  191. ChatHandler(player->GetSession()).PSendSysMessage("Deposit created and ready to use, you can change it's name at anytime.");
  192. player->PlayerTalkClass->SendCloseGossip();
  193.  
  194. return true;
  195. }
  196. // Opens a menu to edit the selected deposit
  197. void EditSelectedDeposit(Player* player, Creature* creature, uint32 uiAction)
  198. {
  199. player->PlayerTalkClass->ClearMenus();
  200. editselectedid[player->GetGUID()].depid = uiAction;
  201. QueryResult depInfo = WorldDatabase.PQuery("SELECT * FROM `gold_bank_data` WHERE `depositGUID`='%u'", editselectedid[player->GetGUID()].depid);
  202.  
  203. player->MENIU(7, "|cff5C5C5C[Return]|r", GOSSIP_SENDER_MAIN, 1);
  204. if(depInfo)
  205. {
  206. Field * pField = depInfo->Fetch();
  207. editselectedid[player->GetGUID()].depname = pField[1].GetString().c_str();
  208.  
  209. player->MENIU_EXTENDED(6, "Withdraw some gold", GOSSIP_SENDER_MAIN, 888, "How much gold would you like to|cffFF0000 withdraw|r?\n Press \"Accept\" button to insert", 0/*copper*/, true);
  210. player->MENIU_EXTENDED(6, "Deposit some gold", GOSSIP_SENDER_MAIN, 777, "How much gold would you like to|cFF00FF00 deposit|r?\n Press \"Accept\" button to insert", 0/*copper*/, true);
  211. player->MENIU_EXTENDED(8, "|cff9E00FFRename deposit|r", GOSSIP_SENDER_MAIN, 555, "|cffEBFF00Press \'Accept\' button to insert a name|r", 0/*copper*/, true);
  212. player->MENIU_EXTENDED(4, "|cffFF0000Disband deposit|r", GOSSIP_SENDER_MAIN, 888, "|cffEBFF00Are you sure about disbanding this deposit?\n |cFFFF0000Once disbanded cannot be recovered!|r", 0/*copper*/, false);
  213. }
  214. else // deposit no longer exists
  215. {
  216. player->MENIU(0, "|cffFF0000Deposit no longer exists or connection could not be established! Please contact a Game Master as soon as it's possible. Thank you|r", GOSSIP_SENDER_MAIN, 1);
  217. }
  218. player->PlayerTalkClass->SendGossipMenu(7777778, creature->GetGUID());
  219. }
  220. // Opens a list with the player's available deposits
  221. void ListPlayerDeposits(Player* pPlayer, Creature* pCreature, unsigned int start = 0)
  222. {
  223. pPlayer->PlayerTalkClass->ClearMenus();
  224. pPlayer->MENIU(0, "|cff5C5C5C[Return]|r", GOSSIP_SENDER_MAIN, 999);
  225. QueryResult depResult = WorldDatabase.PQuery("SELECT * FROM gold_bank_data WHERE plrGUID = %u", pPlayer->GetGUID());
  226.  
  227. uint32 deposits = 0;
  228.  
  229. if(depResult)
  230. {
  231. deposits = depResult->GetRowCount();
  232. int offset = 0;
  233. Field * pField = depResult->Fetch();
  234. bool ranOnce = false;
  235. for(unsigned int i = start; i < deposits; i++)
  236. {
  237. if(start != 0 && ranOnce == false)
  238. {
  239. for(int x = 0; x < start; x++)
  240. {
  241. depResult->NextRow();
  242. }
  243. ranOnce = true;
  244. }
  245.  
  246. if(offset != maxPlayerDeposits) // max returns
  247. {
  248. std::ostringstream cString1, cString2;
  249. cString1 << pField[3].GetUInt32();
  250. cString2 << pField[2].GetUInt32();
  251. pPlayer->MENIU(GOSSIP_ICON_MONEY_BAG, "[Deposit |cffFFFFFF" + cString1.str() + "|r] \"|cff0055FF" + pField[1].GetString() + "|r\"\n |cff00ff00available|r " + cString2.str() + "|cffFF0000 gold|r", GOSSIP_SENDER_MAIN, pField[3].GetUInt32());
  252. offset++;
  253. depResult->NextRow();
  254. }
  255. }
  256. if(deposits < maxPlayerDeposits)
  257. {
  258. uint32 cost = createDepositCost;
  259.  
  260. if(deposits == 0)
  261. {
  262. cost = createDepositCost;
  263. }
  264. else
  265. {
  266. cost = createDepositCost + (deposits * createDepositPlus);
  267. }
  268.  
  269. pPlayer->MENIU_EXTENDED(GOSSIP_ICON_INTERACT_2, "[+] Create a new Deposit", GOSSIP_SENDER_MAIN, 0, "Would you like to create a new deposit?", cost, false);
  270. }
  271. }
  272. if(deposits == 0)
  273. {
  274. uint32 cost = createDepositCost;
  275.  
  276. pPlayer->MENIU_EXTENDED(GOSSIP_ICON_INTERACT_2, "[+] Create a new Deposit", GOSSIP_SENDER_MAIN, 0, "Would you like to create a new deposit?", cost, false);
  277. }
  278. pPlayer->PlayerTalkClass->SendGossipMenu(7777778, pCreature->GetGUID());
  279. }
  280. // Main Gold Banker menu
  281. bool OnGossipHello(Player * player, Creature * creature)
  282. {
  283. player->PlayerTalkClass->ClearMenus();
  284. editselectedid[player->GetGUID()].depid = 0; // reset
  285. player->MENIU(8, "I want to check deposits", GOSSIP_SENDER_MAIN, 1);
  286. player->MENIU(2, "Maybe'..later", GOSSIP_SENDER_MAIN, 2);
  287. player->TRIMITE_MENIU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  288. return true;
  289. }
  290. // ..
  291. bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 uiAction)
  292. {
  293. switch(uiAction)
  294. {
  295. case 0:
  296. CreateDeposit(player, creature);
  297. break;
  298. case 1:
  299. ListPlayerDeposits(player, creature);
  300. break;
  301. case 2:
  302. player->PlayerTalkClass->SendCloseGossip();
  303. break;
  304. case 888:
  305. DisbandDeposit(player, creature, editselectedid[player->GetGUID()].depid);
  306. break;
  307. case 999:
  308. OnGossipHello(player, creature);
  309. break;
  310. default:
  311. if(uiAction != 999 || uiAction != 888 || uiAction != 1 || uiAction != 0 || uiAction != 2)
  312. EditSelectedDeposit(player, creature, uiAction);
  313. break;
  314. }
  315. return true;
  316. }
  317. // ..
  318. bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 uiAction, const char* code)
  319. {
  320. uint32 codexx = uint32(atol(code));
  321.  
  322. switch(uiAction)
  323. {
  324. case 555:
  325. RenameDeposit(player, creature, code);
  326. break;
  327. case 777:
  328. DepositGold(player, creature, codexx, editselectedid[player->GetGUID()].depid);
  329. break;
  330. case 888:
  331. WithdrawGold(player, creature, codexx, editselectedid[player->GetGUID()].depid);
  332. break;
  333. }
  334. return true;
  335. }
  336. };
  337.  
  338. void AddSC_Gold_Banker()
  339. {
  340. new gold_banker();
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement