Compare commits
6 Commits
136847609f
...
master
Author | SHA1 | Date | |
---|---|---|---|
4f255b2f43 | |||
7bb58e5c09 | |||
8463b22928 | |||
88b07a6194 | |||
79b0f2d2ac | |||
a45536aeab |
@ -7,29 +7,29 @@
|
||||
{
|
||||
"name": "burp",
|
||||
"level": 1,
|
||||
"delay": 150,
|
||||
"delay": 150
|
||||
},
|
||||
{
|
||||
"name": "fart",
|
||||
"level": 1,
|
||||
"delay": 250,
|
||||
"delay": 250
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"name": "burp",
|
||||
"level": 1,
|
||||
"delay": 50,
|
||||
"delay": 50
|
||||
},
|
||||
{
|
||||
"name": "fart",
|
||||
"level": 1,
|
||||
"delay": 150,
|
||||
"delay": 150
|
||||
},
|
||||
{
|
||||
"name": "vomit",
|
||||
"level": 0.5,
|
||||
"delay": 500,
|
||||
"delay": 500
|
||||
}
|
||||
]
|
||||
],
|
||||
@ -43,9 +43,13 @@
|
||||
"chance": 0.05
|
||||
}
|
||||
],
|
||||
"stages_durations": [
|
||||
"transmission_zone_stages": [
|
||||
5,
|
||||
10
|
||||
],
|
||||
"stages_duration": [
|
||||
20000,
|
||||
40000,
|
||||
40000
|
||||
]
|
||||
}
|
||||
]
|
||||
|
87
lua/autorun/client/cl_infect.lua
Normal file
87
lua/autorun/client/cl_infect.lua
Normal file
@ -0,0 +1,87 @@
|
||||
local infect_menu
|
||||
|
||||
local selected_diseases = {}
|
||||
local selected_player = {}
|
||||
|
||||
concommand.Add("infect", function(ply)
|
||||
infect_menu = vgui.Create("DFrame")
|
||||
infect_menu:SetTitle("infect_menu")
|
||||
infect_menu:SetSize(400, 300)
|
||||
infect_menu:Center()
|
||||
infect_menu:MakePopup()
|
||||
local infect_button = vgui.Create("DButton", infect_menu)
|
||||
infect_button:SetText("infect")
|
||||
infect_button:SetPos(5, 255)
|
||||
infect_button:SetSize(390, 40)
|
||||
function infect_button:DoClick()
|
||||
if #selected_player == 0 or #selected_diseases == 0
|
||||
then
|
||||
return
|
||||
end
|
||||
net.Start("infect")
|
||||
local data = {}
|
||||
data.infecteds = selected_player
|
||||
data.diseases = selected_diseases
|
||||
net.WriteTable(data)
|
||||
net.SendToServer()
|
||||
selected_player = {}
|
||||
selected_diseases = {}
|
||||
fill_infect_menu()
|
||||
end
|
||||
fill_infect_menu()
|
||||
end)
|
||||
|
||||
function fill_infect_menu()
|
||||
net.Start("get_diseases_name")
|
||||
net.SendToServer()
|
||||
net.Start("get_players_data")
|
||||
net.SendToServer()
|
||||
end
|
||||
|
||||
net.Receive("get_players_data", function ()
|
||||
local players_data = net.ReadTable()
|
||||
local players_panel = vgui.Create("DScrollPanel", infect_menu)
|
||||
players_panel:SetPos(5, 30)
|
||||
players_panel:SetSize(190, 250)
|
||||
for i, player_data in ipairs(players_data)
|
||||
do
|
||||
local button = vgui.Create("DCheckBoxLabel", players_panel)
|
||||
button:SetText(player_data.nick)
|
||||
button:SetSize(180, 25)
|
||||
button:SetPos(5, (i - 1) * 25 + 5)
|
||||
button.SteamID64 = player_data.SteamID64
|
||||
function button:OnChange(bVal)
|
||||
if bVal
|
||||
then
|
||||
table.insert(selected_player, self.SteamID64)
|
||||
|
||||
else
|
||||
table.RemoveByValue(selected_player, self.SteamID64)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
net.Receive("get_diseases_name", function ()
|
||||
local disease_name_list = net.ReadTable()
|
||||
local diseases_panel = vgui.Create("DScrollPanel", infect_menu)
|
||||
diseases_panel:SetPos(200, 30)
|
||||
diseases_panel:SetSize(190, 250)
|
||||
for i, disease_name in ipairs(disease_name_list)
|
||||
do
|
||||
local button = vgui.Create("DCheckBoxLabel", diseases_panel)
|
||||
button:SetText(disease_name)
|
||||
button:SetSize(180, 25)
|
||||
button:SetPos(5, (i - 1) * 25 + 5)
|
||||
function button:OnChange(bVal)
|
||||
if bVal
|
||||
then
|
||||
table.insert(selected_diseases, disease_name)
|
||||
else
|
||||
table.RemoveByValue(selected_diseases, disease_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
print('toto')
|
1
lua/autorun/client/cl_init.lua
Normal file
1
lua/autorun/client/cl_init.lua
Normal file
@ -0,0 +1 @@
|
||||
include("cl_infect.lua")
|
61
lua/autorun/server/menus/sv_infect_menu.lua
Normal file
61
lua/autorun/server/menus/sv_infect_menu.lua
Normal file
@ -0,0 +1,61 @@
|
||||
settings = include("../sv_settings.lua")
|
||||
config = include("../sv_config.lua")
|
||||
|
||||
util.AddNetworkString("get_diseases_name")
|
||||
util.AddNetworkString("get_players_data")
|
||||
util.AddNetworkString("infect")
|
||||
|
||||
net.Receive("get_diseases_name", function (len, ply)
|
||||
local name_list = {}
|
||||
for i, disease in ipairs(settings.diseases)
|
||||
do
|
||||
table.insert(name_list, disease.name)
|
||||
end
|
||||
net.Start("get_diseases_name")
|
||||
net.WriteTable(name_list)
|
||||
net.Send(ply)
|
||||
end)
|
||||
|
||||
net.Receive("get_players_data", function (len, ply)
|
||||
local files, _ = file.Find(config.save_path .. "*", "DATA")
|
||||
local data = {}
|
||||
for i, file_ in ipairs(files)
|
||||
do
|
||||
local ply_data = util.JSONToTable(file.Read(config.save_path .. file_))
|
||||
local ret = {}
|
||||
local ply = player.GetBySteamID64(ply_data.SteamID64)
|
||||
if ply == false
|
||||
then
|
||||
ret.nick = ply_data.name
|
||||
else
|
||||
ret.nick = ply:Nick()
|
||||
end
|
||||
ret.SteamID64 = ply_data.SteamID64
|
||||
table.insert(data, ret)
|
||||
end
|
||||
net.Start("get_players_data")
|
||||
net.WriteTable(data)
|
||||
net.Send(ply)
|
||||
end)
|
||||
|
||||
net.Receive("infect", function (len, ply)
|
||||
local data = net.ReadTable()
|
||||
for _, infected in ipairs(data.infecteds)
|
||||
do
|
||||
for _, disease_name in ipairs(data.diseases)
|
||||
do
|
||||
print(disease_name)
|
||||
disease = settings.getDiseaseByName(disease_name)
|
||||
if (disease == nil)
|
||||
then
|
||||
print(ply:GetName() .. " try to add undifined disease")
|
||||
else
|
||||
print()
|
||||
disease:infect(infected, 1)
|
||||
end
|
||||
print("bozogang")
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
print("bozo")
|
@ -1,21 +1,8 @@
|
||||
utils = include("sv_utils.lua")
|
||||
config = include("../sh_config.lua")
|
||||
config = {}
|
||||
|
||||
local dirs = utils.split(config.config_path, "/")
|
||||
table.remove(dirs)
|
||||
local tmp = "";
|
||||
for i, dir in ipairs(dirs) do
|
||||
tmp = tmp .. dir
|
||||
if not file.Exists(tmp, "DATA")
|
||||
then
|
||||
file.CreateDir(tmp)
|
||||
end
|
||||
tmp = tmp .. "/"
|
||||
end
|
||||
-- the config file path location
|
||||
config.settings_path = "disease/settings.json"
|
||||
|
||||
if not file.Exists(config.config_path, "DATA")
|
||||
then
|
||||
local default_config = {}
|
||||
default_config.diseases = {}
|
||||
file.Write(config.config_path, util.TableToJSON(default_config, true))
|
||||
end
|
||||
config.save_path = "disease/saves/"
|
||||
|
||||
return config
|
@ -1,20 +1,62 @@
|
||||
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 contaminations_methods list? a list of contamination method (string)
|
||||
---@param side transmissions_zone_by_stage list? a list of transmissions zone (int), one number by stage
|
||||
---@param side stages_durations list? a list of stage duration (int), one number by stage
|
||||
function Disease:new(name, symbtoms_by_stages, contaminations_methods, transmissions_zone_by_stages, stages_durations)
|
||||
---@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.contaminations_methods = contaminations_methods
|
||||
instance.transmissions_zone_by_stages = transmissions_zone_by_stages
|
||||
instance.stages_durations = stages_durations
|
||||
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
|
4
lua/autorun/server/sv_init.lua
Normal file
4
lua/autorun/server/sv_init.lua
Normal file
@ -0,0 +1,4 @@
|
||||
include("menus/sv_infect_menu.lua")
|
||||
include("sv_disease.lua")
|
||||
include("sv_saves.lua")
|
||||
include("sv_settings.lua")
|
22
lua/autorun/server/sv_saves.lua
Normal file
22
lua/autorun/server/sv_saves.lua
Normal file
@ -0,0 +1,22 @@
|
||||
utils = include("sv_utils.lua")
|
||||
config = include("sv_config.lua")
|
||||
settings = include("sv_settings.lua")
|
||||
|
||||
utils.path_create(config.save_path .. "/ss")
|
||||
|
||||
hook.Add("PlayerInitialSpawn", "reAddDisease", function (ply)
|
||||
local file_path = config.save_path .. ply:SteamID64() .. ".json"
|
||||
print(file_path)
|
||||
if not file.Exists(file_path, "DATA")
|
||||
then
|
||||
local data = {}
|
||||
data.diseases = {}
|
||||
data.SteamID64 = ply:SteamID64()
|
||||
data.name = ply:Nick()
|
||||
file.Write(file_path, util.TableToJSON(data, true))
|
||||
end
|
||||
local data = util.JSONToTable(file.Read(file_path))
|
||||
data.name = ply:Nick()
|
||||
file.Write(file_path, util.TableToJSON(data, true))
|
||||
ply.diseases = data.diseases
|
||||
end)
|
158
lua/autorun/server/sv_settings.lua
Normal file
158
lua/autorun/server/sv_settings.lua
Normal file
@ -0,0 +1,158 @@
|
||||
utils = include("sv_utils.lua")
|
||||
config = include("sv_config.lua")
|
||||
symbtoms_list = include("sv_symbtom_list.lua")
|
||||
Symbtom = include("sv_symbtom.lua")
|
||||
Disease = include("sv_disease.lua")
|
||||
|
||||
local settings = {}
|
||||
|
||||
utils.path_create(config.settings_path)
|
||||
|
||||
if not file.Exists(config.settings_path, "DATA")
|
||||
then
|
||||
local default_config = {}
|
||||
default_config.diseases = {}
|
||||
file.Write(config.settings_path, util.TableToJSON(default_config, true))
|
||||
end
|
||||
|
||||
local data = file.Read(config.settings_path)
|
||||
data = util.JSONToTable(data)
|
||||
|
||||
if data.diseases == nil
|
||||
then
|
||||
print(config.settings_path .. "file error")
|
||||
return nil
|
||||
end
|
||||
|
||||
settings.diseases = {}
|
||||
|
||||
for i, disease in ipairs(data.diseases)
|
||||
do
|
||||
local name = ""
|
||||
local symbtoms_by_stages = {}
|
||||
local contamination_methods = {}
|
||||
local transmission_zone_stages = {}
|
||||
local stages_duration = {}
|
||||
|
||||
if (disease.name == nil)
|
||||
then
|
||||
print("[SKIP] missing name in the " .. i .. " disease")
|
||||
return nil
|
||||
end
|
||||
name = disease.name
|
||||
|
||||
if (disease.symbtoms_by_stages == nil)
|
||||
then
|
||||
print("[SKIP] missing symbtoms_by_stages in " .. name .." disease")
|
||||
continue
|
||||
end
|
||||
table.insert(symbtoms_by_stages, {})
|
||||
for y, stage in ipairs(disease.symbtoms_by_stages)
|
||||
do
|
||||
symbtoms_by_stages[y] = {}
|
||||
|
||||
for j, symbtom in ipairs(stage)
|
||||
do
|
||||
if symbtom.name == nil
|
||||
then
|
||||
print("[ERROR] missing name in the " .. j .. " symbtom of the " .. y .. " stage of the " .. name .. " disease")
|
||||
return nil
|
||||
end
|
||||
if symbtoms_list[symbtom.name] == nil
|
||||
then
|
||||
print("[ERROR] " .. symbtom.name .. " unknown symbtom in the " .. j .. " symbtom of the " .. y .. " stage of the " .. name .. " disease")
|
||||
return nil
|
||||
end
|
||||
if symbtom.level == nil
|
||||
then
|
||||
print("[ERROR] missing level in the " .. j .. " symbtom (" .. symbtom.name ..") of the " .. y .. " stage of the " .. name .. " disease")
|
||||
return nil
|
||||
end
|
||||
if type(symbtom.level) != "number" or 0 > symbtom.level or symbtom.level > 1
|
||||
then
|
||||
print("[ERROR] invalid level in the " .. j .. " symbtom (" .. symbtom.name ..") of the " .. y .. " stage of the " .. name .. " disease")
|
||||
return nil
|
||||
end
|
||||
if symbtom.delay == nil
|
||||
then
|
||||
print("[ERROR] missing delay in the " .. j .. " symbtom (" .. symbtom.name ..") of the " .. y .. " stage of the " .. name .. " disease")
|
||||
return nil
|
||||
end
|
||||
if type(symbtom.delay) != "number"
|
||||
then
|
||||
print("[ERROR] invalid delay in the " .. j .. " symbtom (" .. symbtom.name ..") of the " .. y .. " stage of the " .. name .. " disease")
|
||||
return nil
|
||||
end
|
||||
table.insert(symbtoms_by_stages[y], Symbtom:new(symbtom.name, symbtoms_list[symbtom.name], symbtom.level, symbtom.delay))
|
||||
end
|
||||
end
|
||||
|
||||
if disease.contaminations_method == nil
|
||||
then
|
||||
print("[SKIP] missing contamination_method in the " .. name .. " disease")
|
||||
continue
|
||||
end
|
||||
for k, contamination_method in ipairs(disease.contaminations_method)
|
||||
do
|
||||
if contamination_method.name == nil
|
||||
then
|
||||
print("[SKIP] missing name in the " .. k .. " contamination_method of the " .. name .. " disease")
|
||||
break
|
||||
end
|
||||
if contamination_method.chance == nil
|
||||
then
|
||||
print("[SKIP] missing chance in the " .. contamination_method.name .. " contaminations_method of the " .. name .. " disease")
|
||||
break
|
||||
end
|
||||
end
|
||||
contamination_methods = disease.contamination_methods
|
||||
|
||||
if disease.transmission_zone_stages == nil
|
||||
then
|
||||
print("[SKIP] missing transmission_zone_stages in the " .. name .. " disease")
|
||||
continue
|
||||
end
|
||||
for k, transmission_zone_stage in ipairs(disease.transmission_zone_stages)
|
||||
do
|
||||
if type(transmission_zone_stage) != "number"
|
||||
then
|
||||
print("[SKIP] non number " .. k .. " transmission_zone_stages in the " .. name)
|
||||
break
|
||||
end
|
||||
end
|
||||
transmission_zone_stages = disease.transmission_zone_stages
|
||||
|
||||
|
||||
if disease.stages_duration == nil
|
||||
then
|
||||
print("[SKIP] missing stages_duration in the " .. name .. " disease")
|
||||
continue
|
||||
end
|
||||
for k, stage_duration in ipairs(disease.stages_duration)
|
||||
do
|
||||
if type(stage_duration) != "number"
|
||||
then
|
||||
print("[SKIP] non number " .. k .. " stages_duration in the " .. name)
|
||||
break
|
||||
end
|
||||
end
|
||||
stages_duration = disease.stages_duration
|
||||
|
||||
table.insert(settings.diseases, Disease:new(name, symbtoms_by_stages, contamination_methods, transmission_zone_stages, stages_durations))
|
||||
end
|
||||
|
||||
print("[OK] settings")
|
||||
|
||||
---name string? the name of the disease
|
||||
function settings.getDiseaseByName(name)
|
||||
for _, disease in ipairs(settings.diseases)
|
||||
do
|
||||
if disease.name == name
|
||||
then
|
||||
return disease
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
return settings
|
18
lua/autorun/server/sv_symbtom.lua
Normal file
18
lua/autorun/server/sv_symbtom.lua
Normal file
@ -0,0 +1,18 @@
|
||||
Symbtom = {}
|
||||
|
||||
--- Disease class
|
||||
---@param side name string? the name of the symbtom (string)
|
||||
---@param side func function? the function called when symbtom
|
||||
---@param side delay number? delay time between two symbtoms
|
||||
---@param side level float? the level of the symbtom (between 0-1)
|
||||
function Symbtom:new(name, func, level, delay)
|
||||
local instance = {}
|
||||
setmetatable(instance, {__index = Disease})
|
||||
instance.name = name
|
||||
instance.func = func
|
||||
instance.level = level
|
||||
instance.delay = delay
|
||||
return instance
|
||||
end
|
||||
|
||||
return Symbtom
|
9
lua/autorun/server/sv_symbtom_list.lua
Normal file
9
lua/autorun/server/sv_symbtom_list.lua
Normal file
@ -0,0 +1,9 @@
|
||||
cough = include("symptoms/sv_cough.lua")
|
||||
vomit = include("symptoms/sv_vomit.lua")
|
||||
|
||||
symbtom_list = {}
|
||||
|
||||
symbtom_list["cough"] = cough
|
||||
symbtom_list["vomit"] = vomit
|
||||
|
||||
return symbtom_list
|
@ -1 +0,0 @@
|
||||
Symbtoms_list = {}
|
@ -8,4 +8,20 @@ function utils.split (str, sep)
|
||||
return new_table
|
||||
end
|
||||
|
||||
function utils.path_create(path)
|
||||
|
||||
local dirs = utils.split(path, "/")
|
||||
table.remove(dirs)
|
||||
local tmp = "";
|
||||
for i, dir in ipairs(dirs) do
|
||||
tmp = tmp .. dir
|
||||
if not file.Exists(tmp, "DATA")
|
||||
then
|
||||
file.CreateDir(tmp)
|
||||
end
|
||||
tmp = tmp .. "/"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return utils
|
@ -1,10 +1,9 @@
|
||||
include("autorun/server/sv_symbtoms.lua")
|
||||
|
||||
table.insert(Symbtoms_list, "cough" = cough_func)
|
||||
|
||||
--- Send a packet to trigger cough animation to the player
|
||||
---@param side UID64 string? UID64 of the player
|
||||
---@param side level float? A float between 0 and 1
|
||||
---@return void
|
||||
function cough(UID64)
|
||||
function cough(UID64, level)
|
||||
|
||||
end
|
||||
|
||||
return cough
|
9
lua/autorun/server/symptoms/sv_vomit.lua
Normal file
9
lua/autorun/server/symptoms/sv_vomit.lua
Normal file
@ -0,0 +1,9 @@
|
||||
--- Send a packet to trigger cough animation to the player
|
||||
---@param side UID64 string? UID64 of the player
|
||||
---@param side level float? A float between 0 and 1
|
||||
---@return void
|
||||
function vomit(UID64, level)
|
||||
|
||||
end
|
||||
|
||||
return vomit
|
@ -1,6 +0,0 @@
|
||||
config = {}
|
||||
|
||||
-- the config file path location
|
||||
config.config_path = "disease/config.json"
|
||||
|
||||
return config
|
Reference in New Issue
Block a user