You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

526 line
17 KiB

  1. local PdkCardNode = require("pk_hejiangpdk.luaScript.Views.Room.Node.hejiangPdkCardNode")
  2. local PdkRoomViewConfig = require("pk_hejiangpdk.luaScript.Views.Room.hejiangPdkRoomViewConfig")
  3. local ETS = PdkRoomViewConfig.EffectType
  4. local PdkEffectHelper = require("pk_hejiangpdk.luaScript.Views.Room.hejiangPdkEffectHelper"):new()
  5. local PdkSoundHelper = require("pk_hejiangpdk.luaScript.Views.Room.hejiangPdkSoundHelper"):new()
  6. local PlayerNode = class("PlayerNode", function ()
  7. return cc.Node:create()
  8. end)
  9. function PlayerNode:ctor()
  10. local ui = loadUI("pk_luzhoupdk/res/ui/ui_room/ui_lzpdk_playernode.ui")
  11. self.ui = ui
  12. self:addChild(ui)
  13. self.txtNickname = self.ui.Items.name
  14. self.imgHead = self.ui.Items.headImg
  15. self.imgBanker = self.ui.Items.banker
  16. self.imgOffline = self.ui.Items.offLine
  17. self.imgReady = self.ui.Items.readyState
  18. self.txtCurScore = self.ui.Items.score
  19. self.txtCurScore.score = 0
  20. self.imgHost = self.ui.Items.imgHost
  21. self.imgTurn = self.ui.Items.ImageView_turn
  22. self.imgOfflineTime = self.ui.Items.ImageView_txkYY
  23. self.ui.Items.ImageView_alarm:setVisible(false)
  24. self.imgTuoGuan = self.ui.Items.ImageView_tuoguan
  25. -- self.txtTotalScore = self.ui.Items.totalScore
  26. self.ui:setLocalZOrder(10000)
  27. self.clockTimer = nil
  28. self.nGameInfo = ""
  29. end
  30. function PlayerNode:setGameInfo(str)
  31. self.nGameInfo = str
  32. end
  33. function PlayerNode:setPlayMode( mode )
  34. self._PlayMode = mode
  35. end
  36. -- 房间最大玩家数
  37. function PlayerNode:setMaxPlayerCount( count )
  38. self.nMaxPlayCount = count
  39. end
  40. -- 是否显示牌张数
  41. function PlayerNode:setShowNum( is )
  42. --暂时改为默认显示剩余牌张数
  43. self.ruleIsShowNum = true
  44. end
  45. -- 设置玩家信息
  46. function PlayerNode:setInfo( info )
  47. self._info = info
  48. local nickname = info.nickname or ""
  49. self.txtNickname:setString(getSubStringNickname(nickname))
  50. setPlayerHeadImage(info.userId, info.headimgurl, self.imgHead)
  51. --
  52. self:setScore(0)
  53. self:setOffline(false)
  54. self:setBanker(false)
  55. self:setReady(false)
  56. self:setHost(false)
  57. self:setTurn(false)
  58. self:setTuoGuan(false)
  59. self:setOfflineTime(false)
  60. self:hideLeft()
  61. if info.viewPos == 2 or (self._PlayMode == 4 and info.viewPos == 3) then --and self.nMaxPlayCount==3
  62. self.imgReady:setPosition(cc.p(-54, 78))
  63. self.imgTurn:setPosition(cc.p(-95, 13))--(cc.p(-55+25, 169-5))
  64. self.ui.Items.ImageView_alarm:setPosition(0, 137)
  65. self.ui.Items.imgLeft:setPosition(cc.p(-30, 13))
  66. self.ui.Items.txtLeftNum:setPosition(cc.p(-30, 13))
  67. elseif info.viewPos == 1 then
  68. -- local ps = self.imgReady:getPosition()
  69. -- local dlt = 1270/2
  70. -- ps.x = dlt
  71. -- ps.y = 180
  72. -- self.imgReady:setPosition(ps)
  73. local ruleInfo = json.decode(self.nGameInfo or "") or {}
  74. if ruleInfo.allowPass and ruleInfo.allowPass > 0 then
  75. self.imgTurn:setPosition(cc.p(260, 265))
  76. else
  77. self.imgTurn:setPosition(cc.p(360, 265))
  78. end
  79. self.imgTurn:setScale(1)
  80. end
  81. end
  82. -- 获取玩家信息
  83. function PlayerNode:getInfo()
  84. return self._info
  85. end
  86. -- 设置最后一组操作牌
  87. function PlayerNode:setLastOp( tp, cards, isContinue )
  88. self._lastOp = {}
  89. self._lastOp.tp = tp
  90. self._lastOp.cards = cards
  91. if tp~=ETS.PASS then
  92. self:showLastCards(self._lastOp.cards, self._lastOp.tp, isContinue)
  93. else
  94. self:showPass()
  95. end
  96. end
  97. function PlayerNode:isShowPass()
  98. if self._lastOp then
  99. return self._lastOp.tp==ETS.PASS
  100. end
  101. return false
  102. end
  103. -- 显示牌背
  104. function PlayerNode:showCardbg(is)
  105. end
  106. -- 显示Pass
  107. function PlayerNode:showPass()
  108. self:cleanLastCards()
  109. local ruleInfo = json.decode(self.nGameInfo)
  110. local fileName = ""
  111. --开房参数1:可不要时,0:必须要
  112. if ruleInfo.allowPass and ruleInfo.allowPass == 1 then
  113. --可不要时显示不出,必须要时显示要不起
  114. fileName = "pdk_zi_buchu.png"
  115. else
  116. fileName = "pdk_zi_yaobuqi.png"
  117. end
  118. local node = cc.ImageView:create()
  119. node:loadTexture(fileName, 1)
  120. node:setTag(2000)
  121. local pos = self._info.viewPos
  122. local pt = clone(PdkRoomViewConfig.PASS_SHOW_POS[self._PlayMode][pos])
  123. node:setPosition(pt)
  124. node:setLocalZOrder(1000)
  125. node:setScale(0)
  126. self:addChild(node)
  127. node:runAction(cc.ScaleTo:create(0.1, 1))
  128. local pInfo = self:getInfo()
  129. local sex = pInfo.sex
  130. local idx = math.random(4)
  131. PdkSoundHelper:effectPass( sex, idx )
  132. end
  133. -- 显示出牌
  134. function PlayerNode:showLastCards(cards, tp, isContinue)
  135. self:cleanLastCards()
  136. local root = cc.Node:create()
  137. local scale = PdkRoomViewConfig.CARD_SCALE[2]
  138. local allCount = #cards
  139. local pos = self._info.viewPos
  140. local firstPos = cc.p(0, 0)
  141. for i,card in ipairs(cards) do
  142. local node = self:genCard(card)
  143. local pt = cc.p(0, 0)
  144. if pos == 1 then
  145. local midIdx = allCount/2
  146. if i<midIdx then--左边
  147. pt.x = 0 - (midIdx-i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*scale
  148. else--右边
  149. pt.x = 0 + (i-midIdx+1)*PdkRoomViewConfig.CARD_DLT_WIDTH*scale
  150. end
  151. pt.x = pt.x - PdkRoomViewConfig.CARD_WIDTH/2*scale
  152. pt.x = pt.x + PdkRoomViewConfig.NEW_SHOW_CARD_POS[self._PlayMode][pos].x - PdkRoomViewConfig.PLAYER_POS[self._PlayMode][pos].x
  153. pt.y = PdkRoomViewConfig.NEW_SHOW_CARD_POS[self._PlayMode][pos].y - PdkRoomViewConfig.PLAYER_POS[self._PlayMode][pos].y
  154. if i==1 then firstPos = pt end
  155. else
  156. if pos == 2 or (self._PlayMode == 4 and pos == 3) then --self._PlayMode == 1 and
  157. node:setLocalZOrder(16-i)
  158. pt.x = pt.x - (i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*scale
  159. pt.x = pt.x + PdkRoomViewConfig.NEW_SHOW_CARD_POS[self._PlayMode][pos].x
  160. if i==1 then firstPos = pt end
  161. else
  162. pt.x = pt.x + (i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*scale
  163. pt.x = pt.x + PdkRoomViewConfig.NEW_SHOW_CARD_POS[self._PlayMode][pos].x - self.imgHead:getContentSize().width - 10
  164. if i==1 then firstPos = pt end
  165. end
  166. pt.y = -28
  167. end
  168. node:setScale(scale)
  169. node:setPosition(pt)
  170. root:addChild(node)
  171. end
  172. root:setTag(1001)
  173. self:addChild(root)
  174. local dltWidth = ((#cards-1)*PdkRoomViewConfig.CARD_DLT_WIDTH + PdkRoomViewConfig.CARD_WIDTH) * PdkRoomViewConfig.CARD_SCALE[2]
  175. local pt = cc.p(firstPos.x,firstPos.y-30)
  176. if pos==2 or (self._PlayMode == 4 and pos == 3) then
  177. pt.x = pt.x - dltWidth/2 + PdkRoomViewConfig.CARD_WIDTH * PdkRoomViewConfig.CARD_SCALE[2]/2
  178. else
  179. pt.x = pt.x + dltWidth/2 - PdkRoomViewConfig.CARD_WIDTH * PdkRoomViewConfig.CARD_SCALE[2]/2
  180. end
  181. self:showEffect(root, cards, tp, pt, isContinue, dltWidth )
  182. end
  183. -- 清除出牌
  184. function PlayerNode:cleanLastCards()
  185. do
  186. local node = self:getChildByTag(1001)
  187. if node then node:removeFromParent() end
  188. end
  189. self:cleanPass()
  190. end
  191. function PlayerNode:cleanPass()
  192. do
  193. local node = self:getChildByTag(2000)
  194. if node then node:removeFromParent() end
  195. end
  196. end
  197. -- 显示剩余牌数量
  198. function PlayerNode:showLeft( num )
  199. self.ui.Items.ImageView_alarm:setVisible(num == 1)
  200. if num == 1 then--报单
  201. self.ui.Items.imgLeft:setVisible(true)
  202. self.ui.Items.txtLeftNum:setVisible(true)
  203. self.ui.Items.txtLeftNum:setString(string.format("%d", num or 0))
  204. self.ui.Items.imgLeft:loadTexture("pdk_game_img_warn.png", 1)
  205. self.ui.Items.ImageView_alarm:stopAllActions()
  206. self.ui.Items.ImageView_alarm:setRotation(0)
  207. local ac = cc.Sequence:create(cc.RotateBy:create(0.1, 30/180), cc.RotateBy:create(0.2, -60/180), cc.RotateBy:create(0.1, 30/180))
  208. self.ui.Items.ImageView_alarm:runAction(cc.RepeatForever:create(cc.Sequence:create(ac, ac:clone(), cc.DelayTime:create(1))))
  209. else
  210. self.ui.Items.imgLeft:setVisible(true)
  211. self.ui.Items.txtLeftNum:setVisible(true)
  212. self.ui.Items.imgLeft:loadTexture("pdk_game_img_leftbg.png", 1)
  213. end
  214. if not self.ruleIsShowNum then
  215. self.ui.Items.imgLeft:setVisible(false)
  216. self.ui.Items.txtLeftNum:setVisible(false)
  217. else
  218. local show = true
  219. if self._info.viewPos == 1 then show = false end
  220. self.ui.Items.imgLeft:setVisible(show)
  221. self.ui.Items.txtLeftNum:setVisible(show)
  222. self.ui.Items.txtLeftNum:setString(string.format("%d", num or 0))
  223. end
  224. end
  225. -- 是否报单
  226. function PlayerNode:isAlarm()
  227. return self.ui.Items.ImageView_alarm:isVisible()
  228. end
  229. -- 隐藏剩余拍数量
  230. function PlayerNode:hideLeft()
  231. self.ui.Items.imgLeft:setVisible(false)
  232. self.ui.Items.txtLeftNum:setVisible(false)
  233. self.ui.Items.ImageView_alarm:setVisible(false)
  234. end
  235. -- 设置分数 remove飘的分数是否移除
  236. function PlayerNode:setScore( scol, remove ,turnScore)
  237. if remove == nil then remove = true end
  238. local dlt = (scol - self.txtCurScore.score)
  239. local curScol = tonumber(self.txtCurScore:getString())
  240. if curScol and curScol ~= self.txtCurScore.score then
  241. logD("PlayerNode:setScore ================curScol = "..curScol)
  242. dlt = scol - curScol
  243. --uploadLogs("lzpdkfenshucuowu")
  244. end
  245. logD("PlayerNode:setScore ================scol = "..scol.."self.txtCurScore.score = "..self.txtCurScore.score)
  246. if turnScore then
  247. logD("PlayerNode:setScore ================turnScore = "..turnScore)
  248. dlt = turnScore
  249. end
  250. if math.abs(dlt) > 0 then
  251. local txt = cc.TextBMFont:createNode()
  252. if dlt > 0 then
  253. txt:setFntFile("res/fonts/dt_jia_num.fnt")
  254. txt:setString(string.format("+%0.1f", dlt))
  255. else
  256. txt:setFntFile("res/fonts/dt_jian_num.fnt")
  257. txt:setString(string.format("%0.1f", dlt))
  258. end
  259. txt:setScale(0.7)
  260. txt:setTag(166)
  261. txt:setLocalZOrder(10001)
  262. self:addChild(txt)
  263. local ac = cc.Sequence:create(cc.Spawn:create(cc.MoveBy:create(1, cc.p(0, 100))), cc.CallFunc:create(function ()
  264. self.txtCurScore:setString(string.format("%0.1f", scol or 0))
  265. self.txtCurScore.score = scol
  266. if remove then txt:removeFromParent() end
  267. end))
  268. txt:runAction(ac)
  269. else
  270. self.txtCurScore:setString(string.format("%0.1f", scol or 0))
  271. self.txtCurScore.score = scol
  272. end
  273. end
  274. function PlayerNode:setScoreNoAnim( scol)
  275. self.txtCurScore:setString(string.format("%0.1f", scol or 0))
  276. self.txtCurScore.score = scol
  277. end
  278. -- 移除飘的分数
  279. function PlayerNode:cleanScore()
  280. local node = self:getChildByTag(166)
  281. if node then node:removeFromParent() end
  282. end
  283. -- 设置总分数
  284. function PlayerNode:setTotalScore( scol )
  285. -- self.txtTotalScore:setString(string.format("%d", scol or 0))
  286. end
  287. -- 设置是否离线
  288. function PlayerNode:setOffline( is )
  289. self.imgOffline:setVisible(is==true)
  290. end
  291. -- 设置离线时间
  292. function PlayerNode:setOfflineTime(is,ptime)
  293. self.imgOfflineTime:setVisible(is == true)
  294. if is == true and ptime then
  295. local ttime = os.date("%M:%S",ptime)
  296. self.ui.Items.Text_offLineTime:setText(ttime)
  297. --关闭定时器
  298. if self.Time then
  299. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  300. self.Time = nil
  301. end
  302. --当前已离线多长时间
  303. self.curOfftime = ptime
  304. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  305. self.curOfftime = self.curOfftime + 1
  306. if self.curOfftime > 300 then--大于5分钟,恒定显示5分钟
  307. self.curOfftime = 300
  308. end
  309. if not tolua.isnull(self.ui.Items.Text_offLineTime) then
  310. local time = os.date("%M:%S",self.curOfftime)
  311. self.ui.Items.Text_offLineTime:setText(time)
  312. else
  313. if self.Time then
  314. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  315. self.Time = nil
  316. end
  317. end
  318. end,1.0,false)
  319. else
  320. if self.Time then
  321. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  322. self.Time = nil
  323. end
  324. end
  325. end
  326. -- 设置是否是房主
  327. function PlayerNode:setHost( is )
  328. --self.imgHost:setVisible(is==true)
  329. self.imgHost:setVisible(false)--隐藏房主标签
  330. end
  331. -- 设置是否是庄家
  332. function PlayerNode:setBanker( is )
  333. self.imgBanker:setVisible(is==true)
  334. end
  335. -- 设置是否准备
  336. function PlayerNode:setReady( is )
  337. self.imgReady:setVisible(is==true)
  338. end
  339. -- 设置轮次时钟
  340. function PlayerNode:setTurn( is, time )
  341. if is then
  342. if self.clockTimer then
  343. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.clockTimer)
  344. self.clockTimer = nil
  345. end
  346. self.imgTurn:setVisible(true)
  347. if self.clockTimer==nil then
  348. self.ui.Items.txtLimitTime.time = time or 10
  349. self.ui.Items.txtLimitTime:setString(string.format("%d", self.ui.Items.txtLimitTime.time))
  350. self.clockTimer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  351. if self.ui.Items.txtLimitTime.time > 0 then
  352. self.ui.Items.txtLimitTime.time = self.ui.Items.txtLimitTime.time - 1
  353. if self.ui.Items.txtLimitTime.time<=5 and self._info.viewPos==1 then
  354. PdkSoundHelper:alarm()
  355. end
  356. else
  357. if self.clockTimer then
  358. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.clockTimer)
  359. self.clockTimer = nil
  360. end
  361. end
  362. self.ui.Items.txtLimitTime:setString(string.format("%d", self.ui.Items.txtLimitTime.time))
  363. end,1.0,false)
  364. end
  365. else
  366. if self.clockTimer then
  367. self.ui.Items.txtLimitTime.time = self.ui.Items.txtLimitTime.time - 1
  368. self.ui.Items.txtLimitTime:setString(string.format("%d", self.ui.Items.txtLimitTime.time))
  369. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.clockTimer)
  370. self.clockTimer = nil
  371. end
  372. self.imgTurn:setVisible(false)
  373. end
  374. end
  375. -- 创建一张牌
  376. function PlayerNode:genCard( card )
  377. local node = PdkCardNode:new()
  378. node:setCard(card)
  379. node:setSelectedHeight(PdkRoomViewConfig.SELECTED_HEIGHT)
  380. node:setNormalHeight(PdkRoomViewConfig.NORMAL_HEIGHT)
  381. return node
  382. end
  383. function PlayerNode:showEffectExt( effectType )
  384. local function __show()
  385. local node = nil
  386. local pInfo = self:getInfo()
  387. local sex = pInfo.sex
  388. local pos = self._info.viewPos
  389. local pt = clone(PdkRoomViewConfig.PASS_SHOW_POS[self._PlayMode][pos])
  390. if effectType == ETS.PASS then
  391. local cb = function ()
  392. self:setTurn(false)
  393. end
  394. node = PdkEffectHelper:getPass(cb)
  395. local idx = math.random(4)
  396. PdkSoundHelper:effectPass( sex, idx )
  397. end
  398. if node then
  399. node:setPosition(pt)
  400. node:setLocalZOrder(1000)
  401. self:addChild(node)
  402. if node.onEnter and type(node.onEnter)=='function' then
  403. node:onEnter()
  404. end
  405. end
  406. end
  407. self.ui:runAction(cc.Sequence:create(cc.DelayTime:create(1), cc.CallFunc:create(__show)))
  408. end
  409. -- 显示牌型
  410. function PlayerNode:showEffect(root, cards, effectType, pt, isContinue, dltWidth )
  411. local rate = math.random(100)
  412. local stdRate = 70
  413. isContinue = isContinue or false
  414. local viewPos = self._info.viewPos
  415. local pInfo = self:getInfo()
  416. local sex = pInfo.sex
  417. local node = nil
  418. if effectType == ETS.PASS then
  419. local cb = function ()
  420. self:setTurn(false)
  421. end
  422. node = PdkEffectHelper:getPass(cb)
  423. local idx = math.random(4)
  424. PdkSoundHelper:effectPass( sex, idx )
  425. elseif effectType == ETS.SINGLE_CARD then
  426. local _, val = pokerParse(cards[1])
  427. PdkSoundHelper:effectSingle( sex ,val )
  428. elseif effectType == ETS.DUI_ZI then
  429. local _, val = pokerParse(cards[1])
  430. if isContinue and rate >= stdRate and PdkSoundHelper:getLanguageType() == 1 then
  431. PdkSoundHelper:daNi( sex )
  432. else
  433. PdkSoundHelper:effectDouble( sex, val )
  434. end
  435. elseif effectType == ETS.SHUN_ZI then
  436. node = PdkEffectHelper:getShunzi()
  437. -- if viewPos==1 and node then
  438. -- node:setScale(1.2)
  439. -- end
  440. if isContinue and rate>=stdRate and PdkSoundHelper:getLanguageType() == 1 then
  441. PdkSoundHelper:daNi( sex )
  442. else
  443. PdkSoundHelper:effectShunzi( sex )
  444. end
  445. elseif effectType == ETS.LIAN_DUI then
  446. node = PdkEffectHelper:getLiandui()
  447. if isContinue and rate>=stdRate and PdkSoundHelper:getLanguageType() == 1 then
  448. PdkSoundHelper:daNi( sex )
  449. else
  450. PdkSoundHelper:effectLiandui( sex )
  451. end
  452. elseif effectType == ETS.THREE_AND_TWO or effectType == ETS.THREE_AND_DUI then
  453. --根据牌获取是否是三带一或三个
  454. local tp = PokerUtil:checkType(cards)
  455. node = PdkEffectHelper:getSandaier()
  456. if tp == ETS.THREE_AND_ONE then
  457. node = nil
  458. node = PdkEffectHelper:getSandaiyi()
  459. PdkSoundHelper:effect3And1( sex )
  460. elseif isContinue and rate>=stdRate and PdkSoundHelper:getLanguageType() == 1 then
  461. PdkSoundHelper:daNi( sex )
  462. else
  463. PdkSoundHelper:effect3And2( sex,effectType )
  464. end
  465. elseif effectType == ETS.THREE then
  466. local _, val = pokerParse(cards[1])
  467. PdkSoundHelper:effectThree( sex, val )
  468. elseif effectType == ETS.THREE_AND_DUI then
  469. if isContinue and rate>=stdRate and PdkSoundHelper:getLanguageType() == 1 then
  470. PdkSoundHelper:daNi( sex )
  471. else
  472. PdkSoundHelper:effect3And2( sex ,effectType)
  473. end
  474. elseif effectType == ETS.BOMB then
  475. node = PdkEffectHelper:getBomb()
  476. pt.y = pt.y + 100
  477. PdkSoundHelper:effectBomb( sex )
  478. elseif effectType == ETS.AIRPLANE or effectType == ETS.AIRPLANE_TOW or effectType == ETS.AIRPLANE_DUI then
  479. node = PdkEffectHelper:getPlan()
  480. PdkSoundHelper:effectPlane( sex )
  481. --[[ elseif effectType == ETS.SPRING_HUA then
  482. node = PdkEffectHelper:getSpring()--]]
  483. end
  484. if node then
  485. if effectType == ETS.SHUN_ZI then
  486. pt.x = pt.x - (dltWidth/2+100)
  487. end
  488. node:setPosition(pt)
  489. node:setLocalZOrder(1000)
  490. root:addChild(node)
  491. if node.onEnter and type(node.onEnter)=='function' then
  492. node:onEnter()
  493. end
  494. end
  495. end
  496. -- 设置是否是房主
  497. function PlayerNode:setTuoGuan( is )
  498. if not tolua.isnull(self.imgTuoGuan) then
  499. self.imgTuoGuan:setVisible(is==true)
  500. end
  501. end
  502. return PlayerNode