Skip to content

Commit

Permalink
make tether tether you to the next HM instead of to the player, if it…
Browse files Browse the repository at this point in the history
… makes sense, warn on different game modes
  • Loading branch information
bgkillas committed Sep 27, 2024
1 parent 6898506 commit b5d31fb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 38 deletions.
6 changes: 1 addition & 5 deletions quant.ew/files/system/notplayer_ai/notplayer_ai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,6 @@ local function choose_movement()
end
end

local function is_in_box(x1, x2, y1, y2, x, y)
return x1 < x and x < x2 and y1 < y and y < y2
end

local function teleport_to_area(area)
async(function()
if np.GetGameModeNr() == 2 then
Expand Down Expand Up @@ -741,7 +737,7 @@ local function teleport_to_next_hm()
for peer_id, player_data in pairs(ctx.players) do
local player = player_data.entity
local x, y = EntityGetTransform(player)
if x == nil or not (-5646 < x and x < 5120 and -1400 < y and y < 14336) and not is_in_box(5632, 7168, 14336, 15872, x, y) then
if x == nil or not_in_normal_area(x, y) then
return
end
if peer_id == ctx.my_id then
Expand Down
9 changes: 9 additions & 0 deletions quant.ew/files/system/player_sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ function rpc.player_update(input_data, pos_data, current_slot)
end
end

function rpc.check_gamemode(gamemode)
if gamemode ~= np.GetGameModeNr() then
GamePrint("Player: " .. ctx.rpc_player_data.name .. ", is on a different gamemode number then you")
end
end

function module.on_world_update()
local input_data = player_fns.serialize_inputs(ctx.my_player)
local pos_data = player_fns.serialize_position(ctx.my_player)
local current_slot = player_fns.get_current_slot(ctx.my_player)
if input_data ~= nil and pos_data ~= nil then
rpc.player_update(input_data, pos_data, current_slot)
if GameGetFrameNum() % 60 == 0 then
rpc.check_gamemode(np.GetGameModeNr())
end
end
end

Expand Down
85 changes: 52 additions & 33 deletions quant.ew/files/system/player_tether/player_tether.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ local tether_length_2 = tether_length + 128

local module = {}

function is_in_box(x1, x2, y1, y2, x, y)
return x1 < x and x < x2 and y1 < y and y < y2
end

function not_in_normal_area(x, y)
return not (-5646 < x and x < 5120 and -1400 < y and y < 14336) and not is_in_box(5632, 7168, 14336, 15872, x, y)
end

function position_to_area_number(x, y)
if np.GetGameModeNr() == 2 then
if y < 1199 then
return 1
return 1, 1199
elseif y < 3759 then
return 2
return 2, 3759
elseif y < 6319 then
return 3
return 3, 6319
elseif y < 10415 then
return 4
return 4, 10415
elseif y < 12975 and (x < 2726 or x > 4135 or y < 12800) then
return 5
elseif is_in_box(5632, 7168, 14336, 15872, x, y) then
Expand All @@ -25,13 +33,13 @@ function position_to_area_number(x, y)
end
elseif tonumber(SessionNumbersGetValue("NEW_GAME_PLUS_COUNT")) > 0 then
if y < 1199 then
return 1
return 1, 1199
elseif y < 2735 then
return 2
return 2, 2735
elseif y < 6319 then
return 3
return 3, 6319
elseif y < 10415 then
return 4
return 4, 10415
elseif y < 12975 and (x < 2726 or x > 4135 or y < 12800) then
return 5
elseif is_in_box(5632, 7168, 14336, 15872, x, y) then
Expand All @@ -41,17 +49,17 @@ function position_to_area_number(x, y)
end
else
if y < 1199 then
return 1
return 1, 1199
elseif y < 2735 then
return 2
return 2, 2735
elseif y < 4783 then
return 3
return 3, 4783
elseif y < 6319 then
return 4
return 4, 6319
elseif y < 8367 then
return 5
return 5, 8367
elseif y < 10415 then
return 6
return 6, 10415
elseif y < 12975 and (x < 2726 or x > 4135 or y < 12800) then
return 7
elseif is_in_box(5632, 7168, 14336, 15872, x, y) then
Expand All @@ -62,8 +70,12 @@ function position_to_area_number(x, y)
end
end

function is_in_box(x1, x2, y1, y2, x, y)
return x1 < x and x < x2 and y1 < y and y < y2
local function new_pos(given)
if given ~= nil then
return -678, given + 149
else
return 1914, 13119
end
end

local function in_normal_hm(list, x, y)
Expand Down Expand Up @@ -138,45 +150,51 @@ local no_tether = false

local tether_length_3 = tether_length_2

local was_in_hm = false

function module.on_world_update_client()
if GameGetFrameNum() < 60 and GameGetFrameNum() % 6 == 0 then
local host_playerdata = player_fns.peer_get_player_data(ctx.host_id, true)
if host_playerdata.entity ~= nil then
local x1, y1 = EntityGetTransform(host_playerdata.entity)
local x2, y2 = EntityGetTransform(ctx.my_player.entity)
local dx = x1-x2
local dy = y1-y2
local dist_sq = dx*dx + dy*dy
tether_length_3 = math.max(math.sqrt(dist_sq) + 256, tether_length_2)
end
end
if GameGetFrameNum() % 10 == 7 then
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
if not no_tether and (host_playerdata == nil or not is_suitable_target(host_playerdata.entity) 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)
end
return
end
if GameHasFlagRun("ending_game_completed") then
tether_enable(false, host_playerdata.entity)
if not no_tether then
tether_enable(false, host_playerdata.entity)
no_tether = true
end
return
end
local x1, y1 = EntityGetTransform(host_playerdata.entity)
local x2, y2 = EntityGetTransform(ctx.my_player.entity)
local dx = x1-x2
local dy = y1-y2
local dist_sq = dx*dx + dy*dy
if x1 ~= nil and x2 ~= nil and not_in_hm(x1, y1) and not_in_hm(x2, y2) then
local in_hm = not_in_hm(x1, y1)
if x1 ~= nil and x2 ~= nil and in_hm and not_in_hm(x2, y2) then
if no_tether then
tether_enable(true, host_playerdata.entity)
no_tether = false
tether_length_3 = math.max(math.sqrt(dist_sq) + 256, tether_length_2)
set_tether_length(tether_length_3 - 128, host_playerdata.entity)
if not was_in_hm then
tether_length_3 = math.max(math.sqrt(dist_sq) + 256, tether_length_2)
set_tether_length(tether_length_3 - 128, host_playerdata.entity)
end
end
if dist_sq > tether_length_3 * tether_length_3 then
EntitySetTransform(ctx.my_player.entity, x1, y1)
local x, y = x1, y1
local my_pos, given = position_to_area_number(x2, y2)
if not not_in_normal_area(x, y) and not not_in_normal_area(x2, y2) and position_to_area_number(x, y) > my_pos then
x, y = new_pos(given)
end
async(function()
EntitySetTransform(ctx.my_player.entity, x, y)
wait(40)
EntitySetTransform(ctx.my_player.entity, x, y)
end)
elseif tether_length_3 > tether_length_2 then
tether_length_3 = math.max(math.min(tether_length_3, math.sqrt(dist_sq) + 256), tether_length_2)
set_tether_length(tether_length_3 - 128, host_playerdata.entity)
Expand All @@ -185,6 +203,7 @@ function module.on_world_update_client()
no_tether = true
tether_enable(false, host_playerdata.entity)
end
was_in_hm = in_hm
end
end

Expand Down

0 comments on commit b5d31fb

Please sign in to comment.