mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Refactor shared health to have a separate counter.
This commit is contained in:
parent
8ecb96606f
commit
37851b18cf
7 changed files with 46 additions and 12 deletions
|
@ -3,6 +3,8 @@
|
|||
- `ctx.hook.on_world_update()`
|
||||
- `ctx.hook.on_world_update_client()`
|
||||
- `ctx.hook.on_world_update_host()`
|
||||
- `ctx.hook.on_new_player_seen(new_playerdata)` - called the first time player with this peer_id has entered the world
|
||||
- `ctx.hook.on_local_player_spawn(my_player)`
|
||||
- `ctx.hook.on_client_spawned(peer_id, new_playerdata)`
|
||||
- `ctx.hook.on_should_send_updates()` - called either when we connect, or somebody else connects (and sends "welcome" message)
|
||||
|
|
@ -425,13 +425,11 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata)
|
|||
local seen = GlobalsGetValue(global, "0")
|
||||
ctx.events.new_player_seen = seen ~= "1"
|
||||
if ctx.events.new_player_seen then
|
||||
ctx.hook.on_new_player_seen(new_playerdata)
|
||||
local count = tonumber(GlobalsGetValue("ew_player_count", "1")) + 1
|
||||
GlobalsSetValue("ew_player_count", tostring(count))
|
||||
GamePrint("Player count "..count)
|
||||
print("Player count "..count)
|
||||
|
||||
local hp, max_hp = util.get_ent_health(ctx.my_player.entity)
|
||||
util.set_ent_health(ctx.my_player.entity, {hp+4, max_hp+4})
|
||||
end
|
||||
GlobalsSetValue(global, "1")
|
||||
-- np.SetPlayerEntity(new, peer_id+1)
|
||||
|
|
|
@ -11,8 +11,8 @@ function damage_received(damage, message, entity_thats_responsible, is_fatal, pr
|
|||
if damageModelComponent ~= nil then
|
||||
local health = ComponentGetValue2( damageModelComponent, "hp" )
|
||||
if health then
|
||||
ComponentSetValue2( damageModelComponent, "hp", health + (damage - new_damage) )
|
||||
ComponentSetValue2( damageModelComponent, "hp", health + damage )
|
||||
end
|
||||
end
|
||||
|
||||
CrossCall("ew_ds_damaged", new_damage, message)
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ function damage_received(damage, message, entity_thats_responsible, is_fatal, pr
|
|||
if damageModelComponent ~= nil then
|
||||
local health = ComponentGetValue2( damageModelComponent, "hp" )
|
||||
if health then
|
||||
ComponentSetValue2( damageModelComponent, "hp", health + damage )
|
||||
ComponentSetValue2( damageModelComponent, "hp", math.max(health + damage, 0.01) )
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@ module.recent_message = "unknown"
|
|||
np.CrossCallAdd("ew_ds_damaged", function (damage, message)
|
||||
module.recent_damage = module.recent_damage + damage
|
||||
module.recent_message = message
|
||||
if ctx.is_host then
|
||||
module.inflict_damage(damage)
|
||||
end
|
||||
end)
|
||||
|
||||
function module.on_local_player_spawn(my_player)
|
||||
|
@ -40,12 +43,40 @@ end
|
|||
|
||||
function module.on_world_update_host()
|
||||
if GameGetFrameNum() % 4 == 3 then
|
||||
local player_info = {}
|
||||
local hp, max_hp = util.get_ent_health(ctx.my_player.entity)
|
||||
local hp, max_hp = module.health(), module.max_health()
|
||||
if not ctx.my_player.currently_polymorphed then
|
||||
util.set_ent_health(ctx.my_player.entity, {hp, max_hp})
|
||||
end
|
||||
rpc.update_shared_health(hp, max_hp)
|
||||
end
|
||||
end
|
||||
|
||||
function module.on_new_player_seen(new_playerdata)
|
||||
module.set_max_health(module.max_health()+4)
|
||||
module.set_health(module.health()+4)
|
||||
end
|
||||
|
||||
function module.health()
|
||||
return tonumber(GlobalsGetValue("ew_shared_hp", "4"))
|
||||
end
|
||||
|
||||
function module.max_health()
|
||||
return tonumber(GlobalsGetValue("ew_shared_max_hp", "4"))
|
||||
end
|
||||
|
||||
function module.set_health(hp)
|
||||
GlobalsSetValue("ew_shared_hp", tostring(hp))
|
||||
end
|
||||
|
||||
function module.set_max_health(hp)
|
||||
GlobalsSetValue("ew_shared_max_hp", tostring(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
|
||||
|
||||
rpc.opts_reliable()
|
||||
function rpc.deal_damage(damage, message)
|
||||
local message = GameTextGetTranslatedOrNot(message) .. " from "..ctx.rpc_player_data.name
|
||||
|
@ -56,7 +87,8 @@ function rpc.deal_damage(damage, message)
|
|||
if protection_component_id ~= 0 then
|
||||
EntitySetComponentIsEnabled(host_entity_id, protection_component_id, false)
|
||||
end
|
||||
EntityInflictDamage(host_entity_id, damage, "DAMAGE_CURSE", message, "NONE", 0, 0, nil)
|
||||
-- EntityInflictDamage(host_entity_id, damage, "DAMAGE_CURSE", message, "NONE", 0, 0, nil)
|
||||
module.inflict_damage(damage)
|
||||
if protection_component_id ~= 0 then
|
||||
EntitySetComponentIsEnabled(host_entity_id, protection_component_id, true)
|
||||
end
|
||||
|
@ -65,7 +97,9 @@ function rpc.deal_damage(damage, message)
|
|||
end
|
||||
|
||||
function rpc.update_shared_health(hp, max_hp)
|
||||
util.set_ent_health(ctx.my_player.entity, {hp, max_hp})
|
||||
if not ctx.my_player.currently_polymorphed then
|
||||
util.set_ent_health(ctx.my_player.entity, {hp, max_hp})
|
||||
end
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -29,7 +29,7 @@ function module.on_world_update_host()
|
|||
if ctx.debug then
|
||||
local hp, max_hp = util.get_ent_health(ctx.my_player.entity)
|
||||
if hp < max_hp / 2 then
|
||||
util.set_ent_health(ctx.my_player.entity, {max_hp, max_hp})
|
||||
-- util.set_ent_health(ctx.my_player.entity, {max_hp, max_hp})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -61,7 +61,7 @@ function world_sync.on_world_update_host()
|
|||
producer_coro = coroutine.wrap(chunk_producer)
|
||||
end
|
||||
|
||||
if GameGetFrameNum() % 2 == 0 then
|
||||
if GameGetFrameNum() % 1 == 0 then
|
||||
local crect = producer_coro()
|
||||
|
||||
if crect == nil then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue