forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserSync.lua
More file actions
109 lines (86 loc) · 3.41 KB
/
UserSync.lua
File metadata and controls
109 lines (86 loc) · 3.41 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
-- The global sync table is copied from the sim layer every time the main and sim threads are
-- synchronized on the sim beat (which is like a tick but happens even when the game is paused)
Sync = {}
-- The PreviousSync table holds just what you'd expect it to, the sync table from the previous
-- beat.
PreviousSync = {}
-- Unit specific data that's been sync'd. Data changes are accumulated by merging
-- the Sync.UnitData table into this table each sync (if there's new data)
UnitData = {}
local reclaim = import('/lua/ui/game/reclaim.lua')
local UpdateReclaim = reclaim.UpdateReclaim
local sendEnhancementMessage = import('/lua/ui/notify/notify.lua').sendEnhancementMessage
local SetPlayableArea = reclaim.SetPlayableArea
-- Here's an opportunity for user side script to examine the Sync table for the new tick
function OnSync()
if Sync.RequestingExit then
ExitGame()
end
if not table.empty(Sync.UnitData) then
UnitData = table.merged(UnitData,Sync.UnitData)
end
for id, v in Sync.ReleaseIds do
UnitData[id] = nil
end
--Play Sounds
for k, v in Sync.Sounds do
PlaySound(Sound{ Bank=v.Bank, Cue=v.Cue })
end
if Sync.ToggleGamePanels then
ConExecute('UI_ToggleGamePanels')
end
if Sync.ToggleLifeBarsOff then
ConExecute('UI_RenderUnitBars false')
end
if Sync.ToggleLifeBarsOn then
ConExecute('UI_RenderUnitBars true')
end
if not table.empty(Sync.AIChat) then
for k, v in Sync.AIChat do
import('/lua/AIChatSorian.lua').AIChat(v.group, v.text, v.sender)
end
end
if Sync.UserConRequests then
for num, execRequest in Sync.UserConRequests do
ConExecute(execRequest)
end
end
if Sync.NukeLaunchData then
import('/lua/ui/game/nukelaunchping.lua').DoNukePing(Sync.NukeLaunchData)
end
-- Each sync, update the user-side data for any prop created, damaged, or destroyed
if not table.empty(Sync.Reclaim) then
UpdateReclaim(Sync.Reclaim)
end
if Sync.Teamkill and not SessionIsReplay() then
local armies, clients = GetArmiesTable().armiesTable, GetSessionClients()
local victim, instigator = Sync.Teamkill.victim, Sync.Teamkill.instigator
local data = {time=Sync.Teamkill.killTime, victim={}, instigator={}}
for k, army in {victim=victim, instigator=instigator} do
data[k].name = armies[army] and armies[army].nickname or "-"
data[k].id = clients[army] and clients[army].uid or 0
end
GpgNetSend('TeamkillHappened', data.time, data.victim.id, data.victim.name, data.instigator.id, data.instigator.name)
WARN(string.format("TEAMKILL: %s KILLED BY %s, TIME: %s", data.victim.name, data.instigator.name, data.time))
if GetFocusArmy() == victim then
import('/lua/ui/dialogs/teamkill.lua').CreateDialog(data)
end
end
if Sync.EnforceRating then
GpgNetSend('EnforceRating')
end
if not table.empty(Sync.EnhanceMessage) then
for _, messageTable in Sync.EnhanceMessage do
sendEnhancementMessage(messageTable)
end
end
if Sync.NewPlayableArea then
SetPlayableArea(Sync.NewPlayableArea)
end
if Sync.StartPositions then
import('/lua/ui/game/worldview.lua').MarkStartPositions(Sync.StartPositions)
end
if Sync.GameEnded then
GpgNetSend('GameEnded')
end
end