Advertisement
Guest User

tfm_monopoly 1.0.2

a guest
Jan 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.92 KB | None | 0 0
  1. local block_width, block_height, start_width, start_height = 80, 50, 100, 100
  2. local purple, white, lightblue, pink = 0xa417ba, 0xffffff, 0x2f2f0, 0xfeafe4
  3. local defaultcolor, jailcolor= 0xc7fafa,0xf4a148
  4. local orange, red, yellow, green, darkblue = 0xfaa114, 0xfa2914, 0xfaf814, 0x14fa27, 0x1104dc
  5. local eventID, beginClock, enableDice, stillNext = 0, false, false, false
  6. local player, order, coor = {}, {}, {}
  7. local turn, pay2target, pay2money, canBuild = nil
  8. local numPlayer = 0
  9. local dice1, dice2, countET, extraTurn = 1, 1, 0, false
  10. local diceAnimation, walkingStep, locationAnimation = 0, 0, false
  11. math.randomseed(os.time())
  12.  
  13. --[[
  14. addTextArea = {
  15. 1-40 = block
  16. -1 = clock
  17. -2 = addDescription
  18. -3 = mortgage button
  19. -4 = build button
  20. -5 = endTurn
  21. -6 = display header
  22. -7 = display info
  23. -8 = close info
  24. -9 = rules
  25. -100 = dice1
  26. -200 = dice2
  27. -300 = roll
  28.  
  29. --independent
  30. -4*player[name].id = done mortgage
  31. -5*player[name].id = property table
  32. player[name].id + 9 = money effect
  33. player[name].id = player
  34. }
  35. addPopup = {
  36. 0 = buy
  37. -1 = 2000/10%
  38. -3 = jail 500
  39. -4 = !new
  40. 1 = notification
  41. 2 = help
  42. }
  43. --]]
  44.  
  45.  
  46. local event = {
  47. ["start"] =
  48. function()
  49. ui.removeTextArea(-2)
  50. randomOrder(order)
  51. if numPlayer > 0 then
  52. turn = order[1]
  53. for i,v in pairs (order) do
  54. updateLocation(v)
  55. tfm.exec.setNameColor(v,player[v].backgroundColor)
  56. end
  57. updateDice(dice1, dice2)
  58. rollDice(turn)
  59. else
  60. addDescription(numPlayer,"人數不足(",")\n !new 重新開始")
  61. ui.removeTextArea(-1)
  62. end
  63. end,
  64. ["endTurn"] =
  65. function()
  66. ui.addTextArea(-5, "<J><font size = \"40\"><p align = \"center\"><a href =\"event:".."endTurn".."\">結束</a></font></p>", turn, 350, 350, 90, 45, 0x01, 0x000000, 0.5, true)
  67. end,
  68. ["nextTurn"] =
  69. function()
  70. if not stillNext then
  71. table.insert(order, order[1])
  72. table.remove(order, 1)
  73. end
  74. countTime(30,"nextTurn")
  75. turn = order[1]
  76. enableDice , locationAnimation = false
  77. pay2target, pay2money, canBuild, stillNext = nil
  78. ui.removeTextArea(-3)
  79. ui.removeTextArea(-5)
  80. ui.removeTextArea(-300)
  81. addMortgageButton(turn)
  82. if player[turn].jailCounter > 0 then
  83. addDescription(turn, "", "考慮是否立即出獄")
  84. addNotification(-3, 1, "<p align=\"center\">支付$500立即出獄?</p>", turn)
  85. elseif player[turn].inJail then
  86. pay(turn, 500)
  87. addDescription(turn, "", "的刑期滿 支付$500出獄")
  88. exitJail(turn)
  89. rollDice(turn)
  90. else
  91. rollDice(turn)
  92. end
  93. end,
  94. }
  95.  
  96. local help = [[
  97. 基本規則:
  98. -如到未被購買的土地,可以付錢買
  99. -如到已有人購買且沒有被抵押的土地,擁有者需收租
  100. -如出現「即時入獄」或擲三次點數相同骰子, 需即時入獄
  101. -如經過或停留起點時,銀行向玩家支付2000元
  102. 出獄方法:
  103. -擲到相同點數
  104. -在擲骰之前支付500元給銀行
  105. -刑期3回合屆滿後支付500元出獄
  106. 抵押:
  107. -該地必需沒有建築物。向銀行拿抵押的值同時不能收租
  108. -解押時需繳付10%手續費
  109. 破產:
  110. -玩家抵押後依然負資產即時破產
  111. -如果破產於一個對象, 該對象接收所有財產, 保留地契狀態
  112. 勝出遊戲:所有其他玩家破產後,餘下的就是贏家
  113.  
  114. 自訂規則:
  115. -可交易: 不能借錢 交易收取10%手續費 集齊同一色系方能建屋 有額外回合
  116. -不可交易: 到達自己地上 能建屋一次 沒有額外回合]]
  117.  
  118. local rule =
  119. {
  120. originMode = false
  121. --[[
  122. step_on_build = { value = true, name = "禁止交易 踩自己能地建屋", tableName = "step_on_build" },
  123. rent_prisoner = { value = false, name = "監禁時收租", tableName = "rent_prisoner" },
  124. average_build = { value = false, name = "系列屋子數量平均", tableName = "average_build" },
  125. extra_turn = { value = false, name = "點數相同獲得額外回合", tableName = "extra_turn" },
  126. --]]
  127. }
  128.  
  129. local tableInfo = {
  130. {name="開始", price=nil, alpha=1, color=defaultcolor, mortgageValue=300},
  131. {name="長洲", price=600, alpha=0.7, color=purple, mortgageValue=300},
  132. {name="公益福利", price=nil,alpha=1, color=defaultcolor, mortgageValue=0},
  133. {name="屯門", price=600, alpha=0.7, color=purple, mortgageValue=300},
  134. {name="入息稅\n(付$2000或10%)", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  135. {name="九龍塘車站", price=2000, alpha=0.7, color=white, mortgageValue=1000},
  136. {name="荃灣", price=1000, alpha=0.7, color=lightblue, mortgageValue=500},
  137. {name="機會", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  138. {name="旺角", price=1000, alpha=0.7, color=lightblue, mortgageValue=500},
  139. {name="加連威老道", price=1200, alpha=0.7, color=lightblue, mortgageValue=600},
  140. {name="赤柱監獄(獄中或探訪)", price=nil, alpha=1, color=jailcolor, mortgageValue=0},
  141. {name="彌敦道", price=1400, alpha=0.7, color=pink, mortgageValue=700},
  142. {name="電燈公司", price=1500, alpha=0.7, color=white, mortgageValue=750},
  143. {name="馬鞍山", price=1400, alpha=0.7, color=pink, mortgageValue=700},
  144. {name="沙田", price=1600, alpha=0.7, color=pink, mortgageValue=800},
  145. {name="銅鑼灣車站", price=2000, alpha=0.7, color=white, mortgageValue=1000},
  146. {name="灣仔", price=1800, alpha=0.7, color=orange, mortgageValue=900},
  147. {name="公益福利", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  148. {name="愉景灣", price=1800, alpha=0.7, color=orange, mortgageValue=900},
  149. {name="西貢", price=2000, alpha=0.7, color=orange, mortgageValue=1000},
  150. {name="免費泊車", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  151. {name="山村道", price=2200, alpha=0.7, color=red, mortgageValue=1100},
  152. {name="機會", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  153. {name="黃泥涌道", price=2200, alpha=0.7, color=red, mortgageValue=1100},
  154. {name="藍塘道", price=2400, alpha=0.7, color=red, mortgageValue=1200},
  155. {name="中環車站", price=2000, alpha=0.7, color=white, mortgageValue=1000},
  156. {name="干諾道中", price=2600, alpha=0.7, color=yellow, mortgageValue=1300},
  157. {name="皇后大道中", price=2600, alpha=0.7, color=yellow, mortgageValue=1300},
  158. {name="水務局", price=1500, alpha=0.7, color=white, mortgageValue=750},
  159. {name="德輔道中", price=2800, alpha=0.7, color=yellow, mortgageValue=1400},
  160. {name="入獄", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  161. {name="羅便臣道", price=3000, alpha=0.7, color=green, mortgageValue=1500},
  162. {name="馬己仙峽道", price=3000, alpha=0.7, color=green, mortgageValue=1500},
  163. {name="公益福利", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  164. {name="淺水灣", price=3200, alpha=0.7, color=green, mortgageValue=1600},
  165. {name="尖沙咀車站", price=2000, alpha=0.7, color=white, mortgageValue=1000},
  166. {name="機會", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  167. {name="南灣", price=3500, alpha=0.7, color=darkblue, mortgageValue=2000},
  168. {name="薪俸稅\n(付$750)", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
  169. {name="山頂", price=4000, alpha=0.7, color=darkblue, mortgageValue=2000},
  170. }
  171.  
  172. local tableRent = {
  173. -- [id] {rent(0 house),1 house,2 house,3 house, 4 house, hotel(5 house), each house, each hotel}
  174. [2] = {[0] = 20,[1] = 100,[2] = 300,[3] = 900,[4] = 1600,[5] = 2500,[6] = 500},
  175. [4] = {[0] = 40,[1] = 200,[2] = 600,[3] = 1800,[4] = 3200,[5] = 4500,[6] = 500},
  176. [6] = {[0] = 250,[1] = 500,[2] = 1000,[3] = 2000,},
  177. [7] = {[0] = 60,[1] = 300,[2] = 900,[3] = 2700,[4] = 4000,[5] = 5500,[6] = 500},
  178. [9] = {[0] = 60,[1] = 300,[2] = 900,[3] = 2700,[4] = 4000,[5] = 5500,[6] = 500},
  179. [10] = {[0] = 80,[1] = 400,[2] = 1000,[3] = 3000,[4] = 4500,[5] = 6000,[6] = 500},
  180. [12] = {[0] = 100,[1] = 500,[2] = 1500,[3] = 4500,[4] = 6250,[5] = 7500,[6] = 1000},
  181. [13] = {[1] = function (x) return x * 40 end,[2] = function (x) return x * 100 end},
  182. [14] = {[0] = 100,[1] = 500,[2] = 1500,[3] = 4500,[4] = 6250,[5] = 7500,[6] = 1000},
  183. [15] = {[0] = 120,[1] = 600,[2] = 1800,[3] = 5000,[4] = 7000,[5] = 9000,[6] = 1000},
  184. [16] = {[0] = 250,[1] = 500,[2] = 1000,[3] = 2000},
  185. [17] = {[0] = 140,[1] = 700,[2] = 2000,[3] = 5500,[4] = 7500,[5] = 9500,[6] = 1000},
  186. [19] = {[0] = 140,[1] = 700,[2] = 2000,[3] = 5500,[4] = 7500,[5] = 9500,[6] = 1000},
  187. [20] = {[0] = 160,[1] = 800,[2] = 2200,[3] = 6000,[4] = 8000,[5] = 10000,[6] = 1000},
  188. [22] = {[0] = 180,[1] = 900,[2] = 2500,[3] = 7000,[4] = 8750,[5] = 10500,[6] = 1500},
  189. [24] = {[0] = 180,[1] = 900,[2] = 2500,[3] = 7000,[4] = 8750,[5] = 10500,[6] = 1500},
  190. [25] = {[0] = 200,[1] = 1000,[2] = 3000,[3] = 7500,[4] = 9250,[5] = 11000,[6] = 1500},
  191. [26] = {[0] = 250,[1] = 500,[2] = 1000,[3] = 2000},
  192. [27] = {[0] = 220,[1] = 1100,[2] = 3300,[3] = 8000,[4] = 9750,[5] = 11500,[6] = 1500},
  193. [28] = {[0] = 220,[1] = 1100,[2] = 3300,[3] = 8000,[4] = 9750,[5] = 11500,[6] = 1500},
  194. [29] = {[1] = function(x) return x * 40 end,[2] = function(x) return x * 100 end},
  195. [30] = {[0] = 240,[1] = 1200,[2] = 3600,[3] = 8500,[4] = 10250,[5] = 12000,[6] = 1500},
  196. [32] = {[0] = 260,[1] = 1300,[2] = 3900,[3] = 9000,[4] = 11000,[5] = 12750,[6] = 2000},
  197. [33] = {[0] = 260,[1] = 1300,[2] = 3900,[3] = 9000,[4] = 11000,[5] = 12750,[6] = 2000},
  198. [35] = {[0] = 280,[1] = 1500,[2] = 4500,[3] = 10000,[4] = 12000,[5] = 14000,[6] = 2000},
  199. [36] = {[0] = 250,[1] = 500,[2] = 1000,[3] = 2000},
  200. [38] = {[0] = 350,[1] = 1750,[2] = 5000,[3] = 11000,[4] = 13000,[5] = 15000,[6] = 2000},
  201. [40] = {[0] = 500,[1] = 2000,[2] = 6000,[3] = 14000,[4] = 17000,[5] = 20000,[6] = 2000},
  202. [purple] = {2,4},
  203. [white] = {6,16,26,36},
  204. [orange] = {17,19,20},
  205. [lightblue] = {7,9,10},
  206. [pink] = {12,14,15},
  207. [red] = {22,24,25},
  208. [yellow] = {27,28,30},
  209. [green] = {32,33,35},
  210. [darkblue] = {38,40},
  211. }
  212.  
  213. local chance = {
  214. function() addNotification(1,0,"機會: 即時入獄\n不准領取$2000",nil) action(31) end,
  215. function()
  216. addNotification(1,0,"機會: 當選董事局主席\n付每人$500",nil)
  217. for i,v in pairs (order) do
  218. if i ~= 1 then
  219. pay(turn, 500, v)
  220. end
  221. end
  222. event["endTurn"]()
  223. end,
  224. function() addNotification(1,0,"機會: 銀行紅利 $500",nil) pay(turn, -500) event["endTurn"]() end,
  225. function()
  226. addNotification(1,0,"機會: 房子維修費\n每棟房子付$250\n每棟旅館付$1000",nil)
  227. for i,v in pairs (player[turn].property) do
  228. if tableInfo[v].house == 5 then
  229. pay(turn, 2000)
  230. else
  231. pay(turn, tableInfo[v].house*250)
  232. end
  233. end
  234. event["endTurn"]()
  235. end,
  236. function()
  237. addNotification(1,0,"機會: 房子維修費\n每棟房子付$250\n每棟旅館付$1000",nil)
  238. for i,v in pairs (player[turn].property) do
  239. if tableInfo[v].house == 5 then
  240. pay(turn, 2000)
  241. else
  242. pay(turn, tableInfo[v].house*250)
  243. end
  244. end
  245. event["endTurn"]()
  246. end,
  247. function()
  248. addNotification(1,0,"機會: 前往最接近車站並支付雙倍租金\n如果沒人擁有則可購買\n經過起點能獲得$2000",nil)
  249. local station = {6,16,26,36}
  250. local min = math.abs(station[1] - player[turn].location)
  251. if min > 20 then
  252. min = 40 - min
  253. end
  254. local des = 1
  255. for i = 2, 4 do
  256. local temp = math.abs(station[i] - player[turn].location)
  257. if temp > 20 then
  258. temp = 40 - min
  259. end
  260. if temp <= min then
  261. min = temp
  262. des = i
  263. end
  264. end
  265. if player[turn].location < station[des] then
  266. pay(turn, -2000)
  267. end
  268. player[turn].location = station[des]
  269. updateLocation(turn)
  270. action(des)
  271. action(des)
  272. end,
  273. function()
  274. addNotification(1,0,"機會: 前往九龍塘車站\n經過起點能獲得$2000",nil)
  275. pay(turn, -2000)
  276. player[turn].location = 6
  277. updateLocation(turn)
  278. action(6)
  279. end,
  280. function()
  281. addNotification(1,0,"機會: 前往彌敦道\n經過起點能獲得$2000",nil)
  282. if player[turn].location > 12 then
  283. pay(turn, -2000)
  284. end
  285. player[turn].location = 12
  286. updateLocation(turn)
  287. action(12)
  288. end,
  289. function()
  290. addNotification(1,0,"機會: 直達山頂",nil)
  291. player[turn].location = 40
  292. updateLocation(turn)
  293. action(40)
  294. end,
  295. function()
  296. addNotification(1,0,"機會: 直達起點\n可獲得$2000",nil)
  297. pay(turn, -2000)
  298. player[turn].location = 1
  299. updateLocation(turn)
  300. action(1)
  301. end,
  302. function()
  303. addNotification(1,0,"機會: 直達藍塘道\n經過起點可獲得$2000",nil)
  304. if player[turn].location > 25 then
  305. pay(turn, -2000)
  306. end
  307. player[turn].location = 25
  308. updateLocation(turn)
  309. action(25)
  310. end,
  311. function()
  312. addNotification(1,0,"機會: 前往最接近公共事業並支付100倍租金\n如果沒人擁有則可購買\n經過起點能獲得$2000",nil)
  313. local station = {13,29}
  314. local min = math.abs(station[1] - player[turn].location)
  315. if min > 20 then
  316. min = 40 - min
  317. end
  318. local des = 1
  319. local min2 = math.abs(station[2] - player[turn].location)
  320. if min2 > 20 then
  321. min2 = 40 - min2
  322. end
  323. if min2 <= min then
  324. des = 2
  325. end
  326. if player[turn].location < station[des] then
  327. pay(turn, -2000)
  328. end
  329. player[turn].location = station[des]
  330. updateLocation(turn)
  331. action(des)
  332. action(des)
  333. end,
  334. function()
  335. addNotification(1,0,"機會: 後退3格",nil)
  336. player[turn].location = player[turn].location - 3
  337. updateLocation(turn)
  338. action(player[turn].location)
  339. end,
  340. function()
  341. addNotification(1,0,"機會: 物業供款完畢\n領取$1500",nil)
  342. pay(turn, -1500)
  343. event["endTurn"]()
  344. end,
  345. function()
  346. addNotification(1,0,"機會: 交稅$150",nil)
  347. pay(turn, 150)
  348. event["endTurn"]()
  349. end,
  350. }
  351.  
  352. local welfare = {
  353. function() addNotification(1,0,"公益福利: 聖誕基金獲得$1000",nil) pay(turn, -1000) event["endTurn"]() end,
  354. function() addNotification(1,0,"公益福利: 選美亞軍獲得$100",nil) pay(turn, -100) event["endTurn"]() end,
  355. function() addNotification(1,0,"公益福利: 出售股票獲得$450",nil) pay(turn, -450) event["endTurn"]() end,
  356. function() addNotification(1,0,"公益福利: 直達起點\n(可領取$2000)",nil) pay(turn, -2000) player[turn].location=1 updateLocation(turn) action(1) end,
  357. function() addNotification(1,0,"公益福利: 入息稅還款獲得$200",nil) pay(turn, -200) event["endTurn"]() end,
  358. function() addNotification(1,0,"公益福利: 繼承財產獲得$1000",nil) pay(turn, -1000) event["endTurn"]() end,
  359. function() addNotification(1,0,"公益福利: 支付住院費$1000",nil) pay(turn, 1000) event["endTurn"]() end,
  360. function()
  361. addNotification(1,0,"公益福利: 道路維修\n每棟房子付$400\n每棟旅館付$1150",nil)
  362. for i,v in pairs (player[turn].property) do
  363. if tableInfo[v].house == 5 then
  364. pay(turn, 2750)
  365. else
  366. pay(turn, tableInfo[v].house*400)
  367. end
  368. end
  369. event["endTurn"]()
  370. end,
  371. function() addNotification(1,0,"公益福利: 領取養老金$1000",nil) pay(turn, -1000) event["endTurn"]() end,
  372. function() addNotification(1,0,"公益福利: 交學費$1500",nil) pay(turn, 1500) event["endTurn"]() end,
  373. function() addNotification(1,0,"公益福利: 收取服務費$250",nil) pay(turn, -250) event["endTurn"]() end,
  374. function() addNotification(1,0,"公益福利: 支付住院費$1000",nil) pay(turn, 1000) event["endTurn"]() end,
  375. function() addNotification(1,0,"公益福利: 支付醫藥費$500",nil) pay(turn, 500) event["endTurn"]() end,
  376. function() addNotification(1,0,"公益福利: 支付住院費$1000",nil) pay(turn, 1000) event["endTurn"]() end,
  377. function() addNotification(1,0,"公益福利: 銀行疏忽 領取$2000",nil) pay(turn, -2000) event["endTurn"]() end,
  378. function()
  379. addNotification(1,0,"公益福利: 即時入獄\n不准領取$2000",nil)
  380. player[turn].location = 11
  381. updateLocation(turn)
  382. action(31)
  383. end,
  384. function()
  385. addNotification(1,0,"公益福利: 向每人收取$500",nil)
  386. for i,v in pairs (order) do
  387. if v ~= turn then
  388. pay(v, 500, turn)
  389. end
  390. end
  391. event["endTurn"]()
  392. end,
  393. }
  394.  
  395. function action(i)
  396. if i == 31 then
  397. addDescription(turn, "", "入獄了")
  398. tfm.exec.movePlayer(turn, 730, 155)
  399. player[turn].location = 11
  400. player[turn].inJail = true
  401. player[turn].jailCounter = 3
  402. updateLocation(turn)
  403. event["endTurn"]()
  404. elseif i % 10 == 1 then
  405. event["endTurn"]()
  406. elseif i == 5 then
  407. addDescription(turn, "", "正選擇支付方法")
  408. addNotification(-1, 1, "支付$2000(是)\n 支付10%(否)", turn)
  409. elseif i == 39 then
  410. pay(turn, 750)
  411. event["endTurn"]()
  412. elseif i == 3 or i == 18 or i == 34 then
  413. welfare[math.random(#welfare)]()
  414. elseif i == 8 or i == 23 or i == 37 then
  415. chance[math.random(#chance)]()
  416. elseif i == 13 or i == 29 then
  417. if tableInfo[i].owner == nil then
  418. addNotification(0, 1, "是否購買這片土地?", turn)
  419. elseif tableInfo[i].owner and tableInfo[i].owner ~= turn then
  420. if tableInfo[13].owner == tableInfo[29].owner then
  421. pay(turn, tableRent[player[turn].location][2](dice1+dice2))
  422. else
  423. pay(turn, tableRent[player[turn].location][1](dice1+dice2))
  424. end
  425. end
  426. event["endTurn"]()
  427. else
  428. if tableInfo[i].owner == nil then
  429. addNotification(0, 1, "是否購買這片土地?", turn)
  430. else
  431. if tableInfo[i].owner == turn then
  432. if not rule.originMode then
  433. if tableRent[i][6] then
  434. addNotification(1,0, "你現在能夠建築\n酒店需要4房子", turn)
  435. canBuild = true
  436. end
  437. end
  438. elseif not tableInfo[i].mortgaged then
  439. if not player[tableInfo[i].owner].inJail or (rule.originMode and player[tableInfo[i].owner].inJail) then
  440. addDescription(turn, tableInfo[i].owner.."向", "\n收取租金: "..tableInfo[i].charge)
  441. pay(turn, tableInfo[i].charge, tableInfo[i].owner)
  442. elseif player[tableInfo[i].owner].inJail then
  443. addDescription(tableInfo[i].owner, "抵押了的地", "無法收租")
  444. end
  445. end
  446. event["endTurn"]()
  447. end
  448. end
  449. displayInfo(i)
  450. end
  451.  
  452. function addDescription(name, txt1, txt2)
  453. if txt1 == nil then txt1="" end
  454. if txt2 == nil then txt2="" end
  455. ui.addTextArea(-2 ,"<B><p align= \"center\"><font size = \"25\" color=\"#FFFFFF\">"..txt1..name..txt2.."</font></p>",nil,0,-70,800,100,0,0,0,0.5,1)
  456. end
  457.  
  458. function addMortgageButton(name)
  459. ui.addTextArea(-3, "<J><font size = \"40\"><p align = \"center\"><a href =\"event:".."startMortgage".."\">抵押</a></font></p>", name, 250, 350, 90, 45, 0x1, 0, 0.5, true)
  460. end
  461.  
  462. function addNotification(id, type, txt, name)
  463. ui.addPopup(id, type, "<p align=\"center\">"..txt.."</p>" , name, 560, 240, 200, false)
  464. end
  465.  
  466. function addRuleConfig()
  467. local txt = "<p align=\"center\"><a href=\"event:ruleConfig\">".."更換模式".."</a></p>"
  468. ui.addTextArea(-9, txt, nil, 5, 35, 150, 200, 0x1, 0, 0.5, true)
  469. end
  470.  
  471. function bankrup(name, nextTurn)
  472. ui.removeTextArea(-3) --mortgage button
  473. ui.removeTextArea(-5) --endTurn
  474. addDescription(name,"","破產了")
  475. if pay2target then
  476. for i,v in pairs (player[name].property) do
  477. tableInfo[v].owner = pay2target
  478. table.insert(player[pay2target].property,v)
  479. end
  480. else
  481. for i,v in pairs (player[name].property) do
  482. tableInfo[v].owner = nil
  483. tableInfo[v].alpha = 0.7
  484. end
  485. end
  486.  
  487. player[name].property = nil
  488.  
  489. --starting with more than 1 player
  490. if #order == 2 then
  491. local c = (turn == name) and 2 or 1
  492. addDescription(order[c], "其他人全破產了,", "勝利了(撒花")
  493. else
  494. local c = 1
  495. for i,v in pairs (order) do
  496. if v == name then
  497. c = i
  498. end
  499. end
  500. table.remove(order, c)
  501.  
  502. if nextTurn then
  503. stillNext = true
  504. countTime(5,"nextTurn")
  505. end
  506. end
  507. end
  508.  
  509. function build(id)
  510. if tableInfo[id].house < 5 then
  511. if originMode then
  512. if series(id, turn) then
  513. if player[turn].money < tableRent[id][6] then
  514. addNotification(1,0,"你沒有足夠金錢",turn)
  515. else
  516. if rule.originMode then
  517. for i,v in pairs (tableRent[tableInfo[id].color]) do
  518. if tableInfo[id].house + 1 - tableInfo[v].house > 1 then
  519. addNotification(1,0,"相同系列的屋子必須平均",turn)
  520. break
  521. end
  522. end
  523. end
  524. pay(turn, tableRent[id][6])
  525. tableInfo[id].house = tableInfo[id].house + 1
  526. tableInfo[id].charge = tableRent[id][tableInfo[id].house]
  527. updateBlock(id)
  528. buildHouse(id)
  529. end
  530. else
  531. addNotification(1,0,"需要完整系列",turn)
  532. end
  533. else
  534. if tableInfo[id].owner == turn and player[turn].location == id and canBuild then
  535. pay(turn, tableRent[id][6])
  536. tableInfo[id].house = tableInfo[id].house + 1
  537. tableInfo[id].charge = tableRent[id][tableInfo[id].house]
  538. updateBlock(id)
  539. buildHouse(id)
  540. else
  541. addNotification(1,0,"上一輪你沒有擁有這塊地\n 或你不在此地上",turn)
  542. end
  543. end
  544. else
  545. addNotification(1,0,"你無法在這裡建造更多屋子",turn)
  546. end
  547. end
  548.  
  549. function buildBlock()
  550. local id = 1
  551. local t = {x = -109, y = -9}
  552.  
  553. updateBlock(id, t.x, t.y)
  554. table.insert(coor,{x = t.x, y = t.y})
  555.  
  556. t.x = 6
  557. t.y = 30
  558. for i = 2,10 do
  559. id = id +1
  560. updateBlock(id, t.x, t.y)
  561. table.insert(coor,{x = t.x, y = t.y})
  562. t.x = t.x+88
  563. end
  564.  
  565. t.x = 804
  566. t.y = -9
  567. id = id +1
  568. updateBlock(id, t.x, t.y)
  569. table.insert(coor,{x = t.x, y = t.y})
  570.  
  571. t.x = 814
  572. t.y = 100
  573. for i = 12,20 do
  574. id = id +1
  575. updateBlock(id, t.x, t.y)
  576. table.insert(coor,{x = t.x, y = t.y})
  577. t.y = t.y+55
  578. end
  579.  
  580. t.x = 807
  581. t.y = 598
  582. id = id +1
  583. updateBlock(id, t.x, t.y)
  584. table.insert(coor,{x = t.x, y = t.y})
  585.  
  586. t.x = 716
  587. t.y = 607
  588. for i = 22,30 do
  589. id = id +1
  590. updateBlock(id, t.x, t.y)
  591. table.insert(coor,{x = t.x, y = t.y})
  592. t.x = t.x-88
  593. end
  594.  
  595. t.x = -103
  596. t.y = 598
  597. id = id +1
  598. updateBlock(id, t.x, t.y)
  599. table.insert(coor,{x = t.x, y = t.y})
  600.  
  601. t.x = -95
  602. t.y = 539
  603. for i = 32,40 do
  604. id = id +1
  605. updateBlock(id, t.x, t.y)
  606. table.insert(coor,{x = t.x, y = t.y})
  607. t.y = t.y-55
  608. end
  609. end
  610.  
  611. function buildHouse(i)
  612. local num = tableInfo[i].house
  613. local color = 0xad1900 --red for house
  614. if num == 5 then
  615. color = 0x006624 --green for hotel
  616. end
  617. ui.addTextArea(i*100+tableInfo[i].house, "", nil, coor[i].x + (num*12) , coor[i].y + 2, 5, 5, color, 1, 1)
  618. end
  619.  
  620. function countTime(s , id)
  621. tfm.exec.setGameTime(s)
  622. eventID = id
  623. beginClock = true
  624. end
  625.  
  626. function displayInfo(i, name)
  627. local header = "<font size = \"30\" color=\"#000000\"><p align= \"center\">"..tableInfo[i].name.."</p></font>"
  628.  
  629. local txt = {}
  630. if tableInfo[i].price then
  631. if tableRent[i][0] == nil then
  632. txt = {
  633. "<font size = \"12\" color=\"#000000\">",
  634. "<p align= \"center\">",
  635. "\n\n擁有者: "..(tableInfo[i].owner or ""),
  636. "\n\n擁有一項公共事業時,\n其租值是骰子點數40倍。",
  637. "\n擁有兩項公共事業時,\n 其租值是骰子點數100倍。",
  638. "\n\n\n 抵押 : "..tableInfo[i].mortgageValue.."</p></font>"
  639. }
  640. elseif tableRent[i][6] == nil then
  641. txt = {
  642. "<font size = \"12\" color=\"#000000\">",
  643. "<p align= \"center\">",
  644. "\n\n擁有者:"..(tableInfo[i].owner or ""),
  645. "\n租金:"..tableRent[i][0].."</p>",
  646. "\n\n 擁有兩個車站:"..tableRent[i][1],
  647. "\n 擁有三個車站:"..tableRent[i][2],
  648. "\n 擁有四個車站:"..tableRent[i][3],
  649. "\n\n 抵押:"..tableInfo[i].mortgageValue.."</font>"
  650. }
  651. else
  652. txt = {
  653. "<font size = \"12\" color=\"#000000\">",
  654. "<p align= \"center\">\n",
  655. " 擁有者: "..(tableInfo[i].owner or ""),
  656. "\n 租金: "..tableRent[i][0].."</p>",
  657. "\n 擁有1所房子:"..tableRent[i][1],
  658. "\n 擁有2所房子:"..tableRent[i][2],
  659. "\n 擁有3所房子:"..tableRent[i][3],
  660. "\n 擁有4所房子:"..tableRent[i][4],
  661. "\n 擁有旅館:"..tableRent[i][5],
  662. "\n 抵押:"..tableInfo[i].mortgageValue,
  663. "\n 每間房子造價:"..tableRent[i][6],
  664. "\n 旅館造價(需要4房子):"..tableRent[i][6],
  665. "\n\n 擁有同一色系的空地租金雙倍</font>",
  666. "\n <U><p align= \"center\"><a href=\"event:"..(i+40).."\">建屋</a></p>"
  667. }
  668. end
  669.  
  670. local txt_info = ""
  671. for i,v in pairs (txt) do
  672. txt_info = txt_info..v
  673. end
  674. ui.addTextArea(-7, txt_info, name, 10, 140, 200, 230, white, 0x000000, 1, true)
  675. else
  676. ui.removeTextArea(-7)
  677. end
  678. ui.addTextArea(-6, header, name, 10, 90, 200, 55, tableInfo[i].color, 0x000000, 1, true)
  679. ui.addTextArea(-8, "<B><a href=\"event:x\"><font size=\"10\">X</font></a>", name, 10, 90, 10, 10, tableInfo[i].color, 0x000001, 0.5, true)
  680. end
  681.  
  682. function eventChatCommand(name,message)
  683. if message == "join" then
  684. if player[name] == nil then
  685. numPlayer = numPlayer + 1
  686. table.insert(order,name)
  687. player[name]={
  688. backgroundColor = math.random(0,0xFFFFFF),
  689. boarderColor = math.random(0,0xFFFFFF),
  690. money = 15000,
  691. location = 1,
  692. property = {},
  693. inJail = false,
  694. jailCounter = 0,
  695. id = numPlayer * 100
  696. }
  697. tfm.exec.setPlayerScore(name, player[name].money, false)
  698. end
  699. elseif message == "new" then
  700. ui.removeTextArea(-9)
  701. initialize()
  702. elseif message == "help" then
  703. local txt = help
  704. ui.addPopup(2, 0, txt, name, 180, 20, 460, true)
  705. elseif message == "assets" then
  706. if player[name] then
  707. local assets = 0
  708. for i,v in pairs (player[name].property) do
  709. assets = assets + (tableInfo[v].mortgaged) and 0 or tableInfo[v].price
  710. assets = assets + (tableInfo[v].house) and tableInfo[v].house * tableRent[v][6] or 0
  711. end
  712. assets = assets + player[name].money
  713. addNotification(1,0, "你的資產: "..assets, name)
  714. end
  715. end
  716. end
  717.  
  718. function eventLoop(time, remaining)
  719. if beginClock then
  720. if remaining > 0 then
  721. local displayTime = math.floor(remaining / 1000)
  722. ui.addTextArea(-1,"<B><p align= \"center\"><font size = \"50\" color=\"#FFFFFF\">"..displayTime.."</font></p>",nil,300,150,200,100,0,0,0,0.5,1)
  723. else
  724. ui.addTextArea(-1,"<B><p align= \"center\"><font size = \"50\" color=\"#FFFFFF\">0</font></p>",nil,300,150,200,100,0,0,0,0.5,1)
  725. beginClock = false
  726. event[eventID]()
  727. end
  728. else
  729. ui.removeTextArea(-1,nil)
  730. end
  731.  
  732. if enableDice and diceAnimation > 0 then
  733. dice1 = math.random(1,6)
  734. dice2 = math.random(1,6)
  735. updateDice(dice1,dice2)
  736. diceAnimation = diceAnimation - 1
  737. elseif enableDice then
  738. locationAnimation = true
  739. walkingStep = dice1 + dice2
  740. enableDice = false
  741. end
  742.  
  743. if locationAnimation and walkingStep > 0 and diceAnimation == 0 then
  744. if player[turn].inJail then
  745. if dice1 == dice2 then
  746. addDescription(turn, "", "成功擲出相同點數出獄")
  747. exitJail(turn)
  748. locationAnimation = false
  749. walkingStep = 0
  750. rollDice(turn)
  751. end
  752. else
  753. if rule.originMode and dice1 == dice2 then
  754. stillNext = true
  755. end
  756. player[turn].location = player[turn].location + 1
  757. if player[turn].location == 41 then
  758. pay(turn, -2000)
  759. player[turn].location = 1
  760. end
  761. walkingStep = walkingStep - 1
  762. updateLocation(turn)
  763. end
  764. elseif locationAnimation then
  765. locationAnimation = false
  766. action(player[turn].location)
  767. end
  768. end
  769.  
  770. function eventPlayerDied(name)
  771. tfm.exec.respawnPlayer(name)
  772. end
  773.  
  774. function eventPlayerLeft(name)
  775. if player[name] then
  776. bankrup(name, name==turn)
  777. end
  778. end
  779.  
  780. function eventPopupAnswer(id, name, ans)
  781. if name == turn then
  782. if id == 0 then
  783. if ans == "yes" then
  784. if player[name].money >= tableInfo[player[name].location].price then
  785. pay(name, tableInfo[player[name].location].price, nil)
  786. table.insert(player[name].property, player[name].location)
  787. tableInfo[player[name].location].alpha = 1.0
  788. tableInfo[player[name].location].owner = name
  789. tableInfo[player[name].location].charge = tableRent[player[name].location][0]
  790. if player[name].location % 10 == 6 then
  791. local count = -1
  792. for i,v in pairs (player[name].property) do
  793. if v % 10 == 6 then
  794. count = count + 1
  795. end
  796. end
  797. for i,v in pairs (player[name].property) do
  798. if v % 10 == 6 then
  799. tableInfo[v].charge = tableRent[v][count]
  800. end
  801. end
  802. elseif series(player[name].location, turn) then
  803. for i,v in pairs (tableRent[tableInfo[player[name].location].color]) do
  804. local charge = tableInfo[v].charge
  805. tableInfo[v].charge = (tableInfo[v].house==0) and charge * 2 or charge
  806. updateBlock(v)
  807. end
  808. end
  809. updateBlock(player[name].location)
  810. addDescription(name, "", "購買了"..tableInfo[player[name].location].name)
  811. else
  812. addNotification(0, 1, "你的金錢不夠\n請先抵押\n是否購買這片土地?", turn)
  813. end
  814. else
  815. addDescription(name, "", "選擇路過這片土地")
  816. end
  817. event["endTurn"]()
  818. elseif id == -1 then
  819. if ans == "yes" then
  820. addDescription(name, "", "選擇支付$2000")
  821. pay(name, 2000)
  822. else
  823. addDescription(name, "", "選擇支付10%金錢")
  824. pay(name, math.floor(player[name].money*0.1))
  825. end
  826. event["endTurn"]()
  827. elseif id == -3 then
  828. if ans == "yes" then
  829. pay(name, 500)
  830. exitJail(name)
  831. addDescription(name,"","出獄了")
  832. else
  833. player[name].jailCounter = player[name].jailCounter - 1
  834. addDescription(name,"","如果擲出相同點數可以出獄")
  835. end
  836. rollDice(name)
  837. event["endTurn"]()
  838. end
  839. end
  840. end
  841.  
  842. function eventTextAreaCallback(id, name, callback)
  843. if callback == "ruleConfig" then
  844. rule.originMode = not rule.originMode
  845. addRuleConfig()
  846. elseif callback == "roll" then
  847. enableDice = true
  848. diceAnimation = 4
  849. ui.removeTextArea(id)
  850. elseif callback == "endTurn" then
  851. if player[name].money < 0 then
  852. mortgage(name)
  853. addNotification(1,0,"抵押後為負資產即時破產",name)
  854. else
  855. ui.removeTextArea(-4*player[name].id) --done button
  856. ui.removeTextArea(-5*player[name].id) --table
  857. countTime(5,"nextTurn")
  858. end
  859. ui.removeTextArea(-300)
  860. ui.removeTextArea(-3) --mortgage button
  861. ui.removeTextArea(id)
  862. elseif callback == "x" then
  863. ui.removeTextArea(-6)
  864. ui.removeTextArea(-7)
  865. ui.removeTextArea(-8)
  866. elseif callback == "startMortgage" then
  867. mortgage(name)
  868. elseif callback == "mortgage4Normal" then
  869. ui.removeTextArea(id) --done button
  870. ui.removeTextArea(-5*player[name].id) --table
  871. if player[name].money < 0 then
  872. bankrup(name)
  873. elseif pay2target then
  874. pay(pay2target, -pay2money)
  875. else
  876. addMortgageButton(name)
  877. end
  878. elseif tonumber(callback) then
  879. local i = tonumber(callback)
  880. if i < 0 then
  881. if tableInfo[-i].house == 0 then
  882. tableInfo[-i].mortgaged = true
  883. tableInfo[-i].alpha = 0.7
  884. pay(name, -tableInfo[-i].mortgageValue)
  885. else
  886. ui.removeTextArea(-i * 100 + tableInfo[-i].house)
  887. tableInfo[-i].house = tableInfo[-i].house - 1
  888. if tableInfo[-i].house == 0 and series(-i, name) then
  889. tableInfo[-i].charge = tableRent[-i][0] * 2
  890. else
  891. tableInfo[-i].charge = tableRent[-i][tableInfo[-i].house]
  892. end
  893. pay(name, -tableRent[-i][6]/2)
  894. end
  895. updateBlock(-i)
  896. for n = 1, tableInfo[-i].house do
  897. ui.updateTextArea(-i * 100 + n, "", nil)
  898. end
  899. mortgage(name)
  900. elseif i > 100 then
  901. if player[name].money >= math.floor(tableInfo[(i/100)].mortgageValue) then
  902. pay(name,math.floor(tableInfo[(i/100)].mortgageValue * 1.1))
  903. tableInfo[(i/100)].mortgaged = false
  904. tableInfo[(i/100)].alpha = 1.0
  905. updateBlock(i/100)
  906. mortgage(name)
  907. else
  908. addNotification(1, 0, "你的金錢不夠", name)
  909. end
  910. elseif i > 40 then
  911. if name == turn then
  912. build(i-40)
  913. else
  914. addNotification(1,0,"現在不是你的回合",name)
  915. end
  916. else
  917. displayInfo(i, name)
  918. end
  919. end
  920. end
  921.  
  922. function exitJail(name)
  923. tfm.exec.movePlayer(turn, 400, 100)
  924. player[turn].inJail = false
  925. player[turn].jailCounter = 0
  926. end
  927.  
  928. function initialize()
  929. period = 0
  930. eventID = 0
  931. beginClock = false
  932. player = {}
  933. order = {}
  934. coor = {}
  935. turn = nil
  936. numPlayer = 0
  937. dice1 = 1
  938. dice2 = 1
  939. diceAnimation = 0
  940. walkingStep = 0
  941. locationAnimation = false
  942. for i,v in pairs (tableInfo) do
  943. if v.price then
  944. v.alpha = 0.7
  945. v.owner = nil
  946. v.house = 0
  947. v.charge = 0
  948. v.mortgage = false
  949. end
  950. end
  951. buildBlock()
  952. addDescription("遊戲即將開始", "!join ", "")
  953. countTime(10,"start")
  954. end
  955.  
  956. function mortgage(name)
  957. ui.removeTextArea(-3)
  958. local header = "<p align=\"center\">完成抵押依然為負資產即進入破產階段</p>\n"
  959. local txt = " 可抵押的地契:\n"
  960. local txt_r = "\n 可贖回的地:\n"
  961. for i,v in pairs (player[name].property) do
  962. if tableInfo[v].mortgaged then
  963. txt_r = txt_r.." <a href =\"event:"..(v*100).."\">"..tableInfo[v].name.." 贖回$"..math.floor(tableInfo[v].mortgageValue*1.1).."</a>\n"
  964. elseif tableInfo[v].house == 0 then
  965. txt = txt.." <a href =\"event:"..(-v).."\">"..tableInfo[v].name.." 抵押$"..tableInfo[v].mortgageValue.."</a>\n"
  966. else
  967. local charge = tableRent[v][6]/2
  968. txt = txt.." <a href =\"event:"..(-v).."\">"..tableInfo[v].name.." 拆除屋子/旅館$"..charge.."</a>\n"
  969. end
  970. end
  971. addDescription(name, "", "正在出售物業")
  972. ui.addTextArea(-4*player[name].id,"<J><font size = \"40\"><p align=\"center\"><a href =\"event:".."mortgage4Normal".."\">完成抵押</a></p></font>", name, 570, 350, 200, 45, 0x01, 0x000000, 0.5, true)
  973. ui.addTextArea(-5*player[name].id, header..txt..txt_r, name, 250, 30, 300, 370, 0x1, 0x000000, 0.8, true)
  974. end
  975.  
  976. function pay(name, money, target)
  977. local gainMoney = -money
  978. addDescription(name, (target) and target.."接收來自" or "", (money >= 0) and "支付$"..money or "獲取$"..gainMoney)
  979. player[name].money = player[name].money - money
  980. tfm.exec.setPlayerScore(name, player[name].money, false)
  981. if target then
  982. if player[name].money >= 0 then
  983. player[target].money = player[target].money + money
  984. tfm.exec.setPlayerScore(target, player[target].money, false)
  985. else
  986. pay2target = target
  987. pay2money = money
  988. end
  989. end
  990. end
  991.  
  992. function randomOrder(o)
  993. if o then
  994. local t = {}
  995. local count = 0
  996. for i,v in pairs (o) do
  997. count = count + 1
  998. end
  999. if count ~= 0 then
  1000. for i = 1, count do
  1001. local c = math.random(#o)
  1002. table.insert(t,o[c])
  1003. table.remove(o, c)
  1004. end
  1005. for i,v in pairs (t) do
  1006. table.insert(o,v)
  1007. end
  1008. end
  1009. end
  1010. end
  1011.  
  1012. function rollDice(name)
  1013. addDescription(name, "現在是", "的回合!")
  1014. addMortgageButton(name)
  1015. ui.addTextArea(-300, "<J><font size = \"40\"><p align = \"center\"><a href =\"event:".."roll".."\">投骰</a></font></p>", name, 450, 350, 90, 45, 0x01, 0x000000, 0.5, true)
  1016. end
  1017.  
  1018. function series(id, name)
  1019. if tableRent[tableInfo[id].color] and tableInfo[id].color ~= white then
  1020. table.sort(player[name].property)
  1021. local j = 0
  1022. for i,v in pairs (player[name].property) do
  1023. if tableRent[tableInfo[id].color][j+1] < v then
  1024. return false
  1025. elseif tableRent[tableInfo[id].color][j+1] == v then
  1026. j = j + 1
  1027. if j == #tableRent[tableInfo[id].color] then
  1028. return true
  1029. end
  1030. end
  1031. end
  1032. end
  1033. return false
  1034. end
  1035.  
  1036. function updateBlock(id, x, y)
  1037. if x == nil or y==nil then
  1038. x = coor[id].x
  1039. y = coor[id].y
  1040. end
  1041.  
  1042. local size = 10
  1043.  
  1044. if id % 10 == 1 then size = 20 end
  1045. local txt = "<p align=\"center\"><font size=\""..size.."\" >"
  1046. local txt_land = "<a href=\"event:"..id.."\">"..tableInfo[id].name.."</a>"
  1047. if tableInfo[id].owner then
  1048. local charge_txt = (tableInfo[id].charge == nil) and "" or tableInfo[id].charge
  1049. txt_land = txt_land.."\n<font size=\"8\">"..tableInfo[id].owner.."</font>\n租金:"..charge_txt
  1050. elseif tableInfo[id].price then
  1051. txt_land = txt_land.."($"..tableInfo[id].price..")"
  1052. end
  1053.  
  1054. if tableRent[id] then
  1055. txt = txt..txt_land.."</font></p>"
  1056. else
  1057. txt = txt..tableInfo[id].name.."</font></p>"
  1058. end
  1059.  
  1060. txt = (id >= 11 and id <= 30 and id ~= 21) and "<BV>"..txt or "<O>"..txt
  1061.  
  1062. if id % 10 == 1 then
  1063. ui.addTextArea(id,txt,nil,x,y,start_width,start_height,tableInfo[id].color,0,tableInfo[id].alpha,1)
  1064. else
  1065. ui.addTextArea(id,txt,nil,x,y,block_width,block_height,tableInfo[id].color,0,tableInfo[id].alpha,1)
  1066. end
  1067.  
  1068. for i,v in pairs (order) do
  1069. if player[v].location == id then
  1070. updateLocation(v)
  1071. end
  1072. end
  1073. end
  1074.  
  1075. function updateDice(d1, d2)
  1076. ui.addTextArea(-100, "<B><font size = \"75\"><p align = \"center\">".. d1.."</font></p>", nil, 290, 240, 100, 100, 0x324650, 0x000000, 0.4, true)
  1077. ui.addTextArea(-200, "<B><font size = \"75\"><p align = \"center\">".. d2.."</font></p>", nil, 410, 240, 100, 100, 0x324650, 0x000000, 0.4, true)
  1078. end
  1079.  
  1080. function updateLocation(name)
  1081. local x = coor[player[name].location].x + math.random(20,60)
  1082. local y = coor[player[name].location].y + math.random(30,40)
  1083. ui.addTextArea(player[name].id, " ", nil, x, y, 10, 10, player[name].backgroundColor, player[name].boarderColor, 1,1)
  1084. end
  1085.  
  1086. --addRuleConfig()
  1087. addDescription("!new 開始遊戲\n !help 查看規則")
  1088. tfm.exec.disableAfkDeath(true)
  1089. tfm.exec.disableAutoScore(true)
  1090. tfm.exec.disableAutoShaman(true)
  1091. tfm.exec.disableAutoNewGame(true)
  1092. tfm.exec.disableMortCommand(true)
  1093. tfm.exec.newGame(7555054)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement