forked from zenyr/PocoHud3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHud3.lua
3031 lines (2906 loc) · 98.9 KB
/
Hud3.lua
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
-- PocoHud3 by [email protected]
if not TPocoBase then return end
local disclaimer = [[
feel free to ask me through my mail: zenyr(at)zenyr.com. But please understand that I'm quite clumsy, cannot guarantee I'll reply what you want..
]]
-- Note: Due to quirky PreCommit hook, revision number would *appear to* be 1 revision before than "released" luac files.
local _ = UNDERSCORE
local REV = 451 -- git shortlog | wc -l
local TAG = '0.34' -- git describe --tags
local inGame = CopDamage ~= nil
local inGameDeep
local me
PocoHud3Class = nil
Poco._req ('poco/Hud3_class.lua')
if not PocoHud3Class then return end
Poco._req ('poco/Hud3_Options.lua')
if not PocoHud3Class.Option then return end
local O = PocoHud3Class.Option:new()
PocoHud3Class.O = O
local K = PocoHud3Class.Kits:new()
PocoHud3Class.K = K
local L = PocoHud3Class.Localizer:new()
PocoHud3Class.L = L
--- Options ---
local YES,NO,yes,no = true,false,true,false
local ALTFONT= PocoHud3Class.ALTFONT
local FONT= PocoHud3Class.FONT
local FONTLARGE = PocoHud3Class.FONTLARGE
local clGood= PocoHud3Class.clGood
local clBad= PocoHud3Class.clBad
local Icon= PocoHud3Class.Icon
local PocoEvent= PocoHud3Class.PocoEvent
local _BAGS = {
['8f59e19e1e45a05e']='Ammo',
['43ed278b1faf89b3']='Med',
['a163786a6ddb0291']='Body',
['e1474cdfd02aa274']='Aid',
}
local _BROADCASTHDR, _BROADCASTHDR_HIDDEN = Icon.Div,Icon.Ghost
local skillIcon = 'guis/textures/pd2/skilltree/icons_atlas'
local perkIcon = 'guis/textures/pd2/specialization/icons_atlas'
local now = function (type) return type and TimerManager:game():time() or managers.player:player_timer():time() end
local _conv = {
city_swat = L('_mob_city_swat'),
cop = L('_mob_cop'),
fbi = L('_mob_fbi'),
fbi_heavy_swat = L('_mob_fbi_heavy_swat'),
fbi_swat = L('_mob_fbi_swat'),
gangster = L('_mob_gangster'),
gensec = L('_mob_gensec'),
heavy_swat = L('_mob_heavy_swat'),
security = L('_mob_security'),
shield = L('_mob_shield'),
sniper = L('_mob_sniper'),
spooc = L('_mob_spooc'),
swat = L('_mob_swat'),
tank = L('_mob_tank'),
taser = L('_mob_taser'),
}
--- Class Start ---
local TPocoHud3 = class(TPocoBase)
PocoHud3Class.TPocoHud3 = TPocoHud3
TPocoHud3.className = 'Hud'
TPocoHud3.classVersion = 3
--- Inherited ---
function TPocoHud3:onInit() -- ★설정
-- Poco:LoadOptions(self:name(1),O)
O:load()
L:load()
clGood = O:get('root','colorPositive')
clBad = O:get('root','colorNegative')
self._ws = managers.gui_data:create_fullscreen_workspace()
error = function(msg)
if self.dead then
_('ERR:',msg)
else
self:err(msg,1)
end
end
--self:_setupWws()
self.pnl = {
dbg = self._ws:panel():panel({ name = 'dbg_sheet' , layer = 50000}),
pop = self._ws:panel():panel({ name = 'dmg_sheet' , layer = 4}),
buff = self._ws:panel():panel({ name = 'buff_sheet' , layer = 5}),
stat = self._ws:panel():panel({ name = 'stat_sheet' , layer = 9}),
}
-- 'customhud' PR #22 related
self.custom_hud_enabled = rawget(_G,'mod_collection') and _.g('mod_collection._data.custom_hud_enabled')
self.killa = self.killa or 0
self.stats = self.stats or {}
self.hooks = {}
self.pops = {}
self.buffs = {}
self.floats = {}
self.sFloats = {}
self.smokes = {}
self.hits = {} -- to prevent HitDirection markers gc
self.gadget = self.gadget or {}
-- self.tmp = self.pnl.dbg:bitmap{name='x', blend_mode = 'add', layer=1, x=0,y=40, color=clGood ,texture = 'guis/textures/hud_icons'}
local dbgO = O:get('corner')
self.dbgLbl = self.pnl.dbg:text{text='HUD '..(inGame and 'Ingame' or 'Outgame'), font= dbgO.defaultFont and FONT or ALTFONT, font_size = dbgO.size, color = dbgO.color:with_alpha(dbgO.opacity/100), x=0,y=self.pnl.dbg:height()-dbgO.size, layer=0}
self:_hook()
self:_updateBind()
return true
end
function TPocoHud3:onResolutionChanged()
if alive(self._ws) then
managers.gui_data:layout_fullscreen_workspace( self._ws )
self.dbgLbl:set_y(self.pnl.dbg:height()-self.dbgLbl:height())
else
self:err('No WS to reschange')
end
end
function TPocoHud3:import(data)
self.killa = data.killa
self.stats = data.stats
self._muted = data._muted
self._startGameT = data._startGameT
end
function TPocoHud3:export()
Poco.save[self.className] = {
stats = self.stats,
killa = self.killa,
_muted = self._muted,
_startGameT = self._startGameT,
}
end
function TPocoHud3:Update(t,dt)
if managers.vote:is_restarting() then return end
local r,err = pcall(self._update,self,t,dt)
if not r then _(err) end
end
function TPocoHud3:onDestroy(gameEnd)
self:Menu(true,true) -- Force dismiss menu
if( alive( self._ws ) ) then
managers.gui_data:destroy_workspace(self._ws)
end
if( alive( self._worldws ) ) then
World:newgui():destroy_workspace( self._worldws )
end
end
function TPocoHud3:AddDmgPopByUnit(sender,unit,offset,damage,death,head,dmgType)
if unit and alive(unit) then
self:AddDmgPop(sender,self:_pos(unit),unit,offset,damage,death,head,dmgType)
end
end
local _lastAttk, _lastAttkpid = 0,0
function TPocoHud3:AddDmgPop(sender,hitPos,unit,offset,damage,death,head,dmgType)
local Opt = O:get('popup')
if self.dead then return end
local pid = self:_pid(sender)
local isPercent = damage<0
local dmgTime = Opt.damageDecay
local rDamage = damage>=0 and damage or -damage
if isPercent and unit and unit:character_damage() and unit:character_damage()._HEALTH_INIT then
rDamage = math.min(unit:character_damage()._HEALTH_INIT * rDamage / 100,unit:character_damage()._health)
end
local isSpecial = false
if unit then
if not alive(sender) then return end -- If an attacker died/nonexist just before this, abandon.
local senderTweak = sender and alive(sender) and sender:base() and sender:base()._tweak_table
local unitTweak = unit and alive(unit) and unit:base() and unit:base()._tweak_table
isSpecial = tweak_data.character[ unitTweak ]
isSpecial = isSpecial and isSpecial.priority_shout
if isSpecial =='f34' then isSpecial = false end
for i = 1,4 do
local minion = self:Stat(i,'minion')
if unit == minion then
local apid = self:_pid(senderTweak)
self:Stat(i,'minionHit',senderTweak)
if (rDamage or 0) > 0 and apid and apid > 0 and (apid ~= _lastAttkpid or now()-_lastAttk > 5) then
_lastAttk = now()
_lastAttkpid = apid
self:Chat('minionShot',L('_msg_minionShot',{self:_name(senderTweak),i==apid and 'own' or self:_name(i)..'\'s',_.f(rDamage*10)}))
end
end
end
end
local color = (self:_color(sender,cl.White)):with_alpha(death and 1 or 0.5)
local texts = { }
if rDamage>0 then
texts[#texts+1] = {_.f(rDamage*10),color}
end
if head then
texts[#texts+1] = {'!',color:with_red(1)}
end
if death then
texts[#texts+1] = {'',isSpecial and cl.Yellow or color}
end
local pos = Vector3()
mvector3.set(pos,hitPos)
mvector3.set_z(pos,pos.z + offset)
local r,err = pcall(function()
if sender then
if self:Stat(pid,'time') == 0 then
self:Stat(pid,'time',now())
end
if dmgType == 'bullet' then
self:Stat(pid,'dmg',rDamage*10,true)
self:Stat(pid,'hit',1,true)
end
if head then
self:Stat(pid,'head',1,true)
end
if death then
self.killa = self.killa +1
self:Stat(pid,'kill',1,true)
if isSpecial then
self:Stat(pid,'killS',1,true)
end
local mA = O:get('chat','midstatAnnounce') or 0
if mA > 0 and Network:is_server() and (self.killa % (mA*50) == 0 ) then
self:AnnounceStat(true)
end
end
end
if pid == self.pid and not Opt.myDamage then return
elseif pid == 0 and not Opt.AiDamage then return
elseif not Opt.crewDamage then
if pid > 0 and pid ~= self.pid then
return
end
end
if Opt.enable then
self:Popup( {pos=pos, text=texts, stay=false, et=now()+dmgTime })
end
end)
if not r then _(err) end
end
--- Internal functions ---
function TPocoHud3:pidToPeer(pid)
local session = managers.network:session()
return session and session:peer(pid)
end
function TPocoHud3:say(line,sync)
if line then
--[[local cs = _.g('managers.player:player_unit():movement()._current_state')
if cs then
cs._intimidate_t = now()
pcall(self.Buff,self,({
key='interact', good=false,
icon=skillIcon,
iconRect = { 2*64, 8*64 ,64,64 },
st=now(), et=now()+tweak_data.player.movement_state.interaction_delay
}) )
end]]
--[[
if _.g('managers.groupai:state()') then
managers.groupai:state():teammate_comment(_.g('managers.player:player_unit()'), line, nil, false, nil, false)
return true
end]]
local sound = _.g('managers.player:player_unit():sound()')
if not sound then return end
return sound:say(line,true,sync)
end
end
function TPocoHud3:toggleRose(show)
if self._noRose then return end
local C = PocoHud3Class
local canOpen = inGameDeep and (not self._lastSay or now()-self._lastSay > tweak_data.player.movement_state.interaction_delay / 2)
local r,err = pcall(function()
local menu = self.menuGui
if menu and not self._guiFading then -- hide
self.menuGui = nil
self._guiFading = true
if self._say then
if self:say(self._say,true) then
self._lastSay = now()
end
self._say = nil
end
menu:fadeOut(function()
self._guiFading = nil
menu:destroy()
end)
elseif canOpen and show and not self._guiFading then -- create
local gui = C.PocoMenu:new(self._ws,true)
self.menuGui = gui
gui:fadeIn()
local tab = gui:add('Rose')
C._drawRose(tab)
elseif not canOpen and show then
-- managers.menu:post_event('menu_error')
end
end)
if not r then
self:err(_.s('ToggleRose',err))
end
end
function TPocoHud3:Menu(dismiss,skipAnim)
local C = PocoHud3Class
local _drawUpgrades = C._drawUpgrades
local _drawPlayer = C._drawPlayer
local r,err = pcall(function()
local menu = self.menuGui
if menu then -- Remove
self:_updateBind()
if not self._stringFocused or (now()-self._stringFocused > 0.1) then
self.menuGui = nil
self._noRose = nil
self._guiFading = true
if self.onMenuDismiss then
local cbk = self.onMenuDismiss
self.onMenuDismiss = nil
cbk()
end
if not self:say('g92',true) then
managers.menu_component:post_event('menu_exit')
end
if skipAnim then
menu:destroy()
self._guiFading = nil
else
menu:fadeOut(function()
self._guiFading = nil
menu:destroy()
end)
end
end
elseif not dismiss and not self._guiFading and not managers.system_menu:is_active() then -- Show
if not self:say('a01x_any',true) then
managers.menu_component:post_event('menu_enter')
end
local gui = C.PocoMenu:new(self._ws)
self.menuGui = gui
self._noRose = true
gui:fadeIn()
--- Install tabs Begin --- ===================================
local tab = gui:add(L('_tab_about'))
C._drawAbout(tab,REV,TAG)
local tab = gui:add(L('_tab_options'))
C._drawOptions(tab)
local y = 0
tab = gui:add(L('_tab_statistics'))
do
local oTabs = C.PocoTabs:new(self._ws,{name = 'stats',x = 10, y = 10, w = 970, th = 30, fontSize = 18, h = tab.pnl:height()-20, pTab = tab})
local oTab = oTabs:add(L('_tab_heistStatus'))
local r,err = pcall(C._drawHeistStats,oTab) -- yeaaaah just in case. I know. I'm cheap
if not r then me:err('DHS:'..tostring(err) ) end
oTab = oTabs:add(L('_tab_upgradeSkills'))
if inGame then
for pid,upg in pairs(_.g('Global.player_manager.synced_team_upgrades',{})) do
if upg then
y = _drawUpgrades(oTab,upg,true,L('_upgr_crewBonusFrom',{self:_name(pid)}) ,y)
end
end
end
y = _drawUpgrades(oTab,_.g('Global.player_manager.team_upgrades'),true,L('_line_youAndCrewsPerks'),y)
y = _drawUpgrades(oTab,_.g('Global.player_manager.upgrades'),false,L('_line_yourPerks'),y)
end
tab = gui:add(L('_tab_tools'))
do
local oTabs = C.PocoTabs:new(self._ws,{name = 'tools',x = 10, y = 10, w = 970, th = 30, fontSize = 18, h = tab.pnl:height()-20, pTab = tab})
local oTab = oTabs:add(L('_tab_kitProfiler'))
PocoHud3Class._drawKit(oTab)
local oTab = oTabs:add(L('_tab_Inspect'))
y = _drawPlayer(oTab, 0)
oTab:set_h(y)
local oTab = oTabs:add(L('_tab_jukebox'))
PocoHud3Class._drawJukebox(oTab)
end
end
end)
if not r then _('MenuCallErr',err) end
end
function TPocoHud3:AnnounceStat(midgame)
local txt = {}
table.insert(txt,Icon.LC..'PocoHud³ r'..REV.. ' '.. Icon.RC..' '..L('_stat_crewKills',{Icon.Skull,self.killa}))
for pid = 0,4 do
local kill = self:Stat(pid,'kill')
local killS = self:Stat(pid,'killS')
if kill > 0 then
local dt = now()-self:Stat(pid,'time')
local dps = _.f(self:Stat(pid,'dmg')/dt or 0)
local hit = math.max(self:Stat(pid,'hit'),1)
local shot = math.max(self:Stat(pid,'shot'),1)
local accuracy = _.f(hit/shot*100,0)..'%'
local kpm = _.f(60*kill/dt)
local downs = self:Stat(pid,'down')+self:Stat(pid,'downAll')
if midgame then
table.insert(txt,
_.s(Icon.LC..self:_name(pid)..Icon.RC,
kill..Icon.Skull..(killS>0 and '('..killS..' Sp)' or ''),
(downs>0 and downs..Icon.Ghost or nil)
)
)
else
table.insert(txt,
_.s(Icon.LC..self:_name(pid)..Icon.RC,
kill..Icon.Skull..(killS>0 and '('..killS..' Sp)' or ''),'|',
'DPS:'..dps,'|',
'KPM:'..kpm,'|',
'Acc:'..(pid==0 and 'N/A' or accuracy),
(downs>0 and downs..Icon.Ghost or nil)
)
)
end
end
end
if #txt > 3 then
for ___,tx in ipairs(txt) do
self:Chat(midgame and 'midStat' or 'endStat',tx)
end
else
self:Chat(midgame and 'midStat' or 'endStat',table.concat(txt,'\n'))
end
if false and not midgame then -- fuck humor.
self:Chat('endStatCredit','-- PocoHud³ : More info @ steam group "pocomods" --')
end
end
local lastSlowT = 0
function TPocoHud3:_slowUpdate(t,dt)
self.ww = self.pnl.dbg:w()
self.hh = self.pnl.dbg:h()
if inGame then
local peers = _.g('managers.network:session():peers()',{})
for pid,peer in pairs( peers ) do
if peer and peer:rpc() then
self:Stat(pid,'ping',math.floor(Network:qos( peer:rpc() ).ping))
end
end
self.pid = _.g('managers.network:session():local_peer():id()')
end
end
function TPocoHud3:_update(t,dt)
if not (PocoHud3Class and not self.dead) then return end
inGameDeep = inGame and BaseNetworkHandler._verify_gamestate(BaseNetworkHandler._gamestate_filter.any_ingame_playing)
if self.inGameDeep ~= inGameDeep then
if inGameDeep then
self._startGameT = now()
else
self._endGameT = now()
end
self.inGameDeep = inGameDeep
end
self:_upd_dbgLbl(t,dt)
self.cam = managers.viewport:get_current_camera()
if not self.cam then return end
self.rot = self.cam:rotation()
self.camPos = self.cam:position()
self.nl_cam_forward = self.rot:y()
if t - lastSlowT > 5 then -- SlowUpdate
lastSlowT = t
self:_slowUpdate(t,dt)
end
if inGame then
self:_updateItems(t,dt)
end
if self.menuGui then
self.menuGui:update(t,dt)
end
local location = PocoHud3Class.PocoLocation
location:update(t,dt)
if inGameDeep and now() - (self._lastRoom or 0) > 1 then
self._lastRoom = now()
local room = _.g('Poco.room')
local session = managers.network:session()
if session then
for pid=1,4 do
local unit = self:Stat(pid,'custody') == 0 and room and session:peer(pid) and session:peer(pid):unit()
if unit and alive(unit) then
self:Stat(pid,'room',room:get(unit:movement():m_pos(),true))
end
end
end
end
if self._music_started then
if O:get('root','showMusicTitle') then
me:SimpleFloat{key='showMusicTitle',x=10,y=10,time=5,anim=1,offset={200,0},
text={{_.s(O:get('root','showMusicTitlePrefix')),cl.White:with_alpha(0.6)},{self._music_started,cl.Tan}},
size=24, icon = {tweak_data.hud_icons:get_icon_data('jukebox_playing_icon')}
}
end
self._music_started = nil
end
end
function TPocoHud3:HitDirection(col_ray,data)
local mobPos
if self._lastAttkUnit and alive(self._lastAttkUnit) then
mobPos = self._lastAttkUnit:position()
self._lastAttkUnit = nil
elseif col_ray and col_ray.position and col_ray.distance then
mobPos = col_ray.position - (col_ray.ray*(col_ray.distance or 0))
end
if not mobPos then -- still nothing? now we search data
local mobUnit = data.weapon_unit or data.attacker_unit
if mobUnit and alive(mobUnit) then
mobPos = mobUnit:position()
else
mobPos = data.hit_pos or data.position
end
end
if not mobPos then -- still no?... set to player position
mobPos = _.g('managers.player:player_unit():position()')
end
if mobPos then
table.insert(self.hits,PocoHud3Class.THitDirection:new(self,{mobPos=mobPos,shield=data.shield,dmg=data.dmg,time=data.time,rate=data.rate}))
end
end
function TPocoHud3:Minion(pid,unit)
if alive(unit) then
self:Stat(pid,'minion',unit)
self:Chat('converted',L('_msg_converted',{self:_name(pid),self:_name(unit),O:get('chat','includeLocation') and self:_name(pid,true) or ''}))
else
self:Stat(pid,'minion',0)
end
end
function TPocoHud3:Chat(category,text,system)
local catInd = O:get('chat',category) or -1
local forceSend = catInd >= 5
if not O:get('chat','enable') then return end
if self._muted and not forceSend then return _('Muted:',text) end
local canRead = catInd >= 1
local isFullGame = not managers.statistics:is_dropin()
local canSend = catInd >= (Network:is_server() and 2 or isFullGame and 3 or 4)
if catInd >= 3 and not canSend and not O:get('chat','fallbackToMe')then
canRead = false
end
local tStr = _.g('managers.hud._hud_heist_timer._timer_text:text()', '')
if canRead or canSend then
_.c(tStr..(canSend and '' or _BROADCASTHDR_HIDDEN), text , canSend and self:_color(self.pid) or nil)
if canSend then
managers.network:session():send_to_peers_ip_verified( 'send_chat_message', system and 8 or 1, tStr.._BROADCASTHDR.._.s(text) )
end
end
end
function TPocoHud3:Float(unit,category,temp,tag)
local key = unit.key and unit:key()
if not O:get('float','enable') then return end
if not key then return end
local float = self.floats[key]
if float then
float:renew({tag=tag,temp=temp})
else
if category == 1 and not O:get('float','showDrills') then
--
else
self.floats[key] = PocoHud3Class.TFloat:new(self,{category=category,key=key,unit=unit,temp=temp, tag=tag})
end
end
end
function TPocoHud3:Buff(data) -- {key='',icon=''||{},text={{},{}},st,et}
if not O:get('buff','enable') then return end
if not O:get('buff','show'.. ((data.key):gsub('^%l', string.upper)) ) then return end
local buff = self.buffs[data.key]
if buff and (buff.data.et ~= data.et or buff.data.good ~= data.good )then
buff:destroy(1)
buff = nil
end
if not buff then
buff = PocoHud3Class.TBuff:new(self,data)
self.buffs[data.key] = buff
else
buff:set(data)
end
end
function TPocoHud3:SimpleFloat(data) -- {key,x,y,time,text,size,val,anim,offset,icon,rect}
local key = data.key
if key and self.sFloats[key] then
self.sFloats[key]:hide()
self.sFloats[key] = nil
end
local pnl = self.pnl.dbg:panel{x = data.x, y = data.y, w=500, h=100}
if key then
self.sFloats[key] = pnl
end
pnl:rect{color=cl.Black,layer=-1,alpha=data.rect or 0.9}
local offset = data.offset or {0,0}
local anim = data.anim
local __, lbl = _.l({pnl=pnl,x=5,y=5, font=FONT, color=cl.White, font_size=data.size},data.text,true)
if data.icon then
local icon,rect = unpack(data.icon)
local bmp = pnl:bitmap{
name = 'icon',
texture = icon,
texture_rect = rect,
x = 5, y = 5
}
bmp:set_center_y(5 + data.size/2)
lbl:set_x(bmp:width()+10)
end
pnl:set_size(lbl:right()+5,lbl:bottom()+5)
pnl:stop()
local t = now()
pnl:animate(function(p)
while alive(p) and p:visible() do
local dt = now() - t
local r = dt / data.time
if r > 1 then break end
if anim == 1 then
r = math.pow(r,0.5)
local rr = math.min(r,1-r)
p:set_alpha(math.pow(rr,0.4))
end
local dx,dy = offset[1] * r, offset[2] * r
p:set_position(math.floor(data.x + dx),math.floor(data.y + dy))
coroutine.yield()
end
if alive(p) then
if p:visible() then
self.sFloats[key] = nil
end
p:parent():remove(p)
end
end)
end
function TPocoHud3:Popup(data) -- {pos=pos,text={{},{}},stay=true,st,et}
table.insert(self.pops ,PocoHud3Class.TPop:new(self,data))
end
function TPocoHud3:_updateBind()
Poco:UnBind(self)
local verboseKey = O:get('root','detailedModeKey')
if verboseKey then
if O:get('root','detailedModeToggle') then
Poco:Bind(self,verboseKey,callback(self,self,'toggleVerbose','toggle'))
else
Poco:Bind(self,verboseKey,callback(self,self,'toggleVerbose',true),callback(self,self,'toggleVerbose',false))
end
end
local pocoRoseKey = O:get('root','pocoRoseKey')
Poco:Bind(self,pocoRoseKey,callback(self,self,'toggleRose',true,false),callback(self,self,'toggleRose',false,false))
Poco:Bind(self,14,function()
self:Menu(false,false)
end)
local keys = K:keys()
for key,index in pairs(keys) do
Poco:Bind(self,key,function()
if not inGameDeep and ctrl() and alt() and not managers.system_menu:is_active() then
K:equip(index,not O:get('root','silentKitShortcut'))
managers.menu:post_event('finalize_mask')
end
end)
end
end
function TPocoHud3:_checkBuff(t)
-- Check Another Buffs
-- Berserker
if managers.player:upgrade_value( 'player', 'melee_damage_health_ratio_multiplier', 0 )>0 then
local health_ratio = _.g('managers.player:player_unit():character_damage():health_ratio()')
if(health_ratio and health_ratio <= tweak_data.upgrades.player_damage_health_ratio_threshold ) then
local damage_ratio = 1 - ( health_ratio / math.max( 0.01, tweak_data.upgrades.player_damage_health_ratio_threshold ) )
local mMul = 1 + managers.player:upgrade_value( 'player', 'melee_damage_health_ratio_multiplier', 0 ) * damage_ratio
local rMul = 1 + managers.player:upgrade_value( 'player', 'damage_health_ratio_multiplier', 0 ) * damage_ratio
if mMul*rMul > 1 then
local text = {{(mMul>1 and _.f(mMul)..'x' or '')..(rMul>1 and ' '.._.f(rMul)..'x' or ''),clBad}}
self:Buff({
key= 'berserker', good=true,
icon=skillIcon,
iconRect = { 2*64, 2*64,64,64 },
text=text,
color=cl.Red,
st=O:get('buff','style')==2 and damage_ratio or 1-damage_ratio, et=1
})
end
else
self:RemoveBuff('berserker')
end
end
-- Stamina
local movement = _.g('managers.player:player_unit():movement()')
if movement then
local currSt = movement._stamina
local maxSt = movement:_max_stamina()
local thrSt = movement:is_above_stamina_threshold()
if currSt < maxSt then
self:Buff({
key= 'stamina', good=false,
icon=skillIcon,
iconRect = { 7*64, 3*64,64,64 },
text=thrSt and '' or L('_buff_exhausted'),
st=(currSt/maxSt), et=1
})
else
self:RemoveBuff('stamina')
end
end
-- KillSkills
local plrManager = managers.player
local t = Application:time()
local killshotT = plrManager._on_killshot_t
if (killshotT and killshotT > t) then
local left = killshotT - t
local total = tweak_data.upgrades.on_killshot_cooldown
self:Buff({
key= 'killshot', good=false,
icon= perkIcon,
iconRect = { 3*64, 5*64, 64, 64 },
st=1-left/total, et=1
})
else
self:RemoveBuff('killshot')
end
-- Suppression
local supp = _.g('managers.player:player_unit():character_damage():effective_suppression_ratio()')
if supp and supp > 0 then
-- Not in effect as of now : local supp2 = math.lerp( 1, tweak_data.player.suppression.spread_mul, supp )
self:Buff({
key= 'suppressed', good=false,
icon=skillIcon,
iconRect = { 7*64, 0*64,64,64 },
text='', --_.f(supp2)..'x',
st=supp, et=1
})
else
self:RemoveBuff('suppressed')
end
local melee = self.state and self.state._state_data.meleeing and self.state:_get_melee_charge_lerp_value( t ) or 0
if melee > 0 then
self:Buff({
key= 'charge', good=true,
icon=skillIcon,
iconRect = { 4*64, 12*64,64,64 },
text='',
st=melee, et=1
})
else
self:RemoveBuff('charge')
end
end
local _roman = {
{'M',1000}, {'CM',900}, {'D',500}, {'CD',400}, {'C',100}, {'XC',90}, {'L',50}, {'XL',40}, {'X',10}, {'IX',9}, {'V',5}, {'IV',4}, {'I',1}
}
function TPocoHud3:_romanic_number(num)
local result = '';
if O:get('game','romanInfamy') then
while(num > 0) do
for i, val in pairs(_roman) do
if(num >= val[2]) then
num = num - val[2];
result = result .. val[1];
break;
end
end
end
else
result = tostring(num)
end
return result;
end
function TPocoHud3:_updatePlayers(t)
if t-(self._lastUP or 0) > 0.05 and inGameDeep then
self._lastUP = t
else
return
end
for i = 1,4 do
if self.custom_hud_enabled then
for _, panel in ipairs(managers.hud._teammate_panels) do
if panel._id == HUDManager.PLAYER_PANEL then
elseif panel:peer_id() == nil then
panel:update_downs(-1)
elseif i == panel:peer_id() then
panel:update_downs(self:Stat(i, 'down'))
end
end
end
local name = self:_name(i)
name = name ~= self:_name(-1) and name
local nData = managers.hud:_name_label_by_peer_id( i )
local isMe = i==self.pid
local pnl = self['pnl_'..i]
local btmO = O:get('playerBottom')
local fltO = O:get('playerFloat')
local _show = function(name,isFlt)
local thr = (isFlt and fltO or btmO)['show'..name] or 0
local ind = self.verbose and 1 or 2
return thr >= ind
end
pnl = pnl ~= 0 and pnl or nil
if pnl and (not name or not btmO.enable or (self:Stat(i,'_refreshBtm') ~= 0)) then
-- killPnl
self.pnl.stat:remove(pnl)
self['pnl_'..i] = nil
self:Stat(i,'_refreshBtm',0)
elseif not pnl and name and (isMe or nData) then
-- makePnl
local __,err = pcall(function()
if not self.custom_hud_enabled and btmO.enable and managers.criminals:character_unit_by_name( managers.criminals:character_name_by_peer_id(i) ) then
local cdata = managers.criminals:character_data_by_peer_id( i ) or {}
local bPnl = managers.hud._teammate_panels[ isMe and 4 or cdata.panel_id or -1 ]
if bPnl and not (not isMe and bPnl == managers.hud._teammate_panels[4]) then
local peer = self:_peer(i)
if peer and alive(peer:unit()) then
if btmO.showRank then
local rank = isMe and managers.experience:current_rank() or (peer and peer:rank())
rank = rank and (rank > 0) and (self:_romanic_number(rank)..'Ї') or ''
local lvl = isMe and managers.experience:current_level() or peer and peer:level() or ''
local defaultLbl = bPnl._panel:child( 'name' )
local nameBg = bPnl._panel:child( 'name_bg' )
local nameTxt = self:_name(i)
if btmO.uppercaseNames then
nameTxt = utf8.to_upper(nameTxt)
end
self:_lbl(defaultLbl,{{rank,cl.White},{lvl..' ',cl.White:with_alpha(0.8)},{nameTxt,self:_color(i)}})
local txtRect = {defaultLbl:text_rect()}
defaultLbl:set_size(txtRect[3],txtRect[4])
local shape = {defaultLbl:shape()}
nameBg:set_shape(shape[1]-3,shape[2],shape[3]+6,shape[4])
end
pnl = self.pnl.stat:panel{x = 0,y=0, w=240,h=btmO.size*2+1}
local wp = {bPnl._player_panel:world_position()}
pnl:set_world_position(wp[1] + (btmO.offsetX or 0) ,wp[2]-pnl:h())
local fontSize = btmO.size
--self['pnl_blur'..i] = pnl:bitmap( { name='blur', texture='guis/textures/test_blur_df', render_template='VertexColorTexturedBlur3D', layer=-1, x=0,y=0 } )
self['pnl_lbl'..i] = pnl:text{rotation=360,name='lbl',align='right', text='-', font=FONT, font_size = fontSize, color = cl.Red, x=1,y=0, layer=2, blend_mode = 'normal'}
self['pnl_lblA'..i] = pnl:text{name='lblA',align='right', text='-', font=FONT, font_size = fontSize, color = cl.Black:with_alpha(0.4), x=0,y=1, layer=1, blend_mode = 'normal'}
self['pnl_lblB'..i] = pnl:text{name='lblB',align='right', text='-', font=FONT, font_size = fontSize, color = cl.Black:with_alpha(0.4), x=2,y=1, layer=1, blend_mode = 'normal'}
self['pnl_'..i] = pnl
-- install arrow
local hPnl = bPnl._player_panel:child('radial_health_panel')
if hPnl:child('arrow') then
hPnl:remove(hPnl:child('arrow'))
end
if O:get('playerBottom','showArrow') then
local arrow = hPnl:bitmap{
name= 'arrow', texture= 'guis/textures/pd2/scrollbar_arrows',
texture_rect = {0,0,12,12},
layer= 10,
color= self:_color(i):with_alpha(0.7),
blend_mode= 'add',
x= 0, y=0,
w= 20,
h= 10,
rotation = 360,
}
local currAngle = 360
local tAngle = 360
local lastT = 0
local unit = isMe and self:Stat(i,'minion') or nData and nData.movement._unit
local mcos,msin = math.cos,math.sin
local w,h = hPnl:w(),hPnl:h()
local r = (isMe and 64 or 48) / 2 +4
hPnl:stop()
hPnl:animate(function(p,t)
while alive(p) and arrow and alive(arrow) do
if now() - lastT > 0.1 then
if isMe then
unit = self:Stat(i,'minion')
end
lastT = now()
tAngle = self:_getAngle(unit)
end
if self.dead then break end
arrow:set_visible(tAngle ~= 360)
if tAngle then
if math.abs(tAngle-currAngle) > 180 then
currAngle = currAngle + (tAngle>currAngle and 360 or -360)
end
currAngle = currAngle + (tAngle - currAngle)/5
if currAngle == 0 then
currAngle = 360
end
arrow:set_rotation(currAngle)
arrow:set_center(w/2 + r*msin(currAngle),h/2 - r*mcos(currAngle))
end
coroutine.yield()
end
end)
self['pnl_arrow'..i] = arrow
end
-- arrow end
end
end
end
end)
end
-- playerBottom
local color = self:_color(i)
local txts = {}
if not self.custom_hud_enabled and pnl and (nData or isMe) and not self.dead then
local lbl = self['pnl_lbl'..i]
local cdata = managers.criminals:character_data_by_peer_id( i ) or {}
local pInd = isMe and 4 or cdata.panel_id
local bPnl = managers.hud._teammate_panels[ pInd ]
local equip = (bPnl and #bPnl._special_equipment > 0)
local interText = nData and nData.interact:visible() and nData.panel:child( 'action' ):text()
if isMe then
interText = managers.hud._progress_timer
and managers.hud._progress_timer._hud_panel:child( 'progress_timer_text' ):visible()
and managers.hud._progress_timer._hud_panel:child( 'progress_timer_text' ):text()
end
local unit = nData and nData.movement._unit
local kill = self:Stat(i,'kill')
local killS = self:Stat(i,'killS')
local dmg = self:Stat(i,'dmg')
local head = self:Stat(i,'head')
local hit = math.max(self:Stat(i,'hit'),1)
local shot = math.max(self:Stat(i,'shot'),1)
local accuracy = _.f(hit/shot*100,0)
local accColor = math.lerp(cl.Red,cl.Green,hit/shot)
local avgDmg = _.f(dmg/hit,1)
local downs = self:Stat(i,'down')
local boost = self:Stat(i,'boost') > now()
local unitPos = unit and alive(unit) and unit:position()
local distance = unitPos and mvector3.distance(unitPos,self.camPos) or 0
local dist_sq = unitPos and mvector3.distance_sq(unitPos,self.camPos) or 0
local rally_skill_data = _.g('managers.player:player_unit():movement():rally_skill_data()')
local canBoost = rally_skill_data and rally_skill_data.long_dis_revive and rally_skill_data.range_sq > dist_sq
local ping = ' '..(self:Stat(i,'ping')>0 and self:Stat(i,'ping')..'ms' or '')
local lives = isMe and managers.player:upgrade_value( 'player', 'additional_lives', 0) or 0
local interT = self:Stat(i,'interactET')
local room = self:Stat(i,'room')
if btmO.underneath then
txts[#txts+1]={'\n'}
end
if interT>0 and _show('InteractionTime') then
local st,et = self:Stat(i,'interactST'), interT
local t,tt = now()-st,et-st
local r,rt = t/math.max(0.01,tt), tt-t
local c = math.lerp(cl.Aqua,cl.Lime,r)
txts[#txts+1]={' '.._.f(rt),c}
if rt < 0 then
self:Stat(i,'interactET',0)
end
end
if interText and _show('Interaction') then
txts[#txts+1]={' '..interText,cl.White}
end
if room and room ~= 0 and _show('Position') then
txts[#txts+1]={' '..utf8.to_upper(room),cl.White:with_alpha(0.5)}
end
if not btmO.underneath then
txts[#txts+1]={'\n'}
end
if _show('DetectionRisk') then
local suspicion
if isMe then
suspicion = managers.blackmarket:get_suspicion_offset_of_local(75)
else
local peer = self:_peer(i)
if peer and alive(peer:unit()) then
suspicion = managers.blackmarket:get_suspicion_offset_of_peer(peer, 75)
end
end
if suspicion then
txts[#txts+1]={' '..Icon.Ghost..string.format("%.0f%%", suspicion),cl.CornFlowerBlue}
end
end
if _show('Kill') then
txts[#txts+1]={' '..Icon.Skull..kill,color}
end
if _show('Special') then
txts[#txts+1]={' '..Icon.Skull..killS,cl.Yellow:with_alpha(0.8)}
end
if _show('AverageDamage') then
txts[#txts+1]={' ±'..avgDmg,color:with_alpha(0.8)}
end
if _show('ConvertedEnemy') then
local minion = self:Stat(i,'minion')
if minion ~= 0 and alive(minion) then
local cd = minion:character_damage()
local c = cd._health
local f = cd._health_max or cd._HEALTH_INIT
if f then
txts[#txts+1]={' '..math.floor(c/f*100)..'%',math.lerp( cl.OrangeRed, color, c/f ):with_alpha(0.5)}
end
else
txts[#txts+1]={' '..Icon.Times,cl.OrangeRed:with_alpha(0.5)}
end
end
--[[
txts[#txts+1]={' !',color:with_red(1)}