tether if above floor even if host notplayer, fix kolmi, fix shield/spectate if spectating entity died~, fix camera going to 0,0 for a frame on revive

This commit is contained in:
bgkillas 2024-10-26 19:32:01 -04:00
parent 27c8a27175
commit c180a5d328
7 changed files with 107 additions and 72 deletions

View file

@ -25,6 +25,12 @@ local EnemyDataWorm = util.make_type({
f32 = {"x", "y", "vx", "vy", "tx", "ty"},
})
local EnemyDataKolmi = util.make_type({
u32 = {"enemy_id"},
f32 = {"x", "y", "vx", "vy"},
bool = {"enabled"},
})
local EnemyDataFish = util.make_type({
u32 = {"enemy_id"},
f32 = {"x", "y", "vx", "vy"},
@ -261,7 +267,16 @@ function enemy_sync.host_upload_entities()
local en_data
local worm = EntityGetFirstComponentIncludingDisabled(enemy_id, "WormAIComponent")
if worm ~= nil then
if EntityHasTag(enemy_id, "boss_centipede") then
en_data = EnemyDataKolmi {
enemy_id = enemy_id,
x = x,
y = y,
vx = vx,
vy = vy,
enabled = EntityGetFirstComponent(enemy_id, "BossHealthBarComponent", "disabled_at_start") ~= nil,
}
elseif worm ~= nil then
local tx, ty = ComponentGetValue2(worm, "mRandomTarget")
en_data = EnemyDataWorm {
enemy_id = enemy_id,
@ -579,6 +594,14 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
local tx, ty = en_data.tx, en_data.ty
ComponentSetValue2(worm, "mRandomTarget", tx, ty)
end
if ffi.typeof(en_data) == EnemyDataKolmi and en_data.enabled then
local lua_components = EntityGetComponentIncludingDisabled(enemy_id, "LuaComponent") or {}
for _, c in ipairs(lua_components) do
EntityRemoveComponent(enemy_id, c)
end
EntitySetComponentsWithTagEnabled(enemy_id, "enabled_at_start", false)
EntitySetComponentsWithTagEnabled(enemy_id, "disabled_at_start", true)
end
end
local inv = EntityGetFirstComponentIncludingDisabled(enemy_id, "Inventory2Component")

View file

@ -81,19 +81,6 @@ function rpc.kolmi_shield(is_on, orbcount)
switch_shield(kolmi, is_on)
end
rpc.opts_reliable()
function rpc.init_boss(orbcount)
local kolmi = EntityGetClosestWithTag(0, 0, "boss_centipede")
if kolmi == nil or kolmi == 0 then
return
end
local lua_components = EntityGetComponentIncludingDisabled(kolmi, "LuaComponent") or {}
for _, c in ipairs(lua_components) do
EntityRemoveComponent(kolmi, c)
end
EntitySetComponentsWithTagEnabled(kolmi, "enabled_at_start", false)
EntitySetComponentsWithTagEnabled(kolmi, "disabled_at_start", true)
end
np.CrossCallAdd("ew_sampo_spawned", function()
local sampo_ent = EntityGetClosestWithTag(0, 0, "this_is_sampo")
@ -138,13 +125,9 @@ ctx.cap.item_sync.register_pickup_handler(function(item_id)
EntitySetTransform(ctx.my_player.entity, x, y)
end)
end
async(function()
wait(10) -- Wait a bit for enemy sync to do it's thing.
local newgame_n = tonumber( SessionNumbersGetValue("NEW_GAME_PLUS_COUNT") )
local orbcount = GameGetOrbCountThisRun() + newgame_n
rpc.kolmi_shield(true, orbcount)
rpc.init_boss(orbcount)
end)
local newgame_n = tonumber( SessionNumbersGetValue("NEW_GAME_PLUS_COUNT") )
local orbcount = GameGetOrbCountThisRun() + newgame_n
rpc.kolmi_shield(true, orbcount)
end
end
end)

View file

@ -23,6 +23,16 @@ function module.on_player_died(player_entity)
-- Also inventory items seem to be borked.
end
local function set_camera_free(enable, entity, dont)
local cam = EntityGetFirstComponentIncludingDisabled(entity, "PlatformShooterPlayerComponent")
if cam ~= nil then
ComponentSetValue2(cam, "center_camera_on_this_entity", not enable)
ComponentSetValue2(cam, "move_camera_with_aim", not enable)
elseif not dont then
GameSetCameraFree(true)
end
end
local function end_poly_effect(ent)
local serialized
for _, child in ipairs(EntityGetAllChildren(ent) or {}) do
@ -42,9 +52,13 @@ local function end_poly_effect(ent)
end
local x, y = EntityGetTransform(ent)
local new_ent = util.deserialize_entity(base64.decode(serialized), x, y)
GameSetCameraFree(true)
np.SetPlayerEntity(new_ent)
async(function()
wait(1)
GameSetCameraFree(false)
end)
EntityKill(ent)
GameAddFlagRun("ew_cam_wait")
return new_ent
end
@ -167,24 +181,13 @@ local function player_died()
rpc.add_nickname_change_cursor()
end
local function set_camera_free(enable)
local cam = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "PlatformShooterPlayerComponent")
if cam ~= nil then
ComponentSetValue2(cam, "center_camera_on_this_entity", not enable)
ComponentSetValue2(cam, "move_camera_with_aim", not enable)
else
GameSetCameraFree(true)
end
end
local function do_game_over(message)
net.proxy_notify_game_over()
ctx.run_ended = true
local damage_model = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "DamageModelComponent")
GameRemoveFlagRun("ew_flag_notplayer_active")
set_camera_free(true, ctx.my_player.entity)
if damage_model ~= nil and #(EntityGetAllChildren(ctx.my_player.entity) or {}) ~= 0 then
set_camera_free(true)
GameRemoveFlagRun("ew_cam_wait")
local ent = end_poly_effect(ctx.my_player.entity)
polymorph.switch_entity(ent)
if ctx.my_player.entity ~= nil then
@ -196,7 +199,6 @@ local function do_game_over(message)
GameTriggerGameOver()
end
else
set_camera_free(true)
GameTriggerGameOver()
end
end

View file

@ -6,6 +6,14 @@ local rpc = net.new_rpc_namespace()
local module = {}
function rpc.send_money(money)
local entity = ctx.rpc_player_data.entity
local wallet = EntityGetFirstComponentIncludingDisabled(entity, "WalletComponent")
if wallet ~= nil then
ComponentSetValue2(wallet, "money", money)
end
end
function rpc.player_update(input_data, pos_data, current_slot, team)
local peer_id = ctx.rpc_peer_id
@ -67,14 +75,22 @@ function module.on_world_update()
for peer_id, player in pairs(ctx.players) do
local ent = player.entity
local x, y = EntityGetTransform(ent)
if x == nil or not EntityGetIsAlive(ent) or EntityHasTag(ent, "polymorphed") then
return
local notplayer = EntityHasTag(ent, "ew_notplayer")
if x == nil or not EntityGetIsAlive(ent) or (not notplayer and EntityHasTag(ent, "polymorphed")) then
goto continue
end
local dx, dy = x - mx, y - my
local cape
for _, child in ipairs(EntityGetAllChildren(ent) or {}) do
if EntityGetName(child) == "cape" then
cape = child
local cpe = EntityGetFirstComponentIncludingDisabled(child, "VerletPhysicsComponent")
local cx, cy = ComponentGetValue2(cpe, "m_position_previous")
local dcx, dcy = x - cx, y - cy
if dcx * dcx + dcy * dcy > 300 * 300 then
EntityKill(child)
else
cape = child
end
break
end
end
@ -83,10 +99,23 @@ function module.on_world_update()
EntityKill(cape)
end
elseif cape == nil then
local player_cape_sprite_file = "mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_cape.xml"
local player_cape_sprite_file
if notplayer then
player_cape_sprite_file = "mods/quant.ew/files/system/local_health/notplayer/notplayer_cape.xml"
else
player_cape_sprite_file = "mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_cape.xml"
end
local cape2 = EntityLoad(player_cape_sprite_file, x, y)
EntityAddChild(ent, cape2)
end
::continue::
end
end
if GameGetFrameNum() % 60 == 47 then
local wallet = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "WalletComponent")
if wallet ~= nil then
rpc.send_money(ComponentGetValue2(wallet, "money"))
end
end
end

