Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local block_width, block_height, start_width, start_height = 80, 50, 100, 100
- local purple, white, lightblue, pink = 0xa417ba, 0xffffff, 0x2f2f0, 0xfeafe4
- local defaultcolor, jailcolor= 0xc7fafa,0xf4a148
- local orange, red, yellow, green, darkblue = 0xfaa114, 0xfa2914, 0xfaf814, 0x14fa27, 0x1104dc
- local eventID, beginClock, enableDice, stillNext = 0, false, false, false
- local player, order, coor = {}, {}, {}
- local turn, pay2target, pay2money, justOwn = nil
- local numPlayer = 0
- local dice1, dice2, countET, extraTurn = 1, 1, 0, false
- local diceAnimation, walkingStep, locationAnimation = 0, 0, false
- math.randomseed(os.time())
- --[[
- addTextArea = {
- 1-40 = block
- -1 = clock
- -2 = addDescription
- -3 = mortgage button
- -4 = build button
- -5 = endTurn
- -6 = display header
- -7 = display info
- -8 = close info
- -9 = rules
- -100 = dice1
- -200 = dice2
- -300 = roll
- --independent
- -4*player[name].id = done mortgage
- -5*player[name].id = property table
- player[name].id + 9 = money effect
- player[name].id = player
- }
- addPopup = {
- 0 = buy
- -1 = 2000/10%
- -3 = jail 500
- -4 = !new
- 1 = notification
- 2 = help
- }
- --]]
- local event = {
- ["start"] =
- function()
- ui.removeTextArea(-2)
- randomOrder(order)
- if numPlayer > 0 then
- turn = order[1]
- for i,v in pairs (order) do
- updateLocation(v)
- tfm.exec.setNameColor(v,player[v].backgroundColor)
- end
- updateDice(dice1, dice2)
- rollDice(turn)
- else
- addDescription(numPlayer,"人數不足(",")\n !new 重新開始")
- ui.removeTextArea(-1)
- end
- end,
- ["endTurn"] =
- function()
- 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)
- end,
- ["nextTurn"] =
- function()
- if not stillNext then
- table.insert(order, order[1])
- table.remove(order, 1)
- end
- countTime(30,"nextTurn")
- turn = order[1]
- pay2target, pay2money, justOwn, stillNext = nil
- ui.removeTextArea(-3)
- ui.removeTextArea(-5)
- ui.removeTextArea(-300)
- addMortgageButton(turn)
- if player[turn].jailCounter > 0 then
- addDescription(turn, "", "考慮是否立即出獄")
- addNotification(-3, 1, "<p align=\"center\">支付$500立即出獄?</p>", turn)
- elseif player[turn].inJail then
- pay(turn, 500)
- addDescription(turn, "", "的刑期滿 支付$500出獄")
- exitJail(turn)
- rollDice(turn)
- else
- rollDice(turn)
- end
- end,
- }
- local help = [[
- 基本規則:
- -如到未被購買的土地,可以付錢買
- -如到已有人購買且沒有被抵押的土地,擁有者需收租
- -如出現「即時入獄」或擲三次點數相同骰子, 需即時入獄
- -如經過或停留起點時,銀行向玩家支付2000元
- 出獄方法:
- -擲到相同點數
- -在擲骰之前支付500元給銀行
- -刑期3回合屆滿後支付500元出獄
- 抵押:
- -該地必需沒有建築物。向銀行拿抵押的值同時不能收租
- -解押時需繳付10%手續費
- 破產:
- -玩家抵押後依然負資產即時破產
- -如果破產於一個對象, 該對象接收所有財產, 保留地契狀態
- 勝出遊戲:所有其他玩家破產後,餘下的就是贏家
- 自訂規則:
- -可交易: 不能借錢 交易收取10%手續費 集齊同一色系方能建屋 有額外回合
- -不可交易: 到達自己地上 能建屋一次 沒有額外回合]]
- local rule =
- {
- originMode = false
- --[[
- step_on_build = { value = true, name = "禁止交易 踩自己能地建屋", tableName = "step_on_build" },
- rent_prisoner = { value = false, name = "監禁時收租", tableName = "rent_prisoner" },
- average_build = { value = false, name = "系列屋子數量平均", tableName = "average_build" },
- extra_turn = { value = false, name = "點數相同獲得額外回合", tableName = "extra_turn" },
- --]]
- }
- local tableInfo = {
- {name="開始", price=nil, alpha=1, color=defaultcolor, mortgageValue=300},
- {name="長洲", price=600, alpha=0.7, color=purple, mortgageValue=300},
- {name="公益福利", price=nil,alpha=1, color=defaultcolor, mortgageValue=0},
- {name="屯門", price=600, alpha=0.7, color=purple, mortgageValue=300},
- {name="入息稅\n(付$2000或10%)", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="九龍塘車站", price=2000, alpha=0.7, color=white, mortgageValue=1000},
- {name="荃灣", price=1000, alpha=0.7, color=lightblue, mortgageValue=500},
- {name="機會", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="旺角", price=1000, alpha=0.7, color=lightblue, mortgageValue=500},
- {name="加連威老道", price=1200, alpha=0.7, color=lightblue, mortgageValue=600},
- {name="赤柱監獄(獄中或探訪)", price=nil, alpha=1, color=jailcolor, mortgageValue=0},
- {name="彌敦道", price=1400, alpha=0.7, color=pink, mortgageValue=700},
- {name="電燈公司", price=1500, alpha=0.7, color=white, mortgageValue=750},
- {name="馬鞍山", price=1400, alpha=0.7, color=pink, mortgageValue=700},
- {name="沙田", price=1600, alpha=0.7, color=pink, mortgageValue=800},
- {name="銅鑼灣車站", price=2000, alpha=0.7, color=white, mortgageValue=1000},
- {name="灣仔", price=1800, alpha=0.7, color=orange, mortgageValue=900},
- {name="公益福利", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="愉景灣", price=1800, alpha=0.7, color=orange, mortgageValue=900},
- {name="西貢", price=2000, alpha=0.7, color=orange, mortgageValue=1000},
- {name="免費泊車", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="山村道", price=2200, alpha=0.7, color=red, mortgageValue=1100},
- {name="機會", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="黃泥涌道", price=2200, alpha=0.7, color=red, mortgageValue=1100},
- {name="藍塘道", price=2400, alpha=0.7, color=red, mortgageValue=1200},
- {name="中環車站", price=2000, alpha=0.7, color=white, mortgageValue=1000},
- {name="干諾道中", price=2600, alpha=0.7, color=yellow, mortgageValue=1300},
- {name="皇后大道中", price=2600, alpha=0.7, color=yellow, mortgageValue=1300},
- {name="水務局", price=1500, alpha=0.7, color=white, mortgageValue=750},
- {name="德輔道中", price=2800, alpha=0.7, color=yellow, mortgageValue=1400},
- {name="入獄", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="羅便臣道", price=3000, alpha=0.7, color=green, mortgageValue=1500},
- {name="馬己仙峽道", price=3000, alpha=0.7, color=green, mortgageValue=1500},
- {name="公益福利", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="淺水灣", price=3200, alpha=0.7, color=green, mortgageValue=1600},
- {name="尖沙咀車站", price=2000, alpha=0.7, color=white, mortgageValue=1000},
- {name="機會", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="南灣", price=3500, alpha=0.7, color=darkblue, mortgageValue=2000},
- {name="薪俸稅\n(付$750)", price=nil, alpha=1, color=defaultcolor, mortgageValue=0},
- {name="山頂", price=4000, alpha=0.7, color=darkblue, mortgageValue=2000},
- }
- local tableRent = {
- -- [id] {rent(0 house),1 house,2 house,3 house, 4 house, hotel(5 house), each house, each hotel}
- [2] = {[0] = 20,[1] = 100,[2] = 300,[3] = 900,[4] = 1600,[5] = 2500,[6] = 500},
- [4] = {[0] = 40,[1] = 200,[2] = 600,[3] = 1800,[4] = 3200,[5] = 4500,[6] = 500},
- [6] = {[0] = 250,[1] = 500,[2] = 1000,[3] = 2000,},
- [7] = {[0] = 60,[1] = 300,[2] = 900,[3] = 2700,[4] = 4000,[5] = 5500,[6] = 500},
- [9] = {[0] = 60,[1] = 300,[2] = 900,[3] = 2700,[4] = 4000,[5] = 5500,[6] = 500},
- [10] = {[0] = 80,[1] = 400,[2] = 1000,[3] = 3000,[4] = 4500,[5] = 6000,[6] = 500},
- [12] = {[0] = 100,[1] = 500,[2] = 1500,[3] = 4500,[4] = 6250,[5] = 7500,[6] = 1000},
- [13] = {[1] = function (x) return x * 40 end,[2] = function (x) return x * 100 end},
- [14] = {[0] = 100,[1] = 500,[2] = 1500,[3] = 4500,[4] = 6250,[5] = 7500,[6] = 1000},
- [15] = {[0] = 120,[1] = 600,[2] = 1800,[3] = 5000,[4] = 7000,[5] = 9000,[6] = 1000},
- [16] = {[0] = 250,[1] = 500,[2] = 1000,[3] = 2000},
- [17] = {[0] = 140,[1] = 700,[2] = 2000,[3] = 5500,[4] = 7500,[5] = 9500,[6] = 1000},
- [19] = {[0] = 140,[1] = 700,[2] = 2000,[3] = 5500,[4] = 7500,[5] = 9500,[6] = 1000},
- [20] = {[0] = 160,[1] = 800,[2] = 2200,[3] = 6000,[4] = 8000,[5] = 10000,[6] = 1000},
- [22] = {[0] = 180,[1] = 900,[2] = 2500,[3] = 7000,[4] = 8750,[5] = 10500,[6] = 1500},
- [24] = {[0] = 180,[1] = 900,[2] = 2500,[3] = 7000,[4] = 8750,[5] = 10500,[6] = 1500},
- [25] = {[0] = 200,[1] = 1000,[2] = 3000,[3] = 7500,[4] = 9250,[5] = 11000,[6] = 1500},
- [26] = {[0] = 250,[1] = 500,[2] = 1000,[3] = 2000},
- [27] = {[0] = 220,[1] = 1100,[2] = 3300,[3] = 8000,[4] = 9750,[5] = 11500,[6] = 1500},
- [28] = {[0] = 220,[1] = 1100,[2] = 3300,[3] = 8000,[4] = 9750,[5] = 11500,[6] = 1500},
- [29] = {[1] = function(x) return x * 40 end,[2] = function(x) return x * 100 end},
- [30] = {[0] = 240,[1] = 1200,[2] = 3600,[3] = 8500,[4] = 10250,[5] = 12000,[6] = 1500},
- [32] = {[0] = 260,[1] = 1300,[2] = 3900,[3] = 9000,[4] = 11000,[5] = 12750,[6] = 2000},
- [33] = {[0] = 260,[1] = 1300,[2] = 3900,[3] = 9000,[4] = 11000,[5] = 12750,[6] = 2000},
- [35] = {[0] = 280,[1] = 1500,[2] = 4500,[3] = 10000,[4] = 12000,[5] = 14000,[6] = 2000},
- [36] = {[0] = 250,[1] = 500,[2] = 1000,[3] = 2000},
- [38] = {[0] = 350,[1] = 1750,[2] = 5000,[3] = 11000,[4] = 13000,[5] = 15000,[6] = 2000},
- [40] = {[0] = 500,[1] = 2000,[2] = 6000,[3] = 14000,[4] = 17000,[5] = 20000,[6] = 2000},
- [purple] = {2,4},
- [white] = {6,16,26,36},
- [orange] = {17,19,20},
- [lightblue] = {7,9,10},
- [pink] = {12,14,15},
- [red] = {22,24,25},
- [yellow] = {27,28,30},
- [green] = {32,33,35},
- [darkblue] = {38,40},
- }
- local chance = {
- function() addNotification(1,0,"機會: 即時入獄\n不准領取$2000",nil) action(31) end,
- function()
- addNotification(1,0,"機會: 當選董事局主席\n付每人$500",nil)
- for i,v in pairs (order) do
- if i ~= 1 then
- pay(turn, 500, v)
- end
- end
- event["endTurn"]()
- end,
- function() addNotification(1,0,"機會: 銀行紅利 $500",nil) pay(turn, -500) event["endTurn"]() end,
- function()
- addNotification(1,0,"機會: 房子維修費\n每棟房子付$250\n每棟旅館付$1000",nil)
- for i,v in pairs (player[turn].property) do
- if tableInfo[v].house == 5 then
- pay(turn, 2000)
- else
- pay(turn, tableInfo[v].house*250)
- end
- end
- event["endTurn"]()
- end,
- function()
- addNotification(1,0,"機會: 房子維修費\n每棟房子付$250\n每棟旅館付$1000",nil)
- for i,v in pairs (player[turn].property) do
- if tableInfo[v].house == 5 then
- pay(turn, 2000)
- else
- pay(turn, tableInfo[v].house*250)
- end
- end
- event["endTurn"]()
- end,
- function()
- addNotification(1,0,"機會: 前往最接近車站並支付雙倍租金\n如果沒人擁有則可購買\n經過起點能獲得$2000",nil)
- local station = {6,16,26,36}
- local min = math.abs(station[1] - player[turn].location)
- if min > 20 then
- min = 40 - min
- end
- local des = 1
- for i = 2, 4 do
- local temp = math.abs(station[i] - player[turn].location)
- if temp > 20 then
- temp = 40 - min
- end
- if temp <= min then
- min = temp
- des = i
- end
- end
- if player[turn].location < station[des] then
- pay(turn, -2000)
- end
- player[turn].location = station[des]
- updateLocation(turn)
- action(des)
- action(des)
- end,
- function()
- addNotification(1,0,"機會: 前往九龍塘車站\n經過起點能獲得$2000",nil)
- pay(turn, -2000)
- player[turn].location = 6
- updateLocation(turn)
- action(6)
- end,
- function()
- addNotification(1,0,"機會: 前往彌敦道\n經過起點能獲得$2000",nil)
- if player[turn].location > 12 then
- pay(turn, -2000)
- end
- player[turn].location = 12
- updateLocation(turn)
- action(12)
- end,
- function()
- addNotification(1,0,"機會: 直達山頂",nil)
- player[turn].location = 40
- updateLocation(turn)
- action(40)
- end,
- function()
- addNotification(1,0,"機會: 直達起點\n可獲得$2000",nil)
- pay(turn, -2000)
- player[turn].location = 1
- updateLocation(turn)
- action(1)
- end,
- function()
- addNotification(1,0,"機會: 直達藍塘道\n經過起點可獲得$2000",nil)
- if player[turn].location > 25 then
- pay(turn, -2000)
- end
- player[turn].location = 25
- updateLocation(turn)
- action(25)
- end,
- function()
- addNotification(1,0,"機會: 前往最接近公共事業並支付100倍租金\n如果沒人擁有則可購買\n經過起點能獲得$2000",nil)
- local station = {13,29}
- local min = math.abs(station[1] - player[turn].location)
- if min > 20 then
- min = 40 - min
- end
- local des = 1
- local min2 = math.abs(station[2] - player[turn].location)
- if min2 > 20 then
- min2 = 40 - min2
- end
- if min2 <= min then
- des = 2
- end
- if player[turn].location < station[des] then
- pay(turn, -2000)
- end
- player[turn].location = station[des]
- updateLocation(turn)
- action(des)
- action(des)
- end,
- function()
- addNotification(1,0,"機會: 後退3格",nil)
- player[turn].location = player[turn].location - 3
- updateLocation(turn)
- action(player[turn].location)
- end,
- function()
- addNotification(1,0,"機會: 物業供款完畢\n領取$1500",nil)
- pay(turn, -1500)
- event["endTurn"]()
- end,
- function()
- addNotification(1,0,"機會: 交稅$150",nil)
- pay(turn, 150)
- event["endTurn"]()
- end,
- }
- local welfare = {
- function() addNotification(1,0,"公益福利: 聖誕基金獲得$1000",nil) pay(turn, -1000) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 選美亞軍獲得$100",nil) pay(turn, -100) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 出售股票獲得$450",nil) pay(turn, -450) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 直達起點\n(可領取$2000)",nil) pay(turn, -2000) player[turn].location=1 updateLocation(turn) action(1) end,
- function() addNotification(1,0,"公益福利: 入息稅還款獲得$200",nil) pay(turn, -200) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 繼承財產獲得$1000",nil) pay(turn, -1000) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 支付住院費$1000",nil) pay(turn, 1000) event["endTurn"]() end,
- function()
- addNotification(1,0,"公益福利: 道路維修\n每棟房子付$400\n每棟旅館付$1150",nil)
- for i,v in pairs (player[turn].property) do
- if tableInfo[v].house == 5 then
- pay(turn, 2750)
- else
- pay(turn, tableInfo[v].house*400)
- end
- end
- event["endTurn"]()
- end,
- function() addNotification(1,0,"公益福利: 領取養老金$1000",nil) pay(turn, -1000) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 交學費$1500",nil) pay(turn, 1500) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 收取服務費$250",nil) pay(turn, -250) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 支付住院費$1000",nil) pay(turn, 1000) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 支付醫藥費$500",nil) pay(turn, 500) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 支付住院費$1000",nil) pay(turn, 1000) event["endTurn"]() end,
- function() addNotification(1,0,"公益福利: 銀行疏忽 領取$2000",nil) pay(turn, -2000) event["endTurn"]() end,
- function()
- addNotification(1,0,"公益福利: 即時入獄\n不准領取$2000",nil)
- player[turn].location = 11
- updateLocation(turn)
- action(31)
- end,
- function()
- addNotification(1,0,"公益福利: 向每人收取$500",nil)
- for i,v in pairs (order) do
- if v ~= turn then
- pay(v, 500, turn)
- end
- end
- event["endTurn"]()
- end,
- }
- function action(i)
- if i == 1 or i == 21 or i == 11 then
- event["endTurn"]()
- elseif i == 5 then
- addDescription(turn, "", "正選擇支付方法")
- addNotification(-1, 1, "支付$2000(是)\n 支付10%(否)", turn)
- elseif i == 39 then
- pay(turn, 750)
- event["endTurn"]()
- elseif i == 31 then
- addDescription(turn, "", "入獄了")
- tfm.exec.movePlayer(turn, 730, 155)
- player[turn].location = 11
- player[turn].inJail = true
- player[turn].jailCounter = 3
- updateLocation(turn)
- event["endTurn"]()
- elseif i == 3 or i == 18 or i == 34 then
- welfare[math.random(#welfare)]()
- elseif i == 8 or i == 23 or i == 37 then
- chance[math.random(#chance)]()
- elseif i == 13 or i == 29 then
- if tableInfo[i].owner == nil then
- addNotification(0, 1, "是否購買這片土地?", turn)
- elseif tableInfo[i].owner and tableInfo[i].owner ~= turn then
- if tableInfo[13].owner == tableInfo[29].owner then
- pay(turn, tableRent[player[turn].location][2](dice1+dice2))
- else
- pay(turn, tableRent[player[name].location][1](dice1+dice2))
- end
- end
- event["endTurn"]()
- else
- if tableInfo[i].owner == nil then
- addNotification(0, 1, "是否購買這片土地?", turn)
- else
- if tableInfo[i].owner == turn then
- if not rule.originMode then
- if tableRent[i][6] then
- addNotification(1,0, "你現在能夠建築\n酒店需要4房子", turn)
- end
- end
- elseif not tableInfo[i].mortgaged then
- if not player[tableInfo[i].owner].inJail or (rule.originMode and player[tableInfo[i].owner].inJail) then
- addDescription(turn, tableInfo[i].owner.."向", "\n收取租金: "..tableInfo[i].charge)
- pay(turn, tableInfo[i].charge, tableInfo[i].owner)
- elseif player[tableInfo[i].owner].inJail then
- addDescription(tableInfo[i].owner, "抵押了的地", "無法收租")
- end
- end
- event["endTurn"]()
- end
- end
- displayInfo(i)
- end
- function addDescription(name, txt1, txt2)
- if txt1 == nil then txt1="" end
- if txt2 == nil then txt2="" end
- 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)
- end
- function addMortgageButton(name)
- 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)
- end
- function addNotification(id, type, txt, name)
- ui.addPopup(id, type, "<p align=\"center\">"..txt.."</p>" , name, 560, 240, 200, false)
- end
- function addRuleConfig()
- local txt = "<p align=\"center\"><a href=\"event:ruleConfig\">".."更換模式".."</a></p>"
- ui.addTextArea(-9, txt, nil, 5, 35, 150, 200, 0x1, 0, 0.5, true)
- end
- function bankrup(name, nextTurn)
- ui.removeTextArea(-3) --mortgage button
- ui.removeTextArea(-5) --endTurn
- addDescription(name,"","破產了")
- if pay2target then
- for i,v in pairs (player[name].property) do
- tableInfo[v].owner = pay2target
- table.insert(player[pay2target].property,v)
- end
- else
- for i,v in pairs (player[name].property) do
- tableInfo[v].owner = nil
- tableInfo[v].alpha = 0.7
- end
- end
- player[name].property = nil
- --starting with more than 1 player
- if #order == 2 then
- local c = (turn == name) and 2 or 1
- addDescription(order[c], "其他人全破產了,", "勝利了(撒花")
- else
- local c = 1
- for i,v in pairs (order) do
- if v == name then
- c = i
- end
- end
- table.remove(order, c)
- if nextTurn then
- stillNext = true
- countTime(5,"nextTurn")
- end
- end
- end
- function build(id)
- if tableInfo[id].house < 5 then
- if originMode then
- if series(id, turn) then
- if player[turn].money < tableRent[id][6] then
- addNotification(1,0,"你沒有足夠金錢",turn)
- else
- if rule.originMode then
- for i,v in pairs (tableRent[tableInfo[id].color]) do
- if tableInfo[id].house + 1 - tableInfo[v].house > 1 then
- addNotification(1,0,"相同系列的屋子必須平均",turn)
- break
- end
- end
- end
- pay(turn, tableRent[id][6])
- tableInfo[id].house = tableInfo[id].house + 1
- tableInfo[id].charge = tableRent[id][tableInfo[id].house]
- buildHouse(id)
- updateBlock(id)
- updateLocation(turn)
- end
- else
- addNotification(1,0,"需要完整系列",turn)
- end
- else
- if tableInfo[id].owner == turn and player[turn].location == id and not justOwn == id then
- pay(turn, tableRent[id][6])
- tableInfo[id].house = tableInfo[id].house + 1
- tableInfo[id].charge = tableRent[id][tableInfo[id].house]
- buildHouse(id)
- updateBlock(id)
- updateLocation(turn)
- else
- addNotification(1,0,"上一輪你沒有擁有這塊地\n 或你不在此地上",turn)
- end
- end
- else
- addNotification(1,0,"你無法在這裡建造更多屋子",turn)
- end
- end
- function buildBlock()
- local id = 1
- local t = {x = -109, y = -9}
- updateBlock(id, t.x, t.y)
- table.insert(coor,{x = t.x, y = t.y})
- t.x = 6
- t.y = 30
- for i = 2,10 do
- id = id +1
- updateBlock(id, t.x, t.y)
- table.insert(coor,{x = t.x, y = t.y})
- t.x = t.x+88
- end
- t.x = 804
- t.y = -9
- id = id +1
- updateBlock(id, t.x, t.y)
- table.insert(coor,{x = t.x, y = t.y})
- t.x = 814
- t.y = 100
- for i = 12,20 do
- id = id +1
- updateBlock(id, t.x, t.y)
- table.insert(coor,{x = t.x, y = t.y})
- t.y = t.y+55
- end
- t.x = 807
- t.y = 598
- id = id +1
- updateBlock(id, t.x, t.y)
- table.insert(coor,{x = t.x, y = t.y})
- t.x = 716
- t.y = 607
- for i = 22,30 do
- id = id +1
- updateBlock(id, t.x, t.y)
- table.insert(coor,{x = t.x, y = t.y})
- t.x = t.x-88
- end
- t.x = -103
- t.y = 598
- id = id +1
- updateBlock(id, t.x, t.y)
- table.insert(coor,{x = t.x, y = t.y})
- t.x = -95
- t.y = 539
- for i = 32,40 do
- id = id +1
- updateBlock(id, t.x, t.y)
- table.insert(coor,{x = t.x, y = t.y})
- t.y = t.y-55
- end
- end
- function buildHouse(i)
- local num = tableInfo[i].house
- local color = 0xad1900 --red for house
- if num == 5 then
- color = 0x006624 --green for hotel
- end
- ui.addTextArea(i*100+tableInfo[i].house, "", nil, coor[i].x + (num*12) , coor[i].y + 2, 5, 5, color, 1, 1)
- end
- function countTime(s , id)
- startTime = os.date("%S")
- tfm.exec.setGameTime(s)
- eventID = id
- beginClock = true
- end
- function displayInfo(i, name)
- local header = "<font size = \"30\" color=\"#000000\"><p align= \"center\">"..tableInfo[i].name.."</p></font>"
- local txt = {}
- if tableInfo[i].price then
- if tableRent[i][0] == nil then
- txt = {
- "<font size = \"12\" color=\"#000000\">",
- "<p align= \"center\">",
- "\n\n擁有者: "..(tableInfo[i].owner or ""),
- "\n\n擁有一項公共事業時,\n其租值是骰子點數40倍。",
- "\n擁有兩項公共事業時,\n 其租值是骰子點數100倍。",
- "\n\n\n 抵押 : "..tableInfo[i].mortgageValue.."</p></font>"
- }
- elseif tableRent[i][6] == nil then
- txt = {
- "<font size = \"12\" color=\"#000000\">",
- "<p align= \"center\">",
- "\n\n擁有者:"..(tableInfo[i].owner or ""),
- "\n租金:"..tableRent[i][0].."</p>",
- "\n\n 擁有兩個車站:"..tableRent[i][1],
- "\n 擁有三個車站:"..tableRent[i][2],
- "\n 擁有四個車站:"..tableRent[i][3],
- "\n\n 抵押:"..tableInfo[i].mortgageValue.."</font>"
- }
- else
- txt = {
- "<font size = \"12\" color=\"#000000\">",
- "<p align= \"center\">\n",
- " 擁有者: "..(tableInfo[i].owner or ""),
- "\n 租金: "..tableRent[i][0].."</p>",
- "\n 擁有1所房子:"..tableRent[i][1],
- "\n 擁有2所房子:"..tableRent[i][2],
- "\n 擁有3所房子:"..tableRent[i][3],
- "\n 擁有4所房子:"..tableRent[i][4],
- "\n 擁有旅館:"..tableRent[i][5],
- "\n 抵押:"..tableInfo[i].mortgageValue,
- "\n 每間房子造價:"..tableRent[i][6],
- "\n 旅館造價(需要4房子):"..tableRent[i][6],
- "\n\n 擁有同一色系的空地租金雙倍</font>"
- }
- end
- local txt_info = ""
- for i,v in pairs (txt) do
- txt_info = txt_info..v
- end
- txt_info = txt_info.."\n <U><p align= \"center\"><a href=\"event:"..(i+40).."\">建屋</a></p>"
- ui.addTextArea(-7, txt_info, name, 10, 140, 200, 230, white, 0x000000, 1, true)
- else
- ui.removeTextArea(-7)
- end
- ui.addTextArea(-6, header, name, 10, 90, 200, 55, tableInfo[i].color, 0x000000, 1, true)
- 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)
- end
- function eventChatCommand(name,message)
- if message == "join" then
- if player[name] == nil then
- numPlayer = numPlayer + 1
- table.insert(order,name)
- player[name]={
- backgroundColor = math.random(0,0xFFFFFF),
- boarderColor = math.random(0,0xFFFFFF),
- money = 15000,
- location = 1,
- property = {},
- inJail = false,
- jailCounter = 0,
- id = numPlayer * 100
- }
- tfm.exec.setPlayerScore(name, player[name].money, false)
- end
- elseif message == "new" then
- ui.removeTextArea(-9)
- initialize()
- elseif message == "help" then
- local txt = help
- ui.addPopup(2, 0, txt, name, 180, 20, 460, true)
- elseif message == "assets" then
- if player[name] then
- local assets = 0
- for i,v in pairs (player[name].property) do
- assets = assets + (tableInfo[v].mortgaged) and 0 or tableInfo[v].price
- assets = assets + (tableInfo[v].house) and tableInfo[v].house * tableRent[v][6] or 0
- end
- assets = assets + player[name].money
- addNotification(1,0, "你的資產: "..assets, name)
- end
- end
- end
- function eventLoop(time, remaining)
- if beginClock then
- if remaining > 0 then
- local displayTime = math.floor(remaining / 1000)
- 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)
- else
- 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)
- beginClock = false
- event[eventID]()
- end
- else
- ui.removeTextArea(-1,nil)
- end
- if enableDice and diceAnimation > 0 then
- dice1 = math.random(1,6)
- dice2 = math.random(1,6)
- updateDice(dice1,dice2)
- diceAnimation = diceAnimation - 1
- elseif enableDice then
- locationAnimation = true
- walkingStep = dice1 + dice2
- enableDice = false
- end
- if locationAnimation and walkingStep > 0 and diceAnimation == 0 then
- if player[turn].inJail then
- if dice1 == dice2 then
- addDescription(turn, "", "成功擲出相同點數出獄")
- exitJail(turn)
- locationAnimation = false
- walkingStep = 0
- rollDice(turn)
- end
- else
- if rule.originMode and dice1 == dice2 then
- stillNext = true
- end
- player[turn].location = player[turn].location + 1
- if player[turn].location == 41 then
- pay(turn, -2000)
- player[turn].location = 1
- end
- walkingStep = walkingStep - 1
- updateLocation(turn)
- end
- elseif locationAnimation then
- locationAnimation = false
- action(player[turn].location)
- end
- end
- function eventPlayerDied(name)
- tfm.exec.respawnPlayer(name)
- end
- function eventPlayerLeft(name)
- if player[name] then
- bankrup(name, name==turn)
- end
- end
- function eventPopupAnswer(id, name, ans)
- if name == turn then
- if id == 0 then
- if ans == "yes" then
- if player[name].money >= tableInfo[player[name].location].price then
- pay(name, tableInfo[player[name].location].price, nil)
- table.insert(player[name].property, player[name].location)
- tableInfo[player[name].location].alpha = 1.0
- tableInfo[player[name].location].owner = name
- justOwn = player[name].location
- if series(player[name].location, turn) then
- for i,v in pairs (tableRent[tableInfo[player[name].location].color]) do
- local charge = tableInfo[v].charge
- tableInfo[v].charge = (tableInfo[v].house==0) and charge * 2 or charge
- updateBlock(v)
- end
- else
- tableInfo[player[name].location].charge = tableRent[player[name].location][0]
- end
- updateBlock(player[name].location)
- addDescription(name, "", "購買了"..tableInfo[player[name].location].name)
- else
- addNotification(0, 1, "你的金錢不夠\n請先抵押\n是否購買這片土地?", turn)
- end
- else
- addDescription(name, "", "選擇路過這片土地")
- end
- event["endTurn"]()
- elseif id == -1 then
- if ans == "yes" then
- addDescription(name, "", "選擇支付$2000")
- pay(name, 2000)
- else
- addDescription(name, "", "選擇支付10%金錢")
- pay(name, math.floor(player[name].money*0.1))
- end
- event["endTurn"]()
- elseif id == -3 then
- if ans == "yes" then
- pay(name, 500)
- exitJail(name)
- addDescription(name,"","出獄了")
- else
- player[name].jailCounter = player[name].jailCounter - 1
- addDescription(name,"","如果擲出相同點數可以出獄")
- end
- rollDice(name)
- event["endTurn"]()
- end
- end
- end
- function eventTextAreaCallback(id, name, callback)
- if callback == "ruleConfig" then
- rule.originMode = not rule.originMode
- addRuleConfig()
- elseif callback == "roll" then
- enableDice = true
- diceAnimation = 4
- ui.removeTextArea(id)
- elseif callback == "endTurn" then
- if player[name].money < 0 then
- mortgage(name)
- addNotification(1,0,"抵押後為負資產即時破產",name)
- else
- ui.removeTextArea(-4*player[name].id) --done button
- ui.removeTextArea(-5*player[name].id) --table
- countTime(5,"nextTurn")
- end
- ui.removeTextArea(-300)
- ui.removeTextArea(-3) --mortgage button
- ui.removeTextArea(id)
- elseif callback == "x" then
- ui.removeTextArea(-6)
- ui.removeTextArea(-7)
- ui.removeTextArea(-8)
- elseif callback == "startMortgage" then
- mortgage(name)
- elseif callback == "mortgage4Normal" then
- ui.removeTextArea(id) --done button
- ui.removeTextArea(-5*player[name].id) --table
- if player[name].money < 0 then
- bankrup(name)
- elseif pay2target then
- pay(pay2target, -pay2money)
- else
- addMortgageButton(name)
- end
- elseif tonumber(callback) then
- local i = tonumber(callback)
- if i < 0 then
- if tableInfo[-i].house == 0 then
- tableInfo[-i].mortgaged = true
- tableInfo[-i].alpha = 0.7
- updateBlock(-i)
- pay(name, -tableInfo[-i].mortgageValue)
- else
- ui.removeTextArea(-i * 100 - tableInfo[-i].house)
- tableInfo[-i].house = tableInfo[-i].house - 1
- if tableInfo[-i].house == 0 and series(-i, name) then
- tableInfo[-i].charge = tableRent[-i][0] * 2
- else
- tableInfo[-i].charge = tableRent[-i][tableInfo[-i].house]
- end
- pay(name, -tableRent[-i][6]/2)
- end
- mortgage(name)
- elseif i > 100 then
- if player[name].money >= math.floor(tableInfo[(i/100)].mortgageValue) then
- pay(name,math.floor(tableInfo[(i/100)].mortgageValue * 1.1))
- tableInfo[(i/100)].mortgaged = false
- tableInfo[(i/100)].alpha = 1.0
- updateBlock(i/100)
- mortgage(name)
- else
- addNotification(1, 0, "你的金錢不夠", name)
- end
- elseif i > 40 then
- if name == turn then
- build(i-40)
- else
- addNotification(1,0,"現在不是你的回合",name)
- end
- else
- displayInfo(i, name)
- end
- end
- end
- function exitJail(name)
- tfm.exec.movePlayer(turn, 400, 100)
- player[turn].inJail = false
- player[turn].jailCounter = 0
- end
- function initialize()
- period = 0
- eventID = 0
- beginClock = false
- player = {}
- order = {}
- coor = {}
- turn = nil
- numPlayer = 0
- dice1 = 1
- dice2 = 1
- diceAnimation = 0
- walkingStep = 0
- locationAnimation = false
- for i,v in pairs (tableInfo) do
- if v.price then
- v.alpha = 0.7
- v.owner = nil
- v.house = 0
- v.charge = 0
- v.mortgage = false
- end
- end
- buildBlock()
- addDescription("遊戲即將開始", "!join ", "")
- countTime(10,"start")
- end
- function mortgage(name)
- ui.removeTextArea(-3)
- local header = "<p align=\"center\">完成抵押依然為負資產即進入破產階段</p>\n"
- local txt = " 可抵押的地契:\n"
- local txt_r = "\n 可贖回的地:\n"
- for i,v in pairs (player[name].property) do
- if tableInfo[v].mortgaged then
- txt_r = txt_r.." <a href =\"event:"..(v*100).."\">"..tableInfo[v].name.." 贖回$"..math.floor(tableInfo[v].mortgageValue*1.1).."</a>\n"
- elseif tableInfo[v].house == 0 then
- txt = txt.." <a href =\"event:"..(-v).."\">"..tableInfo[v].name.." 抵押$"..tableInfo[v].mortgageValue.."</a>\n"
- else
- local charge = tableRent[v][6]/2
- txt = txt.." <a href =\"event:"..(-v).."\">"..tableInfo[v].name.." 拆除屋子/旅館$"..charge.."</a>\n"
- end
- end
- addDescription(name, "", "正在出售物業")
- 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)
- ui.addTextArea(-5*player[name].id, header..txt..txt_r, name, 250, 30, 300, 370, 0x1, 0x000000, 0.8, true)
- end
- function pay(name, money, target)
- local gainMoney = -money
- addDescription(name, (target) and target.."接收來自" or "", (money >= 0) and "支付$"..money or "獲取$"..gainMoney)
- player[name].money = player[name].money - money
- tfm.exec.setPlayerScore(name, player[name].money, false)
- if target then
- if player[name].money >= 0 then
- player[target].money = player[target].money + money
- tfm.exec.setPlayerScore(target, player[target].money, false)
- else
- pay2target = target
- pay2money = money
- end
- end
- end
- function randomOrder(o)
- if o then
- local t = {}
- local count = 0
- for i,v in pairs (o) do
- count = count + 1
- end
- if count ~= 0 then
- for i = 1, count do
- local c = math.random(#o)
- table.insert(t,o[c])
- table.remove(o, c)
- end
- for i,v in pairs (t) do
- table.insert(o,v)
- end
- end
- end
- end
- function rollDice(name)
- addDescription(name, "現在是", "的回合!")
- addMortgageButton(name)
- 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)
- end
- function series(id, name)
- if tableRent[tableInfo[id].color] and tableInfo[id].color ~= white then
- table.sort(player[name].property)
- local j = 0
- for i,v in pairs (player[name].property) do
- if tableRent[tableInfo[id].color][j+1] < v then
- return false
- elseif tableRent[tableInfo[id].color][j+1] == v then
- j = j + 1
- if j == #tableRent[tableInfo[id].color] then
- return true
- end
- end
- end
- end
- return false
- end
- function updateBlock(id, x, y)
- if x == nil or y==nil then
- x = coor[id].x
- y = coor[id].y
- end
- local size = 10
- if id % 10 == 1 then size = 20 end
- local txt = "<p align=\"center\"><font size=\""..size.."\" >"
- local txt_land = "<a href=\"event:"..id.."\">"..tableInfo[id].name.."</a>"
- if tableInfo[id].owner then
- local charge_txt = (tableInfo[id].charge == nil) and "" or tableInfo[id].charge
- txt_land = txt_land.."\n<font size=\"8\">"..tableInfo[id].owner.."</font>\n租金:"..charge_txt
- elseif tableInfo[id].price then
- txt_land = txt_land.."($"..tableInfo[id].price..")"
- end
- if tableRent[id] then
- txt = txt..txt_land.."</font></p>"
- else
- txt = txt..tableInfo[id].name.."</font></p>"
- end
- txt = (id >= 11 and id <= 30 and id ~= 21) and "<BV>"..txt or "<O>"..txt
- if id % 10 == 1 then
- ui.addTextArea(id,txt,nil,x,y,start_width,start_height,tableInfo[id].color,0,tableInfo[id].alpha,1)
- else
- ui.addTextArea(id,txt,nil,x,y,block_width,block_height,tableInfo[id].color,0,tableInfo[id].alpha,1)
- end
- for i,v in pairs (order) do
- if player[v].location == id then
- updateLocation(v)
- end
- end
- end
- function updateDice(d1, d2)
- ui.addTextArea(-100, "<B><font size = \"75\"><p align = \"center\">".. d1.."</font></p>", nil, 290, 240, 100, 100, 0x324650, 0x000000, 0.4, true)
- ui.addTextArea(-200, "<B><font size = \"75\"><p align = \"center\">".. d2.."</font></p>", nil, 410, 240, 100, 100, 0x324650, 0x000000, 0.4, true)
- end
- function updateLocation(name)
- local x = coor[player[name].location].x + math.random(20,60)
- local y = coor[player[name].location].y + math.random(30,40)
- ui.addTextArea(player[name].id, " ", nil, x, y, 10, 10, player[name].backgroundColor, player[name].boarderColor, 1,1)
- end
- --addRuleConfig()
- addDescription("!new 開始遊戲\n !help 查看規則")
- tfm.exec.disableAfkDeath(true)
- tfm.exec.disableAutoScore(true)
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableMortCommand(true)
- tfm.exec.newGame(7555054)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement