2023-09-14 13:23:54 -04:00
|
|
|
config = include("sv_config.lua")
|
2023-09-03 14:03:21 -04:00
|
|
|
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)
|
2023-09-03 18:30:38 -04:00
|
|
|
---@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)
|
2023-09-03 14:03:21 -04:00
|
|
|
local instance = {}
|
|
|
|
setmetatable(instance, {__index = Disease})
|
|
|
|
instance.name = name
|
|
|
|
instance.symbtoms_by_stages = symbtoms_by_stages
|
2023-09-03 18:30:38 -04:00
|
|
|
instance.contamination_methods = contamination_methods
|
|
|
|
instance.transmission_zone_stages = transmission_zone_stages
|
|
|
|
instance.stages_duration = stages_duration
|
2023-09-03 14:03:21 -04:00
|
|
|
return instance
|
|
|
|
end
|
|
|
|
|
2023-09-14 13:23:54 -04:00
|
|
|
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")
|
2023-09-03 14:03:21 -04:00
|
|
|
return Disease
|