View file

@ -134,13 +134,21 @@ local function is_suitable_target(entity)
end
local function tether_enable(to_enable, entity)
local found = false
for _, child in ipairs(EntityGetAllChildren(entity) or {}) do
if EntityGetFilename(child) == "mods/quant.ew/files/system/player_tether/zone_entity.xml" then
local emmiter = EntityGetFirstComponentIncludingDisabled(child, "ParticleEmitterComponent")
EntitySetComponentIsEnabled(child, emmiter, to_enable)
found = true
break
end
end
if not found then
local child = EntityLoad("mods/quant.ew/files/system/player_tether/zone_entity.xml")
EntityAddChild(entity, child)
local emmiter = EntityGetFirstComponentIncludingDisabled(child, "ParticleEmitterComponent")
EntitySetComponentIsEnabled(child, emmiter, to_enable)
end
end
local function set_tether_length(length, entity)
@ -173,7 +181,15 @@ function module.on_world_update_client()
return
end
local host_playerdata = player_fns.peer_get_player_data(ctx.host_id, true)
if host_playerdata == nil or not is_suitable_target(host_playerdata.entity) or not is_suitable_target(ctx.my_player.entity) then
local x1, y1 = EntityGetTransform(host_playerdata.entity)
local x2, y2 = EntityGetTransform(ctx.my_player.entity)
if x1 == nil or x2 == nil then
return
end
if host_playerdata == nil
or (not is_suitable_target(host_playerdata.entity)
and not (not not_in_normal_area(x1, y1) and not not_in_normal_area(x2, y2) and position_to_area_number(x1, y1) > position_to_area_number(x2, y2)))
or not is_suitable_target(ctx.my_player.entity) then
if host_playerdata ~= nil and host_playerdata.entity ~= nil and EntityGetIsAlive(host_playerdata.entity) then
no_tether = true
tether_enable(false, host_playerdata.entity)
@ -188,11 +204,6 @@ function module.on_world_update_client()
end
return
end
local x1, y1 = EntityGetTransform(host_playerdata.entity)
local x2, y2 = EntityGetTransform(ctx.my_player.entity)
if x1 == nil or x2 == nil then
return
end
if is_in_box(9200, 11000, 8300, 9800, x2, y2) then
local any_not = false
for _, player in pairs(ctx.players) do

