-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFPond.lua
More file actions
3514 lines (3190 loc) · 117 KB
/
Copy pathFPond.lua
File metadata and controls
3514 lines (3190 loc) · 117 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
捕鱼主界面
]]
local UIBase = require_ex("ui.base.UIBase")
local M = class("FPond", UIBase)
local _TAG = "FISH"
local Actor = require_ex("ui.base.Actor")
local FPlayer = require_ex("games.fish.views.base.FPlayer")
local FMagicEmoji = require_ex("games.fish.views.minor.FMagicEmoji")
local director = cc.Director:getInstance()
-- 垃圾回收停止
local GARBAGE_DISABLE = false -- device.platform=="windows"
-- 动画特效及图片
--local SpineTideWarn = {res="subgame/catchFish/spine/jingbao/yclx/by_yclx", ani="1", isLoop = false}
local SpineFrozen = {res="subgame/catchFish/spine/bd/by_bd", ani="animation", x=CC_DESIGN_RESOLUTION.cx, y=CC_DESIGN_RESOLUTION.cy, zorder=-10, isLoop=false}
local SpineFBomb = {res = "subgame/catchFish/spine/qpzd/by_qpzd", ani="1", x=CC_DESIGN_RESOLUTION.cx, y=CC_DESIGN_RESOLUTION.cy, isLoop=false}
local SpineDropBg = {res="subgame/catchFish/spine/djdl/by_djdl", ani="1", isLoop=true, scale=1.3}
local SpineCoin = {res="subgame/catchFish/spine/jinbi/by_jinbi"}
local SpineDynjPlate = {res = "subgame/field7/spine/bys/by_bys", center = true, isLoop =false}
-- 雷链
local SpineRayChain = {
{res="subgame/catchFish/spine/leidian/by_leidianyu", ani="1", release=true},
{res="subgame/catchFish/spine/leidian/by_leidianyu", ani="2", release=true},
}
-- 海妖专属
local SpineHYChain = {
{res="subgame/field4/spine/hyxw/lightning/hyxw_lightning", ani="1", release=true},
{res="subgame/field4/spine/hyxw/lightning/hyxw_lightning", ani="2", release=true},
}
-- 玩家聊天冷却
local CHAT_CD = 2
-- 掉落最大展示数量
local ITEM_DROPMAX = 10
-- 弹头类型
--local BULLET_TYPE = 2001
local FPS_CHECKPAD = 60
-- 每帧添加鱼数量
local FPS_ADD_FISH = 3
-- Action逻辑标签
local ActTag = {
plate = 10001
}
local SpecialDropType={
suit = 2008, -- 花色
bottle = 2009, -- 酒瓶
}
local APP_LIST = {
["qgame"] = true,
["mgame"] = true,
}
--[[
掉落物品参数
@param id number 物品ID
@return number,number,boolean (width,height,showLight)
]]
local function _dropItemArgs(id)
local iconWidth, iconHeight, showLight = 90, 90, true
if id == ENUM.ITEM_ID.LOTTERY or id == ENUM.ITEM_ID.DIAMOND
or id == ENUM.ITEM_ID.BATTLE_AXE
or id == ENUM.ITEM_ID.MISSILE1 or id == ENUM.ITEM_ID.MISSILE2
or id == ENUM.ITEM_ID.MISSILE3 or id == ENUM.ITEM_ID.MISSILE4 then
iconWidth, iconHeight = 150, 150
elseif id == ENUM.ITEM_ID.COIN or id == ENUM.ITEM_ID.ENERGY or id == ENUM.ITEM_ID.SCORE then
iconWidth, iconHeight, showLight = 80, 80, false
end
return iconWidth, iconHeight, showLight
end
--[[
物品掉落动作
]]
local function _dropItemAction(id, delay, fromPos, offset, toPos, pSound, callback, dropTime)
local dur = ItemsConfig.drop_time(id)
if not dur or checknumber(dur) <=0 then
dur = 2000
end
dur = dur / 1000
dur = dropTime~=nil and dropTime or dur
local mtime = Number.min(cc.pGetDistance(fromPos,toPos)/700, 0.6)
local seq = {
cc.DelayTime:create(delay),
cc.CallFunc:create(function()
if pSound then
Audio.playSoundConfig("Daoju", "down")
end
end),
cc.Spawn:create(
cc.EaseBackOut:create(cc.MoveBy:create(0.3, offset)),
cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
),
cc.Spawn:create(cc.JumpBy:create(0.7, cc.p(0,0), 50, 2)),
cc.DelayTime:create(dur-delay),
cc.CallFunc:create(function()
if pSound then
Audio.playSoundConfig("Daoju", "fly")
end
end),
cc.Spawn:create(
cc.EaseBackOut:create(cc.MoveTo:create(mtime, toPos)),
cc.EaseSineOut:create(cc.ScaleTo:create(mtime+0.1, 0.1))
),
cc.RemoveSelf:create()
}
if callback then
table.insert(seq, #seq-1, cc.CallFunc:create(callback))
end
return transition.sequence(seq)
end
------------------------------------------------
function M:ctor()
self.funcKey = "fish"
UIBase.ctor(self)
self:init()
end
function M:registerListenEvent()
self:listenCustomEvent(cc.EVENT_COME_TO_FOREGROUND, handler(self, self.onComeToForeGround))
self:listenCustomEvent(cc.EVENT_COME_TO_BACKGROUND, handler(self, self.onComeToBackGround))
self:listenCustomEvent(GEvent("NET_READY_RECONNECT"), handler(self, self.onReadyReconnect))
self:listenCustomEvent(GEvent("NET_HB_CHECK"), handler(self, self.onNetLatency))
self:listenCustomEvent(GEvent("GAME_LV_MODIFY_EVENT"), handler(self, self.onUpdatePlayerLv))
self:listenCustomEvent(GEvent("ON_BAG_DATA_UPDATE"), handler(self, self.updateBagData))
-- self:listenCustomEvent(GEvent("ON_DIAMOND_CHANGE"), handler(self, self.onDiamondChange))
self:listenCustomEvent(GEvent("ON_VIP_CHANGE"), handler(self, self.onVIPChange))
-- self:listenCustomEvent(GEvent("GAME_RED_POINT_EVENT"), handler(self, self.onPlayerDataUpdate))
self:listenCustomEvent(GEvent("CHAT_NORMAL"), handler(self, self.onRoomChat))
self:listenCustomEvent(GEvent(_TAG, "USE_SKILL"), handler(self, self.onPlayerUseSkill))
self:listenCustomEvent(GEvent(_TAG, "ADD_PLAYER"), handler(self, self.addPlayer))
self:listenCustomEvent(GEvent(_TAG, "UPD_PLAYER"), handler(self, self.updatePlayer))
self:listenCustomEvent(GEvent(_TAG, "DEL_PLAYER"), handler(self, self.removePlayer))
self:listenCustomEvent(GEvent(_TAG, "SHOOT"), handler(self, self.onPlayerShoot))
self:listenCustomEvent(GEvent(_TAG, "HIT_FISH"), handler(self, self.onPlayerHit))
self:listenCustomEvent(GEvent(_TAG, "UPD_CANNON"), handler(self, self.updatePlayerCannon))
self:listenCustomEvent(GEvent(_TAG, "UPD_CANNON_CB"), handler(self, self.onUpdateCannonCallback))
self:listenCustomEvent(GEvent(_TAG, "UPD_ROOM"), handler(self, self.refresh))
self:listenCustomEvent(GEvent(_TAG, "ADD_FISH"), handler(self, self.onAddFish))
self:listenCustomEvent(GEvent(_TAG, "RELOCATION"), handler(self, self.onFishRelocation))
self:listenCustomEvent(GEvent(_TAG, "FISH_TIDE"), handler(self, self.onFishTide))
self:listenCustomEvent(GEvent(_TAG, "DEL_BULLET"), handler(self, self.onRemoveBullet))
self:listenCustomEvent(GEvent(_TAG, "UPD_CANNONLV"), handler(self, self.onUpdateCannonLv))
self:listenCustomEvent(GEvent(_TAG, "UPD_LOTTERY"), handler(self, self.onUpdateLottery))
self:listenCustomEvent(GEvent(_TAG, "DO_LOTTERY"), handler(self, self.onPlayerLottery))
self:listenCustomEvent(GEvent(_TAG, "TREAS_TASK_START"), handler(self, self.onTreasureStart))
self:listenCustomEvent(GEvent(_TAG, "TREAS_TASK_CHANGE"), handler(self, self.onTreasureTaskChange))
self:listenCustomEvent(GEvent(_TAG, "TREAS_TASK_RESULT"), handler(self, self.onTreasureResult))
self:listenCustomEvent(GEvent(_TAG, "EXIT_GAME"), handler(self, self.onClose))
self:listenCustomEvent(GEvent(_TAG, "BUGLE_TASK_START"), handler(self, self.onBugleStart))
self:listenCustomEvent(GEvent(_TAG, "BUGLE_TASK_RESULT"), handler(self, self.onBugleResult))
self:listenCustomEvent(GEvent(_TAG, "ADD_SPECIAL_DROP"), handler(self, self.onShowSpecialDrop))
self:listenCustomEvent(GEvent(_TAG, "DEL_SPECIAL_DROP"), handler(self, self.onHideSpecialDrop))
self:listenCustomEvent(GEvent(_TAG, "UPD_BOMBSKILL"), handler(self, self.onBombSkill))
self:listenCustomEvent(GEvent(_TAG, "LOADING_TIMEOUT"), handler(self, self.onLoadingTimeout))
self:listenCustomEvent(GEvent(_TAG, "NOTIFY_EFFECT"), handler(self, self.onNotifyEffect))
self:listenCustomEvent(GEvent(_TAG, "CHANGE_ROOMEXIT_GAME"), handler(self, self.onCRExit))
self:listenCustomEvent(GEvent(_TAG, "PET_HIT_FISH"), handler(self, self.onPetHit))
self:listenCustomEvent(GEvent(_TAG, "PET_SKILL_TIMEOUT"), handler(self, self.onPetSKillTimeOut))
self:listenCustomEvent(GEvent(_TAG, "DRILL_START"), handler(self, self.onDrillStart))
self:listenCustomEvent(GEvent(_TAG, "DRILL_FIRE"), handler(self, self.onDrillFire))
self:listenCustomEvent(GEvent(_TAG, "DRILL_BOMB"), handler(self, self.onDrillBomb))
self:listenCustomEvent(GEvent(_TAG, "DRILL_FINISH"), handler(self, self.onDrillFinish))
self:listenCustomEvent(GEvent(_TAG, "MATCH_TASK_BEGIN"), handler(self, self.onMatchTaskStart))
self:listenCustomEvent(GEvent(_TAG, "MATCH_TASK_END"), handler(self, self.onMatchTaskEnd))
self:listenCustomEvent(GEvent(_TAG, "RESET_IDLETIME"), handler(self, self.onResetIdletime))
self:listenCustomEvent(GEvent(_TAG, "PET_CHANGE"), handler(self, self.onPetChange))
self:listenCustomEvent(GEvent(_TAG, "CHANGE_CLEAR_TASK"), handler(self, self.onChangeClearTask))
self:listenCustomEvent(GEvent(_TAG, "DEVIL_KING_ANGER"), handler(self,self.onDevilKingShow))
self:listenCustomEvent(GEvent(_TAG, "DEVIL_KING_STATUS"), handler(self,self.onDevilKingShow))
end
function M:init()
self._BindWidget = {
["bg"] = {},
["panel_fish"] = {},
["panel_fish1"] = {},
["panel_fish2"] = {},
["panel_fish3"] = {},
["panel_fish4"] = {},
["panel_fish5"] = {},
["panel_surface"] = {},
["panel_bullet"] = {},
["panel_touch"] = {},
["panel_turret"] = {zorder = 1},
["panel_turret/turret1"] = {key = "player1"},
["panel_turret/turret2"] = {key = "player2"},
["panel_turret/turret3"] = {key = "player3"},
["panel_turret/turret4"] = {key = "player4"},
["panel_turret/img_await_1"] = {key = "playerEmpty1"},
["panel_turret/img_await_2"] = {key = "playerEmpty2"},
["panel_turret/img_await_3"] = {key = "playerEmpty3"},
["panel_turret/img_await_4"] = {key = "playerEmpty4"},
["panel_mcPlate"] = {zorder = ENUM.UI_Z.TIP},
["panel_mcPlate/act_mcPlate"] = {key = "act_mcPlate", spine={res="subgame/catchFish/spine/djp/by_djp", isLoop=false}},
["panel_mcPlate/txt_mcPlate"] = {key = "txt_mcPlate"},
["panel_mjPlate"] = {zorder = ENUM.UI_Z.TIP},
["panel_mjPlate/act_mcPlate"] = {key = "act_mjPlate", spine={res="subgame/catchFish/spine/bmj/by_bmj2", isLoop=false}},
["panel_mjPlate/txt_mcPlate"] = {key = "txt_mjPlate"},
["panel_ysPlate"] = {zorder = ENUM.UI_Z.TIP},
["panel_ysPlate/act_mcPlate"] = {key = "act_ysPlate"},
["panel_ysPlate/txt_mcPlate"] = {key = "txt_ysPlate"},
}
self._myUid = Game:doPluginAPI("get", "playerUid")
self._inv = 1 / 30
-- 玩家
self._player = {}
-- 鱼
self._fish = {}
self._fishCount = 0
self._updFishList = {}
-- 子弹
self._bullet = {}
-- 抖屏
self.shakeNodes = {}
self.shakeParams = {duration = 0}
-- 低帧频卡顿
self._fpsRemain = nil
self._fpsCheckTick = FPS_CHECKPAD
self._fpsMessy = 0
-- 流程标记
self._entering = true
self._preloading = true
Game.fishMng = require_ex("games.fish.models.FishMng")
-- 掉落物品,换桌的时候清掉
self.dropList = {}
-- 技能列表,方便换桌的时候移除
self.skilList = {"btn_ice", "btn_summon", "btn_bugle", "btn_lock", "btn_rage", "btn_pet"}
-- 聊天冷却
self._chatPlayerCD = {}
-- 有截图的boss死亡时间
self._bossDieTime = 0
-- 渔场加载界面
if Game.reloadToGame then
self:performWithDelay(function()
self:setLoading(false)
end, 0.1)
else
require_ex("games.fish.views.FLoadingUI").new(self):addToScene(ENUM.UI_Z.TOP)
end
self:initViews()
self:scheduleUpdate(true)
end
function M:initViews()
local uiNode = createCsbNode("subgame/catchFish/pond.csb")
self:addChild(uiNode, 1)
self._rootNode = uiNode
bindWidgetList(uiNode, self._BindWidget, self._widgets)
self._widgets.bg:setPosition(cc.p(0,0))
if FISH_DEBUG then
self:addDebugLabel()
end
if GM_DEBUG and Game:funcIsOpen("gm") then
self:addRapidTestBtn()
end
-- 鱼池附属UI
self._layerBg = require_ex("games.fish.views.FPondBG").new(self._widgets.bg)
self._layerUI = require_ex("games.fish.views.pond.FPondUI").new(self, self._rootNode)
self._layerSkill = require_ex("games.fish.views.pond.FSkillType").new(self, self._rootNode)
self._layerTemp = require_ex("games.fish.views.pond.FTempUI").new(self, self._rootNode)
self._layerPosFlag = require_ex("games.fish.views.pond.FPosFlag").new(self, self._rootNode)
self._layerTip = require_ex("games.fish.views.pond.FTipUI").new(self, self._rootNode)
self._layerGuide = require_ex("games.fish.views.pond.FGuideUI").new(self, self._rootNode)
self._layerWarning = require_ex("games.fish.views.pond.FWarningUI").new(self, self._rootNode)
self._cannonGuide = require_ex("games.fish.views.pond.FCannonGuideUI").new(self, self._rootNode)
if not Game.fishDB:isMatchRoom() and Game:funcIsOpen("task") and
Game:doPluginAPI("get", "nextTaskId",TaskScene.newbie) > 0 then
require_ex("games.fish.views.pond.FTaskUI").new(self, self._rootNode)
end
self._layerHaiyaoResult= require_ex("games.fish.views.haiyao.FHaiyaoResult").new(self, self._rootNode)
self._layerBossEff = require_ex("games.fish.views.pond.FBossPlayEff").new(self, self._rootNode)
-- BOSS展示模块
self._bossPlayModuleList = {
[1]= "games.fish.views.pond.FBugleUI",
[2]= "games.fish.views.haiyao.FHaiyaoUI",
[3]= "games.fish.views.jadeBoss.FJadeTaskUi",
[4]= "games.fish.views.jadeBoss.FJadeTaskUi",
}
self._flyCoinKey = "txt_plateNum"
self._killCoinKey = "txt_killNum"
if Game.fishDB:isRuinsRoom() then
self._flyCoinKey = "txt_plateNum4"
self._killCoinKey = "txt_killNum4"
end
self._layerBg:changeBg(true)
-- 初始化四个玩家对象
local tempCoin = self._layerTemp:getWidget(self._flyCoinKey)
local tempLottery = self._layerTemp:getWidget("panel_lottery_ing")
local panel_tips = self._layerTip:getWidget("panel_tips")
for i = 1, Game.fishDB:getPMAX() do
local ctrl = self._widgets["player"..i]
local emptyNode = self._widgets["playerEmpty"..i]
if emptyNode then
adaptRescale(emptyNode)
end
self._player[i] = FPlayer:new(self, i, ctrl, tempCoin, emptyNode, tempLottery, panel_tips)
Game.fishMng:setCannonOrigin(i, self._player[i]:getCannonPosition())
end
self._layerBossEff:initPlayerPos()
self:initMatchUI()
-- 绑定鱼池点击
self._widgets.panel_touch:onTouch(handler(self, self.onTouchPond))
end
function M:initRoomUI()
if Game.fishDB:isHuntRoom() then
if Assist.isEmpty(self._layerHunt) then
self._layerHunt = require_ex("games.fish.views.hunt.FHunt").new()
self._layerHunt:addTo(self._rootNode,ENUM.UI_Z.TIP)
end
elseif Game.fishDB:isMatchRoom() then
self:initMatchUI()
if self._layerMatch and self._layerMatch.startMatch then
self._layerMatch:startMatch()
end
elseif Game.fishDB:isRuinsRoom() or Game.fishDB:isNewRuinsRoom() then
--
else
self._layerTip:updateRedress()
end
self._layerUI:setBombVisible(self._layerTip:isBombing())
self:onTreasureTaskChange()
end
function M:initMatchUI()
if not self._layerMatch then
local roomId = Game.fishDB:getRoomId()
if roomId == ENUM.ROOM_ID.FREE_MATCH then
self._layerMatch = require_ex("games.fish.views.match.FMatchFreeUI").new():addTo(self._rootNode)
elseif roomId == ENUM.ROOM_ID.GRAND_PRIX then
self._layerMatch = require_ex("games.fish.views.match.FMatchGPUI").new(self._layerUI,self,self._layerTemp:getWidget(self._flyCoinKey))
self._layerMatch:addTo(self._rootNode)
elseif roomId == ENUM.ROOM_ID.ENTIRE then
self._layerMatch = require_ex("games.fish.views.match.FMatchEntireUI").new(self._layerUI,self,self._layerTemp:getWidget(self._flyCoinKey))
self._layerMatch:addTo(self._rootNode)
end
end
end
function M:getWidget(mix)
if String.startWith(mix, "_layer") then
return self[mix]
end
return self._widgets[mix]
end
function M:toFront()
Game:doPluginAPI("query", "quickInfo")
if LOW_MACHINE then
for _, p in ipairs(self._player) do
p:showLockChain()
end
end
end
function M:preloadSpine()
if Game.fishDB:getRoomId() == FishRoomID.haiyao then
preloadSpine(BYFishConfig.spine(FishSpe.haiyao_boss))
preloadSpine(BYFishConfig.spine(FishSpe.haiyao_monster))
end
end
function M:onEnter()
if GARBAGE_DISABLE then
collectgarbage("stop")
end
UIBase.onEnter(self)
Assist.addSpriteFrames("subgame/catchFish/tp/subgame_catchFish")
Assist.addSpriteFrames("subgame/catchFish/tp/subgame_catchFish_fish")
Game:unlockTouch()
-- 隐藏前置界面
local layer = Game.uiManager:getRoomChooseLayer()
if layer then
layer:toBack()
end
if Game.hallUI then
Game.hallUI:toBack()
end
--[[新手引导]]
if Game.fishDB:getRoomId() == FishRoomID.shjs then
self._layerGuide:showGameGuide("shjs")
end
if device.platform ~= "windows" then
-- 背景音乐预加载(延迟)
local bgm = string.format(Sound_fishConfig["BGM>normal"].file, 1)
Audio.preloadMusic(bgm)
if BGM_MAX > 1 then
for i = 2, BGM_MAX do
local _bgm = string.format(Sound_fishConfig["BGM>normal"].file, i)
self:performWithDelay(function()
Audio.preloadMusic(_bgm)
end, 0.1*i)
end
end
if Game.fishDB:isRuinsRoom() then
bgm =Sound_fishConfig["BGM>yushi"].file
Audio.preloadMusic(bgm)
end
-- 低端机优化
if not LOW_MACHINE then
self:performWithDelay(function()
Audio.preloadMusic(Sound_fishConfig["BGM>boss"].file)
end, 0.3)
end
end
self:performWithDelay(function()
for _, id in ipairs(Game.fishDB:getSpecialDrop()) do
self:onShowSpecialDrop(id)
end
end, 0.3)
if COLLISION_PHYSIC then
self:detectCollision()
end
end
function M:onExit()
Game:doPluginAPI("ingore", "redpacket", 2)
Game.connectHandler:setHeartBeatInterval(HEART_BEAT_DEFAULT)
if Game.reloadToGame then
Game.fieldId = Game.fishDB:getRoomId()
else
Game.fishCom:onExit()
end
Game.fishDB:init()
self:resumeMusic()
UIBase.onExit(self)
if COLLISION_PHYSIC then
self:removeCollisionListener()
end
if GARBAGE_DISABLE then
Game:performDelay(function()
if not Game.uiManager:getLayer("FPond") then
collectgarbage("restart")
end
end, 2)
end
end
function M:destroy()
-- 显示前置界面
local layer = Game.uiManager:getRoomChooseLayer()
if layer then
layer:toFront()
elseif Game.hallUI then
Game.hallUI.super.toFront(Game.hallUI)
end
self:unscheduleUpdate()
UIBase.destroy(self)
end
-- 背景音乐控制
function M:stopMusic()
if not self._myVolume then
self._myVolume = Game.setDB:getVolume()
Game.setDB:setVolume(0)
end
end
function M:resumeMusic()
if self._myVolume then
Game.setDB:setVolume(self._myVolume)
self._myVolume = nil
end
end
--[[
跑马灯位置
]]
function M:setMarqueePos()
-- 跑马灯位置偏移
local nodeMarquee = self._layerPosFlag and self._layerPosFlag:getWidget("point_marquee")
if nodeMarquee then
local pos = cc.p(nodeMarquee:getPosition())
Game:doPluginAPI("move", "marquee", pos)
end
end
---------------------------------------------
-- 碰撞检测
function M:detectCollision()
local function _contactLogic_(b_uid, f_uid)
local bullet = self:getBullet(b_uid)
local fish = self._fish[tostring(f_uid)]
if not bullet or not fish then return end -- 非法
if not fish:hitEnable() then return end -- 鱼可以被攻击
if bullet:hitTargetFish() and not bullet:isTargetFish(f_uid) then return end -- 打中的不是目标鱼
local hasLife = bullet:hasLife()
if hasLife then
if bullet:hadHitFish(f_uid) then return end -- 已经打中过这条鱼
bullet:addHitFish(f_uid)
end
Game.fishCom:onHitFish(b_uid, {f_uid}, hasLife)
Game.fishMng:removeMyBullet()
end
local function _onContactBegin_(contact)
local bA = contact:getShapeA():getBody()
local bB = contact:getShapeB():getBody()
local a = bA:getNode()
local b = bB:getNode()
if not a or not b then return end
-- Log.I(bA:getCategoryBitmask(), bB:getCategoryBitmask(), _TAG)
if bA:getCategoryBitmask() == FishPhysic.mask_bullet then
_contactLogic_(a.b_uid, b.f_uid)
elseif bB:getCategoryBitmask() == FishPhysic.mask_bullet then
_contactLogic_(b.b_uid, a.f_uid)
end
return false
end
self._contactListener = cc.EventListenerPhysicsContact:create()
self._contactListener:registerScriptHandler(_onContactBegin_, cc.Handler.EVENT_PHYSICS_CONTACT_BEGIN)
local eventDispatcher = director:getEventDispatcher()
eventDispatcher:addEventListenerWithFixedPriority(self._contactListener, 1)
end
function M:removeCollisionListener()
if self._contactListener then
local eventDispatcher = director:getEventDispatcher()
eventDispatcher:removeEventListener(self._contactListener)
self._contactListener = nil
end
local pWorld = display.getRunningScene():getPhysicsWorld()
if pWorld then
pWorld:removeAllBodies()
end
end
---------------------------------------------
-- 刷新
function M:refresh(event)
if self._preloading then return end
local notUpdateUI, clear
if type(event) == "boolean" then
notUpdateUI = event
else
notUpdateUI = event.data[1]
clear = event.data[2]
end
if clear then
self:clearPond()
end
self:clearDrop()
if not Assist.isEmpty(self._layerHaiyaoResult) then
self._layerHaiyaoResult:closeResult()
end
if Game.fishDB:getBulgeLastTimeCD() > 0 then
self._layerUI:startTimer({"btn_bugle"}, Game.fishDB:getBulgeLastTimeCD())
Game.fishDB:setBulgeLastTimeCD(0)
end
if not Assist.isEmpty(self._wlfxBoss) then
self._wlfxBoss:doStateIdle()
self._wlfxBoss = nil
end
self._layerBg:changeBg(true)
self:initBulletList()
self:initFishPond()
Game.fishDB:setFrencyPause(false)
self._layerUI:checkFuncOpen()
self._layerUI:setFrencySkillType(true)
self._layerSkill:instanceView() -- 恢复技能状态
self._layerTip:setPetSkillVisible(false) -- 宠物提示语
for i = 1, Game.fishDB:getPMAX() do
local player = self._player[i]
local pInfo = Game.fishDB:getPlayerByIdx(i)
if pInfo then
player:onEnterRoom(pInfo, true)
if player:isMySelf() then
if player:getBombId() > 0 then
self._layerUI:setBombVisible(true)
self._layerTip:setBombVisible(true, player)
else
self._layerUI:setBombVisible(false)
self._layerTip:setBombVisible(false)
end
-- 入场时,宠物技能CD
self:defaultSkillCD(pInfo.using_pet_id)
end
else
player:onExitRoom()
end
end
local level = Game.fishDB:getPlayerCannonLv()
if level then
self._layerUI:updateCannonShow(false)
end
if not notUpdateUI then
self._layerUI:updateLotteryShow(false)
self:updateBagData()
end
self._layerUI:updatePetShow()
end
function M:updateFunc(dt)
local player = self:getPlayerById(self._myUid)
if player and player:idleDisable() then
-- 闲置超时踢出房间
Game:performDelay(function ()
showConfirmTip({sTip=Config.localize("fish_idle_kick"), btn2Hide=true}, nil, ENUM.UI_Z.TOP)
end, 0.5)
self:unscheduleUpdate()
self:stopAllActionsForExit()
self:performWithDelay(function()
self:onKickOut(1)
end, 0.04)
return
end
if self:isLoading() then return end
-- 抖屏
if #self.shakeNodes > 0 then
self:updateShake()
end
-- 鱼
for _, fish in pairs(self._fish) do
if fish:getState(FishState.idle) or fish:isWild() then
self:removeFish(fish.fish_uid)
else
if not fish:getFrozen() and fish:faintTimes()<=0 then
-- 没有初始同步过或者非冰封和眩晕
fish:updateActor(dt)
end
end
end
for i = 1, FPS_ADD_FISH do
local v = Game.fishDB:getAddFish()
if v then
self:addFish(v, nil, nil, true)
else
break
end
end
-- 子弹
for _, bullet in pairs(self._bullet) do
if bullet:isWild() then
self:removeBullet(bullet.shoot_uid)
Game.fishDB:removeBullet(bullet.shoot_uid)
else
bullet:updateActor(dt)
end
end
-- 玩家
for _, p in ipairs(self._player) do
p:onUpdate(dt)
end
-- 后端调试
self:updateDebugData()
-- FPS监控
if self._fpsRemain then
self._fpsRemain = self._fpsRemain + self._inv
self._fpsCheckTick = self._fpsCheckTick - dt
if self._fpsCheckTick < 0 then
self._fpsCheckTick = FPS_CHECKPAD
self:checkFPSMessy()
end
end
end
--[[
重置技能cd跑一圈
]]
function M:defaultSkillCD(pId)
if Assist.isEmpty(pId) then return end
local skill_id = PetConfig.skill_id(pId) or 0
local cfg = BYSkillConfig[skill_id]
if Assist.isEmpty(cfg) then return end
self._layerUI:startTimer({"btn_pet"}, cfg.cd_time/1000, cfg.cd_tips)
end
function M:clearDrop()
for _, v in ipairs(self.dropList) do
if not Assist.isEmpty(v) then
v:removeFromParent()
end
end
self.dropList = {}
if self._layerUI then
self._layerUI:getTimer(self.skilList, true)
end
end
--------------------------------------------------
-- 数据接口/查询
function M:isLoading()
return self._preloading
end
function M:setLoading(v)
if v then
self._preloading = v
Game.fishDB:setProgress(0)
else
self:onEnterGame()
self:performWithDelay(function ()
self._preloading = v
self:refresh(false)
Game.fishCom:onFishRelocation()
end, 0.8)
end
end
--[[
FPS监控
掉帧是移除鱼影子,恢复再添加
]]
function M:isFPSMessy()
return self._fpsMessy > 0
end
function M:addFPSMessy()
self._fpsMessy = self._fpsMessy + 1
for _, f in pairs(self._fish) do
f:removeShadow()
end
end
function M:checkFPSMessy()
local fps = Timer:getCurTimeStamp()
if fps - self._fpsRemain > FPS_CHECKPAD/4 then
self:addFPSMessy()
else
self._fpsMessy = 0
end
self._fpsRemain = fps
end
function M:isEntering()
return self._entering
end
function M:getPlayerByIdx(idx)
return self._player[idx]
end
function M:getPlayerById(uid)
local idx = Game.fishDB:getPlayerIndex(uid)
return self._player[idx]
end
function M:resetPlayers()
for i = 1, Game.fishDB:getPMAX() do
if self._player[i] then
self._player[i]:reset()
end
end
end
--[[
搜索目标鱼(倍率最大)
]]
function M:searchTargetFish()
local target
for _, fish in pairs(self._fish) do
if fish:hitEnable() then
if not target or target:getTimesArea() < fish:getTimesArea() then
target = fish
end
end
end
return target
end
--[[
扫描圆形区域内的鱼
@param x, y, r number 圆形参数
@param max number 扫描上限
@param precise boolean 是否精确判断
@param bullet FBullet 子弹(巡游类[钻头])
]]
function M:scanFishInCircle(x, y, r, max, precise, bullet)
local ret, f, retUidList = {}, nil, {}
local checkFishes = Game.fishMng:getAliveFishs()
for i = #checkFishes, 1, -1 do
f = checkFishes[i]
if f:isInScreen() and f:collideCircle(x, y, checknumber(r), precise) then
if not bullet or not bullet:hadHitFish() then
table.insert(ret, f)
table.insert(retUidList, f.fish_uid)
if max and #ret == max then
break
end
end
end
end
return ret, retUidList
end
--[[
扫描线上的鱼(激光炮)
]]
function M:scanFishInLine(p1, p2, area)
local ret, f = {}
local checkFishes = Game.fishMng:getAliveFishs()
for i = #checkFishes, 1, -1 do
f = checkFishes[i]
if f:isInScreen() and f:checkFishInSameDir(p1, p2) and f:collideLine(p1, p2, area) then
table.insert(ret, f.fish_uid)
f:changeState(FishState.hit)
end
end
return ret
end
--[[
冰封
]]
function M:updateFrozenShow(show, dur)
if show then
if not self._widgets.act_frozen then
self._widgets.act_frozen = Actor:new(SpineFrozen.res, SpineFrozen)
self._widgets.panel_surface:addChild(self._widgets.act_frozen)
else
self._widgets.act_frozen:stopAllActions()
self._widgets.act_frozen:setVisible(true)
self._widgets.act_frozen:changeAnimation(SpineFrozen.ani, false, nil, true)
end
self._widgets.act_frozen:performWithDelay(function()
self:updateFrozenShow(false, 0)
end, dur)
else
if self._widgets.act_frozen then
self._widgets.act_frozen:stopAllActions()
self._widgets.act_frozen:pause()
self._widgets.act_frozen:setVisible(false)
end
end
end
--[[
更新鱼的弹头攻击状态(冰封时)
]]
function M:updateBombFish()
local player = self:getPlayerById(self._myUid)
local show = player and player:getBombId() > 0
for _, f in pairs(self._fish) do
f:checkBombState(show)
end
end
function M:showPetCanNotAttTip()
local player = self:getPlayerById(self._myUid)
-- 刷新鱼的锁定状态提示
local petAtt, effType = player:getPetSkillType() > 0, false
for _, f in pairs(self._fish) do
effType = f._petskill_effect_type
f:showPetCanNotAttTip(petAtt and effType)
end
end
--[[
刷新锁定鱼(仅自己)
]]
function M:updateLockFish(info, ignoreFish)
info = info or Game.fishDB:getPlayer() or {}
local showLock = false
if info.frency or info.lock then
local idx = Game.fishDB:getMyIndex()
local player = self._player[idx]
if not player or player:isDrilling() then return end
if not player:canHitTargetFish() then
-- 自动锁定新的鱼 @discarded
-- local maxFish = self:searchTargetFish()
-- player:setTargetFish(maxFish)
self._layerTip:setLockVisible(true, player)
showLock = true
end
end
if not ignoreFish then
-- 刷新鱼的锁定状态提示
for _, f in pairs(self._fish) do
f:checkLockState(showLock)
end
end
end
--[[
更新任务鱼
]]
function M:updateTaskFish()
local show -- nil自行检测
if not Game.fishDB:isInTask() then
show = false
end
for _, f in pairs(self._fish) do
f:checkTaskState(show)
end
end
--[[
击杀获得金币飘字
@param pos point 位置
@param idx number 归属玩家索引
@param num number 奖励数量
@param delay number 延迟时间
]]
function M:flyCoinNumer(pos, idx, num, delay)
delay = checknumber(delay)
local tempKey = self._killCoinKey
if not self._player[idx]:isMySelf() then
tempKey = "txt_killNum2"
end
local tempNode = self._layerTemp:getWidget(tempKey)
local numFloat = tempNode:clone()
numFloat:setString(num)
numFloat:setPosition(pos.x, pos.y + 50)
numFloat:setVisible(delay == 0)
self._rootNode:addChild(numFloat, 100)
local seq = {
cc.DelayTime:create(delay),
cc.Show:create(),
cc.DelayTime:create(0.5),
cc.EaseSineOut:create(cc.FadeOut:create(0.8)),
cc.DelayTime:create(0.8),
cc.ScaleTo:create(0.5, 0.5),
cc.RemoveSelf:create(),
}
numFloat:runAction(transition.sequence(seq))
end
--[[
展示获得金币
@param pos point 位置
@param idx number 座位
@param num number 获得金币数量
@param cannonId number 炮台ID
@param fish FFish/table 鱼
@param ignorePlate boolean 忽略奖金盘展示
]]
function M:displayGetCoin(pos, idx, num, cannonId, fish, ignorePlate)
if num <= 0 or self._entering then return end
-- self:flyCoinNumer(pos, idx, num)
local times, dieName, fishType