Clients can pick up hearts now. Full heal hearts now only heal a part of maximum health according to amount of players

This commit is contained in:
IQuant 2024-05-19 21:23:51 +03:00
parent 02f441d9cb
commit 2bca59260f
11 changed files with 206 additions and 1 deletions

View file

@ -0,0 +1,7 @@
local old_fn = item_pickup
function item_pickup(entity_item, entity_who_picked, name)
GlobalsSetValue("ew_heart_pickup", "normal")
old_fn(entity_item, entity_who_picked, name)
end

View file

@ -0,0 +1,7 @@
local old_fn = item_pickup
function item_pickup(entity_item, entity_who_picked, name)
GlobalsSetValue("ew_heart_pickup", "better")
old_fn(entity_item, entity_who_picked, name)
end

View file

@ -0,0 +1,7 @@
local old_fn = item_pickup
function item_pickup(entity_item, entity_who_picked, name)
GlobalsSetValue("ew_heart_pickup", "evil")
old_fn(entity_item, entity_who_picked, name)
end

View file

@ -0,0 +1,30 @@
dofile( "data/scripts/game_helpers.lua" )
function item_pickup( entity_item, entity_who_picked, name )
GlobalsSetValue("ew_heart_pickup", "fullhp")
local max_hp = 0
local healing = 0
local x, y = EntityGetTransform( entity_item )
local player_count = tonumber(GlobalsGetValue("ew_player_count", "1"))
local damagemodels = EntityGetComponent( entity_who_picked, "DamageModelComponent" )
if( damagemodels ~= nil ) then
for i,damagemodel in ipairs(damagemodels) do
max_hp = tonumber( ComponentGetValue( damagemodel, "max_hp" ) )
local hp = tonumber( ComponentGetValue( damagemodel, "hp" ) )
healing = math.min(max_hp - hp, max_hp / player_count)
ComponentSetValue( damagemodel, "hp", hp+healing)
end
end
EntityLoad("data/entities/particles/image_emitters/heart_fullhp_effect.xml", x, y-12)
EntityLoad("data/entities/particles/heart_out.xml", x, y-8)
GamePrintImportant( "$log_heart_fullhp", GameTextGet( "$logdesc_heart_fullhp", tostring(math.floor(max_hp*25)), tostring(math.floor(healing*25)) ) )
-- remove the item from the game
EntityKill( entity_item )
end

View file

@ -0,0 +1,42 @@
dofile( "data/scripts/game_helpers.lua" )
function item_pickup( entity_item, entity_who_picked, name )
GlobalsSetValue("ew_heart_pickup", "temple")
local max_hp = 0
local max_hp_addition = 0.4
local healing = 0
local x, y = EntityGetTransform( entity_item )
local player_count = tonumber(GlobalsGetValue("ew_player_count", "1"))
local damagemodels = EntityGetComponent( entity_who_picked, "DamageModelComponent" )
if( damagemodels ~= nil ) then
for i,damagemodel in ipairs(damagemodels) do
max_hp = tonumber( ComponentGetValue( damagemodel, "max_hp" ) )
local max_hp_cap = tonumber( ComponentGetValue( damagemodel, "max_hp_cap" ) )
local hp = tonumber( ComponentGetValue( damagemodel, "hp" ) )
max_hp = max_hp + max_hp_addition
if ( max_hp_cap > 0 ) then
max_hp_cap = math.max( max_hp, max_hp_cap )
end
healing = math.min(max_hp - hp, max_hp / player_count)
-- if( hp > max_hp ) then hp = max_hp end
ComponentSetValue( damagemodel, "max_hp_cap", max_hp_cap)
ComponentSetValue( damagemodel, "max_hp", max_hp)
ComponentSetValue( damagemodel, "hp", hp+healing)
end
end
EntityLoad("data/entities/particles/image_emitters/heart_fullhp_effect.xml", x, y-12)
EntityLoad("data/entities/particles/heart_out.xml", x, y-8)
GamePrintImportant( "$log_heart_fullhp_temple", GameTextGet( "$logdesc_heart_fullhp_temple", tostring(math.floor(max_hp_addition * 25)), tostring(math.floor(max_hp * 25)), tostring(math.floor(healing * 25)) ) )
--GameTriggerMusicEvent( "music/temple/enter", true, x, y )
-- remove the item from the game
EntityKill( entity_item )
end

View file

