sync stains on enemys

This commit is contained in:
bgkillas 2024-11-16 09:53:14 -05:00
parent 44b144417e
commit 449c416093
3 changed files with 46 additions and 26 deletions

View file

@ -13,26 +13,7 @@ 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] ~= nil and current_stains[index+1] >= 0.15 then
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
function module.get_stains(entity)
local effect_data = EntityGetFirstComponent(entity, "StatusEffectDataComponent")
if effect_data == nil or effect_data == 0 then
return
@ -42,9 +23,41 @@ function module.on_world_update()
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.15)
if stains[i] >= 0.15 then
present_stains[i] = true
end
end
return present_stains
end
function module.sync_stains(present_stains, 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 i=2, #current_stains do
if current_stains[i] >= 0.15 and not present_stains[i] then
EntityRemoveStainStatusEffect(entity, effect_by_index[i - 1])
end
end
end
function rpc.send_present_stains(present_stains)
module.sync_stains(present_stains, ctx.rpc_player_data.entity)
end
function module.on_world_update()
if GameGetFrameNum() % 15 ~= 8 then
return
end
local present = module.get_stains(ctx.my_player.entity)
if present ~= nil then
rpc.send_present_stains(present)
end
rpc.send_present_stains(present_stains)
end
return module

View file

@ -4,6 +4,7 @@ local net = dofile_once("mods/quant.ew/files/core/net.lua")
local player_fns = dofile_once("mods/quant.ew/files/core/player_fns.lua")
local item_sync = dofile_once("mods/quant.ew/files/system/item_sync.lua")
local effect_sync = dofile_once("mods/quant.ew/files/system/game_effect_sync/game_effect_sync.lua")
local stain_sync = dofile_once("mods/quant.ew/files/system/effect_data_sync/effect_data_sync.lua")
local np = require("noitapatcher")
local ffi = require("ffi")
@ -350,7 +351,10 @@ function enemy_sync.host_upload_entities()
local dont_cull = EntityHasTag(enemy_id, "worm") or EntityGetFirstComponent(enemy_id, "BossHealthBarComponent") ~= nil
table.insert(enemy_data_list, {filename, en_data, phys_info, phys_info_2, wand, effect_data, animation, dont_cull, death_triggers})
local stains = stain_sync.get_stains(enemy_id)
table.insert(enemy_data_list, {filename, en_data, phys_info, phys_info_2, wand,
effect_data, animation, dont_cull, death_triggers, stains})
::continue::
end
@ -437,6 +441,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
local en_data = enemy_info_raw[2]
local dont_cull = enemy_info_raw[8]
local death_triggers = enemy_info_raw[9]
local stains = enemy_info_raw[10]
local remote_enemy_id = en_data.enemy_id
local x, y = en_data.x, en_data.y
if not force_no_cull and not dont_cull then
@ -630,6 +635,10 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
end
end
end
effect_sync.apply_effects(effects, enemy_id, true)
if stains ~= nil then
stain_sync.sync_stains(stains, enemy_id)
end
end
local inv = EntityGetFirstComponentIncludingDisabled(enemy_id, "Inventory2Component")
@ -669,8 +678,6 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
end
end
effect_sync.apply_effects(effects, enemy_id, true)
for _, sprite in pairs(EntityGetComponent(enemy_id, "SpriteComponent", "ew_sprite") or {}) do
ComponentSetValue2(sprite, "rect_animation", animation)
ComponentSetValue2(sprite, "next_rect_animation", animation)

View file

@ -72,7 +72,7 @@ function effect_sync.get_sync_data(entity, perks)
end
function effect_sync.on_world_update()
if GameGetFrameNum() % 30 == 9 then
if GameGetFrameNum() % 15 == 9 then
local sync_data = effect_sync.get_sync_data(ctx.my_player.entity, false)
rpc.send_effects(sync_data, false)
end