Skip to content

Commit

Permalink
Effects System: lord_effect: add mod backbone & register our effect…
Browse files Browse the repository at this point in the history
…s for `speed`,`jump`,`health`. Relates to #1676
  • Loading branch information
alek13 committed Sep 17, 2024
1 parent f6fdf4c commit afb68a8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mods/lord/Core/effects/src/effects/Effect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Effect:new(name, type)
return setmetatable(self, { __index = class })
end

--- @param start fun(self:effects.Effect,player:Player,amount:number)
--- @param start fun(self:effects.Effect,player:Player,amount:number,duration:number)
--- @return effects.Effect
function Effect:on_start(start)
self.start = start
Expand Down
2 changes: 1 addition & 1 deletion mods/lord/Core/effects/src/effects/Processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
--- @param duration number
--- @param after_stop fun()
function Processor.run_effect_for(player, effect, amount, duration, after_stop)
effect:start(player, amount)
effect:start(player, amount, duration)
-- TODO: effect can be reapplied. #1650
minetest.after(duration, function()
-- TODO: the `player` could have already left. #1673
Expand Down
5 changes: 5 additions & 0 deletions mods/lord/Game/lord_effects/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


minetest.mod(function(mod)
require("lord_effects").init(mod)
end)
2 changes: 2 additions & 0 deletions mods/lord/Game/lord_effects/mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = lord_effects
depends = builtin, effects, physics, damage
47 changes: 47 additions & 0 deletions mods/lord/Game/lord_effects/src/lord_effects.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@


lord_effects = {
SPEED = 'speed',
JUMP = 'jump',
HEALTH = 'health',
-- BREATH = 'breath', TODO: #1678
}


local function register_effects()
effects.register(
effects.Effect:new(lord_effects.SPEED)
:on_start(function(self, player, amount)
physics.for_player(player):set({ speed = amount })
end)
:on_stop(function(self, player)
physics.for_player(player):set({ speed = 1 })
end)
)
effects.register(
effects.Effect:new(lord_effects.JUMP)
:on_start(function(self, player, amount)
physics.for_player(player):set({ jump = amount })
end)
:on_stop(function(self, player)
physics.for_player(player):set({ jump = 1 })
end)
)
effects.register(
effects.Effect:new(lord_effects.HEALTH)
:on_start(function(self, player, amount, duration)
damage.Periodical:for_player(player):start(damage.Type.FLESHY, amount, duration)
end)
:on_stop(function(self, player)
-- Periodical Damage stops itself.
end)
)
end


return {
--- @param mod minetest.Mod
init = function(mod)
register_effects()
end,
}

0 comments on commit afb68a8

Please sign in to comment.