From 8ada6ab75d6febe83b312a25bf4103ab2ea85bcf Mon Sep 17 00:00:00 2001 From: bgkillas Date: Sat, 16 Nov 2024 21:11:00 -0500 Subject: [PATCH] fix player when polied into phys object, fix throwing potion mimic --- quant.ew/files/core/inventory_helper.lua | 3 +++ quant.ew/files/core/player_fns.lua | 10 +++++++--- quant.ew/files/system/potion_mimic/pickup.lua | 6 ++++-- quant.ew/files/system/potion_mimic/potion_mimic.lua | 13 +++++++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/quant.ew/files/core/inventory_helper.lua b/quant.ew/files/core/inventory_helper.lua index b7a693de..97ea86de 100644 --- a/quant.ew/files/core/inventory_helper.lua +++ b/quant.ew/files/core/inventory_helper.lua @@ -285,6 +285,9 @@ local function pickup_item(entity, item) if entity_children ~= nil then for _, child in pairs( entity_children ) do if EntityGetName( child ) == "inventory_quick" then + if EntityGetParent(item) ~= 0 then + EntityRemoveFromParent(item) + end EntityAddChild( child, item) end end diff --git a/quant.ew/files/core/player_fns.lua b/quant.ew/files/core/player_fns.lua index 0c9352c8..b618c9cd 100644 --- a/quant.ew/files/core/player_fns.lua +++ b/quant.ew/files/core/player_fns.lua @@ -483,13 +483,12 @@ function player_fns.deserialize_position(message, phys_infos, phys_infos_2, play ComponentSetValue2(velocity_comp, "gravity_y", 0) - ComponentSetValue2(character_data, "mVelocity", message.vel_x, message.vel_y) - - EntityApplyTransform(entity, message.x, message.y) + local had_phys = false for i, phys_component in ipairs(EntityGetComponent(entity, "PhysicsBodyComponent") or {}) do local phys_info = phys_infos[i] if phys_component ~= nil and phys_component ~= 0 and phys_info ~= nil then deserialize_phys_component(phys_component, phys_info) + had_phys = true end end for i, phys_component in ipairs(EntityGetComponent(entity, "PhysicsBody2Component") or {}) do @@ -499,9 +498,14 @@ function player_fns.deserialize_position(message, phys_infos, phys_infos_2, play local initialized = ComponentGetValue2(phys_component, "mInitialized") if initialized then deserialize_phys_component(phys_component, phys_info) + had_phys = true end end end + if not had_phys then + ComponentSetValue2(character_data, "mVelocity", message.vel_x, message.vel_y) + EntityApplyTransform(entity, message.x, message.y) + end end diff --git a/quant.ew/files/system/potion_mimic/pickup.lua b/quant.ew/files/system/potion_mimic/pickup.lua index 2cf4f635..97ddf73b 100644 --- a/quant.ew/files/system/potion_mimic/pickup.lua +++ b/quant.ew/files/system/potion_mimic/pickup.lua @@ -1,5 +1,7 @@ -function throw_item() - CrossCall("ew_potion_mimic_throw", GetUpdatedEntityID()) +function throw_item(xi, yi, xf, yf) + local dx = xf - xi + local dy = yf - yi + CrossCall("ew_potion_mimic_throw", GetUpdatedEntityID(), dx / 8, dy / 8) end function item_pickup() diff --git a/quant.ew/files/system/potion_mimic/potion_mimic.lua b/quant.ew/files/system/potion_mimic/potion_mimic.lua index ddae7f8b..b032d912 100644 --- a/quant.ew/files/system/potion_mimic/potion_mimic.lua +++ b/quant.ew/files/system/potion_mimic/potion_mimic.lua @@ -1,21 +1,26 @@ local rpc = net.new_rpc_namespace() local potion = {} -function rpc.got_thrown(peer_id) +function rpc.got_thrown(peer_id, vx, vy) local item = ctx.players[peer_id].entity for _, com in ipairs(EntityGetAllComponents(item) or {}) do EntitySetComponentIsEnabled(item, com, true) end - EntitySetComponentIsEnabled(item, EntityGetFirstComponentIncludingDisabled(item, "SpriteComponent", "enable_in_hand"), false) + EntitySetComponentIsEnabled(item, EntityGetFirstComponentIncludingDisabled(item, "SpriteComponent", "enabled_in_hand"), false) EntitySetComponentIsEnabled(item, EntityGetFirstComponentIncludingDisabled(item, "ItemChestComponent"), false) EntitySetComponentIsEnabled(item, EntityGetFirstComponentIncludingDisabled(item, "ItemComponent"), false) if EntityGetParent(item) ~= 0 then EntityRemoveFromParent(item) end + if peer_id == ctx.my_player.peer_id then + local phys_component = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "PhysicsBodyComponent") + local px, py, pr, pvx, pvy, pvr = np.PhysBodyGetTransform(phys_component) + np.PhysBodySetTransform(phys_component, px, py, pr, pvx + vx, pvy + vy, pvr) + end end -np.CrossCallAdd("ew_potion_mimic_throw", function(item) - rpc.got_thrown(player_fns.get_player_data_by_local_entity_id(item).peer_id) +np.CrossCallAdd("ew_potion_mimic_throw", function(item, vx, vy) + rpc.got_thrown(player_fns.get_player_data_by_local_entity_id(item).peer_id, vx, vy) end) np.CrossCallAdd("ew_potion_mimic_pickup", function()