-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathunitnetworkhandler.lua
60 lines (53 loc) · 1.74 KB
/
unitnetworkhandler.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
-- Friendly Fire
function UnitNetworkHandler:sync_friendly_fire_damage(peer_id, unit, damage, variant, sender)
if not self._verify_gamestate(self._gamestate_filter.any_ingame) or not self._verify_sender(sender) then
return
end
if managers.network:session():local_peer():id() == peer_id then
local player_unit = managers.player:player_unit()
if alive(player_unit) and alive(unit) then
local attack_info = {
ignore_suppression = true,
range = 1000,
attacker_unit = unit,
damage = damage,
armor_piercing = true,
variant = variant,
col_ray = {
position = unit:position(),
},
push_vel = Vector3(),
}
if variant == "bullet" or variant == "projectile" then
player_unit:character_damage():damage_bullet(attack_info)
elseif variant == "melee" then
player_unit:character_damage():damage_melee(attack_info)
elseif variant == "fire" then
player_unit:character_damage():damage_fire(attack_info)
end
end
end
if not Global.game_settings and Global.game_settings.one_down then
managers.job:set_memory("trophy_flawless", true, false)
end
end
-- Properly sync reload
function UnitNetworkHandler:reload_weapon_cop(cop, sender)
if not self._verify_gamestate(self._gamestate_filter.any_ingame) or not self._verify_character_and_sender(cop, sender) then
return
end
if not alive(cop) then
return
end
local current_action = cop:movement():get_action(3)
if current_action and current_action:type() == "shoot" then
-- If we are currently in shoot action, set the mag to empty
cop:inventory():equipped_unit():base():ammo_base():set_ammo_remaining_in_clip(0)
else
-- Otherwise request an actual reload action
cop:movement():action_request({
body_part = 3,
type = "reload",
})
end
end