Made some stain sync stuff that doesn't work because clients don't get stained for some reason :(

This commit is contained in:
IQuant 2024-08-15 01:22:00 +03:00
parent c56c9ad34e
commit 7255b008c0
5 changed files with 66 additions and 8 deletions

12
.vscode/settings.json vendored
View file

@ -1,3 +1,13 @@
{
"Lua.runtime.version": "LuaJIT"
"Lua.runtime.version": "LuaJIT",
"Lua.diagnostics.disable": [
"cast-local-type",
"param-type-mismatch",
"undefined-global",
"need-check-nil"
],
"Lua.diagnostics.globals": [
"wait",
"async"
]
}

View file

@ -309,10 +309,6 @@
eating_cells_per_frame="2"
></PlatformShooterPlayerComponent>
<StatusEffectDataComponent>
</StatusEffectDataComponent>
<MaterialInventoryComponent
_tags="ingestion"
drop_as_item="0"

View file

@ -0,0 +1,54 @@
-- This module intends to sync stains.
-- Both stains and ingestion effects are handled by StatusEffectDataComponent, thus the name.
dofile_once("data/scripts/status_effects/status_list.lua")
local effect_by_index = {}
for index, effect in ipairs(status_effects) do
effect_by_index[index] = effect.id
end
local rpc = net.new_rpc_namespace()
local module = {}
function rpc.send_present_stains(present_stains)
local entity = ctx.rpc_player_data.entity
local effect_data = EntityGetFirstComponent(entity, "StatusEffectDataComponent")
if effect_data == nil or effect_data == 0 then
return
end
local current_stains = ComponentGetValue2(effect_data, "stain_effects")
for index, is_present in ipairs(present_stains) do
if not is_present and current_stains[index+1] > 0.05 then
GamePrint("Removing "..effect_by_index[index])
EntityRemoveStainStatusEffect(entity, effect_by_index[index])
end
end
end
function module.on_world_update()
if GameGetFrameNum() % 30 ~= 13 then
return
end
local entity = ctx.my_player.entity
local effect_data = EntityGetFirstComponent(entity, "StatusEffectDataComponent")
if effect_data == nil or effect_data == 0 then
return
end
local stains = ComponentGetValue2(effect_data, "stain_effects")
local present_stains = {}
-- For some reason whatever value is at index 1 isn't used?
for i=2, #stains do
table.insert(present_stains, stains[i] > 0.05)
if stains[i] > 0.05 then
GamePrint(effect_by_index[i-1])
end
end
rpc.send_present_stains(present_stains)
end
return module

View file

@ -310,9 +310,6 @@
></PlatformShooterPlayerComponent>
<StatusEffectDataComponent>
</StatusEffectDataComponent>
<MaterialInventoryComponent
_tags="ingestion"
drop_as_item="0"

View file

@ -84,6 +84,7 @@ local function load_modules()
ctx.load_system("player_arrows")
ctx.load_system("extra_genomes")
ctx.load_system("amulet_sync")
-- ctx.load_system("effect_data_sync")
end
function OnProjectileFired(shooter_id, projectile_id, initial_rng, position_x, position_y, target_x, target_y, send_message,