Skip to content

Commit

Permalink
Merge pull request #175 from DaftBrit/death-link-change
Browse files Browse the repository at this point in the history
Change death link to have 3 options
  • Loading branch information
ScipioWright authored Sep 1, 2024
2 parents 19b387d + f30333b commit d30f0cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
45 changes: 32 additions & 13 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,19 @@ end

local function IsDeathLinkEnabled()
if slot_options == nil then
return false
return 0
end
local death_link_setting = ModSettingGet("archipelago.death_link")
if slot_options.death_link == 0 then
return 0
elseif death_link_setting == "on" then
return 1
elseif death_link_setting == "traps" then
return 2
else
Log.Error("Error in IsDeathLinkEnabled")
return 0
end
return slot_options.death_link == 1 and ModSettingGet("archipelago.death_link")
end


Expand Down Expand Up @@ -396,24 +406,33 @@ end
-- https://github.com/ArchipelagoMW/Archipelago/blob/main/docs/network%20protocol.md#bounced
function RECV_MSG.Bounced(msg)
if contains_element(msg["tags"], "DeathLink") then
if not IsDeathLinkEnabled() or not UpdateDeathTime() then return end
local death_link_option = IsDeathLinkEnabled()
if death_link_option == 0 or not UpdateDeathTime() then return end

local cause = msg["data"]["cause"]
local source = msg["data"]["source"]

if cause == nil or cause == "" then
GamePrintImportant(source .. " died and took you with them")
if death_link_option == 1 then
GamePrintImportant(source .. " died and took you with them")
else
GamePrintImportant(source .. " died and is trying to take you with them")
end
else
GamePrintImportant(cause)
end

local player = get_player()
if not DecreaseExtraLife(player) then
local gsc_id = EntityGetFirstComponentIncludingDisabled(player, "GameStatsComponent")
if gsc_id ~= nil then
ComponentSetValue2(gsc_id, "extra_death_msg", cause)
if death_link_option == 1 then
local player = get_player()
if not DecreaseExtraLife(player) then
local gsc_id = EntityGetFirstComponentIncludingDisabled(player, "GameStatsComponent")
if gsc_id ~= nil then
ComponentSetValue2(gsc_id, "extra_death_msg", cause)
end
EntityKill(player)
end
EntityKill(player)
else
BadTimes()
end

else
Expand Down Expand Up @@ -576,11 +595,11 @@ function OnPausedChanged(is_paused, is_inventory_pause)
-- Workaround: When the player creates a new game, OnPlayerDied gets called (triggers DeathLink).
-- However we know they have to pause the game (menu) to start a new game.
game_is_paused = is_paused and not is_inventory_pause
if IsDeathLinkEnabled() and death_link_status == false then
if IsDeathLinkEnabled() > 0 and death_link_status == false then
SetDeathLinkEnabled(true)
death_link_status = true
end
if not IsDeathLinkEnabled() and death_link_status == true then
if IsDeathLinkEnabled() == 0 and death_link_status == true then
SetDeathLinkEnabled(false)
death_link_status = false
end
Expand All @@ -590,7 +609,7 @@ end
-- Called when the player dies
-- https://noita.wiki.gg/wiki/Modding:_Lua_API#OnPlayerDied
function OnPlayerDied(player)
if slot_options == nil or not IsDeathLinkEnabled() or game_is_paused or not UpdateDeathTime() then return end
if slot_options == nil or IsDeathLinkEnabled() == 0 or game_is_paused or not UpdateDeathTime() then return end
local death_msg = GetCauseOfDeath() or "skill issue"
local slotname = ModSettingGet("archipelago.slot_name")
ap:Bounce({
Expand Down
9 changes: 7 additions & 2 deletions settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ local translations = {
en="Allow Death Link"
},
["$ap_death_link_settings_desc"] = {
en="When enabled, the death link setting in your Archipelago YAML will be used.\nWhen disabled, this will override your YAML and disable death link."
en="When set to On, the death link setting in your Archipelago YAML will be used.\nWhen set to Off, this will override your YAML and disable death link.\nWhen set to Traps, it will act as On if death link was enabled in your YAML,\nexcept it will trigger a random trap effect when a death link is received.\nBoth On and Traps will still send death links when you die."
}
}

Expand Down Expand Up @@ -163,7 +163,12 @@ local mod_settings =
id = "death_link",
ui_name = translate("$ap_death_link_settings_name"),
ui_description = translate("$ap_death_link_settings_desc"),
value_default = true,
value_default = "on",
values = {
{"off", "Off"},
{"on", "On"},
{"traps", "Traps"}
},
scope = MOD_SETTING_SCOPE_RUNTIME,
},
{
Expand Down

0 comments on commit d30f0cb

Please sign in to comment.