@ -96,6 +96,10 @@ function net.send(key, value, reliable)
net.send_internal(encoded_msg, DEST_BROADCAST, reliable) net.send_internal(encoded_msg, DEST_BROADCAST, reliable)
end end
function net.send_to_host(key, value, reliable)
net.send(key, value, reliable) -- TODO actually only send to host
end
function net.proxy_send(key, value) function net.proxy_send(key, value)
net.send_internal(key.." "..value, DEST_PROXY) net.send_internal(key.." "..value, DEST_PROXY)
end end
@ -157,7 +161,11 @@ function net.send_localize_request(item_id)
end end
function net.send_item_upload(item_data) function net.send_item_upload(item_data)
net.send("item_upload", item_data, true) net.send_to_host("item_upload", item_data, true)
end
function net.send_heart_pickup(heart_pickup)
net.send("heart_pickup", heart_pickup, true)
end end
return net return net

View file

@ -206,4 +206,52 @@ function net_handling.mod.welcome(peer_id, _)
ctx.events.new_player_just_connected = true ctx.events.new_player_just_connected = true
end end
function net_handling.mod.heart_pickup(peer_id, heart_pickup)
local multiplier = tonumber( GlobalsGetValue( "HEARTS_MORE_EXTRA_HP_MULTIPLIER", "1" ) )
local do_heal_table = {
fullhp = true,
temple = true,
}
local max_hp_increase_table = {
normal = {1, false},
better = {2, false},
evil = {2, false},
temple = {0.4, true},
}
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 cap = util.get_ent_health_cap(ctx.my_player.entity)
local player_count = tonumber(GlobalsGetValue("ew_player_count", "1"))
local max_hp_old = max_hp
if max_hp_increase ~= nil then
max_hp = max_hp + max_hp_increase[1] * multiplier
local adjust_cap = max_hp_increase[2]
if adjust_cap then
util.set_ent_health_cap(max_hp)
end
end
if do_heal then
local healing = math.min(max_hp - hp, max_hp / player_count)
hp = hp + healing
end
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
local entity_who_picked = peer_data.entity
local x_pos, y_pos = EntityGetTransform( entity_who_picked )
local child_id = EntityLoad("data/entities/misc/effect_poison_big.xml", x_pos, y_pos)
EntityAddChild(entity_who_picked, child_id)
end
GamePrint("Player "..peer_data.name.." picked up a heart")
GameTriggerMusicCue( "item" )
end
return net_handling return net_handling

View file

@ -420,6 +420,10 @@ function player_fns.spawn_player_for(peer_id, x, y)
local we = GameGetWorldStateEntity() local we = GameGetWorldStateEntity()
local seen = util.get_ent_variable(we, "player_seen") or {} local seen = util.get_ent_variable(we, "player_seen") or {}
ctx.events.new_player_seen = seen[peer_id] == nil ctx.events.new_player_seen = seen[peer_id] == nil
if ctx.events.new_player_seen then
local count = tonumber(GlobalsGetValue("ew_player_count", "1")) + 1
GlobalsSetValue("ew_player_count", tostring(count))
end
seen[peer_id] = true seen[peer_id] = true
util.set_ent_variable(we, "player_seen", seen) util.set_ent_variable(we, "player_seen", seen)
end end

View file

@ -88,6 +88,23 @@ function util.set_ent_air(entity, air_data)
end end
end end
function util.get_ent_health_cap(entity)
local damage_model = EntityGetFirstComponentIncludingDisabled(entity, "DamageModelComponent")
if damage_model == nil then
return 0
end
local cap = ComponentGetValue2(damage_model, "max_hp_cap")
return cap
end
function util.set_ent_health_cap(entity, cap)
local damage_model = EntityGetFirstComponentIncludingDisabled(entity, "DamageModelComponent")
if damage_model == nil then
return 0
end
ComponentSetValue2(damage_model, "max_hp_cap", cap)
end
function util.lerp(a, b, alpha) function util.lerp(a, b, alpha)
return a * alpha + b * (1 - alpha) return a * alpha + b * (1 - alpha)
end end

View file

