Advertisement
Guest User

tfm_monopoly 1.0.1

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