markets.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. local markets_formspec_base =
  2. 'size[12,7]'..
  3. 'no_prepend[]'..
  4. 'bgcolor[#080808BB;true]'..
  5. 'background[0,0;12,7;hall_chalkboard_bg.png]'..
  6. 'hypertext[0,.2;12,1;;<center><style color=white size=40>~~Commodity Markets~~</style></center>]'
  7. local esc = minetest.formspec_escape
  8. local lesson = "The commodity markets create a network of 'shops' that you can sell and buy from. "..
  9. " Items can be placed for sale at any location, and be purchased from any other location. "..
  10. "This means you can place a Trading Post at your base to summon a caravan when you want to sell or buy without "..
  11. "needing to travel to a central location to access the market.\n"..
  12. " Markets use coins, which can be gathered by killing mobs, or by converting gold ingots. "..
  13. "One gold ingot is equivalent to one thousand coins. You can add coins or gold to your account by clicking on the "..
  14. "'Your Inventory' tab in the market and placing the coins or gold in the input slot on the left. You can withdraw gold or coins "..
  15. "by typing in the value you want to withdraw and clicking 'Withdraw' on the right. A value of more than one thousand will "..
  16. "be automatically converted to gold, with any remainder being cashed out in coins.\n"..
  17. " The markets create a free market, you are able to sell items for any price you want, and buyers can decide if you are "..
  18. "offering a fair deal or not. A savvy player can watch the markets buying items low and selling them high.\n"..
  19. " To sell items add them to the market inventory on the 'Your Inventory' tab, and then click on the 'Market Orders' tab. "..
  20. "Use the search box to easily find the items in your inventory. To put the item up for sale click on the listing, enter the "..
  21. "quantity you want to sell and how many coins you want, and then click the sell button.\n"..
  22. " If you want to buy an item that isn't listed for sale you can create a Buy order. Click on the listing for the item you want to buy, "..
  23. "enter the quantity you'd like to purchase, and how much you're willing to pay, and click on the Buy button. To buy an item that is listed "..
  24. "you need only click on the item, the quantity you want to purchase and a price equal or greater than the listed price.\n"..
  25. " You can cancel your orders by double clicking on them in the list. If it was a sell order the items will be added back to your available "..
  26. "inventory in the 'Your Inventory' tab.\n"..
  27. " You are limited to one thousand items in the market inventory at any one time."
  28. local markets_formspec_lesson =
  29. markets_formspec_base..
  30. "textarea[.75,1.5;11.25,4;;;"..esc(lesson).."]" ..
  31. 'button[4.5,5;3,1;go;Test your knowledge]'
  32. local markets_formspec_1 =
  33. markets_formspec_base..
  34. "textarea[1,1.5;11,3;;;A gold ingot can be converted into how many coins?]" ..
  35. 'button[1,4;3,1;wrong;A) 1]'..
  36. 'button[4.5,4;3,1;wrong;B) 10]'..
  37. 'button[8,4;3,1;wrong;C) 100]'..
  38. 'button[1,5.5;3,1;right;D) 1,000]'..
  39. 'button[4.5,5.5;3,1;wrong;E) 10,000]'..
  40. 'button[8,5.5;3,1;wrong;F) 100,000]'
  41. local markets_formspec_2 =
  42. markets_formspec_base..
  43. "textarea[1,1.5;11,3;;;What item will summon a caravan?]" ..
  44. 'button[1,4;3,1;wrong;A) A Trader Mob]'..
  45. 'button[4.5,4;3,1;wrong;B) A Secret Keyword]'..
  46. 'button[8,4;3,1;wrong;C) A Caravan Scroll]'..
  47. 'button[1,5.5;3,1;wrong;D) A Pile of Zombie Teeth]'..
  48. 'button[4.5,5.5;3,1;wrong;E) A Diamond Block]'..
  49. 'button[8,5.5;3,1;right;F) A Trading Post]'
  50. local markets_formspec_3 =
  51. markets_formspec_base..
  52. "textarea[1,1.5;11,3;;;Can you pull coins/gold out of the market?]" ..
  53. 'button[1,4;3,1;right;A) Yes]'..
  54. 'button[4.5,4;3,1;right;B) Yes]'..
  55. "button[8,4;3,1;right;C) Yes]"..
  56. "button[1,5.5;3,1;wrong;D) No]"..
  57. 'button[4.5,5.5;3,1;wrong;E) No]'..
  58. "button[8,5.5;3,1;wrong;F) No]"
  59. local markets_formspec_4 =
  60. markets_formspec_base..
  61. "textarea[1,1.5;11,3;;;How many items can you have in the market at once?]" ..
  62. 'button[1,4;3,1;wrong;A) 1]'..
  63. 'button[4.5,4;3,1;wrong;B) 10]'..
  64. 'button[8,4;3,1;wrong;C) 100]'..
  65. 'button[1,5.5;3,1;right;D) 1,000]'..
  66. 'button[4.5,5.5;3,1;wrong;E) 10,000]'..
  67. 'button[8,5.5;3,1;wrong;F) 100,000]'
  68. local markets_formspec_5 =
  69. markets_formspec_base..
  70. "textarea[1,1.5;11,3;;;You've passed the quiz! Here's a free trading post.]"..
  71. 'button_exit[4.5,5;3,1;;Exit]'
  72. minetest.register_on_player_receive_fields(function(player, formname, fields)
  73. local name = player:get_player_name()
  74. if formname == 'hall:markets_lesson' then
  75. if fields.go then
  76. minetest.show_formspec(name, 'hall:markets_1', markets_formspec_1)
  77. end
  78. elseif formname == 'hall:markets_1' then
  79. if fields.right then
  80. minetest.show_formspec(name, 'hall:markets_2', markets_formspec_2)
  81. elseif fields.wrong then
  82. minetest.show_formspec(name, 'hall:markets_lesson', markets_formspec_lesson)
  83. end
  84. elseif formname == 'hall:markets_2' then
  85. if fields.right then
  86. minetest.show_formspec(name, 'hall:markets_3', markets_formspec_3)
  87. elseif fields.wrong then
  88. minetest.show_formspec(name, 'hall:markets_lesson', markets_formspec_lesson)
  89. end
  90. elseif formname == 'hall:markets_3' then
  91. if fields.right then
  92. minetest.show_formspec(name, 'hall:markets_4', markets_formspec_4)
  93. elseif fields.wrong then
  94. minetest.show_formspec(name, 'hall:markets_lesson', markets_formspec_lesson)
  95. end
  96. elseif formname == 'hall:markets_4' then
  97. if fields.right then
  98. minetest.show_formspec(name, 'hall:markets_5', markets_formspec_5)
  99. local give = hall.storage:get_string(name..'_market')
  100. if give ~= 'earned' then
  101. local player_inv = player:get_inventory()
  102. if player_inv:room_for_item('main', 'commoditymarket:caravan_post') then
  103. player_inv:add_item('main', 'commoditymarket:caravan_post')
  104. else
  105. local drop_pos = player:get_pos()
  106. minetest.add_item(drop_pos, 'commoditymarket:caravan_post')
  107. end
  108. hall.storage:set_string(name..'_market', 'earned')
  109. end
  110. elseif fields.wrong then
  111. minetest.show_formspec(name, 'hall:markets_lesson', markets_formspec_lesson)
  112. end
  113. end
  114. end)
  115. minetest.register_node('hall:markets', {
  116. description = 'Markets Course',
  117. drawtype = 'mesh',
  118. mesh = 'hall_chalkboard.obj',
  119. tiles = {'hall_chalkboard_markets.png'},
  120. paramtype2 = 'facedir',
  121. paramtype = 'light',
  122. selection_box = {
  123. type = 'fixed',
  124. fixed = {-1, -.75, .4375, 1, .5, .5},
  125. },
  126. collision_box = {
  127. type = 'fixed',
  128. fixed = {-1, -.75, .4375, 1, .5, .5},
  129. },
  130. groups = {oddly_breakable_by_hand = 2, choppy=3, not_in_creative_inventory=1},
  131. on_rightclick = function(pos, node, clicker, itemstack)
  132. local meta = minetest.get_meta(pos)
  133. local name = clicker:get_player_name()
  134. meta:set_string('infotext', 'Market Course')
  135. minetest.show_formspec(name, 'hall:markets_lesson', markets_formspec_lesson)
  136. end,
  137. })