View file

@ -22,6 +22,8 @@ local has_switched = false
local attached = false
local redo = false
local function perks_ui(enable)
for _, child in ipairs(EntityGetAllChildren(ctx.my_player.entity) or {}) do
if EntityHasTag(child, "perk_entity") then
@ -86,7 +88,7 @@ local function set_camera_free(enable)
end
end
local function set_camera_pos(x, y)
local function set_camera_position(x, y)
local cam = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "PlatformShooterPlayerComponent")
if cam ~= nil then
ComponentSetValue2(cam, "mDesiredCameraPos", x, y)
@ -107,15 +109,7 @@ local function target()
if sprite ~= nil and not EntityHasTag(ctx.my_player.entity, "ew_notplayer") then
EntityRemoveComponent(ctx.my_player.entity, sprite)
end
if GameHasFlagRun("ew_cam_wait") then
GameRemoveFlagRun("ew_cam_wait")
async(function()
wait(1)
set_camera_free(false)
end)
else
set_camera_free(false)
end
set_camera_free(false)
if camera_target == nil then
camera_target = ctx.my_player
elseif camera_target.entity ~= ctx.my_player.entity then
@ -138,6 +132,7 @@ local function target()
end
set_camera_free(true)
if cam_target == nil or not EntityGetIsAlive(cam_target.entity) then
redo = true
return
end
local my_x, my_y = GameGetCameraPos()
@ -156,17 +151,18 @@ local function target()
local dx, dy = t_x - my_x, t_y - my_y
local di = dx * dx + dy * dy
if di > 512 * 512 then
set_camera_pos(to_x, to_y)
set_camera_position(to_x, to_y)
else
local cos, sin = dx / 512, dy / 512
local d = math.sqrt(di)
dx, dy = d * cos, d * sin
set_camera_pos(my_x + dx, my_y + dy)
set_camera_position(my_x + dx, my_y + dy)
end
if camera_target == nil then
camera_target = ctx.my_player
end
if camera_target.entity ~= cam_target.entity then
if camera_target.entity ~= cam_target.entity or redo then
redo = false
if EntityHasTag(ctx.my_player.entity, "ew_notplayer") then
if cam_target.entity ~= ctx.my_player.entity then
spectate.disable_throwing(false, ctx.my_player.entity)

View file

@ -3,6 +3,7 @@ local rpc = net.new_rpc_namespace()
local shield_entities = {}
rpc.opts_everywhere()
rpc.opts_reliable()
function rpc.add_shield(target)
if GameHasFlagRun("ending_game_completed") then
return
@ -20,6 +21,7 @@ function rpc.add_shield(target)
end
rpc.opts_everywhere()
rpc.opts_reliable()
function rpc.del_shield()
if shield_entities[ctx.rpc_peer_id] ~= nil then
EntityKill(shield_entities[ctx.rpc_peer_id][2])
@ -70,14 +72,6 @@ function module.on_local_player_polymorphed(_currently_polymorphed)
kill_all_shields()
end
function rpc.send_money(money)
local entity = ctx.rpc_player_data.entity
local wallet = EntityGetFirstComponentIncludingDisabled(entity, "WalletComponent")
if wallet ~= nil then
ComponentSetValue2(wallet, "money", money)
end
end
local last_spectate
function module.on_world_update()
@ -86,6 +80,9 @@ function module.on_world_update()
end
if GameGetFrameNum() % 10 == 8 then
local notplayer_active = GameHasFlagRun("ew_flag_notplayer_active")
if shield_entities[ctx.my_id] ~= nil and not EntityGetIsAlive(shield_entities[ctx.my_id]) then
rpc.del_shield()
end
if notplayer_active and ctx.spectating_over_peer_id ~= nil and is_acceptable_help_target(ctx.spectating_over_peer_id) then
rpc.add_shield(ctx.spectating_over_peer_id)
elseif last_spectate ~= nil and last_spectate ~= ctx.spectating_over_peer_id then
@ -132,12 +129,6 @@ function module.on_world_update()
end
::continue::
end
if GameGetFrameNum() % 60 == 47 then
local wallet = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "WalletComponent")
if wallet ~= nil then
rpc.send_money(ComponentGetValue2(wallet, "money"))
end
end
end
return module