sync worms a bit more(pls help quant why no worky)

This commit is contained in:
bgkillas 2024-11-02 22:21:45 -04:00
parent ae3520f3c4
commit 3ea359f89c
2 changed files with 26 additions and 1 deletions

View file

@ -21,8 +21,9 @@ local EnemyDataNoMotion = util.make_type({
})
local EnemyDataWorm = util.make_type({
u32 = {"enemy_id"},
u32 = {"enemy_id", "target"},
f32 = {"x", "y", "vx", "vy", "tx", "ty"},
string = {"peer_id"}
})
local EnemyDataKolmi = util.make_type({
@ -285,6 +286,13 @@ function enemy_sync.host_upload_entities()
}
elseif worm ~= nil then
local tx, ty = ComponentGetValue2(worm, "mRandomTarget")
local target = ComponentGetValue2(worm, "mTargetEntityId")
local peer_id
local data = player_fns.get_player_data_by_local_entity_id(target)
if data ~= nil then
peer_id = data.peer_id
target = nil
end
en_data = EnemyDataWorm {
enemy_id = enemy_id,
x = x,
@ -293,6 +301,8 @@ function enemy_sync.host_upload_entities()
vy = vy,
tx = tx,
ty = ty,
target = target,
peer_id = peer_id,
}
elseif math.abs(vx) < 0.01 and math.abs(vy) < 0.01 then
en_data = EnemyDataNoMotion {
@ -601,6 +611,20 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
if worm ~= nil and ffi.typeof(en_data) == EnemyDataWorm then
local tx, ty = en_data.tx, en_data.ty
ComponentSetValue2(worm, "mRandomTarget", tx, ty)
local ent
if en_data.peer_id == nil then
if ctx.entity_by_remote_id[en_data.target] ~= nil then
ent = ctx.entity_by_remote_id[en_data.target].id
end
else
--help quant :( GamePrint(ffi.string(en_data.peer_id))
--if ctx.players[ffi.string(en_data.peer_id)] ~= nil then
-- ent = ctx.players[ffi.string(en_data.peer_id)].entity
--end
end
if ent ~= nil then
ComponentSetValue2(worm, "mTargetEntityId", ent)
end
end
if ffi.typeof(en_data) == EnemyDataKolmi and en_data.enabled then
local lua_components = EntityGetComponentIncludingDisabled(enemy_id, "LuaComponent") or {}

View file

@ -60,6 +60,7 @@ np.CrossCallAdd("ew_pet_hamis", function(x, y)
for a, b in pairs(ctx.entity_by_remote_id) do
if b.id == y then
ent = a
break
end
end
rpc.pet(ctx.player_data_by_local_entity[x] or x, ent, frame(), hx, hy)