mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Heart pickup and game over sync, again.
This commit is contained in:
parent
37851b18cf
commit
dc815e2faa
5 changed files with 62 additions and 15 deletions
22
docs/capabilities.md
Normal file
22
docs/capabilities.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Capabilities
|
||||
|
||||
Capabilities allow several systems provide same functionality in different ways. Exactly one capability implementation should be active.
|
||||
|
||||
Capabilities are registered by having an entry in `ctx.cap` table.
|
||||
|
||||
# List of capabilities
|
||||
|
||||
## `health` capability
|
||||
|
||||
Functions:
|
||||
- `health() -> num`
|
||||
- `max_health() -> num`
|
||||
- `set_health(hp: num)`
|
||||
- `set_max_health(hp: num)`
|
||||
- `inflict_damage(dmg: num)`
|
||||
|
||||
Provided by:
|
||||
- damage (shared health) system
|
||||
|
||||
Used by:
|
||||
- heart pickups (core)
|
|
@ -3,6 +3,7 @@ local ctx = {
|
|||
lib = {},
|
||||
hook = {},
|
||||
proxy_opt = {},
|
||||
cap = {}, -- Capabilities
|
||||
}
|
||||
|
||||
setmetatable(ctx.hook, {
|
||||
|
|
|
@ -201,7 +201,7 @@ function net_handling.mod.heart_pickup(peer_id, heart_pickup)
|
|||
local do_heal = do_heal_table[heart_pickup] or false
|
||||
local max_hp_increase = max_hp_increase_table[heart_pickup]
|
||||
|
||||
local hp, max_hp = util.get_ent_health(ctx.my_player.entity)
|
||||
local hp, max_hp = ctx.cap.health.health(), ctx.cap.health.max_health()
|
||||
local cap = util.get_ent_health_cap(ctx.my_player.entity)
|
||||
local player_count = tonumber(GlobalsGetValue("ew_player_count", "1"))
|
||||
|
||||
|
@ -220,7 +220,9 @@ function net_handling.mod.heart_pickup(peer_id, heart_pickup)
|
|||
hp = hp + healing
|
||||
end
|
||||
|
||||
util.set_ent_health(ctx.my_player.entity, {hp, max_hp})
|
||||
ctx.cap.health.set_max_health(max_hp)
|
||||
ctx.cap.health.set_health(hp)
|
||||
-- util.set_ent_health(ctx.my_player.entity, {hp, max_hp})
|
||||
|
||||
local peer_data = player_fns.peer_get_player_data(peer_id)
|
||||
if max_hp ~= max_hp_old and heart_pickup == "evil" then
|
||||
|
|
|
@ -28,9 +28,11 @@ function module.on_local_player_spawn(my_player)
|
|||
else
|
||||
EntityAddComponent2(my_player.entity, "LuaComponent", {script_damage_received = "mods/quant.ew/files/src/system/damage/cbs/send_damage_to_host.lua"})
|
||||
|
||||
local damage_model = EntityGetFirstComponentIncludingDisabled(my_player.entity, "DamageModelComponent")
|
||||
-- ComponentSetValue2(damage_model, "damage_multipliers", "melee", 0)
|
||||
end
|
||||
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()
|
||||
|
@ -48,6 +50,12 @@ function module.on_world_update_host()
|
|||
util.set_ent_health(ctx.my_player.entity, {hp, max_hp})
|
||||
end
|
||||
rpc.update_shared_health(hp, max_hp)
|
||||
if hp <= 0 then
|
||||
GameTriggerGameOver()
|
||||
ctx.run_ended = true
|
||||
net.proxy_notify_game_over()
|
||||
rpc.trigger_game_over()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,6 +85,14 @@ function module.inflict_damage(dmg)
|
|||
module.set_health(math.min(math.max(hp-dmg, 0), module.max_health()))
|
||||
end
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
rpc.opts_reliable()
|
||||
function rpc.deal_damage(damage, message)
|
||||
local message = GameTextGetTranslatedOrNot(message) .. " from "..ctx.rpc_player_data.name
|
||||
|
@ -102,4 +118,10 @@ function rpc.update_shared_health(hp, max_hp)
|
|||
end
|
||||
end
|
||||
|
||||
function rpc.trigger_game_over()
|
||||
GameTriggerGameOver()
|
||||
net.proxy_notify_game_over()
|
||||
ctx.run_ended = true
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -188,18 +188,18 @@ local function on_world_pre_update_inner()
|
|||
ctx.is_inventory_open = inventory_open
|
||||
end
|
||||
|
||||
if not ctx.is_host then
|
||||
local hp, _ = util.get_ent_health(ctx.my_player.entity)
|
||||
if hp == 0 then
|
||||
EntityInflictDamage(ctx.my_player.entity, 10000000, "DAMAGE_CURSE", "Out of shared health", "NONE", 0, 0, GameGetWorldStateEntity())
|
||||
GameTriggerGameOver()
|
||||
if not ctx.run_ended then
|
||||
GamePrint("Notifying of run end")
|
||||
net.proxy_notify_game_over()
|
||||
ctx.run_ended = true
|
||||
end
|
||||
end
|
||||
end
|
||||
-- if not ctx.is_host then
|
||||
-- local hp, _ = util.get_ent_health(ctx.my_player.entity)
|
||||
-- if hp == 0 then
|
||||
-- EntityInflictDamage(ctx.my_player.entity, 10000000, "DAMAGE_CURSE", "Out of shared health", "NONE", 0, 0, GameGetWorldStateEntity())
|
||||
-- GameTriggerGameOver()
|
||||
-- if not ctx.run_ended then
|
||||
-- GamePrint("Notifying of run end")
|
||||
-- net.proxy_notify_game_over()
|
||||
-- ctx.run_ended = true
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
if GameGetFrameNum() % 120 == 0 then
|
||||
player_fns.respawn_if_necessary()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue