This commit is contained in:
ZXb125 2024-11-18 03:40:24 -03:00
commit b2447905c8
3 changed files with 100 additions and 8 deletions

View file

@ -0,0 +1,3 @@
function death( damage_type_bit_field, damage_message, entity_thats_responsible, drop_items )
CrossCall("ew_item_death_notify", GetUpdatedEntityID(), entity_thats_responsible)
end

View file

@ -164,13 +164,13 @@ function enemy_sync.host_upload_entities()
if ai_component ~= 0 and ai_component ~= nil then
ComponentSetValue2(ai_component, "max_distance_to_cam_to_start_hunting", math.pow(2, 29))
end
local hp, max_hp, has_hp = util.get_ent_health(enemy_id)
local phys_info = util.get_phys_info(enemy_id, true)
if phys_info == nil then
goto continue
end
local hp, max_hp, has_hp = util.get_ent_health(enemy_id)
if has_hp then
util.ensure_component_present(enemy_id, "LuaComponent", "ew_death_notify", {
script_death = "mods/quant.ew/files/resource/cbs/death_notify.lua"

View file

@ -12,6 +12,19 @@ local item_sync = {}
local pending_remove = {}
local pickup_handlers = {}
local dead_entities = {}
util.add_cross_call("ew_item_death_notify", function(enemy_id, responsible_id)
local player_data = player_fns.get_player_data_by_local_entity_id(responsible_id)
local responsible
if player_data ~= nil then
responsible = player_data.peer_id
else
responsible = responsible_id
end
table.insert(dead_entities, {item_sync.get_global_item_id(enemy_id), responsible})
end)
function item_sync.ensure_notify_component(ent)
local notify = EntityGetFirstComponentIncludingDisabled(ent, "LuaComponent", "ew_notify_component")
if notify == nil then
@ -166,6 +179,13 @@ function item_sync.make_item_global(item, instant, give_authority_to)
--end
local item_data = inventory_helper.serialize_single_item(item)
item_data.gid = gid
local hp, max_hp, has_hp = util.get_ent_health(item)
if has_hp then
util.ensure_component_present(item, "LuaComponent", "ew_item_death_notify", {
script_death = "mods/quant.ew/files/resource/cbs/item_death_notify.lua"
})
end
ctx.item_prevent_localize[gid] = false
rpc.item_globalize(item_data)
end)
@ -194,6 +214,61 @@ local function is_my_item(gid)
return string.sub(gid, 1, 16) == ctx.my_id
end
rpc.opts_reliable()
function rpc.handle_death_data(death_data)
for _, remote_data in ipairs(death_data) do
local remote_id = remote_data[1]
--[[if confirmed_kills[remote_id] then
GamePrint("Remote id has been killed already..?")
goto continue
end
confirmed_kills[remote_id] = true]]
local responsible_entity = 0
local peer_data = player_fns.peer_get_player_data(remote_data[2], true)
if peer_data ~= nil then
responsible_entity = peer_data.entity
elseif ctx.entity_by_remote_id[remote_data[2]] ~= nil then
responsible_entity = ctx.entity_by_remote_id[remote_data[2]]
end
--if unsynced_enemys[remote_id] ~= nil then
--sync_enemy(unsynced_enemys[remote_id], true)
--end
local enemy_id = item_sync.find_by_gid(remote_id)
if enemy_id ~= nil and EntityGetIsAlive(enemy_id) then
local immortal = EntityGetFirstComponentIncludingDisabled(enemy_id, "LuaComponent", "ew_immortal")
if immortal ~= 0 then
EntityRemoveComponent(enemy_id, immortal)
end
local protection_component_id = GameGetGameEffect(enemy_id, "PROTECTION_ALL")
if protection_component_id ~= 0 then
EntitySetComponentIsEnabled(enemy_id, protection_component_id, false)
end
local damage_component = EntityGetFirstComponentIncludingDisabled(enemy_id, "DamageModelComponent")
if damage_component and damage_component ~= 0 then
ComponentSetValue2(damage_component, "wait_for_kill_flag_on_death", false)
end
-- Enable explosion back
local expl_component = EntityGetFirstComponent(enemy_id, "ExplodeOnDamageComponent")
if expl_component ~= nil and expl_component ~= 0 then
ComponentSetValue2(expl_component, "explode_on_death_percent", 1)
end
local current_hp = util.get_ent_health(enemy_id)
local dmg = current_hp
if dmg > 0 then
EntityInflictDamage(enemy_id, dmg+0.1, "DAMAGE_CURSE", "", "NONE", 0, 0, responsible_entity)
end
EntityInflictDamage(enemy_id, 1000000000, "DAMAGE_CURSE", "", "NONE", 0, 0, responsible_entity) -- Just to be sure
EntityKill(enemy_id)
end
::continue::
end
end
local function send_item_positions()
local position_data = {}
for _, item in ipairs(EntityGetWithTag("ew_global_item")) do
@ -210,10 +285,17 @@ local function send_item_positions()
ComponentSetValue2(costcom, "stealable", true)
end
end
position_data[gid] = {x, y, cost}
local phys_info = util.get_phys_info(item, true)
if phys_info ~= nil then
position_data[gid] = {x, y, phys_info, cost}
end
end
end
rpc.update_positions(position_data)
if #dead_entities > 0 then
rpc.handle_death_data(dead_entities)
end
dead_entities = {}
end
function item_sync.on_world_update_host()
@ -265,9 +347,6 @@ function item_sync.on_world_update()
item_sync.remove_item_with_id_now(gid)
end
end
if GameGetFrameNum() % 60 == 31 then
send_item_positions()
end
if GameGetFrameNum() % 5 == 2 then
for _, ent in ipairs(EntityGetWithTag("mimic_potion")) do
if ctx.is_host and not EntityHasTag(ent, "polymorphed_player") then
@ -277,6 +356,9 @@ function item_sync.on_world_update()
end
end
end
if GameGetFrameNum() % 5 == 3 then
send_item_positions()
end
end
function item_sync.on_should_send_updates()
@ -358,6 +440,9 @@ function rpc.item_globalize(item_data)
if is_safe_to_remove() then
item_sync.remove_item_with_id_now(item_data.gid)
end
if item_sync.find_by_gid(item_data.gid) ~= nil then
return
end
local item = inventory_helper.deserialize_single_item(item_data)
add_stuff_to_globalized_item(item, item_data.gid)
local coms = EntityGetComponent(item, "VariableStorageComponent")
@ -366,6 +451,7 @@ function rpc.item_globalize(item_data)
ComponentSetValue2(com, "value_int", GameGetFrameNum())
end
end
EntityAddComponent2(item, "LuaComponent", {_tags="ew_immortal", script_damage_about_to_be_received = "mods/quant.ew/files/resource/cbs/immortal.lua"})
end
rpc.opts_reliable()
@ -394,11 +480,14 @@ function rpc.update_positions(position_data)
local cx, cy = GameGetCameraPos()
for gid, el in pairs(position_data) do
local x, y = el[1], el[2]
local price = el[3]
local phys_info = el[3]
local price = el[4]
if math.abs(x - cx) < LIMIT and math.abs(y - cy) < LIMIT then
local item = item_sync.find_by_gid(gid)
if item ~= nil then
if not util.set_phys_info(item, phys_info) then
EntitySetTransform(item, x, y)
end
local costcom = EntityGetFirstComponentIncludingDisabled(item, "ItemCostComponent")
if costcom ~= nil then
if price == 0 then