@ -22,6 +22,12 @@ local inventory_helper = dofile_once("mods/quant.ew/files/src/inventory_helper.l
ModLuaFileAppend("data/scripts/gun/gun.lua", "mods/quant.ew/files/append/gun.lua") ModLuaFileAppend("data/scripts/gun/gun.lua", "mods/quant.ew/files/append/gun.lua")
ModLuaFileAppend("data/scripts/gun/gun_actions.lua", "mods/quant.ew/files/append/action_fix.lua") ModLuaFileAppend("data/scripts/gun/gun_actions.lua", "mods/quant.ew/files/append/action_fix.lua")
ModLuaFileAppend("data/scripts/items/heart.lua", "mods/quant.ew/files/append/heart.lua")
ModLuaFileAppend("data/scripts/items/heart_better.lua", "mods/quant.ew/files/append/heart_better.lua")
ModLuaFileAppend("data/scripts/items/heart_evil.lua", "mods/quant.ew/files/append/heart_evil.lua")
ModLuaFileAppend("data/scripts/items/heart_fullhp.lua", "mods/quant.ew/files/append/heart_fullhp.lua")
ModLuaFileAppend("data/scripts/items/heart_fullhp_temple.lua", "mods/quant.ew/files/append/heart_fullhp_temple.lua")
local my_player = nil local my_player = nil
function OnProjectileFired(shooter_id, projectile_id, initial_rng, position_x, position_y, target_x, target_y, send_message, function OnProjectileFired(shooter_id, projectile_id, initial_rng, position_x, position_y, target_x, target_y, send_message,
@ -113,6 +119,10 @@ end
function OnPlayerSpawned( player_entity ) -- This runs when player entity has been created function OnPlayerSpawned( player_entity ) -- This runs when player entity has been created
GamePrint( "OnPlayerSpawned() - Player entity id: " .. tostring(player_entity) ) GamePrint( "OnPlayerSpawned() - Player entity id: " .. tostring(player_entity) )
if GlobalsGetValue("ew_player_count", "") == "" then
GlobalsSetValue("ew_player_count", "1")
end
for _, client in pairs(EntityGetWithTag("ew_client")) do for _, client in pairs(EntityGetWithTag("ew_client")) do
GamePrint("Removing previous client: "..client) GamePrint("Removing previous client: "..client)
EntityKill(client) EntityKill(client)
@ -126,6 +136,7 @@ function OnPlayerSpawned( player_entity ) -- This runs when player entity has be
ctx.players[ctx.my_id] = my_player ctx.players[ctx.my_id] = my_player
ctx.player_data_by_local_entity[player_entity] = my_player ctx.player_data_by_local_entity[player_entity] = my_player
ctx.ready = true ctx.ready = true
ctx.my_player = my_player
np.SetPauseState(4) np.SetPauseState(4)
np.SetPauseState(0) np.SetPauseState(0)
@ -151,6 +162,7 @@ function OnPlayerSpawned( player_entity ) -- This runs when player entity has be
perk_spawn(x, y, "LASER_AIM", true) perk_spawn(x, y, "LASER_AIM", true)
perk_spawn(x-50, y, "GLASS_CANNON", true) perk_spawn(x-50, y, "GLASS_CANNON", true)
perk_spawn(x-25, y, "EDIT_WANDS_EVERYWHERE", true) perk_spawn(x-25, y, "EDIT_WANDS_EVERYWHERE", true)
EntityLoad("data/entities/items/pickup/heart.xml", x-75, y-20)
end end
end end
@ -255,6 +267,12 @@ local function on_world_pre_update_inner()
net.send_player_perks(perk_data) net.send_player_perks(perk_data)
end end
end end
local heart_pickup = GlobalsGetValue("ew_heart_pickup", "")
if heart_pickup ~= "" then
net.send_heart_pickup(heart_pickup)
GlobalsSetValue("ew_heart_pickup", "")
end
end end
function OnWorldPreUpdate() -- This is called every time the game is about to start updating the world function OnWorldPreUpdate() -- This is called every time the game is about to start updating the world

17
redist/release_text.md Normal file
View file

@ -0,0 +1,17 @@
# Installation
Download Noita Proxy (noita-proxy-win.zip) and unpack it somewhere.
Download the mod in quant.ew.zip
Go to Noita mod folder (can be done from in-game Mods menu item) and unpack the archive here. There should now be quant.ew folder inside the mods folder. Enable the mod in noita.
# Running
Note: order is important.
Start the game, start the proxy.
Now you'll probably want to use Steam for connection. Use "Create lobby" and "Connect to lobby in clipboard" buttons to do so.
Another option is to connect by ip. Proxy creates a socket on port 5123, UDP protocol.
Press new game button in Noita now.