fix player when polied into phys object, fix throwing potion mimic

This commit is contained in:
bgkillas 2024-11-16 21:11:00 -05:00
parent 65714117b2
commit 8ada6ab75d
4 changed files with 23 additions and 9 deletions

View file

@ -285,6 +285,9 @@ local function pickup_item(entity, item)
if entity_children ~= nil then if entity_children ~= nil then
for _, child in pairs( entity_children ) do for _, child in pairs( entity_children ) do
if EntityGetName( child ) == "inventory_quick" then if EntityGetName( child ) == "inventory_quick" then
if EntityGetParent(item) ~= 0 then
EntityRemoveFromParent(item)
end
EntityAddChild( child, item) EntityAddChild( child, item)
end end
end end

View file

@ -483,13 +483,12 @@ function player_fns.deserialize_position(message, phys_infos, phys_infos_2, play
ComponentSetValue2(velocity_comp, "gravity_y", 0) ComponentSetValue2(velocity_comp, "gravity_y", 0)
ComponentSetValue2(character_data, "mVelocity", message.vel_x, message.vel_y) local had_phys = false
EntityApplyTransform(entity, message.x, message.y)
for i, phys_component in ipairs(EntityGetComponent(entity, "PhysicsBodyComponent") or {}) do for i, phys_component in ipairs(EntityGetComponent(entity, "PhysicsBodyComponent") or {}) do
local phys_info = phys_infos[i] local phys_info = phys_infos[i]
if phys_component ~= nil and phys_component ~= 0 and phys_info ~= nil then if phys_component ~= nil and phys_component ~= 0 and phys_info ~= nil then
deserialize_phys_component(phys_component, phys_info) deserialize_phys_component(phys_component, phys_info)
had_phys = true
end end
end end
for i, phys_component in ipairs(EntityGetComponent(entity, "PhysicsBody2Component") or {}) do 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") local initialized = ComponentGetValue2(phys_component, "mInitialized")
if initialized then if initialized then
deserialize_phys_component(phys_component, phys_info) deserialize_phys_component(phys_component, phys_info)
had_phys = true
end end
end 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 end

View file

@ -1,5 +1,7 @@
function throw_item() function throw_item(xi, yi, xf, yf)
CrossCall("ew_potion_mimic_throw", GetUpdatedEntityID()) local dx = xf - xi
local dy = yf - yi
CrossCall("ew_potion_mimic_throw", GetUpdatedEntityID(), dx / 8, dy / 8)
end end
function item_pickup() function item_pickup()

View file

@ -1,21 +1,26 @@
local rpc = net.new_rpc_namespace() local rpc = net.new_rpc_namespace()
local potion = {} local potion = {}
function rpc.got_thrown(peer_id) function rpc.got_thrown(peer_id, vx, vy)
local item = ctx.players[peer_id].entity local item = ctx.players[peer_id].entity
for _, com in ipairs(EntityGetAllComponents(item) or {}) do for _, com in ipairs(EntityGetAllComponents(item) or {}) do
EntitySetComponentIsEnabled(item, com, true) EntitySetComponentIsEnabled(item, com, true)
end 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, "ItemChestComponent"), false)
EntitySetComponentIsEnabled(item, EntityGetFirstComponentIncludingDisabled(item, "ItemComponent"), false) EntitySetComponentIsEnabled(item, EntityGetFirstComponentIncludingDisabled(item, "ItemComponent"), false)
if EntityGetParent(item) ~= 0 then if EntityGetParent(item) ~= 0 then
EntityRemoveFromParent(item) EntityRemoveFromParent(item)
end 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 end
np.CrossCallAdd("ew_potion_mimic_throw", function(item) 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) rpc.got_thrown(player_fns.get_player_data_by_local_entity_id(item).peer_id, vx, vy)
end) end)
np.CrossCallAdd("ew_potion_mimic_pickup", function() np.CrossCallAdd("ew_potion_mimic_pickup", function()