fix potion mimic when held by someone who died, dont require pheremones to pick up players

This commit is contained in:
bgkillas 2024-11-16 22:06:08 -05:00
parent 9e249cdff1
commit 3efee1293b
2 changed files with 15 additions and 4 deletions

View file

@ -2,6 +2,7 @@ local util = dofile_once("mods/quant.ew/files/core/util.lua")
local ctx = dofile_once("mods/quant.ew/files/core/ctx.lua") local ctx = dofile_once("mods/quant.ew/files/core/ctx.lua")
local net = dofile_once("mods/quant.ew/files/core/net.lua") 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 player_fns = dofile_once("mods/quant.ew/files/core/player_fns.lua")
local potion = dofile_once("mods/quant.ew/files/system/potion_mimic/potion_mimic.lua")
local np = require("noitapatcher") local np = require("noitapatcher")
local rpc = net.new_rpc_namespace() local rpc = net.new_rpc_namespace()
@ -90,7 +91,7 @@ function module.on_world_update_post()
if ent ~= nil and ent ~= ctx.my_player.entity then if ent ~= nil and ent ~= ctx.my_player.entity then
if EntityHasTag(ent, "mimic_potion") then if EntityHasTag(ent, "mimic_potion") then
local effect local effect
for _, child in ipairs(EntityGetAllChildren(ctx.my_player.entity) or {}) do for _, child in ipairs(EntityGetAllChildren(ent) or {}) do
local com = EntityGetFirstComponentIncludingDisabled(child, "GameEffectComponent") local com = EntityGetFirstComponentIncludingDisabled(child, "GameEffectComponent")
if com ~= nil then if com ~= nil then
local effect_name = ComponentGetValue2(com, "effect") local effect_name = ComponentGetValue2(com, "effect")
@ -107,6 +108,9 @@ function module.on_world_update_post()
ComponentSetValue2(effect, "frames", 1200) ComponentSetValue2(effect, "frames", 1200)
end end
end end
local item = EntityGetFirstComponentIncludingDisabled(ent, "ItemComponent")
ComponentRemoveTag(item, "enabled_if_charmed")
EntitySetComponentIsEnabled(ent, item, true)
EntityAddComponent2(ent, "LuaComponent", { EntityAddComponent2(ent, "LuaComponent", {
script_item_picked_up = "mods/quant.ew/files/system/potion_mimic/pickup.lua", script_item_picked_up = "mods/quant.ew/files/system/potion_mimic/pickup.lua",
@ -145,6 +149,10 @@ function rpc.replicate_projectile(seri_ent, position_x, position_y, target_x, ta
end end
local function apply_seri_ent(player_data, seri_ent) local function apply_seri_ent(player_data, seri_ent)
if EntityGetRootEntity(ctx.my_player.entity) == player_data.entity
and player_data.peer_id ~= ctx.my_player.peer_id then
potion.enable_in_world(ctx.my_player.entity)
end
if seri_ent ~= nil then if seri_ent ~= nil then
local ent = util.deserialize_entity(seri_ent.data) local ent = util.deserialize_entity(seri_ent.data)
EntityAddTag(ent, "ew_no_enemy_sync") EntityAddTag(ent, "ew_no_enemy_sync")

View file

@ -1,17 +1,20 @@
local rpc = net.new_rpc_namespace() local rpc = net.new_rpc_namespace()
local potion = {} local potion = {}
function rpc.got_thrown(peer_id, vx, vy) function potion.enable_in_world(item)
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", "enabled_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)
if EntityGetParent(item) ~= 0 then if EntityGetParent(item) ~= 0 then
EntityRemoveFromParent(item) EntityRemoveFromParent(item)
end end
end
function rpc.got_thrown(peer_id, vx, vy)
local item = ctx.players[peer_id].entity
potion.enable_in_world(item)
if peer_id == ctx.my_player.peer_id then if peer_id == ctx.my_player.peer_id then
local phys_component = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "PhysicsBodyComponent") local phys_component = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "PhysicsBodyComponent")
local px, py, pr, pvx, pvy, pvr = np.PhysBodyGetTransform(phys_component) local px, py, pr, pvx, pvy, pvr = np.PhysBodyGetTransform(phys_component)