-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgasmask.lua
More file actions
68 lines (59 loc) · 2.17 KB
/
gasmask.lua
File metadata and controls
68 lines (59 loc) · 2.17 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
-- gasmask.lua
-- Units wearing a gasmask are immune to SYN_INHALED syndromes.
local CALLBACK_ID = "gasmask"
local enabled = false
local eventful = require('plugins.eventful')
local syndromeUtil = require('syndrome-util')
local PROTECTED_HELMS = {
ITEM_HELM_GASMASK1 = true,
ITEM_HELM_GASMASK2 = true,
}
local function is_wearing_gasmask(unit)
for _, inv_item in ipairs(unit.inventory) do
if inv_item.mode == df.inv_item_role_type.Worn then
local item = inv_item.item
if item:getType() == df.item_type.HELM then
local ok, sub_id = pcall(function()
return dfhack.items.getSubtypeDef(df.item_type.HELM, item:getSubtype()).id
end)
if ok and PROTECTED_HELMS[sub_id] then return true end
end
end
end
return false
end
local function on_syndrome(unit_id, syndrome_index)
local unit = df.unit.find(unit_id)
if not unit or not dfhack.units.isActive(unit) then return end
local unit_syndrome = unit.syndromes.active[syndrome_index]
if not unit_syndrome then return end
local syn_id = unit_syndrome['type']
local syn_def = df.syndrome.find(syn_id)
if not syn_def or not syn_def.flags.SYN_INHALED then return end
if is_wearing_gasmask(unit) then
syndromeUtil.eraseSyndrome(unit, syn_id, true)
end
end
local function enable()
if enabled then print("[gasmask] Already enabled"); return end
eventful.enableEvent(eventful.eventType.SYNDROME, 5)
eventful.onSyndrome[CALLBACK_ID] = on_syndrome
enabled = true
print("[gasmask] Enabled - inhaled syndrome protection active")
end
local function disable()
if not enabled then print("[gasmask] Already disabled"); return end
eventful.onSyndrome[CALLBACK_ID] = nil
enabled = false
print("[gasmask] Disabled")
end
local function status()
print(("[gasmask] Status: %s"):format(enabled and "ENABLED" or "DISABLED"))
end
local args = { ... }
local command = args[1] or "enable"
if command == "enable" then enable()
elseif command == "disable" then disable()
elseif command == "status" then status()
else print("[gasmask] Usage: gasmask [enable|disable|status]")
end