62 lines
2.0 KiB
Lua
62 lines
2.0 KiB
Lua
config = include("sv_config.lua")
|
|
Disease = {}
|
|
|
|
--- Disease class
|
|
---@param side name string? the name of the disease (string)
|
|
---@param side symbtoms_by_stages list? a list of list of symbtom, a list of symbtoms by stage (Symbtom)
|
|
---@param side contamination_methods list? a list of contamination method (string)
|
|
---@param side transmission_zone_stages list? a list of transmissions zone (int), one number by stage
|
|
---@param side stages_duration list? a list of stage duration (int), one number by stage
|
|
function Disease:new(name, symbtoms_by_stages, contamination_methods, transmission_zone_stages, stages_duration)
|
|
local instance = {}
|
|
setmetatable(instance, {__index = Disease})
|
|
instance.name = name
|
|
instance.symbtoms_by_stages = symbtoms_by_stages
|
|
instance.contamination_methods = contamination_methods
|
|
instance.transmission_zone_stages = transmission_zone_stages
|
|
instance.stages_duration = stages_duration
|
|
return instance
|
|
end
|
|
|
|
local function get_disease(diseases, to_find)
|
|
PrintTable(diseases)
|
|
for _, disease in ipairs(diseases)
|
|
do
|
|
print(disease.name .. " == " .. to_find)
|
|
if disease.name == to_find
|
|
then
|
|
return disease
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
---@param side infected number? the steam id 64 of player infected
|
|
---@param side stage number? the the stage of the disease
|
|
function Disease:infect(infected, stage)
|
|
|
|
if (stage == nil)
|
|
then
|
|
stage = 1
|
|
end
|
|
|
|
local file_path = config.save_path .. infected .. ".json"
|
|
|
|
local disease = {}
|
|
disease.name = self.name
|
|
disease.stage = stage
|
|
disease.contamination_time = 0
|
|
|
|
local data = util.JSONToTable(file.Read(file_path))
|
|
prev_disease = get_disease(data.diseases, self.name)
|
|
if prev_disease != nil
|
|
then
|
|
if (prev_disease.stage >= stage) then return end
|
|
prev_disease = disease
|
|
else
|
|
table.insert(data.diseases, disease)
|
|
end
|
|
file.Write(file_path, util.TableToJSON(data, true))
|
|
end
|
|
print("bozo")
|
|
return Disease |