Skip to content

Commit

Permalink
Fix some naming (source -> cause). Relates to #1509
Browse files Browse the repository at this point in the history
  • Loading branch information
Doloment authored and alek13 committed Sep 8, 2024
1 parent b1b3b00 commit 5379a1e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
48 changes: 24 additions & 24 deletions mods/lord/_experimental/lord_damage/src/damage/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ end

--- @class DamageReason:PlayerHPChangeReason
--- @field damage_type string
--- @field source string
--- @field cause string

--- @alias DamageBehavior fun(object:ObjectRef,amount:number,reason:DamageReason,chunks:number|nil,run:function|nil)

--- @type table<string,DamageBehavior>
local damage_behaviors = {}

--- @param object Player|Entity object to set the source onto
--- @param source string source name
--- @param value boolean whether source is active (true) or not (false)
local function set_source(object, source, value)
--- @param object Player|Entity object to set the cause onto
--- @param cause string cause name
--- @param value boolean whether cause is active (true) or not (false)
local function set_cause(object, cause, value)
local state = base_classes.ObjectState:new(object)
state:set_entry(source, value)
state:set_entry(cause, value)
state:save(object)
end

--- @param object Player|Entity object to get the source from
--- @param source string source name
--- @return boolean whether source is active (true) or not (false)
local function get_source_status(object, source)
--- @param object Player|Entity object to get the cause from
--- @param cause string cause name
--- @return boolean whether cause is active (true) or not (false)
local function get_cause(object, cause)
local state = base_classes.ObjectState:new(object)

return state:get_entry(source)
return state:get_entry(cause)
end

--- @param damage_type string damage type name
Expand Down Expand Up @@ -80,12 +80,12 @@ end
local function periodic_base_behavior(object, amount, reason, chunks, run)
dump(chunks)
local damage_type = reason.damage_type
local source = reason.source
local cause = reason.cause
amount = calculate_damage_absorption(object, amount, damage_type)
run = run or function() end
local caused_by_source = false
if source then
caused_by_source = true
local has_a_cause = false
if cause then
has_a_cause = true
end


Expand All @@ -94,7 +94,7 @@ local function periodic_base_behavior(object, amount, reason, chunks, run)
local player_has_died = false
local object_has_died = false
local player_has_left = false
local source_removed = false
local cause_removed = false



Expand Down Expand Up @@ -125,11 +125,11 @@ local function periodic_base_behavior(object, amount, reason, chunks, run)
end
end

if caused_by_source and not object_has_died then
source_removed = (source and not get_source_status(object, source))
if has_a_cause and not object_has_died then
cause_removed = (cause and not get_cause(object, cause))
end

local reset_damage = player_has_died or player_has_left or object_has_died or source_removed
local reset_damage = player_has_died or player_has_left or object_has_died or cause_removed
if reset_damage then
minetest.chat_send_all("Reset")
leftover_damage = 0
Expand Down Expand Up @@ -171,11 +171,11 @@ local function periodic_base_behavior(object, amount, reason, chunks, run)
end
end

if caused_by_source and not object_has_died then
source_removed = (source and not get_source_status(object, source))
if has_a_cause and not object_has_died then
cause_removed = (cause and not get_cause(object, cause))
end

local reset_damage = player_has_died or player_has_left or object_has_died or source_removed
local reset_damage = player_has_died or player_has_left or object_has_died or cause_removed
if reset_damage then
return
end
Expand All @@ -193,10 +193,10 @@ return {
-- calculate_damage_absorption = calculate_damage_absorption,
register_damage_type = register_damage_type,
get_registered_damage_types = get_registered_damage_types,
-- get_source_status = get_source_status,
-- get_cause = get_cause,
base_behavior = base_behavior,
periodic_base_behavior = periodic_base_behavior,
deal_damage = deal_damage,
-- THE FOLLOWING LINE IS FOR TESTING PURPOSES ONLY! REMOVE IT WHEN THE DAMAGE SYSTEM IS INTEGRATED INTO THE GAME.
set_source = set_source,
set_cause = set_cause,
}
20 changes: 10 additions & 10 deletions mods/lord/_experimental/lord_damage/src/for_testing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ for name, _ in pairs(damage_types) do
})
end

minetest.register_tool("lord_damage:target_source_burning_dealer",{
description = "Target source 'burning' damage dealer",
minetest.register_tool("lord_damage:target_cause_burning_dealer",{
description = "Target cause 'burning' damage dealer",
on_use = function(itemstack, user, pointed_thing)
local player_name = user:get_player_name()
if not minetest.check_player_privs(player_name, "server") then
Expand All @@ -103,23 +103,23 @@ minetest.register_tool("lord_damage:target_source_burning_dealer",{
return
end

local source = "burning"
local cause = "burning"

lord_damage.set_source(object, source, true)
lord_damage.set_cause(object, cause, true)
print(minetest.serialize(object:get_properties()))


lord_damage.deal_damage(object, 13, {
type = "set_hp",
dealer = user,
damage_type = "fiery_periodic", tool = "lord_damage:target_source_burning_dealer",
source = source,
damage_type = "fiery_periodic", tool = "lord_damage:target_cause_burning_dealer",
cause = cause,
}, 3, function() minetest.chat_send_all("In cycle") end)
end
})

minetest.register_tool("lord_damage:target_source_burning_remover",{
description = "Target source 'burning' state remover",
minetest.register_tool("lord_damage:target_cause_burning_remover",{
description = "Target cause 'burning' state remover",
on_use = function(itemstack, user, pointed_thing)
local player_name = user:get_player_name()
if not minetest.check_player_privs(player_name, "server") then
Expand All @@ -133,8 +133,8 @@ minetest.register_tool("lord_damage:target_source_burning_remover",{
return
end

local source = "burning"
local cause = "burning"

lord_damage.set_source(object, source, nil)
lord_damage.set_cause(object, cause, nil)
end
})

0 comments on commit 5379a1e

Please sign in to comment.