mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Unshare health (in local health mode)
This commit is contained in:
parent
46c25c121c
commit
5867d76c47
5 changed files with 115 additions and 6 deletions
|
@ -15,9 +15,11 @@ Functions:
|
||||||
- `set_max_health(hp: num)`
|
- `set_max_health(hp: num)`
|
||||||
- `inflict_damage(dmg: num)`
|
- `inflict_damage(dmg: num)`
|
||||||
- `do_game_over(msg: str)`
|
- `do_game_over(msg: str)`
|
||||||
|
- `on_poly_death(msg: str)`
|
||||||
|
|
||||||
Provided by:
|
Provided by:
|
||||||
- damage (shared health) system
|
- damage (shared health) system
|
||||||
|
- local health system
|
||||||
|
|
||||||
Used by:
|
Used by:
|
||||||
- heart pickups system
|
- heart pickups system
|
||||||
|
|
|
@ -149,7 +149,8 @@ ctx.cap.health = {
|
||||||
set_health = module.set_health,
|
set_health = module.set_health,
|
||||||
set_max_health = module.set_max_health,
|
set_max_health = module.set_max_health,
|
||||||
inflict_damage = module.inflict_damage,
|
inflict_damage = module.inflict_damage,
|
||||||
do_game_over = function(message) do_game_over(message) rpc.trigger_game_over(message) end
|
do_game_over = function(message) do_game_over(message) rpc.trigger_game_over(message) end,
|
||||||
|
on_poly_death = function(message) do_game_over(message) rpc.trigger_game_over(message) end,
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc.opts_reliable()
|
rpc.opts_reliable()
|
||||||
|
|
97
quant.ew/files/src/system/local_health/local_health.lua
Normal file
97
quant.ew/files/src/system/local_health/local_health.lua
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
-- This module allows to handle getting damaged locally and redirects that damage to host.
|
||||||
|
-- Also handles shared health system in general.
|
||||||
|
-- Also recalculates percentage-based damage.
|
||||||
|
|
||||||
|
local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
|
||||||
|
local net = dofile_once("mods/quant.ew/files/src/net.lua")
|
||||||
|
local util = dofile_once("mods/quant.ew/files/src/util.lua")
|
||||||
|
local np = require("noitapatcher")
|
||||||
|
|
||||||
|
local rpc = net.new_rpc_namespace()
|
||||||
|
|
||||||
|
local module = {}
|
||||||
|
|
||||||
|
module.recent_damage = 0
|
||||||
|
module.recent_message = "unknown"
|
||||||
|
module.last_damage_message = "unknown"
|
||||||
|
|
||||||
|
ModLuaFileAppend("data/scripts/game_helpers.lua", "mods/quant.ew/files/src/system/damage/append/game_helpers.lua")
|
||||||
|
ModTextFileSetContent("data/entities/misc/effect_hearty.xml", ModTextFileGetContent("mods/quant.ew/files/src/system/damage/append/hearty_effect.xml"))
|
||||||
|
|
||||||
|
local function do_game_over(message)
|
||||||
|
net.proxy_notify_game_over()
|
||||||
|
ctx.run_ended = true
|
||||||
|
|
||||||
|
local damage_model = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "DamageModelComponent")
|
||||||
|
ComponentSetValue2(damage_model, "wait_for_kill_flag_on_death", false)
|
||||||
|
EntityInflictDamage(ctx.my_player.entity, 1000000, "DAMAGE_CURSE", message, "NONE", 0, 0, GameGetWorldStateEntity())
|
||||||
|
GameTriggerGameOver()
|
||||||
|
EntityKill(ctx.my_player.entity)
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.on_local_player_spawn(my_player)
|
||||||
|
local damage_model = EntityGetFirstComponentIncludingDisabled(my_player.entity, "DamageModelComponent")
|
||||||
|
ComponentSetValue2(damage_model, "wait_for_kill_flag_on_death", true)
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.on_world_update_client()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.on_world_update_host()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.on_new_player_seen(new_playerdata, player_count)
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.on_client_spawned(peer_id, playerdata)
|
||||||
|
if ctx.is_host then
|
||||||
|
EntityAddComponent2(playerdata.entity, "LuaComponent", {script_damage_received = "mods/quant.ew/files/src/system/damage/cbs/send_damage_to_client.lua"})
|
||||||
|
else
|
||||||
|
EntityAddComponent2(playerdata.entity, "LuaComponent", {script_damage_about_to_be_received = "mods/quant.ew/files/cbs/immortal.lua"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.health()
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.max_health()
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.set_health(hp)
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.set_max_health(hp)
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.inflict_damage(dmg)
|
||||||
|
local hp = module.health()
|
||||||
|
module.set_health(math.min(math.max(hp-dmg, 0), module.max_health()))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Provides health capability
|
||||||
|
ctx.cap.health = {
|
||||||
|
health = module.health,
|
||||||
|
max_health = module.max_health,
|
||||||
|
set_health = module.set_health,
|
||||||
|
set_max_health = module.set_max_health,
|
||||||
|
inflict_damage = module.inflict_damage,
|
||||||
|
do_game_over = function(message) do_game_over(message) rpc.trigger_game_over(message) end,
|
||||||
|
on_poly_death = function() end,
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc.opts_reliable()
|
||||||
|
function rpc.trigger_game_over(message)
|
||||||
|
do_game_over(message)
|
||||||
|
end
|
||||||
|
|
||||||
|
rpc.opts_reliable()
|
||||||
|
function rpc.melee_damage_client(target_peer, damage, message)
|
||||||
|
if ctx.my_player.peer_id == target_peer then
|
||||||
|
EntityInflictDamage(ctx.my_player.entity, damage, "DAMAGE_MELEE", message, "NONE", 0, 0, 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
np.CrossCallAdd("ew_ds_client_damaged", rpc.melee_damage_client)
|
||||||
|
|
||||||
|
return module
|
|
@ -48,7 +48,7 @@ function module.on_world_update()
|
||||||
local hp, _, has_hp_component = util.get_ent_health(ctx.my_player.entity)
|
local hp, _, has_hp_component = util.get_ent_health(ctx.my_player.entity)
|
||||||
-- Added a check for having damage model component at all, as entity can't die from lack of health in that case.
|
-- Added a check for having damage model component at all, as entity can't die from lack of health in that case.
|
||||||
if has_hp_component and hp <= 0 and not gameover_requested then
|
if has_hp_component and hp <= 0 and not gameover_requested then
|
||||||
ctx.cap.health.do_game_over()
|
ctx.cap.health.on_poly_death()
|
||||||
gameover_requested = true
|
gameover_requested = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,19 @@ local function load_modules()
|
||||||
|
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/player_sync.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/player_sync.lua")
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/enemy_sync.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/enemy_sync.lua")
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/damage/sync.lua")
|
|
||||||
|
|
||||||
|
if ctx.proxy_opt.game_mode == "shared_health" then
|
||||||
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/damage/sync.lua")
|
||||||
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/heart_pickups/sync.lua")
|
||||||
|
ctx.load_system("patch_meat_biome")
|
||||||
|
ctx.load_system("kivi_patch")
|
||||||
|
end
|
||||||
|
if ctx.proxy_opt.game_mode == "local_health" then
|
||||||
|
ctx.load_system("local_health")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/nickname.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/nickname.lua")
|
||||||
|
|
||||||
if ctx.proxy_opt.debug then
|
if ctx.proxy_opt.debug then
|
||||||
|
@ -49,7 +61,6 @@ local function load_modules()
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/world_sync_v2.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/world_sync_v2.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/heart_pickups/sync.lua")
|
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/spawn_hooks/init.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/spawn_hooks/init.lua")
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/proxy_info.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/proxy_info.lua")
|
||||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/perk_patches/init.lua")
|
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/perk_patches/init.lua")
|
||||||
|
@ -63,8 +74,6 @@ local function load_modules()
|
||||||
ctx.load_system("spell_patches")
|
ctx.load_system("spell_patches")
|
||||||
ctx.load_system("enemy_scaling")
|
ctx.load_system("enemy_scaling")
|
||||||
|
|
||||||
ctx.load_system("kivi_patch")
|
|
||||||
ctx.load_system("patch_meat_biome")
|
|
||||||
ctx.load_system("patch_dragon_boss")
|
ctx.load_system("patch_dragon_boss")
|
||||||
|
|
||||||
ctx.load_system("player_arrows")
|
ctx.load_system("player_arrows")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue