forked from minetest-mods/armor_monoid
Use player_monoids
This commit is contained in:
parent
e67d3b7a75
commit
92b243ad27
20
README.md
20
README.md
@ -1,23 +1,21 @@
|
|||||||
#The Armor Monoid
|
#The Armor Monoid
|
||||||
|
|
||||||
This mod provides a monoidal_effects monoid for handling armor groups. It
|
This mod provides a player_monoids monoid for handling armor groups. It
|
||||||
provides the ```"armor"``` monoid, and a way to register new damage types
|
provides a monoid for damage resistance, and a way to register new damage types
|
||||||
for players. It is also compatible with 3d_armor.
|
for players. It is also compatible with 3d_armor.
|
||||||
|
|
||||||
Using the monoid
|
Using the monoid
|
||||||
================
|
================
|
||||||
The values in the monoid are tables mapping armor group names to damage
|
The values in the monoid are tables mapping armor group names to damage
|
||||||
multipliers. For example, if I wanted to register an effect granting arcane
|
multipliers. For example, if I wanted to apply an effect granting arcane
|
||||||
damage resistance but fleshy damage vulnerability, I could do <br/>
|
damage resistance but fleshy damage vulnerability, I could do <br/>
|
||||||
```
|
```
|
||||||
monoidal_effects.register_effect_type("magic_barrier", {
|
local tab = {
|
||||||
disp_name = "Magic Barrier",
|
arcane = 50,
|
||||||
tags = { magical = 1 },
|
fleshy = 150,
|
||||||
monoids = { armor = true },
|
}
|
||||||
cancel_on_death = true,
|
|
||||||
values = { armor = { fleshy = 1.5, arcane = 0.3 } },
|
armor_monoid.monoid:add_change(player, tab, "mymod:arcane_boost")
|
||||||
icon = "magic_barrier.png",
|
|
||||||
})
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Registering damage types
|
Registering damage types
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
monoidal_effects
|
player_monoids
|
||||||
3d_armor?
|
3d_armor?
|
||||||
|
@ -1 +1 @@
|
|||||||
A monoidal_effects monoid for armor
|
A player_monoids monoid for armor
|
||||||
|
39
init.lua
39
init.lua
@ -22,7 +22,7 @@ end
|
|||||||
-- For example { fleshy = 0.5, fire = 1.2 } would mean that a player takes
|
-- For example { fleshy = 0.5, fire = 1.2 } would mean that a player takes
|
||||||
-- half fleshy damage and 120% fire damage. Nil values are the same as putting
|
-- half fleshy damage and 120% fire damage. Nil values are the same as putting
|
||||||
-- 1. The final multipliers are multiplied to the base damage for the group.
|
-- 1. The final multipliers are multiplied to the base damage for the group.
|
||||||
monoidal_effects.register_monoid("armor", {
|
armor_monoid.monoid = player_monoids.make_monoid({
|
||||||
combine = function(tab1, tab2)
|
combine = function(tab1, tab2)
|
||||||
local res = {}
|
local res = {}
|
||||||
|
|
||||||
@ -101,25 +101,6 @@ end
|
|||||||
if not minetest.global_exists("armor") then return end
|
if not minetest.global_exists("armor") then return end
|
||||||
|
|
||||||
|
|
||||||
monoidal_effects.register_type("armor_monoid:compat_armor", {
|
|
||||||
disp_name = "3D Armor Compatibility",
|
|
||||||
dynamic = true,
|
|
||||||
monoids = { armor = true },
|
|
||||||
hidden = true,
|
|
||||||
cancel_on_death = false,
|
|
||||||
values = { armor = {} },
|
|
||||||
})
|
|
||||||
|
|
||||||
monoidal_effects.register_type("armor_monoid:compat_phys", {
|
|
||||||
disp_name = "3D Armor Physics Compatibility",
|
|
||||||
dynamic = true,
|
|
||||||
monoids = { speed = true, jump = true, gravity = true },
|
|
||||||
hidden = true,
|
|
||||||
cancel_on_death = false,
|
|
||||||
values = { speed = 1, jump = 1, gravity = 1 },
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
-- Armor override
|
-- Armor override
|
||||||
armor.set_player_armor = function(self, player)
|
armor.set_player_armor = function(self, player)
|
||||||
local name, player_inv = armor:get_valid_player(player, "[set_player_armor]")
|
local name, player_inv = armor:get_valid_player(player, "[set_player_armor]")
|
||||||
@ -196,13 +177,19 @@ armor.set_player_armor = function(self, player)
|
|||||||
armor_groups.fleshy = 100 - armor_level
|
armor_groups.fleshy = 100 - armor_level
|
||||||
end
|
end
|
||||||
|
|
||||||
monoidal_effects.cancel_effect_type("armor_monoid:compat_armor", name)
|
armor_monoid.monoid:del_change(player, "armor_monoid:compat")
|
||||||
monoidal_effects.cancel_effect_type("armor_monoid:compat_phys", name)
|
player_monoids.speed:del_change(player, "armor_monoid:compat")
|
||||||
|
player_monoids.jump:del_change(player, "armor_monoid:compat")
|
||||||
|
player_monoids.gravity:del_change(player, "armor_monoid:compat")
|
||||||
|
|
||||||
monoidal_effects.apply_effect("armor_monoid:compat_armor", "perm", name, {
|
armor_monoid.add_change(player, { fleshy = armor_groups.fleshy / 100 },
|
||||||
armor = { fleshy = armor_groups.fleshy / 100 },
|
"armor_monoid:compat")
|
||||||
})
|
player_monoids.speed:add_change(player, physics_o.speed,
|
||||||
monoidal_effects.apply_effect("armor_monoid:compat_phys", "perm", name, physics_o)
|
"armor_monoid:compat")
|
||||||
|
player_monoids.jump:add_change(player, physics_o.jump,
|
||||||
|
"armor_monoid:compat")
|
||||||
|
player_monoids.gravity:add_change(player, physics_o.gravity,
|
||||||
|
"armor_monoid:compat")
|
||||||
|
|
||||||
self.textures[name].armor = armor_texture
|
self.textures[name].armor = armor_texture
|
||||||
self.textures[name].preview = preview
|
self.textures[name].preview = preview
|
||||||
|
Loading…
Reference in New Issue
Block a user